GV\Widget
The \GV\Widget class.
An interface that most GravityView widgets would want to adhere to and inherit from.
Source: future/includes/class-gv-widget.php:14
Details
- Kind:
class - Namespace:
GV
Properties
| Property | Type | Description |
|---|---|---|
$widget_label | string | Widget admin label |
$widget_description | string | Widget description, shown on the "+ Add Widget" picker |
$widget_subtitle | string | Widget details, shown in the widget modal |
$widget_id | string | Widget admin ID |
$defaults | array | Default configuration for header and footer |
$settings | array | Widget admin advanced settings |
$shortcode_name | string | Allow class to automatically add widget_text filter for you in shortcode |
$position | string | The position of the widget. |
$UID | string | A unique ID for this widget. |
$configuration | \GV\Settings | The actual configuration for this widget instance. |
$icon | string | An icon that represents the widget type in the widget picker. Supports these icon formats: - Gravity Forms icon class: The string starts with "gform-icon". Note: the site must be running GF 2.5+. No need to also pass "gform-icon". - Dashicons: The string starts with "dashicons". No need to also pass "dashicons". - Inline SVG: Starts with "data:". Note: No single quotes are allowed! - If not matching those formats, the value will be used as a CSS class in a <i> element. |
Methods
| Method | Description |
|---|---|
__construct() | Constructor. |
get_widget_id() | Get the Widget ID. |
get_settings() | Get the widget settings |
get_setting() | Get a setting by the setting key. |
get_default_widget_areas() | Default widget areas. |
register_widget() | Register widget to become available in admin. And for lookup. |
assign_widget_options() | Assign template specific widget options |
maybe_do_shortcode() | Do shortcode if the Widget's shortcode exists. |
add_shortcode() | Add $this->shortcode_name shortcode to output self::render_frontend() |
render_frontend() | Frontend logic. |
get_view() | Gets View considering the current context. |
pre_render_frontend() | General validations when rendering the widget |
render_shortcode() | Shortcode. |
registered() | Return all registered widgets. |
is_registered() | Whether this Widget's been registered already or not. |
Method Reference
__construct()
public function __construct( $label, $id, $defaults=[], $settings=[] )
Constructor.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$label | string | The Widget label as shown in the admin. | |
$id | string | The Widget ID, make this something unique. | |
$defaults | array | [] | Default footer/header Widget configuration. |
$settings | array | [] | Advanced Widget settings. |
Returns
Source: future/includes/class-gv-widget.php:123
get_widget_id()
public function get_widget_id()
Get the Widget ID.
Returns
string— The Widget ID.
Source: future/includes/class-gv-widget.php:207
get_settings()
public function get_settings()
Get the widget settings
Returns
array|null— Settings array; NULL if not set for some reason.
Source: future/includes/class-gv-widget.php:216
get_setting()
public function get_setting( $key )
Get a setting by the setting key.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$key | string | Key for the setting |
Returns
mixed|null— Value of the setting; NULL if not set
Source: future/includes/class-gv-widget.php:229
get_default_widget_areas()
public static function get_default_widget_areas()
Default widget areas.
Usually overridden by the selected template.
Returns
array— The default areas where widgets can be rendered.
Source: future/includes/class-gv-widget.php:240
register_widget()
public function register_widget( $widgets )
Register widget to become available in admin. And for lookup.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$widgets | array | Usually just empty. Used to gather them all up. |
Returns
array— $widgets
Source: future/includes/class-gv-widget.php:271
assign_widget_options()
public function assign_widget_options( $options=[], $template='', $widget='' )
Assign template specific widget options
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$options | array | [] | (default: array()) |
$template | string | '' | (default: '') |
$widget | '' |
Returns
array
Source: future/includes/class-gv-widget.php:297
maybe_do_shortcode()
public function maybe_do_shortcode( $text, $widget=null )
Do shortcode if the Widget's shortcode exists.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$text | string | Widget text to check | |
$widget | null |
Returns
string— Widget text
Source: future/includes/class-gv-widget.php:314
add_shortcode()
public function add_shortcode()
Add $this->shortcode_name shortcode to output self::render_frontend()
Returns
void
Source: future/includes/class-gv-widget.php:326
render_frontend()
public function render_frontend( $widget_args, $content='', $context='' )
Frontend logic.
Override in child class.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$widget_args | array | The Widget shortcode args. | |
$content | string | '' | The content. |
$context | string | \GV\Template_Context | '' | The context, if available. |
Returns
void
Source: future/includes/class-gv-widget.php:367
get_view()
public function get_view( $context='' )
Gets View considering the current context.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$context | string | \GV\Template_Context | '' | Context. Default: empty string. |
Returns
- \GV\View |
null
Since: 2.17.3
Source: future/includes/class-gv-widget.php:379
pre_render_frontend()
public function pre_render_frontend( $context='' )
General validations when rendering the widget
Always call this from your render_frontend() override!
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$context | string | \GV\Template_Context | '' | Context. Default: empty string. |
Returns
boolean— True: render frontend; False: don't render frontend
Since: 2.17.3 (Added $context param.)
Source: future/includes/class-gv-widget.php:420
render_shortcode()
public function render_shortcode( $atts, $content='', $context='' )
Shortcode.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$atts | array | The Widget shortcode args. | |
$content | string | '' | The content. |
$context | string | \GV\Template_Context | '' | The context, if available. |
Returns
string— Whatever the widget echoed.
Source: future/includes/class-gv-widget.php:476
registered()
public static function registered()
Return all registered widgets.
Returns
array
Since: 2.0
Source: future/includes/class-gv-widget.php:541
is_registered()
public function is_registered()
Whether this Widget's been registered already or not.
Returns
bool
Since: 2.0
Source: future/includes/class-gv-widget.php:568