Make WordPress Core


Ignore:
Timestamp:
10/06/2023 02:04:22 PM (8 months ago)
Author:
SergeyBiryukov
Message:

Editor: Move wp_navigation schema updating to WP_Navigation_Fallback class.

This aims to better align the navigation fallback implementation with core architecture and best practices.

The function that updates the wp_navigation post response schema is now a public method of the WP_Navigation_Fallback class, so an extra file previously used for that specific function is no longer necessary.

Follow-up to [56052].

Props ramonopoly, scruffian, isabel_brison, mukesh27, swissspidy, rajinsharwar, afercia, audrasjb, mikeschroder, JeffPaul, johnjamesjacoby, TimothyBlynJacobs, oglekler, SergeyBiryukov.
Fixes #58910.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-navigation-fallback.php

    r56559 r56793  
    1919
    2020    /**
     21     * Updates the wp_navigation custom post type schema, in order to expose
     22     * additional fields in the embeddable links of WP_REST_Navigation_Fallback_Controller.
     23     *
     24     * The Navigation Fallback endpoint may embed the full Navigation Menu object
     25     * into the response as the `self` link. By default, the Posts Controller
     26     * will only expose a limited subset of fields but the editor requires
     27     * additional fields to be available in order to utilize the menu.
     28     *
     29     * Used with the `rest_wp_navigation_item_schema` hook.
     30     *
     31     * @since 6.4.0
     32     *
     33     * @param array $schema The schema for the `wp_navigation` post.
     34     * @return array The modified schema.
     35     */
     36    public static function update_wp_navigation_post_schema( $schema ) {
     37        // Expose top level fields.
     38        $schema['properties']['status']['context']  = array_merge( $schema['properties']['status']['context'], array( 'embed' ) );
     39        $schema['properties']['content']['context'] = array_merge( $schema['properties']['content']['context'], array( 'embed' ) );
     40
     41        /*
     42         * Exposes sub properties of content field.
     43         * These sub properties aren't exposed by the posts controller by default,
     44         * for requests where context is `embed`.
     45         *
     46         * @see WP_REST_Posts_Controller::get_item_schema()
     47         */
     48        $schema['properties']['content']['properties']['raw']['context']           = array_merge( $schema['properties']['content']['properties']['raw']['context'], array( 'embed' ) );
     49        $schema['properties']['content']['properties']['rendered']['context']      = array_merge( $schema['properties']['content']['properties']['rendered']['context'], array( 'embed' ) );
     50        $schema['properties']['content']['properties']['block_version']['context'] = array_merge( $schema['properties']['content']['properties']['block_version']['context'], array( 'embed' ) );
     51
     52        /*
     53         * Exposes sub properties of title field.
     54         * These sub properties aren't exposed by the posts controller by default,
     55         * for requests where context is `embed`.
     56         *
     57         * @see WP_REST_Posts_Controller::get_item_schema()
     58         */
     59        $schema['properties']['title']['properties']['raw']['context'] = array_merge( $schema['properties']['title']['properties']['raw']['context'], array( 'embed' ) );
     60
     61        return $schema;
     62    }
     63
     64    /**
    2165     * Gets (and/or creates) an appropriate fallback Navigation Menu.
    2266     *
     
    2670     */
    2771    public static function get_fallback() {
    28 
    2972        /**
    3073         * Filters whether or not a fallback should be created.
Note: See TracChangeset for help on using the changeset viewer.