sinanisler logo

Enabling Subscribers to View Private Posts and Pages

This code snippet is designed to modify the capabilities of WordPress ‘Subscriber’ users, allowing them to view private posts and pages. By default, WordPress restricts the viewing of private content to users with higher roles like editors or administrators.

This snippet grants ‘Subscriber’ users the additional capability to read private posts and pages, making it useful for sites that want to provide exclusive content to registered users without elevating their role to a higher level

function snn_make_private_posts_visible_to_subscribers() {
    $subRole = get_role('subscriber');
    $subRole->add_cap('read_private_posts');
    $subRole->add_cap('read_private_pages');
}
add_action('init', 'snn_make_private_posts_visible_to_subscribers');

Leave the first comment