WP_View_Config_Data::apply_filters( string $kind, string $name ): array
- Since
- 7.1.0
- Source
wp-includes/class-wp-view-config-data.php:135
Description
Exposes the container through the dynamic get_entity_view_config_{$kind}_{$name} filter (with the dynamic portions lowercased), so that core and third parties can provide the configuration for a specific entity, then reconciles the filtered container back into a plain configuration array, limited to the documented configuration keys.
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
$kindstring- The entity kind (e.g.
postType). $namestring- The entity name (e.g.
page).
Return value
array- The filtered configuration, limited to the documented keys.
Performance profile
How much work a call to WP_View_Config_Data::apply_filters() 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
- Trivial
- Scaling
- Constant
- Instructions
- 25
- Plugin surface
- 1 hook
- Called by
- 0
Touches nothing outside its own arguments.
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5. The body compiles to 25.
Third-party callbacks on '{$kind,}' run inside this call, and their cost is not bounded by anything here.
Nothing in core calls this; the cost is only what you spend yourself.
What it touches
- hookthird-party callbacks
apply_filters()called directly
What one call costs · 1 distinct outcome
One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_View_Config_Data::apply_filters() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 25 | wp_get_entity_view_config_hook_name(), kind(), ->get_data(), array_flip(), array_intersect_key() |
Across PHP versions
Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 25 instructions, 25 executed per call, 0 branches. The work does not change between versions.
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.
Hooks and filters fired · 1
One hook fires while WP_View_Config_Data::apply_filters() runs, in this order:
- apply_filters( {$kind,} )filterline 187 (+52 into the body)
Filters the view configuration for a given entity.
Uses · 3
- apply_filters()Calls the callback functions that have been added to a filter hook.
- wp_get_entity_view_config_hook_name()Builds the name of the dynamic filter that provides the view configuration for an entity.
- WP_View_Config_Data::get_data()Returns the current configuration array.
Source code
public function apply_filters( $kind, $name ) { /** * Filters the view configuration for a given entity. * * The dynamic portions of the hook name, `$kind` and `$name`, refer to the * entity kind (e.g. `postType`) and the entity name (e.g. `page`), * lowercased — so the `postType`/`page` entity maps to the * `get_entity_view_config_posttype_page` hook. * * Callbacks receive a WP_View_Config_Data object and change the * configuration through its methods. Each write method takes the schema * version the change was authored against as its second argument, * and returns the object for chaining: * * - `merge( $patch, $version )` merges a partial change into the current * configuration. It touches only the top-level keys the patch names, and * merges each named value into the current one by shape: a scalar * replaces, an associative array merges key by key, and a list merges by * member identity (`id`, `slug`, or `field`). A `null` value drops the * key it names, resetting it to its default. * - `replace( $patch, $version )` applies a patch exactly like `merge()`, * but swaps any list it names wholesale instead of merging that list by * member identity. * - `set( $patch, $version )` also touches only the keys the patch names, * but swaps each named value in wholesale, dropping whatever the key held * before — for a callback that owns those keys outright. * - `remove( $spec, $version )` deletes named properties. The spec mirrors * the configuration shape: a list of names deletes entries at that level, * and a nested map recurses to prune from within a named value, down to * individual list members. * * A change that declares an unsupported schema version is rejected and does * not alter anything. As with any filter, each callback's return value is * passed to the next callback as `$data`, so callbacks must return the * container they received: a callback that returns nothing, or any other * value, hands that result to every callback hooked at a later priority * instead of the container. Since the write methods return the container, * a callback can end with `return $data->merge( $patch, $version );`. * * @since 7.1.0 * * @param WP_View_Config_Data $data The view configuration container * for the entity, exposing the * `default_view`, `default_layouts`, * `view_list`, and `form` keys. * @param array $entity { * The entity the configuration is built for. * * @type string $kind The entity kind. * @type string $name The entity name. * } */ apply_filters( wp_get_entity_view_config_hook_name( $kind, $name ), $this, array( 'kind' => $kind, 'name' => $name, ) ); // Discard any keys the filter introduced that are not part of the // documented configuration shape. return array_intersect_key( $this->get_data(), array_flip( self::CONFIG_KEYS ) ); }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.