On this page
WP_Customize_Manager::add_setting( WP_Customize_Setting|string $id, array $args = array() ): WP_Customize_Setting
Adds a customize setting.
Description
See also
Parameters
$idWP_Customize_Setting|string Required-
Customize Setting object, or ID.
$argsarray Optional-
Array of properties for the new Setting object.
See WP_Customize_Setting::__construct() for information on accepted arguments.More Arguments from WP_Customize_Setting::__construct( ... $args )
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()
Return
WP_Customize_Setting The instance of the setting that was added.
Source
File: wp-includes/class-wp-customize-manager.php. View all references
public function add_setting( $id, $args = array() ) {
if ( $id instanceof WP_Customize_Setting ) {
$setting = $id;
} else {
$class = 'WP_Customize_Setting';
/** This filter is documented in wp-includes/class-wp-customize-manager.php */
$args = apply_filters( 'customize_dynamic_setting_args', $args, $id );
/** This filter is documented in wp-includes/class-wp-customize-manager.php */
$class = apply_filters( 'customize_dynamic_setting_class', $class, $id, $args );
$setting = new $class( $this, $id, $args );
}
$this->settings[ $setting->id ] = $setting;
return $setting;
}
Hooks
- apply_filters( 'customize_dynamic_setting_args',
false|array $setting_args ,string $setting_id ) -
Filters a dynamic setting’s constructor args.
- apply_filters( 'customize_dynamic_setting_class',
string $setting_class ,string $setting_id ,array $setting_args ) -
Allow non-statically created settings to be constructed with custom WP_Customize_Setting subclass.
Related
Uses
| Uses | Description |
|---|---|
| apply_filters() wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. |
Used By
| Used By | Description |
|---|---|
| WP_Customize_Manager::add_dynamic_settings() wp-includes/class-wp-customize-manager.php | Registers any dynamically-created settings, such as those from $_POST[‘customized’] that have no corresponding setting created. |
| WP_Customize_Manager::register_controls() wp-includes/class-wp-customize-manager.php | Registers some default controls. |
Changelog
| Version | Description |
|---|---|
| 4.5.0 | Return added WP_Customize_Setting instance. |
| 3.4.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wp_customize_manager/add_setting