Skip to content

Instantly share code, notes, and snippets.

@paulgibbs
Created July 9, 2014 08:49
Show Gist options
  • Save paulgibbs/cdcad706ac11d8e3b628 to your computer and use it in GitHub Desktop.
Save paulgibbs/cdcad706ac11d8e3b628 to your computer and use it in GitHub Desktop.
add a dynamic member profile link structure to BuddyPress. Untested. YYMV.
<?php
// .com/my/profile/edit --> .com/members/paulgibbs/profile/edit
function maybe_redirect_all_the_things() {
if ( ! is_user_logged_in() ) {
return;
}
$request = parse_url( $_SERVER ['REQUEST_URI'] );
if ( ! $request ) {
return;
}
$request['path'] = trim( $request_path['path'], '/\\' );
$path = explode( '/', $request['path'] );
// Intercept URLs starting with /my/.
if ( array_shift( $path ) !== 'my' ) {
return;
}
$new_path = implode( '/', $path );
$new_query = isset( $request['query'] ) ? "?{$request['query']}" : '';
// Build the URL to redirect to.
$new_url = sprintf(
'%s/%s/%s',
bp_loggedin_user_domain(),
$new_path,
$new_query
);
bp_core_redirect( esc_url_raw( $new_url ) );
exit;
}
add_action( 'bp_template_redirect', 'maybe_redirect_all_the_things', 1 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment