itthinx / groups

Groups provides group-based user membership management, group-based capabilities and content access control. It integrates standard WordPress capabilities and application-specific capabilities along with an extensive API.
GNU General Public License v3.0
49 stars 35 forks source link

Get all the children group ids of current user #117

Closed elievischel closed 2 years ago

elievischel commented 4 years ago

I wanted to implement and share a functionnality that a lot of users asked on the wordpress comments :

the possibility to retrieve all the children groups below a current group we are currently assigned to. parent child1 grandchild1 grandchild2 child2

if the user is only affected to the parent group, the function get_below_group_ids_from_user($user_id) will return the ids from all the descendants (child1, child2, grandchiild1, grandchild2)

maybe we need to rename these functions, but it helped me a lot.

itthinx commented 2 years ago

Thanks for the suggestion, you seem to try to obtain what is already provided via the group_ids_deep property of the Groups_User object:

$groups_user = new Groups_User( get_current_user_id() );
// get group ids (user is direct member or by group inheritance)
$user_group_ids_deep = $groups_user->group_ids_deep;

See https://docs.itthinx.com/document/groups/api/examples/