Skip to content

Commit c278311

Browse files
committed
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. git-svn-id: https://develop.svn.wordpress.org/trunk@59795 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 551e474 commit c278311

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/wp-admin/edit-form-blocks.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ static function ( $classes ) {
5151

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(
5858
'/wp/v2/types?context=view',
@@ -71,7 +71,14 @@ static function ( $classes ) {
7171
'/wp/v2/global-styles/themes/' . $active_theme . '/variations?context=view',
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

7784
block_editor_rest_api_preload( $preload_paths, $block_editor_context );

0 commit comments

Comments
 (0)