• Resolved jbonlinea

    (@jbonlinea)


    Hi there,

    I’ve been digging into your module for a little while and really enjoy it, the way it integrated into wordpress is just awesome !

    Now I would like to programmatically subscribe/unsubscribe user to lists.
    According to your documentation , there is no need for the API extension to use the TNP class, which should perfectly fit my needs.

    I’ve thus tried a code example you provide with partial success. Indeed this code copied for the above linked documentation page, TNP::subscribe(['email'=>'[email protected]', 'name'=>'My name', 'gender'=>'f', 'lists' => [2,12]]); do indeed add a subscriber with its name and email, but not add it to any list.

    I’ve tried to simply the code like this TNP::subscribe(['email'=>'[email protected]', 'lists' => [1]]); but withut success.

    In the same vein, I’ve tried to unsubscribe a user from a list like this TNP::unsubscribe(['email'=>'[email protected]', 'lists' => [1]]);. This happens to change the subscriber statute from confirmed to un-subscribed on the subscriber general tab, but do not change its subscription to a given list.
    Also, , I manually added a subscriber to a list, and then trigged this later snippet, and the behaviour is exactly the same as above.

    Ok I’ve noted that you now have a API V2, but I’m more confortable using the TNP class.

    Could you please help me sort that with the TNP class, or provide me a very basic example of usage of the new API (I’m fine for creating an api key), but would really appreciate an example of usage in a php file.

    Thank’s in advance for your support

    Regards

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Roberto Fietta

    (@webagile)

    Hi, and thank you for contacting our support.

    Please check your lists configuration, lists must have a name and be set to something different than “private”.

    Regards,
    Roberto

    Thread Starter jbonlinea

    (@jbonlinea)

    Hi,

    Thank’s for your reply
    Ok if the list must be public, then there is at least one reason for the above code to fail.
    But I really don’t want the list to be public, and thus used your wordpress user plug-in a a starting point, and have seen that there is a class Newsletter which seems to provide much more possibilities than TNP.

    The weird thing is that I couldn’t find any documentation on this class, thus I “reversed engineered” based on your wordpress user plug-in to find out that these very few line of code can unlock many situations

    Case when Newsletter-Subscriber is linked to Wp-User

    
    // you'll need to populate this vars with a wp user id
    // $user_id 
    // get the subscriber thank's to its linked wp_user ID
    $subscriber = Newsletter::instance()->get_user_by_wp_user_id($user_id);
    
    //  create an array that you'll use to update the subscriber
    $nl_user = array();
    
    // specify which subscriber you'll update
    $nl_user['id'] = $subscriber->id; 
    
    // populated the array with the values you want (not all of them are needed)
    $nl_user['email'] = '[email protected]'; // update the subscriber
    $nl_user['status'] = 'C'; // update the subscriber statute ; C for confirmed S for unconfirmed
    $nl_user['list_1'] = 1; // subscribe the subscriber to list_1 ; to unsbubsciber from the list set the value to 0
    
    // save the subscriber
    Newsletter::instance()->save_user($nl_user);

    if your subscriber is not linked to a wp user, just select it thank’s to his email,

    
    $subscriber_email= '[email protected]';
    $subscriber = Newsletter::instance()->get_user(Newsletter::instance()->normalize_email($subscriber_email));

    Now I have two question :
    Is there any documentation about the Newsletter Class, and if not why ?

    If the recommended way to achieve this is through the API Rest V2, could you kindly provide a snippet in the same veins as above ? it would most certainty enable many to actually use the API which documentation lacks a basic PHP and JS example/boilerplate

    Regards

    • This reply was modified 3 years ago by jbonlinea.
    • This reply was modified 3 years ago by jbonlinea.
    Thread Starter jbonlinea

    (@jbonlinea)

    hi,

    May I ask if there is any documention on the the Newsletter Class, or if it is not advised to use it, if you could provide here or on the documentation (the later might even be better) a basic php example of the api rest usage ?

    Thank’s in advance

    Plugin Author Roberto Fietta

    (@webagile)

    You can find all the available documentation at https://www.thenewsletterplugin.com/documentation/developers/

    For other type of use, like inner classes, we don’t provide documentation but you can dig into the code and make your own tests.

    Regards,
    Roberto

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Progamatically subscribe / unsbscribe to list’ is closed to new replies.