PHP Class WP_Customize_Control, wordpress

Show file Open project: johnpbloch/wordpress Class Usage Examples

Public Properties

Property Type Description
$active_callback Callback.
$allow_addition boolean Show UI for adding new content, currently only used for the dropdown-pages control.
$capability string Normally this is empty and the capability is derived from the capabilities of the associated $settings.
$choices array
$description string
$id string
$input_attrs array
$instance_number integer Order in which this instance was created in relation to other instances.
$json array
$label string
$manager WP_Customize_Manager
$priority integer
$section string
$setting string The primary setting for the control (if there is one).
$settings array All settings tied to the control.
$type string

Protected Properties

Property Type Description
$instance_count integer Used when sorting two instances whose priorities are equal.

Public Methods

Method Description
__construct ( WP_Customize_Manager $manager, string $id, array $args = [] ) Constructor.
active ( ) : boolean Check whether control is active to current Customizer preview.
active_callback ( ) : true Default callback used when invoking WP_Customize_Control::active().
check_capabilities ( ) : boolean Checks if the user can use this control.
enqueue ( ) Enqueue control related scripts/styles.
get_content ( ) : string Get the control's content for insertion into the Customizer pane.
get_link ( string $setting_key = 'default' ) : string Get the data link attribute for a setting.
input_attrs ( ) Render the custom attributes for the control's input element.
json ( ) : array Get the data to export to the client via JSON.
link ( string $setting_key = 'default' ) Render the data link attribute for the control's input element.
maybe_render ( ) Check capabilities and render the control.
print_template ( ) Render the control's JS template.
to_json ( ) Refresh the parameters passed to the JavaScript via JSON.
value ( string $setting_key = 'default' ) : mixed Fetch a setting's value.

Protected Methods

Method Description
content_template ( ) An Underscore (JS) template for this control's content (but not its container).
render ( ) Renders the control wrapper and calls $this->render_content() for the internals.
render_content ( ) Render the control's content.

Method Details

__construct() public method

Supplied $args override class property defaults. If $args['settings'] is not defined, use the $id as the setting ID.
Since: 3.4.0
public __construct ( WP_Customize_Manager $manager, string $id, array $args = [] )
$manager WP_Customize_Manager Customizer bootstrap instance.
$id string Control ID.
$args array { Optional. Arguments to override class property defaults. @type int $instance_number Order in which this instance was created in relation to other instances. @type WP_Customize_Manager $manager Customizer bootstrap instance. @type string $id Control ID. @type array $settings All settings tied to the control. If undefined, `$id` will be used. @type string $setting The primary setting for the control (if there is one). Default 'default'. @type int $priority Order priority to load the control. Default 10. @type string $section Section the control belongs to. Default empty. @type string $label Label for the control. Default empty. @type string $description Description for the control. Default empty. @type array $choices List of choices for 'radio' or 'select' type controls, where values are the keys, and labels are the values. Default empty array. @type array $input_attrs List of custom input attributes for control output, where attribute names are the keys and values are the values. Not used for 'checkbox', 'radio', 'select', 'textarea', or 'dropdown-pages' control types. Default empty array. @type array $json Deprecated. Use WP_Customize_Control::json() instead. @type string $type Control type. Core controls include 'text', 'checkbox', 'textarea', 'radio', 'select', and 'dropdown-pages'. Additional input types such as 'email', 'url', 'number', 'hidden', and 'date' are supported implicitly. Default 'text'. }

active() final public method

Check whether control is active to current Customizer preview.
Since: 4.0.0
final public active ( ) : boolean
return boolean Whether the control is active to the current preview.

active_callback() public method

Subclasses can override this with their specific logic, or they may provide an 'active_callback' argument to the constructor.
Since: 4.0.0
public active_callback ( ) : true
return true Always true.

check_capabilities() final public method

Returns false if the user cannot manipulate one of the associated settings, or if one of the associated settings does not exist. Also returns false if the associated section does not exist or if its capability check returns false.
Since: 3.4.0
final public check_capabilities ( ) : boolean
return boolean False if theme doesn't support the control or user doesn't have the required permissions, otherwise true.

content_template() protected method

Class variables for this control class are available in the data JS object; export custom variables by overriding WP_Customize_Control::to_json().
See also: WP_Customize_Control::print_template()
Since: 4.1.0
protected content_template ( )

enqueue() public method

Enqueue control related scripts/styles.
Since: 3.4.0
public enqueue ( )

get_content() final public method

Get the control's content for insertion into the Customizer pane.
Since: 4.1.0
final public get_content ( ) : string
return string Contents of the control.

input_attrs() public method

Render the custom attributes for the control's input element.
Since: 4.0.0
public input_attrs ( )

json() public method

Get the data to export to the client via JSON.
Since: 4.1.0
public json ( ) : array
return array Array of parameters passed to the JavaScript.

maybe_render() final public method

Check capabilities and render the control.
Since: 3.4.0
final public maybe_render ( )

print_template() final public method

This function is only run for control types that have been registered with WP_Customize_Manager::register_control_type(). In the future, this will also print the template for the control's container element and be override-able.
Since: 4.1.0
final public print_template ( )

render() protected method

Renders the control wrapper and calls $this->render_content() for the internals.
Since: 3.4.0
protected render ( )

render_content() protected method

Allows the content to be overridden without having to rewrite the wrapper in $this::render(). Supports basic input types text, checkbox, textarea, radio, select and dropdown-pages. Additional input types such as email, url, number, hidden and date are supported implicitly. Control content can alternately be rendered in JS. See WP_Customize_Control::print_template().
Since: 3.4.0
protected render_content ( )

to_json() public method

Refresh the parameters passed to the JavaScript via JSON.
Since: 3.4.0
public to_json ( )

value() final public method

Grabs the main setting by default.
Since: 3.4.0
final public value ( string $setting_key = 'default' ) : mixed
$setting_key string
return mixed The requested setting's value, if the setting exists.

Property Details

$active_callback public property

Callback.
See also: WP_Customize_Control::active()
Since: 4.0.0
public $active_callback

$allow_addition public property

Show UI for adding new content, currently only used for the dropdown-pages control.
Since: 4.7.0
public bool $allow_addition
return boolean

$capability public property

Normally this is empty and the capability is derived from the capabilities of the associated $settings.
Since: 4.5.0
public string $capability
return string

$choices public property

public array $choices
return array

$description public property

public string $description
return string

$id public property

public string $id
return string

$input_attrs public property

public array $input_attrs
return array

$instance_count protected static property

Used when sorting two instances whose priorities are equal.
Since: 4.1.0
protected static int $instance_count
return integer

$instance_number public property

Order in which this instance was created in relation to other instances.
Since: 4.1.0
public int $instance_number
return integer

$json public property

Deprecation: It is better to just call the json() method
public array $json
return array

$label public property

public string $label
return string

$manager public property

public WP_Customize_Manager $manager
return WP_Customize_Manager

$priority public property

public int $priority
return integer

$section public property

public string $section
return string

$setting public property

The primary setting for the control (if there is one).
public string $setting
return string

$settings public property

All settings tied to the control.
public array $settings
return array

$type public property

public string $type
return string