Make WordPress Core


Ignore:
Timestamp:
02/13/2024 02:07:38 PM (3 months ago)
Author:
spacedmonkey
Message:

REST API: Refactor global styles endpoints in REST API to register with post type.

Updated the global styles endpoints in the REST API to extend from existing posts and revisions controllers. This reduces duplicated code and inconsistencies. The revisions controller is now a subclass of the WP_REST_Revisions_Controller. Related redundant methods were removed and schema generation and collection parameters were adjusted to suit the global styles context. Updated permission checks, constructor, and collection parameters accordingly. This change allows for easy override of these classes using the register_post_type_args filter.

Props ramonopoly, spacedmonkey, mukesh27.
Fixes #60131.

File:
1 edited

Legend:

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

    r57548 r57624  
    474474        'wp_global_styles',
    475475        array(
    476             'label'        => _x( 'Global Styles', 'post type general name' ),
    477             'description'  => __( 'Global styles to include in themes.' ),
    478             'public'       => false,
    479             '_builtin'     => true, /* internal use only. don't use this when registering your own post type. */
    480             '_edit_link'   => '/site-editor.php?canvas=edit', /* internal use only. don't use this when registering your own post type. */
    481             'show_ui'      => false,
    482             'show_in_rest' => false,
    483             'rewrite'      => false,
    484             'capabilities' => array(
     476            'label'                           => _x( 'Global Styles', 'post type general name' ),
     477            'description'                     => __( 'Global styles to include in themes.' ),
     478            'public'                          => false,
     479            '_builtin'                        => true, /* internal use only. don't use this when registering your own post type. */
     480            '_edit_link'                      => '/site-editor.php?canvas=edit', /* internal use only. don't use this when registering your own post type. */
     481            'show_ui'                         => false,
     482            'show_in_rest'                    => true,
     483            'rewrite'                         => false,
     484            'rest_base'                       => 'global-styles',
     485            'rest_controller_class'           => 'WP_REST_Global_Styles_Controller',
     486            'revisions_rest_controller_class' => 'WP_REST_Global_Styles_Revisions_Controller',
     487            'late_route_registration'         => true,
     488            'capabilities'                    => array(
    485489                'read'                   => 'edit_theme_options',
    486490                'create_posts'           => 'edit_theme_options',
     
    491495                'delete_others_posts'    => 'edit_theme_options',
    492496            ),
    493             'map_meta_cap' => true,
    494             'supports'     => array(
     497            'map_meta_cap'                    => true,
     498            'supports'                        => array(
    495499                'title',
    496500                'editor',
Note: See TracChangeset for help on using the changeset viewer.