Skip to content

Instantly share code, notes, and snippets.

@scottopolis
Last active September 23, 2022 18:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scottopolis/6fca3bb8000725b2fb5cfaa7d80b17a1 to your computer and use it in GitHub Desktop.
Save scottopolis/6fca3bb8000725b2fb5cfaa7d80b17a1 to your computer and use it in GitHub Desktop.
BuddyPress Profile redirect
<?php
function appp_redirect() {
global $wp;
$current_url = home_url( $wp->request );
$string = apply_filters( 'ap3_bp_me_url', '/me/' );
$me = stripos( $current_url, $string );
if( $me !== false ) {
$user = wp_get_current_user();
if( $user->exists() ) {
$url = str_replace( $string,'/' . bp_core_get_username($user->ID) . '/', $current_url );
wp_redirect( $url );
exit();
} else {
// instead of redirecting home, show login modal and refresh current page
wp_redirect( apply_filters( 'ap3_bp_redirect', home_url() ) );
exit();
}
}
}
add_action( 'wp', 'appp_redirect' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment