Make WordPress Core


Ignore:
Timestamp:
11/09/2021 06:58:59 PM (4 years ago)
Author:
TimothyBlynJacobs
Message:

REST API: Introduce Menu management endpoints.

This commit introduces the /wp/v2/menus, /wp/v2/menu-items and /wp/v2/menu-locations REST API endpoints. These endpoints are fully available to users with the edit_theme_options capability, but can be read by any user who can edit a REST API available post type.

The nav_menu taxonomy and nav_menu_item post type now map their capabilities to the edit_theme_options primitive capability. This allows developers to provide more fine-grained access control. However, if a developer is currently dynamically removing the edit_theme_options capability using map_meta_cap, they should use the user_has_cap filter instead.

The wp_update_nav_menu_item() function has been adjusted to return an error if saving the menu item post or assigning the menu item to a menu generate an error.

Lastly, a new menu item type is introduced, block, that can be used to store a Block as a menu item.

Props andraganescu, antonvlasenko, dingo_d, dlh, isabel_brison, kadamwhite, Mamaduka, NateWr, noisysocks, peterwilsoncc, ryelle, schlessera, soean, Spacedmonkey, talldanwp, TimothyBlynJacobs, tobifjellner, westonruter, wpscholar, zieladam.
Fixes #40878.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/post.php

    r52069 r52079  
    127127        'nav_menu_item',
    128128        array(
    129             'labels'           => array(
     129            'labels'                => array(
    130130                'name'          => __( 'Navigation Menu Items' ),
    131131                'singular_name' => __( 'Navigation Menu Item' ),
    132132            ),
    133             'public'           => false,
    134             '_builtin'         => true, /* internal use only. don't use this when registering your own post type. */
    135             'hierarchical'     => false,
    136             'rewrite'          => false,
    137             'delete_with_user' => false,
    138             'query_var'        => false,
     133            'public'                => false,
     134            '_builtin'              => true, /* internal use only. don't use this when registering your own post type. */
     135            'hierarchical'          => false,
     136            'rewrite'               => false,
     137            'delete_with_user'      => false,
     138            'query_var'             => false,
     139            'map_meta_cap'          => true,
     140            'capability_type'       => array( 'edit_theme_options', 'edit_theme_options' ),
     141            'capabilities'          => array(
     142                // Meta Capabilities.
     143                'edit_post'              => 'edit_post',
     144                'read_post'              => 'read_post',
     145                'delete_post'            => 'delete_post',
     146                // Primitive Capabilities.
     147                'edit_posts'             => 'edit_theme_options',
     148                'edit_others_posts'      => 'edit_theme_options',
     149                'delete_posts'           => 'edit_theme_options',
     150                'publish_posts'          => 'edit_theme_options',
     151                'read_private_posts'     => 'edit_theme_options',
     152                'read'                   => 'read',
     153                'delete_private_posts'   => 'edit_theme_options',
     154                'delete_published_posts' => 'edit_theme_options',
     155                'delete_others_posts'    => 'edit_theme_options',
     156                'edit_private_posts'     => 'edit_theme_options',
     157                'edit_published_posts'   => 'edit_theme_options',
     158            ),
     159            'show_in_rest'          => true,
     160            'rest_base'             => 'menu-items',
     161            'rest_controller_class' => 'WP_REST_Menu_Items_Controller',
    139162        )
    140163    );
Note: See TracChangeset for help on using the changeset viewer.