Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KaineLabs/3357ad1584b155dbef090629197f4e58 to your computer and use it in GitHub Desktop.
Save KaineLabs/3357ad1584b155dbef090629197f4e58 to your computer and use it in GitHub Desktop.
Allow access to profile to only followers.
<?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