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
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()$typestringType of the partial to be created.$selectorstringThe 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,$idwill be used.$primary_settingstringThe 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.$capabilitystringCapability required to edit this partial. Normally this is empty and the capability is derived from the capabilities of the associated$settings.$render_callbackcallableRender 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_inclusiveboolWhether the container element is included in the partial, or if only the contents are rendered.$fallback_refreshboolWhether 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
- Scaling
- Scales with input
- Instructions
- 45–61
- Plugin surface
- None
- Called by
- 0
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 71.
Nothing here hands control to plugin code.
Nothing in core calls this; the cost is only what you spend yourself.
What it touches
- regexregular expression over the whole input
preg_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.
| When | Instructions | Calls it makes |
|---|---|---|
!empty($value) | 45–55 | get_object_vars(), array_keys(), preg_split(), array_shift() |
empty($value) | 51–61 | get_object_vars(), array_keys(), preg_split(), array_shift(), current() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 71 | 45–61 | 7 | |
| 8.5 | 71 | 45–61 | 7 | |
| 8.4 | 71 | 45–61 | 7 | 3 fewer instructions than PHP 8.3 |
| 8.3 | 74 | 48–64 | 7 | |
| 8.2 | 74 | 48–64 | 7 | |
| 8.1 | 74 | 48–64 | 7 | |
| 7.4 | 74 | 48–64 | 7 |
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.
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.