Created
April 6, 2018 17:55
-
-
Save webprogramacion/19a5ebe75c86e506989e6dc3b7196470 to your computer and use it in GitHub Desktop.
Alta de un shortcode en WordPress para redirigir un usuario en función a su rol
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
add_shortcode('sc_redireccion_personalizada', 'redireccion_personalizada'); | |
function redireccion_personalizada() | |
{ | |
$usuario = new WP_User(get_current_user_id()); | |
if( $usuario && is_object( $usuario ) && is_a( $usuario, 'WP_User' ) ) | |
{ | |
switch ($usuario->roles[0]) | |
{ | |
case 'administrator': | |
$url = admin_url(); | |
echo '<script> window.location="'.$url.'"; </script>'; | |
break; | |
case 'rol_que_sea': | |
$url = "https://...url...destino..."; | |
echo '<script> window.location="'.$url.'"; </script>'; | |
break; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment