WP_View_Config_Data::apply( array $patch, int $version, string $method, string $mode ): WP_View_Config_Data
- Since
- 7.1.0
- Source
wp-includes/class-wp-view-config-data.php:410
Description
Shared by merge(), replace(), and set(); the three differ only in how the value of a named key is applied, which is carried by $mode:
mergemerges the value into the current one, lists by member identity;replacemerges the value in the same way but swaps lists wholesale;setswaps the whole value in wholesale, without merging.
In every mode a top-level null resets the key it names to its default, a nested null drops the property it names, and an omitted key is left untouched, so all three treat nulls the same way at every depth.
Compatibility
- WordPress
- since 7.1.0
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in 1 of the 5 tracked releases, added in 7.1.0, and compiles on PHP 7.4 through 8.6-dev.
Parameters
$patcharray- The partial configuration to apply.
$versionint- The schema version the patch was authored against.
$methodstring- The public method the patch was passed to, for misuse reporting.
$modestring- How to apply each named key's value:
merge,replace, orset.
Return value
WP_View_Config_Data- The instance, for chaining.
Performance profile
How much work a call to WP_View_Config_Data::apply() 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
- 13–22
- 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 83.
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
- hookthird-party callbacks
do_action()one call below WP_View_Config_Data::apply()
Further down the call graph this can also reach option, cache, serialize, query and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.
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_View_Config_Data::apply() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
!$version | 13–14 | none |
$version | 19–22 | esc_html(), esc_html__(), _doing_it_wrong() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 81 | 13–22 | 9 | 2 fewer instructions than PHP 8.5 |
| 8.5 | 83 | 13–22 | 9 | |
| 8.4 | 83 | 13–22 | 9 | 3 fewer instructions than PHP 8.3 |
| 8.3 | 86 | 13–22 | 9 | |
| 8.2 | 86 | 13–22 | 9 | |
| 8.1 | 86 | 13–22 | 9 | |
| 7.4 | 86 | 13–22 | 9 |
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 · 5
- _doing_it_wrong()Marks something as being incorrectly called.
- esc_html()Escaping for HTML blocks.
- esc_html__()Retrieves the translation of $text and escapes it for safe use in HTML output.
- WP_View_Config_Data::strip_nulls()Recursively drops every property whose value is `null` from a value.
- WP_View_Config_Data::merge_properties()Merges an incoming value into the current one, recursing by value shape.
Used by · 3
- WP_View_Config_Data::merge()Merges a partial configuration into the existing one.
- WP_View_Config_Data::replace()Replaces list values while merging the rest of a partial configuration.
- WP_View_Config_Data::set()Replaces whole top-level keys, leaving the rest of the configuration alone.
Source code
private function apply( array $patch, int $version, $method, $mode ) { if ( $version <= 0 || $version > self::LATEST_VERSION ) { _doing_it_wrong( esc_html( $method ), esc_html__( 'A view configuration patch must declare a supported schema version.' ), '7.1.0' ); return $this; } foreach ( $patch as $key => $value ) { if ( ! in_array( $key, self::CONFIG_KEYS, true ) ) { _doing_it_wrong( esc_html( $method ), sprintf( /* translators: %s: the configuration key. */ esc_html__( '"%s" is not a documented view configuration key.' ), esc_html( $key ) ), '7.1.0' ); continue; } // A null patch value makes the top-level property reset to defaults. if ( null === $value ) { $this->config[ $key ] = $this->defaults[ $key ] ?? array(); continue; } // set() swaps the whole value in; merge()/replace() merge it into the // current one, differing only in how they treat lists. In every mode a // nested null still drops the property it names. $this->config[ $key ] = 'set' === $mode ? $this->strip_nulls( $value ) : $this->merge_properties( $this->config[ $key ] ?? array(), $value, 'replace' === $mode ); } return $this; }Changelog
Introduced in 7.1.0.
Signature, return type and hooks compared across 1 parsed release.
About this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 tag, from
src/wp-includes/class-wp-view-config-data.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.