WP_View_Config_Data::replace( array $patch, int $version ): WP_View_Config_Data

Replaces list values while merging the rest of a partial configuration.

Description

Takes the same arguments as merge() and applies the patch the same way, with one difference: a list in the patch replaces the current list wholesale instead of merging into it by member identity. Associative arrays still merge key by key, null still drops what it names, and a scalar still replaces the current value.

It shouldn’t be the default choice — a callback that replaces a list stops inheriting core’s future additions to it — but it’s useful when a contributor needs to pin a list to an exact set of members.

The shape rule applies here too: a patch value whose shape does not match the current value — an associative array where a list lives, or a non-empty list where an associative value lives — is rejected with a notice and leaves the current value unchanged. An empty array is exempt, so replacing a list with an empty list still clears it.

A patch that declares an unsupported schema version is rejected and does not change anything.

Parameters

$patcharrayrequired
The partial configuration to apply.
$versionintrequired
The schema version the patch was authored against.

Return

WP_View_Config_Data The instance, for chaining.

Source

public function replace( array $patch, int $version ) {
	return $this->apply( $patch, $version, __METHOD__, 'replace' );
}

Changelog

VersionDescription
7.1.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.