Skip to content

Instantly share code, notes, and snippets.

@anneallen
Last active August 29, 2015 14:15
Show Gist options
  • Save anneallen/999b386d2fb89b51fd62 to your computer and use it in GitHub Desktop.
Save anneallen/999b386d2fb89b51fd62 to your computer and use it in GitHub Desktop.
Add user level for editing custom post only Wordpress
<?php
/**
* Plugin Name: Sermon User
* Description: Adds a user level with access only to Sermons via wp admin
* Version: 0.1.0
* Author: Anne Allen
* Author URI: http://nustart.solutions/
* License: GPL2
*/
register_activation_hook( __FILE__, 'psp_add_sermon_management_role' );
//* Add sermon Manager Role
function psp_add_sermon_management_role() {
add_role('psp_sermon_manager','Sermon Manager',
array(
'read' => true,
'edit_posts' => false,
'delete_posts' => false,
'publish_posts' => false,
'upload_files' => true,
)
);
}
add_action('admin_init','psp_add_role_caps',999);
function psp_add_role_caps() {
// Add the roles you'd like to administer the custom post types
$roles = array('psp_sermon_manager','editor','administrator');
// Loop through each role and assign capabilities
foreach($roles as $the_role) {
$role = get_role($the_role);
$role->add_cap( 'read_sermon');
$role->add_cap( 'read_private_sermons' );
$role->add_cap( 'edit_sermon' );
$role->add_cap( 'edit_sermons' );
$role->add_cap( 'edit_others_sermons' );
$role->add_cap( 'edit_published_sermons' );
$role->add_cap( 'publish_sermons' );
$role->add_cap( 'delete_others_sermons' );
$role->add_cap( 'delete_private_sermons' );
$role->add_cap( 'delete_published_sermons' );
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment