Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rest API: move hook that handles wp_navigation post type schema to WP_Navigation_Fallback #4957

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 38 additions & 1 deletion src/wp-includes/class-wp-navigation-fallback.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,44 @@
* @since 6.3.0
*/
class WP_Navigation_Fallback {
/**
* Updates the wp_navigation custom post type schema,
* in order to expose additional fields in the
* embeddable links of WP_REST_Navigation_Fallback_Controller.
* Used with the `rest_wp_navigation_item_schema` hook.
*
* @since 6.3.0
*
* @param array $schema the schema for the `wp_navigation` post.
* @return array the modified schema.
*/
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;
}

/**
* Gets (and/or creates) an appropriate fallback Navigation Menu.
Expand All @@ -25,7 +63,6 @@ class WP_Navigation_Fallback {
* @return WP_Post|null the fallback Navigation Post or null.
*/
public static function get_fallback() {

/**
* Filters whether or not a fallback should be created.
*
Expand Down
3 changes: 3 additions & 0 deletions src/wp-includes/default-filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,9 @@
add_action( 'setup_theme', 'wp_enable_block_templates' );
add_action( 'wp_loaded', '_add_template_loader_filters' );

// wp_navigation post type.
add_filter( 'rest_wp_navigation_item_schema', array( 'WP_Navigation_Fallback', 'update_wp_navigation_post_schema' ), 22 );

// Fluid typography.
add_filter( 'render_block', 'wp_render_typography_support', 10, 2 );

Expand Down
56 changes: 0 additions & 56 deletions src/wp-includes/navigation-fallback.php

This file was deleted.

1 change: 0 additions & 1 deletion src/wp-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,6 @@
require ABSPATH . WPINC . '/block-supports/spacing.php';
require ABSPATH . WPINC . '/block-supports/typography.php';
require ABSPATH . WPINC . '/block-supports/settings.php';
require ABSPATH . WPINC . '/navigation-fallback.php';
require ABSPATH . WPINC . '/style-engine.php';
require ABSPATH . WPINC . '/style-engine/class-wp-style-engine.php';
require ABSPATH . WPINC . '/style-engine/class-wp-style-engine-css-declarations.php';
Expand Down
Loading