Last active
November 24, 2024 17:11
-
-
Save gugaalves/3d4b72dc2f4d63d6ab42 to your computer and use it in GitHub Desktop.
Redirecionar usuários
This file contains hidden or 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
//Redirecionar o usuário após o login | |
function redirect_user_login() { | |
if (!current_user_can('manage_woocommerce')) { | |
$url = home_url(); //redirecionar pra home | |
return $url | |
} | |
} | |
add_filter( 'login_redirect', 'redirect_user_login', 10, 3 ); | |
// Redirecionar quem tentar entrar no wp-admin | |
function redirect_non_admin_users() { | |
if ( ! current_user_can( 'manage_woocommerce' ) && '/wp-admin/admin-ajax.php' != $_SERVER['PHP_SELF'] ) { | |
// Se não for admin nem estiver tentando acessar arquivos via ajax | |
show_admin_bar(false); | |
wp_redirect( home_url() ); | |
exit; | |
} | |
} | |
add_action( 'admin_init', 'redirect_non_admin_users' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment