WP_Customize_Setting::__construct( WP_Customize_Manager $manager, string $id, array $args = array() )
- Since
- 3.4.0
- Source
wp-includes/class-wp-customize-setting.php:183
Description
Any supplied $args override class property defaults.
Compatibility
- WordPress
- since 3.4.0
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.
Parameters
$managerWP_Customize_Manager- Customizer bootstrap instance.
$idstring- A specific ID of the setting.
Can be a theme mod or option name. $argsarrayoptional- Array of properties for the new Setting object. Default empty array.Default:
array()$typestringdefault: 'theme_mod'Type of the setting.$capabilitystringdefault: is noneCapability required for the setting. Default 'edit_theme_options' @type string|string[] $theme_supports Theme features required to support the panel.$defaultstringdefault: value for the setting. Default is empty string$transportstringdefault: is 'refresh'Options 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.$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.
Performance profile
How much work a call to WP_Customize_Setting::__construct() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.
- Cost class
- Light
- Scaling
- Scales with input
- Instructions
- 55–109
- Plugin surface
- None
- Called by
- 3
Touches nothing outside its own arguments.
The body loops, so the work grows with what you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 115.
Nothing here hands control to plugin code.
3 places in core call this, so the cost is paid more often than your own code shows.
What it touches
- regexregular expression over the whole input
preg_split()called directly
What one call costs · 8 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_Customize_Setting::__construct() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 55–63 | get_object_vars(), array_keys(), preg_split(), array_shift() |
| always | 57–79 | get_object_vars(), array_keys(), preg_split(), array_shift(), ->aggregate_multidimensional() |
| always | 65–73 | get_object_vars(), array_keys(), preg_split(), array_shift(), add_filter() |
| always | 67–89 | get_object_vars(), array_keys(), preg_split(), array_shift(), add_filter(), ->aggregate_multidimensional() |
| always | 75–83 | get_object_vars(), array_keys(), preg_split(), array_shift(), add_filter(), add_filter() |
| always | 77–99 | get_object_vars(), array_keys(), preg_split(), array_shift(), add_filter(), add_filter(), ->aggregate_multidimensional() |
| always | 85–93 | get_object_vars(), array_keys(), preg_split(), array_shift(), add_filter(), add_filter(), add_filter() |
| always | 87–109 | get_object_vars(), array_keys(), preg_split(), array_shift(), add_filter(), add_filter(), add_filter(), ->aggregate_multidimensional() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 115 | 55–109 | 11 | |
| 8.5 | 115 | 55–109 | 11 | |
| 8.4 | 115 | 55–109 | 11 | 6 fewer instructions than PHP 8.3 |
| 8.3 | 121 | 58–115 | 11 | |
| 8.2 | 121 | 58–115 | 11 | |
| 8.1 | 121 | 58–115 | 11 | |
| 7.4 | 121 | 58–115 | 11 |
An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.
Uses · 2
- add_filter()Adds a callback function to a filter hook.
- WP_Customize_Setting::aggregate_multidimensional()Set up the setting for aggregated multidimensional values.
Used by · 3
- WP_Customize_Custom_CSS_Setting::__construct()WP_Customize_Custom_CSS_Setting constructor.
- WP_Customize_Nav_Menu_Item_Setting::__construct()Constructor.
- WP_Customize_Nav_Menu_Setting::__construct()Constructor.
Source code
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']; } } }Changelog
Introduced in 3.4.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 tag, from
src/wp-includes/class-wp-customize-setting.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.