• Resolved carloz san

    (@wajaraja)


    Hi there…

    In section :

    ” Ultimate Member> Settings> Appearance> Profile Menu ” ;

    1. There is an option to enable/disable the tab

    2. If tab activated, it will display “who can see tab? (ex : who can see about tab?)”
    with options:

    1. Anyone,
    2. Guest Only,
    3. Members Only,
    4. Only the owner,
    5. Only specific roles,
    6. Owners and specific roles.

    My question, is it possible to make one additional option like :

    7. Anyone, except.

    Usage examples;

    I want to show the promo tab (custom tab that I have created) to anyone except the buyer.

    Any help is greatly appreciated,

    Thank You

    • This topic was modified 3 years, 2 months ago by carloz san. Reason: add information on who can see tab
Viewing 15 replies - 1 through 15 (of 36 total)
  • Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @wajaraja

    This requires customization on your end. You can check the example code below that hides the “Posts” tab for administrator. You can modify it to hide the tab from specific user role:

    add_filter( 'um_user_profile_tabs', 'um_121721_show_tabs', 6, 1 );
    function um_121721_show_tabs( $tabs ){
    
        $user_id = get_current_user_id();
        um_fetch_user( $user_id );
        if( "administrator" == um_user('role') ){
            unset( $tabs['posts'] );
        }
    
        return $tabs;
    }

    Regards,

    Thread Starter carloz san

    (@wajaraja)

    Hi @champsupertramp

    Thank you for your quick reply.

    I created a custom tab as described here.

    So, I’ve replaced the code you provided, to :

    add_filter( 'um_user_profile_tabs', 'um_121721_show_tabs', 6, 1 );
    function um_121721_show_tabs( $tabs ){
    
        $user_id = get_current_user_id();
        um_fetch_user( $user_id );
        if( "partner" == um_user('role') ){
            unset( $tabs['uo_learndash_certificates'] );
        }
    
        return $tabs;
    }

    “administrator” = > “partner”

    ‘post’ => ‘uo_learndash_certificates’

    But the tab still shows (shouldn’t be).

    Tab Settings “MY CERTIFICATES” on the who can see tab? => I set it to anyone.

    Can you revisit what I’ve missed?

    Thank You

    • This reply was modified 3 years, 2 months ago by carloz san.

    @wajaraja

    Try with um_partner for the UM User Role

    Thread Starter carloz san

    (@wajaraja)

    Hi @missveronicatv @champsupertramp

    I would like to revise my previous answer that the code has worked fine in the scenario if the user “partner” is logged in then the certificates tab will be hidden.

    The problem/condition that I forgot to mention at the beginning is that I has set the profile page to be accessible by anyone.
    (the reason is because I have a “salesperson” user/roles who will sell their wares on profile tab).

    So, for users who are not logged in, the certificates tab still appears, and when the user logs in (partners) the tab will be hidden.

    How can I keep the certificate tab hidden with profile settings can be accessed by anyone

    Thank you

    @wajaraja

    This code snippet will remove the certificate tab for non logged in users and keep same action for logged in users as before:

    add_filter( 'um_user_profile_tabs', 'um_121721_show_tabs', 6, 1 );
    function um_121721_show_tabs( $tabs ){
    
        if( !is_user_logged_in()) {
            unset( $tabs['uo_learndash_certificates'] );
            return $tabs;
        }
        
        $user_id = get_current_user_id();
        um_fetch_user( $user_id );
        if( "um_partner" == um_user('role') ){
            unset( $tabs['uo_learndash_certificates'] );
        }
    
        return $tabs;
    }
    • This reply was modified 3 years, 2 months ago by missveronica.
    Thread Starter carloz san

    (@wajaraja)

    Perfect..!!

    Thank you for the time you have spent @missveronicatv @champsupertramp

    Plugin Contributor Champ Camba

    (@champsupertramp)

    Thanks for letting us know. I’m marking this as resolved now

    Regards,

    Thread Starter carloz san

    (@wajaraja)

    Hi i’m really sorry,
    now i have 2 questions.

    (Similar case to the previous problem with a bit of repeating to make things clearer)

    Question 1 :

    I have a ‘unit_promo’ tab to display for anyone, except for the agent role.

    What I have done:

    1. Set the profile/user page so that anyone can access it.
    (Page where profile shortcode is stored)

    2. Set the ‘unit_promo’ tab on Ultimate Member > Settings > Appearance > Profile Menu, so that anyone can access it.

    To prevent the agent role from seeing the ‘unit_promo’ tab either has logged in or not, I customized the code provided from @missveronicatv but it didn’t work.
    (For the previous case the code works)

    Can you see what I’ve missed?

    Here’s the code :

    add_filter( 'um_user_profile_tabs', 'um_unit_promo_show_tabs', 6, 1 );
    function um_unit_promo_show_tabs( $tabs ){
    
        if( !is_user_logged_in()&& "agent" == um_user('role')) {
    		$user_id = get_current_user_id();
        	um_fetch_user( $user_id );
            unset( $tabs['unit_promo'] );
            return $tabs;
        }
        
        $user_id = get_current_user_id();
        um_fetch_user( $user_id );
        if( "agent" == um_user('role') ){
            unset( $tabs['unit_promo'] );
        }
    
        return $tabs;
    }

    Question 2 :

    How to adapt code to different conditions
    (more than one role).

    Example :

    add_filter( 'um_user_profile_tabs', 'um_121721_show_tabs', 6, 1 );
    function um_121721_show_tabs( $tabs ){
    
        if( !is_user_logged_in()) {
            unset( $tabs['uo_learndash_certificates'] );
            return $tabs;
        }
        
        $user_id = get_current_user_id();
        um_fetch_user( $user_id );
        if( "partner" || "subscriber" || "customer"  == um_user('role') ){
            unset( $tabs['uo_learndash_certificates'] );
        }
    
        return $tabs;
    }

    Please help me again,

    Really really Thank You

    • This reply was modified 3 years, 2 months ago by carloz san.
    Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @wajaraja

    1. Are you sure that the role slug/ID is agent? You can confirm it in WP Admin > Ultimate Member > User Roles > see the table column “Role ID”.

    2. Here’s how you can accept multiple validation:

    if( in_array( um_user('role'), ["partner","subscriber","customer" ] ) ){
        unset( $tabs['uo_learndash_certificates'] );
    }

    Regards,

    Thread Starter carloz san

    (@wajaraja)

    1. Yes, I sure the role/slug ID is agent

    2. Please wait a moment, I will try it.

    Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @wajaraja

    1. Please try this modified code:

    add_filter( 'um_user_profile_tabs', 'um_unit_promo_show_tabs', 6, 1 );
    function um_unit_promo_show_tabs( $tabs ){
         	$user_id = get_current_user_id();
        	um_fetch_user( $user_id );
            
        if( !is_user_logged_in() || "agent" == um_user('role')) {
    	unset( $tabs['unit_promo'] );
            return $tabs;
        }
        
        if( "agent" == um_user('role') ){
            unset( $tabs['unit_promo'] );
        }
    
        return $tabs;
    }

    Regards,

    Thread Starter carloz san

    (@wajaraja)

    Hi @champsupertramp

    Unfortunately your code (1) has not worked for me.

    Is there any other way?

    Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @wajaraja

    Could you please try this one?

    add_filter( 'um_user_profile_tabs', 'um_unit_promo_show_tabs', 6, 1 );
    function um_unit_promo_show_tabs( $tabs ){
         	$user_id = get_current_user_id();
        	um_fetch_user( $user_id );
            
        if( ! is_user_logged_in() || "agent" == um_user('role') ) {
    	unset( $tabs['unit_promo'] );
        }
        
        return $tabs;
    }

    The above code will hide the Unit Promo tab from non-logged-in users and users with a role “Agent”.

    Regards,

    Thread Starter carloz san

    (@wajaraja)

    I’ve checked in every section and I’m sure like the slug and tab names are correct.

    but code still not working…

    Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @wajaraja

    Are you logged in as an Agent? And it doesn’t hide the Unit Promo tab when you view other profiles?

    Regards,

Viewing 15 replies - 1 through 15 (of 36 total)
  • The topic ‘Add conditions to the profile menu settings’ is closed to new replies.