How to give special user roles the right to manage global snippets

A customer today asked if it’s possible to give other user roles the permission to manage global snippets. The answer is yes, but this needs some preparation. Here is how it works:

Please note that the following only works for version 2.3.6 and up.

Starting position

Let’s say you’re using the popular Yoast SEO Plugin. When you activate it, it installs two new roles: SEO Editor and SEO Manager. Let’s say you want to give the SEO Editor the right to edit global snippets. This is what you have to do:

Step 1) Install the permission plugin

  1. Here you can download a permission plugin that sets a special property when the “global snippet” post type is generated.
  2. Download and upload it to your wp-content/plugins/ folder OR just use the downloaded ZIP file to upload it right within your WordPress dashboard.
  3. Then activate  the plugin.

Note that after the permission plugin has been activated you will maybe not be able to edit global snippets anymore. Correct that by following step 2.

Step 2) Install User Role Editor Plugin

  1. Now please install and activate the free User Role Editor Plugin from the official WordPress Plugin repository.
  2. After activation go to Users -> User Role Editor.
  3. Select “SEO Editor” on the top selectbox field.
  4. Click “Global Rich Snippets” from the left.
  5. Select the permissions you want to change.
  6. Update user role.
Select the checkboxes to correct the permissions.

Done! The user with the role “SEO Editor” should now be able to edit global snippets.

Optional: Step 3)

If you do not see the global snippets menu as an administrator, follow the steps below:

  1. Go to Settings -> User Role Editor.
  2. Check the checkbox that says “Show Administrator role at User Role Editor”.
  3. Save the settings.
  4. Go to Users -> User Role Editor.
  5. Select “Administrator” on the top selectbox field.
  6. Give the Administrator role the rights to read/edit/delete the global snippet posts.

Permissions for editors

Another customer asked if it’s possible to give editors the permission to just edit overridable Global Snippet values. That’s also possible. It needs a few lines of code.

<?php
/*
Plugin Name: snip Permissions
Description: Sets permissions to use SNIPs REST API the way you like it.
Version: 0.1.0
*/


add_filter(
    'wpbuddy/rich_snippets/rest/permission',
    function () {
        # change this to any capability you want: https://wordpress.org/support/article/roles-and-capabilities/
        return current_user_can('edit_posts');
    }
);

You can download the file here as a ZIP file that can be uploaded to your WordPress site.

The file allows any user with the permission to edit posts to change Global Snippet values.