Last active
June 10, 2019 04:13
-
-
Save goatboy91587/9096762cb74ed549616bcbd63662a32f to your computer and use it in GitHub Desktop.
Extending Roles via Plugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Plugin Name: Allow Subscribers to Read Private Content | |
* Plugin URI: https://brettwidmann.com | |
* Description: A plugin that allows subscribers to read private posts and pages | |
* Version: 1.0 | |
* Author: Brett Widmann | |
* Author URI: https://brettwidmann.com | |
*/ | |
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' ); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This gist is for my article at https://brettwidmann.com/extending-role-capabilities-in-wordpress/