Skip to content

Instantly share code, notes, and snippets.

@KaineLabs
Created January 27, 2023 00:49
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/8741d4cfdfdf1702d73a2a4e9870c589 to your computer and use it in GitHub Desktop.
Save KaineLabs/8741d4cfdfdf1702d73a2a4e9870c589 to your computer and use it in GitHub Desktop.
yzc_redirect_tab.php
<?php
/**
* Redirect Custom Tab
**/
function yzc_redirect_tab() {
if ( ! is_user_logged_in() || bp_current_component() != 'visitors' ) {
return;
}
$redirect_url = 'https:/google.com';
// Get roles that cannot have visitors tab.
$restricted_roles = get_option( 'yzbpv_restricted_visitors_tab_roles_list' );
if ( ! empty( $restricted_roles ) ) {
// Get Current User Data.
$user = get_userdata( bp_loggedin_user_id() );
// Get User Roles.
$user_roles = (array) $user->roles;
foreach( $user_roles as $key => $role ) {
if ( in_array( $role, $restricted_roles ) ) {
wp_redirect( $redirect_url );
exit;
}
}
}
}
add_action( 'bp_init', 'yzc_redirect_tab', 100);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment