Make WordPress Core

Opened 5 weeks ago

Last modified 5 weeks ago

#62322 new enhancement

Global styles: preload user global styles based on user caps in the Post Editor

Reported by: ramonopoly's profile ramonopoly Owned by:
Milestone: 6.8 Priority: normal
Severity: normal Version: 6.7
Component: Editor Keywords: has-patch
Focuses: Cc:

Description

A ticket to track the syncing of https://github.com/WordPress/gutenberg/pull/66541

What

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.

Why

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

Different clientside requests fire for each.

Change History (1)

This ticket was mentioned in PR #7681 on WordPress/wordpress-develop by @ramonopoly.


5 weeks ago
#1

## What
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.

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

Different clientside requests fire for each.

## How?
Use current_user_can( 'edit_theme_options' ) to test for global styles edit caps. This matches post type caps.

## Testing Instructions

  1. Create two users: one admin, another editor or other role that can edit posts.
  2. For each user, fire up this branch and head to the post editor.
  3. Check that global-styles endpoints aren't fetched client side, but are, rather, preloaded via rest_preload_api_request
  4. As admin, check the same for the site editor to make sure this patch does not cause any regressions there.

For admins in the POST and SITE editors the following URLS should be preloaded:

 "/wp/v2/global-styles/<id>"  - "OPTIONS"
"/wp/v2/global-styles/themes/twentytwentyfive?context=view"  - "GET"
"/wp/v2/global-styles/themes/twentytwentyfive/variations?context=view"  - "GET"
"/wp/v2/global-styles/<id>5?context=edit"  - "GET"

For editors in the POST editor:

"/wp/v2/global-styles/<id>"  - "OPTIONS"
"/wp/v2/global-styles/themes/twentytwentyfive?context=view"  - "GET"
"/wp/v2/global-styles/themes/twentytwentyfive/variations?context=view"  - "GET"
"/wp/v2/global-styles/<id>?context=view"  - "GET"

Trac ticket: https://core.trac.wordpress.org/ticket/62322

Note: See TracTickets for help on using tickets.