Showing excerpt only on single posts for level+ccap

Hey there,
Up until now I’ve only used S2M with roles to restricted my content, without the ccap functionalities. In order to show users only the excerpt of a post in a single page, without redirecting them to the membership options page, I’ve bypassed the default restriction with add_filter("ws_plugin__s2member_check_post_level_access_excluded", "__return_true"); in functions.php, and added is_permitted_by_s2member() conditional in single.php. so my single.php looks like this:

if ( is_permitted_by_s2member() ) {
the_content();
}else{
the_excerpt();
//click to login or register
}

It’s working just fine. Also, I changed one specific post restriction settings from level-1 to level-0 + ccap_0_test capability. then I created a testing user with level-0 role and manually gave the user ccap_0_test capability. This user can see the post content - great.
Now - I want also level-1 users to be able to see the post content, so I add ccap_0_test to the level-1 role, and changed back my testing user to level-1 (also deleted its ccap manually). like this:

function itamar_s2m_add_ccaps() {
    // gets the author role
    $level_1 = get_role( 's2member_level1' );
    $level_1->add_cap( 'ccap_0_test' ); 
}
add_action( 'admin_init', 'itamar_s2m_add_ccaps'); 

Now when I login as this user and open that specific post - I only see the excerpt and not the full content.

Any ideas would be appreciated,
Thanks,
Itamar

Still need help here, I’m willing to pay if the solution requires a more complex coding.

Hi Ituk.

changed back my testing user to level-1 (also deleted its ccap manually)

Did you do other tests after that one?

With the plugin User Role Editor you can easily edit the capabilities each role has, including s2Member’s Level 1. And you can also view a user’s capabilities, which may be useful to verify if the user really has the capability you were expecting him to.

You will also see that s2Member custom capabilities are really WordPress capabilities with the name prefixed by access_s2member_ccap_.

So review what you did, maybe you just got a name wrong, or you removed the test user’s ccap by mistake. Keeping the above in mind, try doing your tests again with a new test user.

I hope that helps. :slight_smile:

Hey Cristian and thank you very much,
After checking with your suggested plugin that everything is okay with my coding, I realized the most embarrassing this - it was the site cache preventing from my test user from seeing the full content.

So my method works fine!

Thanks a lot,
Itamar

1 Like

Great! Thanks for the update! :slight_smile: