How to restrict access to post programmatically?

Posted in

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.

3 Responses to How to restrict access to post programmatically?

  1. Yves November 11, 2017 at 8:22 am #

    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.

    • antonio November 12, 2017 at 7:14 pm #

      Perfect,
      cheers.

  2. antonio November 10, 2017 at 3:27 pm #

    Hi Yves,
    Please try using ‘groups_read’ instead of ‘group_id’. Here you have a code using the ‘update’ method.
    Kind Regards,
    Antonio B.

We use cookies to optimize your experience on our site and assume you're OK with that if you stay.
OK, hide this message.

Affiliates · Contact · Jobs · Terms & Conditions · Privacy Policy · Documentation · Downloads · Useful Plugins · My Account

Share