wppaste
WordPress

WP_View_Config_Data::remove( array $spec, int $version ): WP_View_Config_Data

Since
7.1.0
Source
wp-includes/class-wp-view-config-data.php:261
Removes named properties from the configuration, leaving the rest alone.

Description

Where merge(), replace(), and set() take a patch of values to write, remove() takes a spec of names to delete, and its shape mirrors the configuration it prunes:

  • A list of names deletes each named entry from the value at that level: a key from an associative array, or the member with a matching identity (id, slug, field, or a bare scalar) from a list.
  • An associative array maps a name to a nested spec, recursing into that entry's value to delete from within it.

Naming a top-level configuration key is the one exception: like a null value in a patch, it resets that key to its default rather than dropping it outright, so top-level removal and top-level null compose the same way.

So array( 'default_view' ) resets the whole default_view key to its default, array( 'default_view' => array( 'sort' ) ) drops just its sort property, and array( 'default_view' => array( 'fields' => array( 'f2' ) ) ) drops the f2 member from its fields list. A name that is not present is ignored, and a list is renumbered after a member is removed.

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

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

$specarray
The names to remove, keyed to match the configuration shape.
$versionint
The schema version the spec was authored against.

Return value

WP_View_Config_Data
The instance, for chaining.

Performance profile

How much work a call to WP_View_Config_Data::remove() 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
14–17

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

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

  • hookthird-party callbacksdo_action()one call below WP_View_Config_Data::remove()

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::remove() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
!$version14–15array_is_list()
$version14–17esc_html__(), _doing_it_wrong()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev7414–179
8.57414–179
8.47414–1793 fewer instructions than PHP 8.3
8.37714–179
8.27714–179
8.17714–1791 fewer instruction than PHP 7.4
7.47814–179

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

Source code

	public function remove( array $spec, int $version ) {		if ( $version <= 0 || $version > self::LATEST_VERSION ) {			_doing_it_wrong(				__METHOD__,				esc_html__( 'A view configuration patch must declare a supported schema version.' ),				'7.1.0'			); 			return $this;		} 		// A flat list names top-level keys to reset; a map recurses into each		// named key to prune from within its value.		$spec_is_list = array_is_list( $spec );		foreach ( $spec as $spec_key => $spec_value ) {			$key = $spec_is_list ? $spec_value : $spec_key; 			if ( ! in_array( $key, self::CONFIG_KEYS, true ) ) {				_doing_it_wrong(					__METHOD__,					sprintf(						/* translators: %s: the configuration key. */						esc_html__( '"%s" is not a documented view configuration key.' ),						esc_html( $key )					),					'7.1.0'				);				continue;			} 			if ( $spec_is_list ) {				// Removing a top-level key resets it to its default, just as a				// null patch value does.				$this->config[ $key ] = $this->defaults[ $key ] ?? array();			} elseif ( array_key_exists( $key, $this->config ) ) {				$this->config[ $key ] = $this->remove_properties( $this->config[ $key ], $spec_value );			}		} 		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.