Make WordPress Core

Opened 2 years ago

Closed 21 months ago

#62322 closed enhancement (fixed)

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

Reported by: ramonopoly Owned by: peterwilsoncc
Priority: normal Milestone: 6.8
Component: Editor Version: 6.7
Severity: normal Keywords: has-patch, gutenberg-merge
Cc: Focuses:

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 (3)

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


2 years 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

#2 @joemcgill
21 months ago

  • Keywords gutenberg-merge added

#3 @peterwilsoncc
21 months ago

  • Owner set to peterwilsoncc
  • Resolution → fixed
  • Status new → closed

In 59795:

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.

Note: See TracTickets for help on using tickets.