Redirections
-
Hello how to make redirection after login (if using only the button from wp-login.php page by example, without addind any page parameter inside the shortcode) ?
EDIT : FIXED, this works:
/ 🔒 1. Empêche la redirection par défaut du plugin vers /wp-admin
add_filter('rtcamp.google_default_redirect', function($url) {
return home_url('/'); // fallback par défaut
});
// 🧠 2. Gère la redirection personnalisée avec ?redirect_to=...
add_action('rtcamp.google_user_logged_in', 'hello_google_login_redirect', 10, 2);
function hello_google_login_redirect($user_wp, $user_google) {
if (!($user_wp instanceof WP_User)) return;
// ✅ Sécurité : empêcher redirection multiple
if (isset($_COOKIE['google_redirect_done'])) return;
setcookie('google_redirect_done', '1', time() + 3600, '/');
// ✅ Redirection sécurisée vers redirect_to si présent
$redirect = $_GET['redirect_to'] ?? $_REQUEST['redirect_to'] ?? '';
if (!empty($redirect)) {
$redirect = urldecode($redirect);
// ✅ Autorise URL relative ou absolue interne uniquement
if (strpos($redirect, 'http') !== 0 || strpos($redirect, home_url()) === 0) {
$final_url = (strpos($redirect, 'http') === 0) ? $redirect : home_url($redirect);
wp_safe_redirect($final_url);
exit;
}
}
// 🎯 Sinon, redirection par rôle
if (in_array('contributor', (array) $user_wp->roles)) {
wp_safe_redirect(home_url('/'));
exit;
}
if (in_array('administrator', (array) $user_wp->roles)) {
wp_safe_redirect(home_url('/'));
exit;
}
if (in_array('subscriber', (array) $user_wp->roles)) {
wp_safe_redirect(home_url('/'));
exit;
}
// 🧭 Fallback générique
wp_safe_redirect(home_url('/'));
exit;
}
// 🔁 3. Supprime le cookie à la déconnexion pour permettre redirection future
add_action('wp_logout', function() {
setcookie('google_redirect_done', '', time() - 3600, '/');
});It work now.
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
You must be logged in to reply to this topic.