Are you a GenerateCustomer?

Do you have an active GP Premium or GenerateBlocks Pro license key?

Create a GenerateSupport account for GeneratePress and GenerateBlocks support in one dedicated place.

Create an account
Already have a GenerateSupport account? Login

Just browsing?

Feel free to browse the forums. Support for our free versions is provided on WordPress.org (GeneratePress, GenerateBlocks).

Want to become a premium user? Learn more below.

Global styles user capabilities

  • Hi,
    I was wondering if there is a way to assign to a (custom) user role other than admin the capability to edit global styles.

    Thank you.

  • Hi there,

    By default, the Editor role has capability to edit the global styles, other than Admin. So just assign the custom role the same capabilities as the Editor.

  • Dear Alvind,

    Thank you for your answer.

    However, I was interested in knowing against which specific USER CAPABILITY it checks against to allow (or not) editing of global styles, not which USER ROLE.

    Thanks for your kind reply.

  • I was interested in knowing against which specific USER CAPABILITY it checks against to allow

    Basically, all of the Editor capabilities. You can refer to the full list of Editor capabilities here:
    https://wordpress.org/documentation/article/roles-and-capabilities/#capability-vs-role-table

  • Dear Alvind,

    I am pretty sure that in the code there is a conditional statement where it checks for a specific capability and therefore allows (or not) editing of the global styles, is not that it checks for all the capabilities.

    Can you please escalate my question to a support engineer if you are not able to provide a specific answer?

    Thank you

  • Sorry for the confusion, you didn’t specify what capability the plugin checks for initially, so I assumed you wanted to know all the capabilities to create a custom role.

    In the source code, it only checks for the edit-post capability, which you can find in includes/class-global-styles.php on line 158.

    Is that what you were looking for? If not, I can escalate this question as you asked.

  • Hi Alvind,

    Thank you for your reply, unfortunately that is not what I am referring to. In the class it just exits the function if lacking edit_post capability when rendering the backend menu for the global classes.

    What I am referring to is what capability determines if the Edit/Remove elements are rendered in the block editor.

    This one: https://postimg.cc/mzXdHCPd

  • I’m not sure I understand the question, if you assign the edit_posts ability to the custom role, then the role should be able to use the global style.

  • Hi Ying.

    Nope.

    Besides, edit_posts is a capability assigned by default not only to administrators and editors (the roles that your colleague Alvind said are the ones able to use global styles by default) but also to authors and contributors, as per WordPress documentation, specifically in the table that your colleague linked in the first reply.

    Kind regards.

  • Yes, I know that not only admin role have can use the global style, all user roles with edit_posts can.

    I thought your question was how to give a custom user role the capability to use global style, right?

    If this is what you were asking for, then you need to assign the edit_posts to your custom role.

    Let me know if I didn’t understand your request correctly.

  • Dear Ying,

    Users with edit_posts capability can only add existing global styles to a post or page, they cannot edit them.
    In fact, in the block editor, whilst logged in as a user with edit_posts cap (for example an editor), if you click on the 3 dots next to a style, only the option to remove it appears.

    My question was how to allow non-admin users to eventually edit the global styles, therefore which capability needs to be assigned to the role.

    Thanks

  • Hi there,

    By default, you need the manage_options capability in order to create and edit existing Global Styles.

    You can change this using this filter: generateblocks_manage_classes_capability

    For example:

    add_filter( 'generateblocks_manage_classes_capability', function() {
        return 'edit_posts';
    } );

    Let us know if that helps or not 🙂

  • Hi Tom,

    Indeed this is the filter I was looking for, thank you very much! (note that there is a missing ‘ after the filter name and before the comma though, just writing this in case anybody stumbles upon this thread).

    btw: the new global styles look really promising, I just wish that – speaking of filters – they would honor the breakpoints set via generateblocks_media_query filter (or have a separate filter with matching functionality). Right now, having to edit them one by one every single time is a bit of a pain.

  • Thanks for the heads up – just updated the function.

    There will be a new filter in the next version to set the default at-rules in the styles builder 🙂

  • Good to hear, that would be a great quality of life feature.

Viewing 15 posts - 1 through 15 (of 15 total)
  • You must be logged in to reply to this topic.