Skip to main content

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

PropertyTypeDescription
$widget_labelstringWidget admin label
$widget_descriptionstringWidget description, shown on the "+ Add Widget" picker
$widget_subtitlestringWidget details, shown in the widget modal
$widget_idstringWidget admin ID
$defaultsarrayDefault configuration for header and footer
$settingsarrayWidget admin advanced settings
$shortcode_namestringAllow class to automatically add widget_text filter for you in shortcode
$positionstringThe position of the widget.
$UIDstringA unique ID for this widget.
$configuration\GV\SettingsThe actual configuration for this widget instance.
$iconstringAn 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

MethodDescription
__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

NameTypeDefaultDescription
$labelstringThe Widget label as shown in the admin.
$idstringThe Widget ID, make this something unique.
$defaultsarray[]Default footer/header Widget configuration.
$settingsarray[]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

NameTypeDefaultDescription
$keystringKey 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

NameTypeDefaultDescription
$widgetsarrayUsually 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

NameTypeDefaultDescription
$optionsarray[](default: array())
$templatestring''(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

NameTypeDefaultDescription
$textstringWidget text to check
$widgetnull

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

NameTypeDefaultDescription
$widget_argsarrayThe Widget shortcode args.
$contentstring''The content.
$contextstring | \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

NameTypeDefaultDescription
$contextstring | \GV\Template_Context''Context. Default: empty string.

Returns

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

NameTypeDefaultDescription
$contextstring | \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

NameTypeDefaultDescription
$attsarrayThe Widget shortcode args.
$contentstring''The content.
$contextstring | \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