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
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
- Scaling
- Scales with input
- Instructions
- 14–17
- 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 74.
Nothing here hands control to plugin code.
Nothing in core calls this; the cost is only what you spend yourself.
What it touches
- hookthird-party callbacks
do_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.
| When | Instructions | Calls it makes |
|---|---|---|
!$version | 14–15 | array_is_list() |
$version | 14–17 | esc_html__(), _doing_it_wrong() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 74 | 14–17 | 9 | |
| 8.5 | 74 | 14–17 | 9 | |
| 8.4 | 74 | 14–17 | 9 | 3 fewer instructions than PHP 8.3 |
| 8.3 | 77 | 14–17 | 9 | |
| 8.2 | 77 | 14–17 | 9 | |
| 8.1 | 77 | 14–17 | 9 | 1 fewer instruction than PHP 7.4 |
| 7.4 | 78 | 14–17 | 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__()Retrieves the translation of $text and escapes it for safe use in HTML output.
- array_is_list()Polyfill for `array_is_list()` function added in PHP 8.1.
- esc_html()Escaping for HTML blocks.
- WP_View_Config_Data::remove_properties()Removes the properties a spec names from the current value.
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.