BuddyPress commone link to user/member profile

I need add static link to menu for redirect user to profile BuddyPress. But BP have only individual links for each user.

I writed short snippet for add root endpoint /my-profile/ and redirect to user profile.


//Add root endpoint /my-profile/
function wpcc_add_redirect_endpoint() {
    add_rewrite_endpoint( 'my-profile', EP_ROOT );
}
add_action( 'init', 'wpcc_add_redirect_endpoint' );

//Add redirect for endpoint
function wpcc_profile_redirect(){
  $check = get_query_var('my-profile', false);

  if($check === ''){
    wp_redirect(bp_loggedin_user_domain(get_current_user_id()));
  }
}
add_action( "template_redirect", 'wpcc_profile_redirect' );

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s