Make WordPress Core


Ignore:
Timestamp:
05/28/2024 12:38:28 PM (14 months ago)
Author:
swissspidy
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.

This reintroduces [57624] (reverted in [57628]) with improved backward compatibility and further enhancements.

Props ramonopoly, spacedmonkey, mukesh27, swissspidy.
Fixes #60131.

File:
1 edited

Legend:

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

    r58201 r58225  
    477477        'wp_global_styles',
    478478        array(
    479             'label'        => _x( 'Global Styles', 'post type general name' ),
    480             'description'  => __( 'Global styles to include in themes.' ),
    481             'public'       => false,
    482             '_builtin'     => true, /* internal use only. don't use this when registering your own post type. */
    483             '_edit_link'   => '/site-editor.php?canvas=edit', /* internal use only. don't use this when registering your own post type. */
    484             'show_ui'      => false,
    485             'show_in_rest' => false,
    486             'rewrite'      => false,
    487             'capabilities' => array(
     479            'label'                           => _x( 'Global Styles', 'post type general name' ),
     480            'description'                     => __( 'Global styles to include in themes.' ),
     481            'public'                          => false,
     482            '_builtin'                        => true, /* internal use only. don't use this when registering your own post type. */
     483            '_edit_link'                      => '/site-editor.php?canvas=edit', /* internal use only. don't use this when registering your own post type. */
     484            'show_ui'                         => false,
     485            'show_in_rest'                    => true,
     486            'rewrite'                         => false,
     487            'rest_base'                       => 'global-styles',
     488            'rest_controller_class'           => 'WP_REST_Global_Styles_Controller',
     489            'revisions_rest_controller_class' => 'WP_REST_Global_Styles_Revisions_Controller',
     490            'late_route_registration'         => true,
     491            'capabilities'                    => array(
    488492                'read'                   => 'edit_theme_options',
    489493                'create_posts'           => 'edit_theme_options',
     
    494498                'delete_others_posts'    => 'edit_theme_options',
    495499            ),
    496             'map_meta_cap' => true,
    497             'supports'     => array(
     500            'map_meta_cap'                    => true,
     501            'supports'                        => array(
    498502                'title',
    499503                'editor',
     
    502506        )
    503507    );
     508    // Disable autosave endpoints for global styles.
     509    remove_post_type_support( 'wp_global_styles', 'autosave' );
    504510
    505511    $navigation_post_edit_link = 'site-editor.php?' . build_query(
Note: See TracChangeset for help on using the changeset viewer.