This simple plugin, built for my WordPress DC Presentation on the Users API adds a role called link master, that gets the capability to edit links and also read private posts and pages and also removes the ability for editors to manage categories.
This plugin only needs to run once, and in fact to make sure it doesn’t run the actual adding or roles multiple times, we are going to use an option to prevent it from happening.
* Add our init action
add_action(‘init’, array($this, ‘init’) );
We start by creating our class, and when it is initialized add an action to the WordPress init hook.
* Check to see if we need to do anything
if ( FALSE === get_option(‘jorbin_role_master’) ):
add_option(‘jorbin_role_master’, ‘1’, ”, ‘yes’);
On the init hook, we check to see if our option exists. If it doesn’t, we call our method that add the roles and then add an option to prevent the role from getting added over and over again.
* Initial role population for link master and strip editor of manage cats
add_role(‘link_master’, ‘Link Master’);
$role =& get_role(‘link_master’);
$role =& get_role(‘editor’);
$jorbin_role_master = new jorbin_role_master();
Our method that actually calls the option first adds the role, the loads it into a variable where we can call add_cap to add the specific capabilities we want. After that, we remove the manage_categories capability from the editor. After we create a new object with our class, we are good to go. Easy. As. Pie.