Skip to content

Instantly share code, notes, and snippets.

@RadGH
Created August 14, 2013 17:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RadGH/6233199 to your computer and use it in GitHub Desktop.
Save RadGH/6233199 to your computer and use it in GitHub Desktop.
This script adds capabilities to wordpress role by role name
<?php
/* --------------------------------------------------
/ If used within a plugin, you will want to run this function on plugin activation
/ For development, you can simply call the function below . To do this, uncomment
/ the line below, then visit any page.
-------------------------------------------------- */
// custom_user_roles();
function custom_user_roles() {
global $wp_roles;
// More info:
// http://codex.wordpress.org/Roles_and_Capabilities
// Remove stock roles:
remove_role( 'author' );
remove_role( 'contributor' );
// Add custom roles
add_role( 'student', 'Student' );
add_role( 'instructor', 'Instructor' );
// New permissions added based on role.
$add_new_roles = array(
'administrator' => array(
'publish_events',
'read_events',
'edit_events',
'edit_others_events',
),
'editor' => array(
'publish_events',
'read_events',
'edit_events',
'edit_others_events',
),
'student' => array(
'read',
'read_event',
),
'instructor' => array(
'read',
'read_event',
'edit_event',
),
);
// Loop through our array, assigning the new roles.
// If you would like to remove roles, you can replicate
// this code and use remove_cap instead of add_cap
foreach($add_new_roles as $role_name => $new_roles) {
foreach($new_roles as $role) {
$wp_roles->add_cap( $role_name, $role );
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment