Skip to content

Commit

Permalink
Moving the hook that updates the wp_navigation post response schema t…
Browse files Browse the repository at this point in the history
…o a public method of WP_Navigation_Fallback

Delete the single file
  • Loading branch information
ramonjd committed Sep 27, 2023
1 parent 6fa2ce4 commit 1102596
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 58 deletions.
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

0 comments on commit 1102596

Please sign in to comment.