• 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 2 years, 11 months ago by carloz san. Reason: add information on who can see tab
Viewing 6 replies - 31 through 36 (of 36 total)
  • Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @wajaraja

    1. I just noticed that you’re declaring the new tabs with a priority number 1000. And then you’re unsetting the tabs with a priority 6. Please try changing the unsetting function’s priority to 9999. Let’s see if this is causing the issue.

    2. As for the product agent and partner, it works on my end. Could you please check this issue after fixing issue #1? Here’s my test:

    3. Do you want to retrieve the $regno value of the current viewing profile or the currently logged-in user?

    Regards,

    Thread Starter carloz san

    (@wajaraja)

    Hi @champsupertramp

    Thank you for your reply.

    I answer starting with question :

    2. As for the product agent and partner, it works on my end. Could you please check this issue after fixing issue #1? Here’s my test :

    Sorry, I don’t understand this point.
    Can you explain more simply and in detail?

    ===============================================

    3. Do you want to retrieve the $regno value of the current viewing profile or the currently logged-in user?

    From the current view.

    But these 2 days I tried to make it like this:

    add_filter( 'um_profile_tabs', 'um_my_product_add_tab', 1000 );
    function um_my_product_add_tab( $tabs ) {
        $tabs[ 'my_product' ] = array(
            'name'   => 'My Product',
            'icon'   => 'um-faicon-list-ul',
            'custom' => true
        );
    
        UM()->options()->options[ 'profile_tab_' . 'my_product' ] = true;
    
        return $tabs;
    }
    
    add_action( 'um_profile_content_my_product_default', 'um_profile_content_my_product_default' );
    function um_profile_content_my_product_default( $args ) {
    	
    		$user_id = get_current_user_id();
        	um_fetch_user( $user_id );
    					
    		$actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
    		$url=$actual_link;
    		$lastSegment = basename(parse_url($url, PHP_URL_PATH));
    		$name = mb_strcut(($lastSegment),0,30);
    		
    		$args = array( 'post_type' => 'product', 'post_status' => 'publish', 
    			'posts_per_page' => -1,
    			'pa_agent' =>$name		 
    					 );
    		
    			$products = new WP_Query( $args );
    			$count = $products->found_posts;
    		
    		if($count>2){
    			
    		echo do_shortcode ('[products columns="2" attribute="pa_agent" terms="('.$name.')" orderby="rand" paginate="true"]');
    		}
    		else{
    			echo '<p>Cooming Soon</p>';
    		}
    	}

    For now it works as I expected.
    But I’m not sure if I’m on the right path?
    If there’s anything you need to correct, I’d be happy to accept it.

    ========================================================

    1. I just noticed that you’re declaring the new tabs with a priority number 1000. And then you’re unsetting the tabs with a priority 6. Please try changing the unsetting function’s priority to 9999. Let’s see if this is causing the issue .

    This is the latest code I had until this answer was posted :

    add_filter( 'um_profile_tabs', 'um_unit_promo_add_tab', 1000 );
    function um_unit_promo_add_tab( $tabs ) {
        $tabs[ 'unit_promo' ] = array(
            'name'   => 'Unit Promo',
            'icon'   => 'um-faicon-list-ul',
            'custom' => true
        );
    
        UM()->options()->options[ 'profile_tab_' . 'unit_promo' ] = true;
    
        return $tabs;
    }
    
    add_action( 'um_profile_content_unit_promo_default', 'um_profile_content_unit_promo_default' );
    function um_profile_content_unit_promo_default( $args ) {
    	echo do_shortcode('[products columns="2" orderby="rand" per_page="8" paginate="true"]');
    
    }

    Then I duplicated it according to the number of tabs I currently need, namely, 9 custom tabs by replacing certain parts as in the code in point 3.(all priorty number 1000)

    The code in point 2 on the previous question can indeed be an alternative.

    However, I have a condition where certain tabs can be seen by anyone (by accessing the direct url address)
    but exclude urls from certain roles.
    So for 2 days I tried to make it like this :

    #HIDE TAB PROMO#

    add_filter( 'um_user_profile_tabs', 'um_hide_tabs', 9999, 1 );
    function um_hide_tabs( $tabs ){
    	if( in_array( um_user('role'), ["um_agent","subscriber","customer"] )  && is_page('profile')){
            unset( $tabs['promotion'] );
    		return $tabs;
    	}
    	$user_id = get_current_user_id();
        um_fetch_user( $user_id );
        if( in_array( um_user('role'), ["um_agent","subscriber","customer","partner" ] )){
            unset( $tabs['promotion'] );
        	}	
        return $tabs;	
    	}

    The code seems to work.

    Under conditions:

    1. Partner roles when not logged in > “Promotion Tab” is shown

    2. Partner roles on login > “Promotion Tab” hidden

    3. The “Promotion Tab” is hidden from all roles other than partners when either the user condition is logged in or not.

    It’s like I want.

    However I have many tabs with different conditions and that has to be adjusted too.

    Finally I duplicated the code above and added it to a new file, and the code looks like this:

    #HIDE TAB UNIT PROMO#

    add_filter( 'um_user_profile_tabs', 'um_unit_promo_tabs', 6, 1 );
    function um_unit_promo_tabs( $tabs ){
    //Hide Unit Promo Tabs from Agents when not logged in
    if( in_array( um_user('role'), ["um_agent"] )  && is_page('profile')){
        unset( $tabs['unit_promo'] );
        return $tabs;
    }
    
    $user_id = get_current_user_id();
    um_fetch_user( $user_id );
    if( in_array( um_user('role'), ["um_agent"] )){
        unset( $tabs['unit_promo'] );
        }   
    return $tabs;   
    }

    And

    #HIDE TAB UNIT RECOMMENDATION#

    add_filter( 'um_user_profile_tabs', 'um_unit_rekomendasi_tabs', 6, 1 );
    function um_unit_recommendation_tabs( $tabs ){
    //Hide unit_recommendation Tabs from Subscribers, Customers, Partner when not logged in
    if( in_array( um_user('role'), ["partner","subscriber","customer" ] )  && is_page('profile')){
        unset( $tabs['unit_recommendation'] );
        return $tabs;
    }
    
    $user_id = get_current_user_id();
    um_fetch_user( $user_id );
    if( in_array( um_user('role'), ["subscriber","customer","partner" ] )){
        unset( $tabs['unit_recommendation'] );
        }   
    return $tabs;   
    }

    If only activate the code #TAB PROMO > Display tabs looks fine.

    But if I also activate #TAB UNIT PROMO and #TAB UNIT RECOMMENDATION this tab display is not what it should be.

    Can you help see this error and how I should refine the code so that I still get what I want?

    Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @wajaraja

    Please try changing the priority from 6 to 9999 for the following hooks:

    add_filter( 'um_user_profile_tabs', 'um_unit_rekomendasi_tabs', 6, 1 );
    add_filter( 'um_user_profile_tabs', 'um_unit_rekomendasi_tabs', 6, 1 );

    to

    add_filter( 'um_user_profile_tabs', 'um_unit_rekomendasi_tabs', 9999, 1 );
    add_filter( 'um_user_profile_tabs', 'um_unit_rekomendasi_tabs', 9999, 1 );

    Regards,

    Thread Starter carloz san

    (@wajaraja)

    Hi @champsupertramp

    Thanks for the quick reply.

    I’ve changed everything from 6 to 9999.

    However it doesn’t work (when I enable all three codes at the same time).

    However it works fine when only 1 code is enabled.

    Thank You

    Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @wajaraja

    Could you please share all the custom codes in a single code format in the editor?
    I’ll test it on my end.

    Regards,

    Plugin Contributor Champ Camba

    (@champsupertramp)

    Hey there!

    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 by changing the Topic Status to ‘Not Resolved’ if any other questions come up and we’d be happy to help. ??

    Regards,

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