diff --git a/src/wp-admin/includes/update-core.php b/src/wp-admin/includes/update-core.php index 5f5c7a9ab6..51d786fa6d 100644 --- a/src/wp-admin/includes/update-core.php +++ b/src/wp-admin/includes/update-core.php @@ -867,6 +867,8 @@ $_old_files = array( 'wp-includes/images/wlw', 'wp-includes/wlwmanifest.xml', 'wp-includes/random_compat', + // 6.4 + 'wp-includes/navigation-fallback.php', ); /** diff --git a/src/wp-includes/class-wp-navigation-fallback.php b/src/wp-includes/class-wp-navigation-fallback.php index bd9583d1fa..59fe023d80 100644 --- a/src/wp-includes/class-wp-navigation-fallback.php +++ b/src/wp-includes/class-wp-navigation-fallback.php @@ -17,6 +17,50 @@ */ 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. + * + * 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. + * + * @since 6.4.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. * @@ -25,7 +69,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. * diff --git a/src/wp-includes/default-filters.php b/src/wp-includes/default-filters.php index 99116470d5..4a7787761b 100644 --- a/src/wp-includes/default-filters.php +++ b/src/wp-includes/default-filters.php @@ -711,6 +711,9 @@ add_action( 'wp_footer', 'the_block_template_skip_link' ); 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' ) ); + // Fluid typography. add_filter( 'render_block', 'wp_render_typography_support', 10, 2 ); diff --git a/src/wp-includes/navigation-fallback.php b/src/wp-includes/navigation-fallback.php deleted file mode 100644 index cfd92f07e8..0000000000 --- a/src/wp-includes/navigation-fallback.php +++ /dev/null @@ -1,56 +0,0 @@ -