Skip to content

Instantly share code, notes, and snippets.

@goatboy91587
Last active June 10, 2019 04:13
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save goatboy91587/9096762cb74ed549616bcbd63662a32f to your computer and use it in GitHub Desktop.
Extending Roles via Plugin
<?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' );
});
@goatboy91587
Copy link
Author

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