
// ✅ Force redirect after social login success → Homepage
add_filter( 'nsl_login_redirect_url', function( $url, $provider ) {
    return home_url( '/' );
}, 10, 2 );

// ✅ When registration is disabled, force redirect → custom login page
add_filter( 'nsl_registration_blocked_redirect_url', function( $url, $provider ) {
    return home_url( '/login/' ); // change /login/ to your actual login page slug
}, 10, 2 );

// ✅ Catch WordPress default wp-login redirect and override
add_action( 'login_init', function() {
    if ( isset($_GET['registration']) && $_GET['registration'] === 'disabled' ) {
        wp_redirect( home_url( '/login/?nsl_error=registration_disabled' ) );
        exit;
    }
});

// ✅ Show a styled error message below header (French version)
add_action( 'wp_body_open', function() {
    if ( isset($_GET['nsl_error']) && $_GET['nsl_error'] === 'registration_disabled' ) {
        echo '<div style="
            background:#ffebeb;
            color:#b30000;
            text-align:center;
            padding:12px;
            font-weight:bold;
            border-bottom:2px solid #b30000;
        ">
            🚫 Veuillez vous connecter avec un compte existant ou <a href="https://www.holistic-babe.fr/register/" style="color:#b30000; text-decoration:underline;">inscrivez-vous ici</a>.
        </div>';
    }
});
