Make WordPress Core

Changeset 56793


Ignore:
Timestamp:
10/06/2023 02:04:22 PM (5 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.

Location:
trunk
Files:
1 deleted
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/update-core.php

    r56727 r56793  
    868868    'wp-includes/wlwmanifest.xml',
    869869    'wp-includes/random_compat',
     870    // 6.4
     871    'wp-includes/navigation-fallback.php',
    870872);
    871873
  • 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.
  • trunk/src/wp-includes/default-filters.php

    r56757 r56793  
    712712add_action( 'wp_loaded', '_add_template_loader_filters' );
    713713
     714// wp_navigation post type.
     715add_filter( 'rest_wp_navigation_item_schema', array( 'WP_Navigation_Fallback', 'update_wp_navigation_post_schema' ) );
     716
    714717// Fluid typography.
    715718add_filter( 'render_block', 'wp_render_typography_support', 10, 2 );
  • trunk/src/wp-settings.php

    r56614 r56793  
    355355require ABSPATH . WPINC . '/block-supports/typography.php';
    356356require ABSPATH . WPINC . '/block-supports/settings.php';
    357 require ABSPATH . WPINC . '/navigation-fallback.php';
    358357require ABSPATH . WPINC . '/style-engine.php';
    359358require ABSPATH . WPINC . '/style-engine/class-wp-style-engine.php';
  • trunk/tests/phpunit/tests/rest-api/rest-navigation-fallback-controller.php

    r56548 r56793  
    153153     * @ticket 58557
    154154     *
    155      * @covers ::wp_add_fields_to_navigation_fallback_embedded_links
     155     * @covers WP_Navigation_Fallback::update_wp_navigation_post_schema
    156156     *
    157157     * @since 6.3.0 Added Navigation Fallbacks endpoint.
Note: See TracChangeset for help on using the changeset viewer.