wppaste
WordPress

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
Applies a patch to the configuration, top-level key by top-level key.

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:

  • merge merges the value into the current one, lists by member identity;
  • replace merges the value in the same way but swaps lists wholesale;
  • set swaps 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, or set.

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

Touches nothing outside its own arguments.

Scaling
Scales with input

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

Instructions
13–22

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

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

  • hookthird-party callbacksdo_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.

WhenInstructionsCalls it makes
!$version13–14none
$version19–22esc_html(), esc_html__(), _doing_it_wrong()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev8113–2292 fewer instructions than PHP 8.5
8.58313–229
8.48313–2293 fewer instructions than PHP 8.3
8.38613–229
8.28613–229
8.18613–229
7.48613–229

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

Used by · 3

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.