- This topic has 4 replies, 3 voices, and was last updated 9 years, 5 months ago by .
Viewing 5 posts - 1 through 5 (of 5 total)
Viewing 5 posts - 1 through 5 (of 5 total)
- You must be logged in to reply to this topic.
WordPress Membership Plugin
Simple Membership Plugin › Forums › Simple Membership Plugin › Simple Membership and categories
Tagged: categories
Sorry if this is a stupid question but …
How do I check if a user can read a category? I can see how to check if user can read a post from your documentation …
Thanks very much!
Thanks v very much – I read this already … I’m trying to include a check on categories in a template I’m writing … something like:
$access_ctrl = SwpmAccessControl::get_instance();
if ($access_ctrl->can_i_read_category($category)){
//do something
}
I want to test if a user can read a particular category rather than can read a particular post. Is that clear now?
Thanks
Laurence
Thank you for clarifying your question further. The plugin developers will investigate further your request.
Kind regards
I don’t think we have a function for exactly waht you are after. The can_i_read_post() function will consider everything that needs to be considered (including the category that is assigned to the post) and then return true if all those checks succeed.
We do have another function that can tell you if the post belongs to a category that the current user has access to or not.
$permission = SwpmPermission::get_instance($auth->get('membership_level'));
if($permission->is_post_in_permitted_category($post_id) || $permission->is_post_in_permitted_parent_category($post_id)) {
//This post belongs to a category that this user has access to.
}