Created
January 27, 2023 00:49
-
-
Save KaineLabs/8741d4cfdfdf1702d73a2a4e9870c589 to your computer and use it in GitHub Desktop.
yzc_redirect_tab.php
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 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