On this page
WP_Customize_Setting::__construct( WP_Customize_Manager $manager, string $id, array $args = array() )
Constructor.
Description
Any supplied $args override class property defaults.
Parameters
$managerWP_Customize_Manager Required-
Customizer bootstrap instance.
$idstring Required-
A specific ID of the setting.
Can be a theme mod or option name. $argsarray Optional-
Array of properties for the new Setting object.
typestringType of the setting. Default'theme_mod'.capabilitystringCapability required for the setting. Default'edit_theme_options'theme_supportsstring|string[]Theme features required to support the panel. Default is none.defaultstringDefault value for the setting. Default is empty string.transportstringOptions for rendering the live preview of changes in Customizer.
Using'refresh'makes the change visible by reloading the whole preview.
Using'postMessage'allows a custom JavaScript to handle live changes.
Default is'refresh'.validate_callbackcallableServer-side validation callback for the setting's value.sanitize_callbackcallableCallback to filter a Customize setting value in un-slashed form.sanitize_js_callbackcallableCallback to convert a Customize PHP setting value to a value that is JSON serializable.dirtyboolWhether or not the setting is initially dirty when created.
Default:
array()
Source
File: wp-includes/class-wp-customize-setting.php. View all references
public function __construct( $manager, $id, $args = array() ) {
$keys = array_keys( get_object_vars( $this ) );
foreach ( $keys as $key ) {
if ( isset( $args[ $key ] ) ) {
$this->$key = $args[ $key ];
}
}
$this->manager = $manager;
$this->id = $id;
// Parse the ID for array keys.
$this->id_data['keys'] = preg_split( '/\[/', str_replace( ']', '', $this->id ) );
$this->id_data['base'] = array_shift( $this->id_data['keys'] );
// Rebuild the ID.
$this->id = $this->id_data['base'];
if ( ! empty( $this->id_data['keys'] ) ) {
$this->id .= '[' . implode( '][', $this->id_data['keys'] ) . ']';
}
if ( $this->validate_callback ) {
add_filter( "customize_validate_{$this->id}", $this->validate_callback, 10, 3 );
}
if ( $this->sanitize_callback ) {
add_filter( "customize_sanitize_{$this->id}", $this->sanitize_callback, 10, 2 );
}
if ( $this->sanitize_js_callback ) {
add_filter( "customize_sanitize_js_{$this->id}", $this->sanitize_js_callback, 10, 2 );
}
if ( 'option' === $this->type || 'theme_mod' === $this->type ) {
// Other setting types can opt-in to aggregate multidimensional explicitly.
$this->aggregate_multidimensional();
// Allow option settings to indicate whether they should be autoloaded.
if ( 'option' === $this->type && isset( $args['autoload'] ) ) {
self::$aggregated_multidimensionals[ $this->type ][ $this->id_data['base'] ]['autoload'] = $args['autoload'];
}
}
}
Related
Uses
| Uses | Description |
|---|---|
| WP_Customize_Setting::aggregate_multidimensional() wp-includes/class-wp-customize-setting.php | Set up the setting for aggregated multidimensional values. |
| add_filter() wp-includes/plugin.php | Adds a callback function to a filter hook. |
Used By
| Used By | Description |
|---|---|
| WP_Customize_Custom_CSS_Setting::__construct() wp-includes/customize/class-wp-customize-custom-css-setting.php | WP_Customize_Custom_CSS_Setting constructor. |
| WP_Customize_Nav_Menu_Setting::__construct() wp-includes/customize/class-wp-customize-nav-menu-setting.php | Constructor. |
| WP_Customize_Nav_Menu_Item_Setting::__construct() wp-includes/customize/class-wp-customize-nav-menu-item-setting.php | Constructor. |
Changelog
| Version | Description |
|---|---|
| 3.4.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wp_customize_setting/__construct