Last active
September 23, 2022 18:50
-
-
Save scottopolis/6fca3bb8000725b2fb5cfaa7d80b17a1 to your computer and use it in GitHub Desktop.
BuddyPress Profile redirect
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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