• Resolved flaviese

    (@flaviese)


    Following this article https://kb.mailpoet.com/article/195-add-subscribers-through-your-own-form-or-plugin#addSubscriber I am trying to add a user to a list, but it goes the the default wordpress user’s list only.

    Here is the code used in our functions.php in child theme, using the “user_register” hook.

    We are using mailpoet 3.18.1 on a premium license (I don’t know if I can write here or I nedd to open a ticket, in case let me know).

    ///////////////////////////////////////////////////////////////////////////////

    add_action( ‘user_register’, ‘es_registration_save’, 10, 1 );

    function es_registration_save( $user_id ) {

    $Email = $_POST[‘user_email’];

    $firstName = $_POST[‘cimy_uef_wp_FIRSTNAME’];

    $lastName = $_POST[‘cimy_uef_wp_LASTNAME’];

    $Nation = $_POST[‘cimy_uef_NATION’];

    $newsletter = $_POST[‘cimy_uef_NEWSLETTER’];

    if (!isset($newsletter) || empty($newsletter)){

    // return “error”;

    } else {

    $subscriber_data = array(

    ’email’ => sanitize_text_field($Email),

    ‘first_name’ => sanitize_text_field($firstName),

    ‘last_name’ => sanitize_text_field($lastName)

    );

    if ($Nation == ‘Italy’) {

    $lists = array(11);

    } else {

    $lists = array(10);

    }

    try {

    $subscriber = \MailPoet\API\API::MP(‘v1’)->addSubscriber($subscriber_data, $lists, $options);

    } catch(Exception $exception) {

    // return $exception->getMessage();

    }

    }

    }

    //////////////////////////////////////////////////////////////////////////////

    The result is that the user is not added to one of the two lists (id 10 or 11) but only to the default WordPress users only.

    Flavio

Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘subscribe a user to a particular list when he registers as a WP user’ is closed to new replies.