WP_REST_Meta_Fields::get_registered_fields(): array
- Since
- 4.7.0
- Source
wp-includes/rest-api/fields/class-wp-rest-meta-fields.php:449
Compatibility
- WordPress
- since 4.7.0
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.
Return value
array- Registered fields.
Performance profile
How much work a call to WP_REST_Meta_Fields::get_registered_fields() 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
- 16–26
- Plugin surface
- None
- Called by
- 4
Touches nothing outside its own arguments.
The body loops, so the work grows with how much data it finds.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 124.
Nothing here hands control to plugin code.
4 places in core call this, so the cost is paid more often than your own code shows.
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_REST_Meta_Fields::get_registered_fields() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
empty($meta_subtype) | 16–17 | ->get_meta_type(), ->get_meta_subtype(), get_registered_meta_keys() |
!empty($meta_subtype) | 25–26 | ->get_meta_type(), ->get_meta_subtype(), get_registered_meta_keys(), get_registered_meta_keys(), array_merge() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 124 | 16–26 | 14 | |
| 8.5 | 124 | 16–26 | 14 | |
| 8.4 | 124 | 16–26 | 14 | |
| 8.3 | 124 | 16–26 | 14 | |
| 8.2 | 124 | 16–26 | 14 | |
| 8.1 | 124 | 16–26 | 14 | 5 fewer instructions than PHP 7.4 |
| 7.4 | 129 | 16–26 | 14 |
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
- get_registered_meta_keys()Retrieves a list of registered metadata args for an object type, keyed by their meta keys.
- rest_default_additional_properties_to_false()Sets the "additionalProperties" to false by default for all object definitions in the schema.
- WP_REST_Meta_Fields::get_meta_type()Retrieves the object meta type.
- WP_REST_Meta_Fields::get_meta_subtype()Retrieves the object meta subtype.
- static::get_empty_value_for_type()
Used by · 4
- WP_REST_Meta_Fields::get_field_schema()Retrieves the object's meta schema, conforming to JSON Schema.
- WP_REST_Meta_Fields::get_value()Retrieves the meta field value.
- WP_REST_Meta_Fields::is_meta_value_same_as_stored_value()Checks if the user provided value is equivalent to a stored value for the given meta key.
- WP_REST_Meta_Fields::update_value()Updates meta values.
Source code
protected function get_registered_fields() { $registered = array(); $meta_type = $this->get_meta_type(); $meta_subtype = $this->get_meta_subtype(); $meta_keys = get_registered_meta_keys( $meta_type ); if ( ! empty( $meta_subtype ) ) { $meta_keys = array_merge( $meta_keys, get_registered_meta_keys( $meta_type, $meta_subtype ) ); } foreach ( $meta_keys as $name => $args ) { if ( empty( $args['show_in_rest'] ) ) { continue; } $rest_args = array(); if ( is_array( $args['show_in_rest'] ) ) { $rest_args = $args['show_in_rest']; } $default_args = array( 'name' => $name, 'single' => $args['single'], 'type' => ! empty( $args['type'] ) ? $args['type'] : null, 'schema' => array(), 'prepare_callback' => array( $this, 'prepare_value' ), ); $default_schema = array( 'type' => $default_args['type'], 'title' => empty( $args['label'] ) ? '' : $args['label'], 'description' => empty( $args['description'] ) ? '' : $args['description'], 'default' => $args['default'] ?? null, ); $rest_args = array_merge( $default_args, $rest_args ); $rest_args['schema'] = array_merge( $default_schema, $rest_args['schema'] ); $type = ! empty( $rest_args['type'] ) ? $rest_args['type'] : null; $type = ! empty( $rest_args['schema']['type'] ) ? $rest_args['schema']['type'] : $type; if ( null === $rest_args['schema']['default'] ) { $rest_args['schema']['default'] = static::get_empty_value_for_type( $type ); } $rest_args['schema'] = rest_default_additional_properties_to_false( $rest_args['schema'] ); if ( ! in_array( $type, array( 'string', 'boolean', 'integer', 'number', 'array', 'object' ), true ) ) { continue; } if ( empty( $rest_args['single'] ) ) { $rest_args['schema'] = array( 'type' => 'array', 'items' => $rest_args['schema'], ); } $registered[ $name ] = $rest_args; } return $registered; }Changelog
Introduced in 4.7.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 tag, from
src/wp-includes/rest-api/fields/class-wp-rest-meta-fields.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.