Your cart is currently empty!
How to restrict access to post programmatically?
—
by
Hello,
I want to programmatically restrict access of a given page to members of a given group. I tried this code but it doesn’t work:
Groups_Post_Access::create( array( 'post_id' => $custpage_id, 'group_id' => $cai_group_id ));
where $custpage_id is the id of an existing page and $cai_group_id is the id of an existing group.
Could you please tell me what’s wrong with this code? I didn’t find any documentation on this.
Thanks in advance,
Yves.
Posted in Groups
Comments
3 responses to “How to restrict access to post programmatically?”
Hi Antonio,
Thanks for the answer. ‘groups_read’ doesn’t work for Groups_Post_Access::create(), at least for my version of the Groups plugin which is 2.0.3.
But actually your hint allowed me to investigate further how the plugin works and I have found that I had a hierarchical ‘groups_read_post’ access restriction which was the cause of my issue.
All is going fine, now. Thanks again!
Yves.
Perfect,
cheers.
Hi Yves,
Please try using ‘groups_read’ instead of ‘group_id’. Here you have a code using the ‘update’ method.
Kind Regards,
Antonio B.