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
- Here you can download a permission plugin that sets a special property when the “global snippet” post type is generated.
- 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.
- 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
- Now please install and activate the free User Role Editor Plugin from the official WordPress Plugin repository.
- After activation go to Users -> User Role Editor.
- Select “SEO Editor” on the top selectbox field.
- Click “Global Rich Snippets” from the left.
- Select the permissions you want to change.
- Update user role.
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:
- Go to Settings -> User Role Editor.
- Check the checkbox that says “Show Administrator role at User Role Editor”.
- Save the settings.
- Go to Users -> User Role Editor.
- Select “Administrator” on the top selectbox field.
- 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.