Skip to content

Instantly share code, notes, and snippets.

@tomatillodesign
Created February 2, 2017 21:04
Show Gist options
  • Save tomatillodesign/fbbe01c46c57b4d8a994db45d808cff6 to your computer and use it in GitHub Desktop.
Save tomatillodesign/fbbe01c46c57b4d8a994db45d808cff6 to your computer and use it in GitHub Desktop.
Super Editor simple plugin
<?php
/*
Plugin Name: SuperEditor
Description: Create New Role for Safe WordPress Editing
Author: Chris Liu-Beers | Tomatillo Design
Author URI: http://www.tomatillodesign.com
Version: 1.0
*/
// For Testing, remove the role and then add it back
// OK to comment this out once the plugin has run once
//check if role exist before removing it
// if( get_role('super_editor') ){
// remove_role( 'super_editor' );
// }
// Add a custom user role
$result = add_role( 'super_editor', __(
'Super Editor' ),
array(
'read' => true, // true allows this capability
'edit_posts' => true, // Allows user to edit their own posts
'edit_pages' => true, // Allows user to edit pages
'edit_others_posts' => true, // Allows user to edit others posts not just their own
'create_posts' => true, // Allows user to create new posts
'list_users' => true,
'manage_categories' => true, // Allows user to manage post categories
'publish_posts' => true, // Allows the user to publish, otherwise posts stays in draft mode
'edit_themes' => false, // false denies this capability. User can’t edit your theme
'install_plugins' => false, // User cant add new plugins
'update_plugin' => false, // User can’t update any plugins
'update_core' => false, // user cant perform core updates
'install_plugins' => false,
'activate_plugins' => false,
'delete_plugins' => false,
'edit_users' => true,
'create_users' => true,
'delete_users' => true,
'unfiltered_html' => true,
'activate_plugins' => false,
'delete_others_pages' => true,
'delete_others_posts' => true,
'delete_pages' => true,
'delete_posts' => true,
'delete_private_pages' => true,
'delete_private_posts' => true,
'delete_published_pages' => true,
'delete_published_posts' => true,
'edit_others_pages' => true,
'edit_others_posts' => true,
'edit_pages' => true,
'edit_posts' => true,
'edit_private_pages' => true,
'edit_private_posts' => true,
'edit_published_pages' => true,
'edit_published_posts' => true,
'edit_theme_options' => true,
'export' => true,
'import' => true,
'list_users' => true,
'manage_categories' => true,
'manage_links' => true,
'manage_options' => true,
'moderate_comments' => true,
'publish_pages' => true,
'publish_posts' => true,
'read_private_pages' => true,
'read_private_posts' => true,
'read' => true,
'remove_users' => true,
'upload_files' => true,
// Tribe Events Calendar
'edit_tribe_event' => true,
'read_tribe_event' => true,
'delete_tribe_event' => true,
'delete_tribe_events' => true,
'edit_tribe_events' => true,
'edit_others_tribe_events' => true,
'delete_others_tribe_events' => true,
'publish_tribe_events' => true,
'edit_published_tribe_events' => true,
'delete_published_tribe_events' => true,
'delete_private_tribe_events' => true,
'edit_private_tribe_events' => true,
'read_private_tribe_events' => true,
'edit_tribe_venue' => true,
'read_tribe_venue' => true,
'delete_tribe_venue' => true,
'delete_tribe_venues' => true,
'edit_tribe_venues' => true,
'edit_others_tribe_venues' => true,
'delete_others_tribe_venues' => true,
'publish_tribe_venues' => true,
'edit_published_tribe_venues' => true,
'delete_published_tribe_venues' => true,
'delete_private_tribe_venues' => true,
'edit_private_tribe_venues' => true,
'read_private_tribe_venues' => true,
'edit_tribe_organizer' => true,
'read_tribe_organizer' => true,
'delete_tribe_organizer' => true,
'delete_tribe_organizers' => true,
'edit_tribe_organizers' => true,
'edit_others_tribe_organizers' => true,
'delete_others_tribe_organizers' => true,
'publish_tribe_organizers' => true,
'edit_published_tribe_organizers' => true,
'delete_published_tribe_organizers' => true,
'delete_private_tribe_organizers' => true,
'edit_private_tribe_organizers' => true,
'read_private_tribe_organizers' => true,
//NOT ALLOWED
'edit_plugins' => false,
'edit_themes' => false,
'edit_files' => false,
'edit_dashboard' => false,
'update_core' => false,
'update_plugins' => false,
'update_themes' => false,
'switch_themes' => false,
'install_themes' => false,
'delete_themes' => false
)
);
// Prevent Super Editor from Creating Admins
class JPB_User_Caps {
// Add our filters
function JPB_User_Caps(){
add_filter( 'editable_roles', array(&$this, 'editable_roles'));
add_filter( 'map_meta_cap', array(&$this, 'map_meta_cap'),10,4);
}
// Remove 'Administrator' from the list of roles if the current user is not an admin
function editable_roles( $roles ){
if( isset( $roles['administrator'] ) && !current_user_can('administrator') ){
unset( $roles['administrator']);
}
return $roles;
}
// If someone is trying to edit or delete and admin and that user isn't an admin, don't allow it
function map_meta_cap( $caps, $cap, $user_id, $args ){
switch( $cap ){
case 'edit_user':
case 'remove_user':
case 'promote_user':
if( isset($args[0]) && $args[0] == $user_id )
break;
elseif( !isset($args[0]) )
$caps[] = 'do_not_allow';
$other = new WP_User( absint($args[0]) );
if( $other->has_cap( 'administrator' ) ){
if(!current_user_can('administrator')){
$caps[] = 'do_not_allow';
}
}
break;
case 'delete_user':
case 'delete_users':
if( !isset($args[0]) )
break;
$other = new WP_User( absint($args[0]) );
if( $other->has_cap( 'administrator' ) ){
if(!current_user_can('administrator')){
$caps[] = 'do_not_allow';
}
}
break;
default:
break;
}
return $caps;
}
}
$jpb_user_caps = new JPB_User_Caps();
@JessicaLawson
Copy link

Hello
Happy to meet you, my name is Miss Jessica Lawson, it is my pressure to meet you here  today through this site, i will like you to write to me so that i can be able to tell you more about me and the reason of my contact with you. here is my private email address, please write to me here so that i can tell you more anout me and also to send my picture  to you ( [email protected] )  thanks

Yours Miss Jessica Lawson

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment