Skip to:
Content
Pages
Categories
Search
Top
Bottom

Get Buddypress username in php and put it in url


  • elan1337
    Participant

    @elan1337

    Hello friends,

    i am using this code to direct users after login to a page:

    <?php
    /**
     * Redirect users to custom URL based on their role after login
     *
     * @param string $redirect
     * @param object $user
     * @return string
     */
     
     
    function wc_custom_user_redirect( $redirect, $user ) {
    	// Get the first of all the roles assigned to the user
    	$role = $user->roles[0];
    
    	$dashboard = admin_url();
    	<strong>$myaccount = 'https://elearningathome.de/mitglieder/';</strong>
    
    	if( $role == 'administrator' ) {
    		//Redirect administrators to the dashboard
    		$redirect = $dashboard;
    	} elseif ( $role == 'shop-manager' ) {
    		//Redirect shop managers to the dashboard
    		$redirect = $dashboard;
    	} elseif ( $role == 'editor' ) {
    		//Redirect editors to the dashboard
    		$redirect = $dashboard;
    	} elseif ( $role == 'author' ) {
    		//Redirect authors to the dashboard
    		$redirect = $dashboard;
    	} elseif ( $role == 'customer' || $role == 'subscriber' ) {
    		//Redirect customers and subscribers to the "My Account" page
    		$redirect = $myaccount;
    	} else {
    		//Redirect any other role to the previous visited page or, if not available, to the home
    		$redirect = wp_get_referer() ? wp_get_referer() : home_url();
    	}
    
    	return $redirect;
    }
    add_filter( 'woocommerce_login_redirect', 'wc_custom_user_redirect', 10, 2 );
    ?>

    Now i want to redirect to a page with the specific username in the url, e.g.

    $myaccount = 'https://elearningathome.de/mitglieder/username/shop';

    i tried bp_displayed_user_username() but don’t know how to put it into the url

    doesn’t work

    please help! thank you very much in advance!

Viewing 1 replies (of 1 total)

  • shanebp
    Moderator

    @shanebp

    What is in $user ?
    It probably has the user ID.
    Try: $myaccount = bp_core_get_user_domain( $user->ID ) . 'shop';

Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.
Skip to toolbar