wppaste
WordPress

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
Constructor.

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 none

    Capability 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_callbackcallable

    Server-side validation callback for the setting's value.
  • $sanitize_callbackcallable

    Callback to filter a Customize setting value in un-slashed form.
  • $sanitize_js_callbackcallable

    Callback to convert a Customize PHP setting value to a value that is JSON serializable.
  • $dirtybool

    Whether 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

Touches nothing outside its own arguments.

Scaling
Scales with input

The body loops, so the work grows with what you pass in.

Instructions
55–109

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 115.

Plugin surface
None

Nothing here hands control to plugin code.

Called by
3

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 inputpreg_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.

WhenInstructionsCalls it makes
always55–63get_object_vars(), array_keys(), preg_split(), array_shift()
always57–79get_object_vars(), array_keys(), preg_split(), array_shift(), ->aggregate_multidimensional()
always65–73get_object_vars(), array_keys(), preg_split(), array_shift(), add_filter()
always67–89get_object_vars(), array_keys(), preg_split(), array_shift(), add_filter(), ->aggregate_multidimensional()
always75–83get_object_vars(), array_keys(), preg_split(), array_shift(), add_filter(), add_filter()
always77–99get_object_vars(), array_keys(), preg_split(), array_shift(), add_filter(), add_filter(), ->aggregate_multidimensional()
always85–93get_object_vars(), array_keys(), preg_split(), array_shift(), add_filter(), add_filter(), add_filter()
always87–109get_object_vars(), array_keys(), preg_split(), array_shift(), add_filter(), add_filter(), add_filter(), ->aggregate_multidimensional()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev11555–10911
8.511555–10911
8.411555–109116 fewer instructions than PHP 8.3
8.312158–11511
8.212158–11511
8.112158–11511
7.412158–11511

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

Used by · 3

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.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 7.0.4 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.