wppaste
WordPress

WP_Customize_Partial::__construct( WP_Customize_Selective_Refresh $component, string $id, array $args = array() )

Since
4.5.0
Source
wp-includes/customize/class-wp-customize-partial.php:161
Constructor.

Description

Supplied $args override class property defaults.

If $args['settings'] is not defined, use the $id as the setting ID.

Compatibility

WordPress
since 4.5.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

$componentWP_Customize_Selective_Refresh
Customize Partial Refresh plugin instance.
$idstring
Control ID.
$argsarrayoptional
Array of properties for the new Partials object. Default empty array.Default: array()
  • $typestring

    Type of the partial to be created.
  • $selectorstring

    The jQuery selector to find the container element for the partial, that is, a partial's placement.
  • $settingsstring[]

    IDs for settings tied to the partial. If undefined, $id will be used.
  • $primary_settingstring

    The ID for the setting that this partial is primarily responsible for rendering. If not supplied, it will default to the ID of the first setting.
  • $capabilitystring

    Capability required to edit this partial. Normally this is empty and the capability is derived from the capabilities of the associated $settings.
  • $render_callbackcallable

    Render callback. Callback is called with one argument, the instance of WP_Customize_Partial. The callback can either echo the partial or return the partial as a string, or return false if error.
  • $container_inclusivebool

    Whether the container element is included in the partial, or if only the contents are rendered.
  • $fallback_refreshbool

    Whether to refresh the entire preview in case a partial cannot be refreshed. A partial render is considered a failure if the render_callback returns false.

Performance profile

How much work a call to WP_Customize_Partial::__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
45–61

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

Plugin surface
None

Nothing here hands control to plugin code.

Called by
0

Nothing in core calls this; the cost is only what you spend yourself.

What it touches

  • regexregular expression over the whole inputpreg_split()called directly

What one call costs · 2 distinct outcomes

One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_Customize_Partial::__construct() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
!empty($value)45–55get_object_vars(), array_keys(), preg_split(), array_shift()
empty($value)51–61get_object_vars(), array_keys(), preg_split(), array_shift(), current()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev7145–617
8.57145–617
8.47145–6173 fewer instructions than PHP 8.3
8.37448–647
8.27448–647
8.17448–647
7.47448–647

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.

Source code

	public function __construct( WP_Customize_Selective_Refresh $component, $id, $args = array() ) {		$keys = array_keys( get_object_vars( $this ) );		foreach ( $keys as $key ) {			if ( isset( $args[ $key ] ) ) {				$this->$key = $args[ $key ];			}		} 		$this->component       = $component;		$this->id              = $id;		$this->id_data['keys'] = preg_split( '/\[/', str_replace( ']', '', $this->id ) );		$this->id_data['base'] = array_shift( $this->id_data['keys'] ); 		if ( empty( $this->render_callback ) ) {			$this->render_callback = array( $this, 'render_callback' );		} 		// Process settings.		if ( ! isset( $this->settings ) ) {			$this->settings = array( $id );		} elseif ( is_string( $this->settings ) ) {			$this->settings = array( $this->settings );		} 		if ( empty( $this->primary_setting ) ) {			$this->primary_setting = current( $this->settings );		}	}

Changelog

Introduced in 4.5.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 6.8.8 tag, from src/wp-includes/customize/class-wp-customize-partial.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.