I’ve set up a new blog for a friend recently, and I didn’t want to give her administrative privileges, so I assigned her the role of editor. But she should be able to change the look of the theme. It is her site after all, not mine.
By default, WordPress doesn’t allow editors to do that, so I had to change this role.
Roles and capabilities in WordPress
What each user can do depends on her or his role. Each role is a name for a set of capabilities.
The role administrator for example has capabilities like delete_users, update_core, edit_theme_options and many others.
The role editor does not have the capability edit_theme_options, so editors cannot change theme options.
Every role has the capability exist. Isn’t that nice?
Roles are not hierarchical, they work more like taxonomies: We can assign multiple roles to each user. There is no user interface for that, but technically it is possible. We can create new roles and capabilities, for example edit_pending_posts, and we can remove existing ones.
Roles and their capabilities are stored in the options table under $wpdb->prefix . 'user_roles'.
There is also a nice Codex page: Roles and Capabilities.
What is visible and editable for a user is decided in the source code with current_user_can( $capability ).
current_user_can( 'edit_theme_options' ) is
TRUE, WordPress will show the theme options.
And if current_user_can( 'install_themes' ) is TRUE, WordPress will show the option to install a new theme.
My friend has the role editor, so I decided to add just the capability edit_theme_options. There are many plugins to manage user roles, but all of them have some side effects, I haven’t seen a single one without any bugs.
And because this change is permanent, the plugin has to run just once. It can be deactivated after the database update.
The update is made during plugin activation, so I used register_activation_hook().
register_activation_hook( __FILE__, 'marketpress_theme_options_for_editors' );
* Add new capability to "editor" role.
* @wp-hook "activate_" . __FILE__
* @return void
if ( empty( $wp_roles ) )
$wp_roles = new WP_Roles;
$wp_roles->add_cap( 'editor', 'edit_theme_options' );
Now the deactivation. I could deactivate the plugin silently, but I think it is better to tell the user what is going on and why the plugin doesn’t show up in the list of active plugins.
add_action( 'admin_notices', 'marketpress_deactivate_theme_options_for_editors', 0 );
* Print an explanation and deactivate this plugin.
* @wp-hook admin_notices
* @return void
// Suppress default activation message.
unset( $_GET['activate'] );
$name = get_file_data( __FILE__, array ( 'Plugin Name' ), 'plugin' );
<p>Editors can change theme options now.<br>
This is a permanent option, so you don’t need the plugin running anymore.</p>
<p><b></b> has been deactivated.</p>
deactivate_plugins( plugin_basename( __FILE__ ) );
And that’s all. Editors can now tweak the appearance of the site, add widgets and menus, change backgrounds and headers and use the customizer.
New Plugin: Slack Connector - Connect WordPress, WooCommerce and Slackby Michael Firnkes
Initially we merely wanted to optimize our own Slack-processes. With automated notifications from our MarkettPress shop, the blog and our forums. The resul ...Read more
Inpsyde is the first WordPress.com VIP partner in Germanyby Michael Firnkes
Automattic has given us the title of WordPress.com VIP Service Partner, the first in Germany, Austria and Switzerland. Worldwide, there are only eleven com ...Read more
Inpsyde is a WooExperts Gold Partner of WooCommerceby Michael Firnkes
A few weeks ago, Inpsyde GmbH with MarketPress became a certified WooExperts Gold Partner. This is confirmation from WooThemes of our agency’s know-h ...Read more
New: WooCommerce Shop Theme Münchenby Michael Firnkes
A WordPress and WooCommerce theme that not only looks great, but also excels in functionality? Welcome to München. The template is an addition to our WooC ...Read more