Updates the wp_navigation custom post type schema, in order to expose additional fields in the embeddable links of WP_REST_Navigation_Fallback_Controller.
Description
The Navigation Fallback endpoint may embed the full Navigation Menu object into the response as the self
link. By default, the Posts Controller will only expose a limited subset of fields but the editor requires additional fields to be available in order to utilize the menu.
Used with the rest_wp_navigation_item_schema
hook.
Parameters
$schema
arrayrequired- The schema for the
wp_navigation
post.
Source
public static function update_wp_navigation_post_schema( $schema ) {
// Expose top level fields.
$schema['properties']['status']['context'] = array_merge( $schema['properties']['status']['context'], array( 'embed' ) );
$schema['properties']['content']['context'] = array_merge( $schema['properties']['content']['context'], array( 'embed' ) );
/*
* Exposes sub properties of content field.
* These sub properties aren't exposed by the posts controller by default,
* for requests where context is `embed`.
*
* @see WP_REST_Posts_Controller::get_item_schema()
*/
$schema['properties']['content']['properties']['raw']['context'] = array_merge( $schema['properties']['content']['properties']['raw']['context'], array( 'embed' ) );
$schema['properties']['content']['properties']['rendered']['context'] = array_merge( $schema['properties']['content']['properties']['rendered']['context'], array( 'embed' ) );
$schema['properties']['content']['properties']['block_version']['context'] = array_merge( $schema['properties']['content']['properties']['block_version']['context'], array( 'embed' ) );
/*
* Exposes sub properties of title field.
* These sub properties aren't exposed by the posts controller by default,
* for requests where context is `embed`.
*
* @see WP_REST_Posts_Controller::get_item_schema()
*/
$schema['properties']['title']['properties']['raw']['context'] = array_merge( $schema['properties']['title']['properties']['raw']['context'], array( 'embed' ) );
return $schema;
}
Changelog
Version | Description |
---|---|
6.4.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.