Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an edit_global_styles user capability to limit access to Global Styles #56299

Open
ndiego opened this issue Nov 19, 2023 · 2 comments
Open
Labels
[Feature] Extensibility The ability to extend blocks or the editing experience [Feature] Site Editor Related to the overarching Site Editor (formerly "full site editing") [Focus] Blocks Adoption For issues that directly impact the ability to adopt features of Gutenberg. [Type] Enhancement A suggestion for improvement.

Comments

@ndiego
Copy link
Member

ndiego commented Nov 19, 2023

What problem does this address?

By default, the Site Editor is restricted to Administrators. You can enable Site Editor access by granting any user role, or a new role, the capability of edit_theme_options. Here is an example:

function create_custom_site_editor_role() {
    $capabilities = array(
        'read' => true,
        'edit_theme_options' => true,  // Allows access to the Site Editor and appearance settings
    );
    add_role( 'site_editor', 'Site Editor', $capabilities );
}
add_action( 'init', 'create_custom_site_editor_role' );

This example user role is extremely restrictive, but as soon as the user accesses the Site Editor they have a lot of power to modify they site. Certain things won't work, like adding/modifying patterns, adding templates, adding pages, etc. It takes a bit of trial and error to figure out what does.

This role does, however, have near complete control over Global Styles, which might not be ideal in specific scenarios.

Consider the situation where I have built a site for a client. The client wants some of their users to have limited access to the Site Editor so they can modify templates, pages, and patterns, but the users should not have access to modify the styling of the site. A designer configured the styling to match the client's brand guidelines.

I want to be able to create a new user role for the client that provides access to the Site Editor but restricts access to Global Styles, perhaps with a capability called edit_global_styles.

What is your proposed solution?

Create a new user capability called edit_global_styles (or something similar), which would allow the creation of a user role like the following.

function create_custom_site_editor_role() {
    $capabilities = array(
        'read' => true,
        'edit_theme_options' => true,  // Allows access to the Site Editor and appearance settings
        'edit_global_styles' => false // Restrict access to Global Styles
    );
    add_role( 'site_editor', 'Site Editor', $capabilities );
}
add_action( 'init', 'create_custom_site_editor_role' );

This capability would have the following effect.

Site Editor sidebar

Before After
image image

Global Styles panel

Before After
image image

Push to Global Styles panel

Before After
image image
@ndiego ndiego added [Type] Enhancement A suggestion for improvement. [Feature] Extensibility The ability to extend blocks or the editing experience [Focus] Blocks Adoption For issues that directly impact the ability to adopt features of Gutenberg. labels Nov 19, 2023
@ndiego ndiego changed the title Add a global_styles user capability to limit access to Global Styles Add a edit_global_styles user capability to limit access to Global Styles Nov 19, 2023
@ndiego ndiego changed the title Add a edit_global_styles user capability to limit access to Global Styles Add an edit_global_styles user capability to limit access to Global Styles Nov 19, 2023
@ndiego ndiego added the [Feature] Site Editor Related to the overarching Site Editor (formerly "full site editing") label Nov 19, 2023
@genepine
Copy link

In block themes, the navigation menu cannot be edited with editor privileges.
In classic themes, we can use UserRoleEditor or AdminMenu to give editor privileges and above (i.e. general users) the appropriate privileges for customizing the navigation menu, which allows you to change the order of the menu and change the destination of links.
This is not possible with block themes.

@ramonjd
Copy link
Member

ramonjd commented Sep 12, 2024

Indirectly related:

The proposal is to open up READ access to all users that can edit posts. I don't think there's a conceptual conflict.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Extensibility The ability to extend blocks or the editing experience [Feature] Site Editor Related to the overarching Site Editor (formerly "full site editing") [Focus] Blocks Adoption For issues that directly impact the ability to adopt features of Gutenberg. [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

No branches or pull requests

3 participants