Auto login

Hello

I have membership plugin with PayPal Express – with Single Payments as payment gateway.

After the user registers and makes the payment he is redirected to the main page of the site. I want that the users should be auto logged in once they are redirected back from paypal.

I already have login redirection in place which will take the user to the specific page i want. So basically what i want is after the successful transaction from paypal the user gets auto logged in and is sent to the page which is configured in login redirection.

I already have the code which is given in the below thread in place in my functions.php

https://premium.wpmudev.org/forums/topic/membership-auto-login

But it is not working. I dont think it is executing this part of code at all. Please guide me how i can achieve this.

Thanks & Regards

Bhavi

  • DavidM
    • DEV MAN’s Mascot

    Hi Bhavi,

    I just gave it a try in the form of a plugin and it worked perfectly with the latest version of Membership and WordPress. Perhaps you could give that method a try instead? Here’s the code I used.

    <?php
    /*
    Plugin Name: Membership auto-login
    Plugin URI: https://premium.wpmudev.org/forums/topic/membership-auto-login
    Description: Autologin after registration
    Version: 1.0
    Author: fuzu42
    Author URI: https://premium.wpmudev.org/forums/topic/membership-auto-login
    License: GPL2
    */

    add_action( 'membership_subscription_form_after_subscriptions', 'membership_autologin' );

    function membership_autologin($user_id) {
    if ($user_id && function_exists('wp_set_auth_cookie') ) {
    wp_set_auth_cookie($user_id);
    }
    else {
    echo 'Does not work!';
    }
    }
    ?>

    Let us know how that goes!

    -David

  • Philip John
    • DEV MAN’s Apprentice

    Hiya,

    Just checking if it was eventually resolved in another thread? Or by yourself separately to us? Or by us over email with you? Or using our live support?

    If so, no need to reply, that’s great news.

    If not, could you let us know by re-opening this topic, and we’ll get onto it and helping you out asap!

    Otherwise, happy days, glad you got it sorted :slight_smile:

    Cheers,

    Phil

  • poltaj
    • Site Builder, Child of Zeus

    Hi there,

    looks like doesn’t work for me…

    I get these 3 erorrs below subscription form after submitting registration form :

    Warning: Cannot modify header information – headers already sent by (output started at /nfs/c09/h02/mnt/130135/domains/mysite.com/html/wp-content/themes/gt2/template_fullwidth.php:7) in /nfs/c09/h02/mnt/130135/domains/mysite.com/html/wp-includes/pluggable.php on line 737

    Warning: Cannot modify header information – headers already sent by (output started at /nfs/c09/h02/mnt/130135/domains/mysite.com/html/wp-content/themes/gt2/template_fullwidth.php:7) in /nfs/c09/h02/mnt/130135/domains/mysite.com/html/wp-includes/pluggable.php on line 738

    Warning: Cannot modify header information – headers already sent by (output started at /nfs/c09/h02/mnt/130135/domains/mysite.com/html/wp-content/themes/gt2/template_fullwidth.php:7) in /nfs/c09/h02/mnt/130135/domains/mysite.com/html/wp-includes/pluggable.php on line 739

    And when user returns from paypal after having paid they are not logged in.

    Can you help?

    Thanks,

    Paolo

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.