• Resolved Kir 2012

    (@kir-2012)


    I can use the code below to make a tab which will show to the logged in user if their role is NOT one of the roles customer, owner, renter or admin.

    But what I need, is for EVERYONE to see the tab if it’s added, but for it just not to be added unless you’re a certain role. IE add it if your not one of the listed roles.

    So it should be based on the role of the DISPLAYED user not the LOGGED IN user, if you see what I mean….

    So what I already have below is:
    Role A DOES have tab on their profile & CAN see it on other roles/profiles who also do.
    Role B DOES NOT have tab, and CANNOT see it on roles who do (which is not what I need)

    But what I need is (very close to that but not quite…):
    Role A DOES have tab on their profile & CAN see it on other roles/profiles who also do.
    Role B DOES NOT have tab, and CAN ALSO see it on any roles who do.

    How do I amend the below to make that work? I’ve looked for hours for an example and tried all sorts of things I’d have thought should work but I’m getting something wrong, although it seems to me quite simple an idea I can’t find anything similar or make it work. Here’s the code I’ve got:

    function um_mycustomtab_add_tab( $tabs ) {
    $hide_from_roles = array( 'um_customer','um_owner','um_renter','administrator' );
    if ( is_user_logged_in() && ! in_array( um_user('role') , $hide_from_roles )  ) {
    	
    $tabs[ 'places' ] = array(
    'name' => 'Places',
    'icon' => 'um-faicon-map-icon',
    'default_privacy' => 0,
    );
    }
    UM()->options()->options[ 'profile_tab_' . 'places' ] = true;
    return $tabs; 
    } 
    add_filter( 'um_profile_tabs', 'um_mycustomtab_add_tab', 1000 );
    

    There was a plugin called Ultimate Member Profile Tabs but it’s not in date now and doesn’t work properly any more. You’re kind of using this functionality in the posts tab and about tab etc, however there’s no option to deal with it based on PROFILE DISPLAYED rather than profile of user that’s looked / logged in.

    All ideas gratefully received
    Thank you very much

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @kir-2012

    Could you please try this code? User A won’t see this tab when viewing User B profile and when User A is not in any of these roles: ‘um_customer’,’um_owner’,’um_renter’,’administrator’.

    function um_mycustomtab_add_tab( $tabs ) {
          $hide_from_roles = array( 'um_customer','um_owner','um_renter','administrator' );
          $user_id = get_current_user_id();
          um_fetch_user( $user_id );  
    if ( is_user_logged_in() && ! in_array( um_user('role') , $hide_from_roles )  ) {
    	
        $tabs[ 'places' ] = array(
          'name' => 'Places',
          'icon' => 'um-faicon-map-icon',
          'default_privacy' => 0,
          );
        }
        UM()->options()->options[ 'profile_tab_' . 'places' ] = true;
    
        return $tabs; 
    } 
    add_filter( 'um_profile_tabs', 'um_mycustomtab_add_tab', 1000 );
    

    Regards,

    Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @kir-2012

    This thread has been inactive for a while so we’re going to go ahead and mark it Resolved.

    Please feel free to re-open this thread if any other questions come up and we’d be happy to help. ??

    Regards,

    Thread Starter Kir 2012

    (@kir-2012)

    Hi there,

    Thank you for this, but using this code the user (Role B) who does not need the tab still cannot see the tab on the profile of another (Role A) who does have it.

    Some users need to have listed ‘places’ (post type) to show at their profile, and everyone looking at their profile should get to see the tab with a list of those places, even if their own profile does not have any ‘places’, if that makes sense.

    So this is what the code needs to do:
    Role A DOES have the places tab on their profile
    Role B DOES NOT have the places tab on their profile, but Role A can still view that places tab if role A has it on their profile.

    The code supplied doesn’t allow all roles to view the tab, only the role who has it displaying at their profile. How would we tweak the code to make it possible for all Role A and Role B to view the tab when it appears on someone’s profile, even if only Role A has it appearing at their profile?

    So the tab will appear for all to view based on ‘display tab (to all) if currently displayed profile user role is A’ rather than ‘display the tab if currently logged in user role is A’

    It’s a bit like something like Trip Advisor for instance: where the user profile for a business is different to a normal user. The business profile may need to show a tab with a menu. The normal user wouldn’t need to have this menu tab displayed at their profile as they’re not a business with a menu, but they still need to be able to view that tab at the business pages’ profiles.

    Thank you very much

    Thread Starter Kir 2012

    (@kir-2012)

    This code caused an issue where the admin, when viewing another profile, could see the other profile’s cover image and pic, but not tabs, the tabs always remained the admin’s tabs.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Add Tab Based On DISPLAYED User Not LOGGED IN User’ is closed to new replies.