Make WordPress Core

Changeset 59795


Ignore:
Timestamp:
02/10/2025 03:54:35 AM (6 weeks ago)
Author:
peterwilsoncc
Message:

Editor: Preload Global Styles REST requests based on user permissions.

For the Post Editor, preload '/wp/v2/global-styles/' . $global_styles_id with a context corresponding to user caps, that is, 'edit' for users that can edit global styles, and 'view' for everyone else.

Preloading the global styles endpoint according to role context means that admins and non admins, e.g., editors, avoid unnecessary client side requests.

Props ramonopoly.
Fixes #62322.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/edit-form-blocks.php

    r59316 r59795  
    5252$rest_path = rest_get_route_for_post( $post );
    5353
    54 $active_theme = get_stylesheet();
    55 
     54$active_theme                   = get_stylesheet();
     55$global_styles_endpoint_context = current_user_can( 'edit_theme_options' ) ? 'edit' : 'view';
    5656// Preload common data.
    5757$preload_paths = array(
     
    7272    '/wp/v2/themes?context=edit&status=active',
    7373    array( '/wp/v2/global-styles/' . WP_Theme_JSON_Resolver::get_user_global_styles_post_id(), 'OPTIONS' ),
    74     '/wp/v2/global-styles/' . WP_Theme_JSON_Resolver::get_user_global_styles_post_id() . '?context=edit',
     74    /*
     75     * Preload the global styles path with the correct context based on user caps.
     76     * NOTE: There is an equivalent conditional check in the client-side code to fetch
     77     * the global styles entity using the appropriate context value.
     78     * See the call to `canUser()`, under `useGlobalStylesUserConfig()` in `packages/edit-site/src/components/use-global-styles-user-config/index.js`.
     79     * Please ensure that the equivalent check is kept in sync with this preload path.
     80     */
     81    '/wp/v2/global-styles/' . WP_Theme_JSON_Resolver::get_user_global_styles_post_id() . '?context=' . $global_styles_endpoint_context,
    7582);
    7683
Note: See TracChangeset for help on using the changeset viewer.