Skip to content

Instantly share code, notes, and snippets.

@NeilJS
Created October 18, 2011 09:47
Show Gist options
  • Save NeilJS/1295062 to your computer and use it in GitHub Desktop.
Save NeilJS/1295062 to your computer and use it in GitHub Desktop.
Add / remove role capabilities in WP
// ADD CAPABILITIES FOR EDITOR ROLE
function update_capabilities() {
$role = get_role( 'editor' );
$caps_to_add = array(
'manage_options'
);
foreach( $caps_to_add as $cap )
$role->add_cap( $cap );
}
function remove_menu_pages() {
remove_menu_page('link-manager.php');
remove_menu_page('edit-comments.php'); // comments
remove_menu_page('users.php');
remove_menu_page('plugins.php');
remove_menu_page('themes.php'); // appearance
remove_menu_page('tools.php');
//remove_menu_page('options-general.php'); // ALL settings
}
// ADD / REMOVE CAPABILITIES FOR EDITOR ROLE
if (current_user_can('administrator') != 1) { // not admin, probably an editor
add_action( 'admin_init', 'update_capabilities' );
add_action( 'admin_init', 'remove_menu_pages' );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment