“deep” group ids for posts?

Posted in

I am trying to migrate a custom plugin I wrote from the old to new Groups API (which I do like much better BTW!).

It is basically a e-mail notification system for new posts. I have three groups, each of which is a daughter of the next in the tree with respect to access. i.e. G1 can see everything, G2 can’t see G1 posts, G3 can’t see G1 or G2 posts.

I would like to send one email per group with post titles for posts they can see and I’m trying to find an elegant way of accomplishing that with the new system.

I guess I’m looking for something like:


I can certainly figure out a hacky way to sort it out—get the deep ids for a group member, for example—but I was hoping I overlooked something in the documentation that would get me there more elegantly…

3 Responses to “deep” group ids for posts?

  1. George July 16, 2019 at 12:57 pm #

    Hi Sean,

    I’m glad you resolved this.

    Although I haven’t tested it myself, it should work. Nevertheless, I’ll keep this post as a feature request and check this case on my test installation.

    Kind regards,

  2. Sean July 9, 2019 at 6:45 pm #

    I don’t think that captures the hierarchical group relationships though does it?

    If post P is restricted to group G1 and group G2 is a parent of G1 and can view G1 content members of G1 that are not in G2 will be overlooked in the above no? get_read_group_ids(P) returns only G1 and $group->users will only pull those users that explicitly belong to G1 and not the G2 members that inherited G1 access… or am I missing something?

    But actually, after I asked the question are thought it through, pulling the “deep_ids” for a group member wasn’t as kludgey as I originally thought it was so the problem is solved, for me at least. However, my scenario is quite specific and quite limited—it wouldn’t work if there were more complicated hierachies in my groups or if my users belonged to more than one group at a time… I definitely see a need to for a function that somehow pulls the inherited access a given group has.

  3. George July 9, 2019 at 12:57 pm #

    Hi Sean,

    I’m glad you’re enjoying our plugin and using it in a constructive way.
    Although it would depend on your implementation and how you’re implementing it, what I would based on your description would be this:

    First I would fetch the groups set for a given post
    $group_ids = Groups_Post_Access:: get_read_group_ids( $post_id );
    If there are any groups set and for each of these groups, get the users
    $group = new Groups_Group( $group_id );
    $users = $group->users;

    Finally, notify each of the existing users.

    Kind regards,

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