1 | <?php |
---|
2 | function bp_universal_profile_redirect_catch_uri() { |
---|
3 | // Allow for internationalization. |
---|
4 | $me_string = __( 'me', 'buddypress' ); |
---|
5 | // Or direct filtration. |
---|
6 | $me_string = apply_filters( 'bp_universal_user_profile_slug', $me_string ); |
---|
7 | |
---|
8 | // Catch URIs that start with the 'me string' and redirect to the user's profile. |
---|
9 | if ( strpos( $_SERVER['REQUEST_URI'], '/' . $me_string . '/' ) === 0 ) { |
---|
10 | |
---|
11 | if ( $current_user_id = get_current_user_id() ) { |
---|
12 | // For logged-in users, we replace '/myprofile/' and send them to their user domain. |
---|
13 | $target = bp_loggedin_user_domain() . str_replace( '/' . $me_string . '/', '', $_SERVER['REQUEST_URI'] ); |
---|
14 | } else { |
---|
15 | // If the user is not logged in, we send them to login screen |
---|
16 | // with the redirect args set to return them here. Then, case #1 kicks in. |
---|
17 | $target = wp_login_url( ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER["HTTP_HOST"] . $_SERVER['REQUEST_URI'] ); |
---|
18 | } |
---|
19 | |
---|
20 | bp_core_redirect( $target ); |
---|
21 | exit; |
---|
22 | |
---|
23 | } |
---|
24 | } |
---|
25 | add_action( 'bp_init', 'bp_universal_profile_redirect_catch_uri', 9 ); |
---|