How to save Restrict Content Pro’s Group ID in User Meta

When a Restrict Content Pro’s Group owner invites a new member into his group, a new user profile will be created even though the new member has yet to accept the invitation. Restrict Content Pro will also create a entry in rcp_group_members table for the newly invited member. Its role will be set as ‘invited’.

Hence, If you want to save Group ID in user meta, you can use WordPress’s “user_register” hook which is triggered when an user is successfully registered. You just need to add the ‘custom function’.

add_action( 'user_register', 'custom_function', 9, 2);

However, the current logged in user is the Group owner. Hence, to store the Group ID in the newly added member’s user meta table, you would need to get the Group owner’s Group_ID. The code below is how one could get the Group ID of the Group owner.

//if current logged in user is owner of a group
    if (rcpga_user_is_group_member($ownerID,'owner'))
        // Get all group memberships where the current user is "owner"
        $group_memberships = rcpga_get_group_members( array(
	    'user_id'  => get_current_user_id(),
	    'role__in' => array( 'owner' )
        ) );

        foreach ( $group_memberships as $group_membership ) {
            $group = $group_membership->get_group();
            if ( $group instanceof RCPGA_Group ) {
                // This is the user ID of the group owner.
                $user_group_id = $group->get_group_id();


If the user is part of any Group, then store $user_group_id in ‘groupID’ of the user meta table.

//if the user is not part of a group, then the user email will be used
    if ($user_group_id <> "")

Leave a Comment

Your email address will not be published. Required fields are marked *

88 − 86 =