• Resolved pixluser

    (@pixluser)


    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)
  • Plugin Support Neha Sharma

    (@nehamysharma)

    Hi @pixluser,

    EDIT : FIXED, this works:

    That’s great news! Thanks a lot for sharing what worked for you! I realize it’s been quite some time since you first opened this thread, and we appreciate your patience (and persistence!) in getting it sorted out.

    It’s always rewarding to see a thread come full circle, and your update will definitely help others who might be looking for the same solution down the road.

    Appreciate your patience and the time you took to follow up on this. We’ll mark the topic as resolved, but you’re always welcome to jump back in if you’d like to share more or have new questions come up.

Viewing 1 replies (of 1 total)

You must be logged in to reply to this topic.