diff --git a/src/wp-admin/edit-form-blocks.php b/src/wp-admin/edit-form-blocks.php index 5dbb9f33e4..bd66ac60ba 100644 --- a/src/wp-admin/edit-form-blocks.php +++ b/src/wp-admin/edit-form-blocks.php @@ -51,8 +51,8 @@ wp_enqueue_script( 'wp-edit-post' ); $rest_path = rest_get_route_for_post( $post ); -$active_theme = get_stylesheet(); - +$active_theme = get_stylesheet(); +$global_styles_endpoint_context = current_user_can( 'edit_theme_options' ) ? 'edit' : 'view'; // Preload common data. $preload_paths = array( '/wp/v2/types?context=view', @@ -71,7 +71,14 @@ $preload_paths = array( '/wp/v2/global-styles/themes/' . $active_theme . '/variations?context=view', '/wp/v2/themes?context=edit&status=active', array( '/wp/v2/global-styles/' . WP_Theme_JSON_Resolver::get_user_global_styles_post_id(), 'OPTIONS' ), - '/wp/v2/global-styles/' . WP_Theme_JSON_Resolver::get_user_global_styles_post_id() . '?context=edit', + /* + * Preload the global styles path with the correct context based on user caps. + * NOTE: There is an equivalent conditional check in the client-side code to fetch + * the global styles entity using the appropriate context value. + * See the call to `canUser()`, under `useGlobalStylesUserConfig()` in `packages/edit-site/src/components/use-global-styles-user-config/index.js`. + * Please ensure that the equivalent check is kept in sync with this preload path. + */ + '/wp/v2/global-styles/' . WP_Theme_JSON_Resolver::get_user_global_styles_post_id() . '?context=' . $global_styles_endpoint_context, ); block_editor_rest_api_preload( $preload_paths, $block_editor_context );