Clients & Buddypress Logged in User's issue

Hello,

I have created a Buddypress website where the members are Service Providers. I recently installed woocommerce plugin in order to sell products to the visitors of website= clients. The issue is that the clients can only create a profile within Buddypress as they are providers and can see all the logged in users links that are supposed to be visible only by providers.

1) Is there a way to allow clients to create a profile different than the providers' with the use of the classic wordpress template and not the buddypress template?

2) Is there a way to make the dynamic links in the menu (My Profile,Notifications etc.) visible only for Buddypress Members and not for the clients?

Thank you!!

  • Sajid

    Hi @loannis,
    Hope you are doing good today :slight_smile:

    1. You can use following plugin to create frontend profile pages and allow users to register users and manage their profiles on frontend.
    https://wordpress.org/plugins/profile-builder/

    2. Yes, I am assuming you have different roles assigned to Clients and Service Providers. If yes then you can manage menu or menu items to display to users with a specificuser role.
    https://wordpress.org/plugins/nav-menu-roles/

    Hope that helps! Feel free to post a reply if you need further assistance :slight_smile:

    Best Regards,
    Sajid

  • Ioannis

    Hello Sajid,

    the solution that you provided me worked like a charm!! I have one more question. I use this code to redirect Buddypress members after login to their profile

    add_filter("login_redirect","bpdev_redirect_to_profile",10,3);
    
    function bpdev_redirect_to_profile($redirect_to_calculated,$redirect_url_specified,$user)
    
    {
    
    if(empty($redirect_to_calculated))
    
    $redirect_to_calculated=admin_url();
    
    /*if the user is not site admin,redirect to his/her profile*/
    
    if(!is_site_admin($user->user_login))
    
    return bp_core_get_user_domain($user->ID );
    
    else
    
    return $redirect_to_calculated; /*if site admin or not logged in,do not do anything much*/
    
    }

    But now that I have Customers in my website they are redirected to a Buddypress profile too. Is there a way to make the code work by roles? I would like to allow Buddypress Users to be redirected to their profile as they already do but the Customers be redirected to my account page. I attach a screenshot to be more clear. Could that be possible?

    Thank you,
    Ioannis

  • Ioannis

    Hello Sajid,

    1) The roles that I would like to be redirected to current user's profile as already do with the above code are:
    admin, s2member_level1, s2member_level2 and s2member_level3

    2) The user with the role customer should be redirected to myaccount page of woocomerce.

    If that helps help I have found the following code. With that code if the customer logins from my account page of woocomerce is not redirected to buddypress profile but he is forced to stay in my account page. If he logins from wordpress login page the code doesn't work and the customer goes to Buddypress profile. You may need to combine these 2 codes if you think that it would work

    /*Add LoginOut in primary Menu */
    add_filter( 'wp_nav_menu_items', 'add_loginout_link', 10, 2 );
    function add_loginout_link( $items, $args ) {
    	if (is_user_logged_in() && $args->theme_location == 'primary-menu') {
    			$items .= '
    <a href="'. wp_logout_url( get_permalink( wc_get_page_id( 'myaccount' ) ) ) .'">Log Out</a>
    
    ';
    	}
    	elseif (!is_user_logged_in() && $args->theme_location == 'primary-menu') {
    			$items .= '
    <a href="' . get_permalink( wc_get_page_id( 'myaccount' ) ) . '">Log In</a>';
    	}
    	return $items;
    }

    Thank you,
    Ioannis

  • Sajid

    Hi Ioannis,

    Hope you are doing good :slight_smile:

    No need to use the second code. Try using the following code, it should work for all of your users. Also, I replaced is_site_admin with current_user_can since that function is deprecated and will be removed permanently in future version of WordPress.

    add_filter('login_redirect','bpdev_redirect_to_profile',10,3);
    
    function bpdev_redirect_to_profile($redirect_to_calculated,$redirect_url_specified,$user)
    
    {
    
    	if(empty($redirect_to_calculated))
    		$redirect_to_calculated=admin_url();
    
    	/*if the user is not site admin,redirect to his/her profile*/
    
    	if(current_user_can('administrator')){
    		return $redirect_to_calculated; /*if site admin or not logged in,do not do anything much*/	
    
    	}elseif(current_user_can('customer')){
    
    		return get_permalink( get_option('woocommerce_myaccount_page_id') );
    
    	}else{
    		return bp_core_get_user_domain($user->ID );
    	}
    
    }

    Take care and have a nice day :slight_smile:

    Best Regards,
    Sajid

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.