• Resolved runofthemill

    (@runofthemill)


    Hi there – great plugin! I’m having a hard time understanding the API documentation; I’m trying to write a filter that lists the single (admin-enforced) group a user belongs to within a specific parent group, in order to modify a menu link.

    Group hierarchy:
    – Regions
    |- Region I
    |- Region II
    |- Region III
    |- Region IV

    If user is in Region I, function returns example.com/region-i, and if user is in region IV, function returns example.com/region-iv

    I’m pretty sure I could figure out if I was using a flat group structure, but I’m not sure how to deal with the parent level

    Any suggestions on how to tackle?

    Thanks!

    https://www.ads-software.com/plugins/groups/

Viewing 1 replies (of 1 total)
  • Thread Starter runofthemill

    (@runofthemill)

    Nevermind, figured it out!

    function dynamic_home_link( $args ) {
      $homepage = '';
      $groups_user = new Groups_User( get_current_user_id() );
      $user_groups = $groups_user->groups;
      foreach ($user_groups as $user_group) {
        if ($user_group_id = $user_group->group->parent_id) {
          if ($user_group_id = 2) {
            $homepage = strtolower(str_replace(" ", "-", $user_group->group->name));
          }
        }
      }
      return str_replace('user_homepage', $homepage, $args);
    }
    add_filter( 'wp_nav_menu', __NAMESPACE__ . '\\dynamic_home_link' );
Viewing 1 replies (of 1 total)
  • The topic ‘Get current users sub-group’ is closed to new replies.