• Resolved batman42ca

    (@batman42ca)


    I have a custom registration form that permits the user to register for various programs. Each program has it’s own mailing list so based on the selected program, I want my code to add the user to the appropriate mailing list.

    It looks like I need to call:

    alo_em_add_subscriber_to_list ( $subscriber->ID, $list_id );

    $list_id. I understand, but since the user will not be logged into WordPress, what do I use for $subscriber->ID?

    The other way, I guess, is to directly add a record to the “wp_easymail_subscribers” database table. For the “unikey” field, can I just use UUID() from Mysql?

    http://ww.wp.xz.cn/extend/plugins/alo-easymail/

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

    (@eventualo)

    Here you are the right sequence:

    $fields['email'] = $email; // from your custom form
    $fields['name'] = $name; // from your custom form
    $lang = ''; // language, optional: 2 letters code, e.g. "en"
    if ( alo_em_add_subscriber( $fields, 1, $lang ) == "OK" )
    {
        $subscriber_id = alo_em_is_subscriber ( $email );
        alo_em_add_subscriber_to_list ( $subscriber_id, $list_id );
    }

    Otherwise, of course, insert directly in database table. About “unikey”, you should create a random alphanumeric string (the plugin checks allow only letters and numbers). In php I’m using:

    $unikey = substr(md5(uniqid(rand(), true)), 0,24);

    Thread Starter batman42ca

    (@batman42ca)

    Thanks for the response. That’s very helpful.

    One further question. Only knowing the name of the mailing list, where can I look up the id of the list? The list ids will be dependent on the order in which they were added to WordPress. I’d rather not hard code those numbers. I like to use the name of the mailing list instead.

    I’ve poked around the WordPress database tables but I haven’t found where that information is stored yet.

    Thread Starter batman42ca

    (@batman42ca)

    I should clarify. I know where to see the mailing list id’s for myself. What I mean is, someone selects a program from my form and the name of the program is also the name of the mailing list. I could create my own look up table of hard coded numbers to translate a program name to a mailing list id, but I’d rather be able to use a mailing list name to look up the mailing list id in the database.

    Should I call alo_em_get_mailinglists() and loop through the returned array looking for an entry matching the mailing list name and get the mailing list id from that?

    Thread Starter batman42ca

    (@batman42ca)

    For anyone reading this, I can confirm that the above code and my plan to use alo_em_get_mailinglists() works.

    Problems solved.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘programmatically adding subscribers’ is closed to new replies.