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);
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.
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?
For anyone reading this, I can confirm that the above code and my plan to use alo_em_get_mailinglists() works.
Problems solved.