Last active
May 25, 2019 18:45
-
-
Save KaineLabs/be2cdc05589253cf1c0f749c9f05dcd8 to your computer and use it in GitHub Desktop.
Redirect User Profile Page URL
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 | |
/** | |
* Redirect User Profile Page URL | |
*/ | |
function yzc_redirect_user_profile_url() { | |
if ( current_user_can( 'administrator' ) ) { | |
return false; | |
} | |
global $pagenow; | |
if ( $pagenow == 'profile.php' ) { | |
// Get User ID. | |
$user_id = bp_loggedin_user_id(); | |
// Get Current User Domain. | |
$user_domain = bp_core_get_user_domain( $user_id ); | |
// Get Profile Url. | |
$profile_url = $user_domain . bp_get_profile_slug() . '/'; | |
// Redirect to profile. | |
wp_redirect( $profile_url ); | |
exit; | |
} | |
} | |
add_action( 'admin_init' , 'yzc_redirect_user_profile_url' ); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm a noob, how do I integrate this to my site? I downloaded a plugin to turn the code into a shortcode, inserted it into a page, but no luck.
I also uploaded this code in a file called "profile.php" to my current themes dir, not sure how to call it though. Do I need to change anything in the code to get it to work?