Skip to content

Instantly share code, notes, and snippets.

Last active June 10, 2019 04:13
What would you like to do?
Extending Roles via Plugin
* Plugin Name: Allow Subscribers to Read Private Content
* Plugin URI:
* Description: A plugin that allows subscribers to read private posts and pages
* Version: 1.0
* Author: Brett Widmann
* Author URI:
register_activation_hook(__FILE__, function()
// Make private posts and pages available to subscribers
$subRole = get_role( 'subscriber' );
$subRole->add_cap( 'read_private_posts' );
$subRole->add_cap( 'read_private_pages' );
register_deactivation_hook(__FILE__, function()
// Make private posts and pages unavailable to subscribers
$subRole = get_role( 'subscriber' );
$subRole->remove_cap( 'read_private_posts' );
$subRole->remove_cap( 'read_private_pages' );
Copy link

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