Last active
July 20, 2020 00:11
-
-
Save KaineLabs/3357ad1584b155dbef090629197f4e58 to your computer and use it in GitHub Desktop.
Allow access to profile to only followers.
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 | |
/** | |
* Allow access to profile to only followers. | |
*/ | |
function yzc_allow_profile_access_to_followers_only() { | |
if ( bp_is_user() ) { | |
// Get Redirect URL. | |
$redirect_url = home_url(); | |
if ( ! is_user_logged_in() ) { | |
wp_redirect( $redirect_url ); | |
exit(); | |
} | |
if ( bp_is_my_profile() || current_user_can( 'administrator' ) ) { | |
return; | |
} | |
if ( ! bp_follow_is_following( array( 'leader_id' => bp_displayed_user_id(), 'follower_id' => bp_loggedin_user_id() ) ) ) { | |
wp_redirect( $redirect_url ); | |
exit(); | |
} | |
} | |
} | |
add_action( 'template_redirect', 'yzc_allow_profile_access_to_followers_only' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment