Give s2member level 1 access to private posts

Hi, if I use the generic “subscriber” role, this code grants my subscriber user access to private posts. However, when I try to do the same for s2member_level1 (everything else on my site relies on the s2 member levels), then the user does not have access. This is in my child theme functions.php file:
Hoping Ijust have syntax wrong for referencng s2 member level:

function prc_subscribers_can_read_private_posts() {

$subRole = get_role( 'subscriber' ); //change the name of the user here 

$subRole->add_cap( 'read_private_posts' ); //allows the above to read posts 

$subRole->add_cap( 'read_private_pages' ); //allows the above to read pages
$subRoleL1 = get_role("s2member_level1"); //change the name of the user here 

$subRoleL1->add_cap( 'read_private_posts' ); //allows the above to read posts 

$subRoleL1->add_cap( 'read_private_pages' ); //allows the above to read pages

}

add_action( 'init', 'prc_subscribers_can_read_private_posts' );

I changed the last line to this (to change priority) - and now it works. :slight_smile:

add_action( 'init', 'prc_subscribers_can_read_private_posts' ,11);

Thanks for sharing that, Karen.

Remember that when modifying s2Member roles, it’s best to “lock” them to avoid losing your changes in future updates. See this article: https://s2member.com/kb-article/s2member-rolescapabilities/#toc-2501f80b

add_filter('ws_plugin__s2member_lock_roles_caps', '__return_true');

:slight_smile: