I need to programatically in php subscribe a new user to all or selected mailing lists... I've trying with the below code but am making some mistake... I think I'm not specifying the list correctly in the last update()... but I've tried specifying just one list (id, and name)... but can't get anything to work.
$output = $wpdb->update( "{$wpdb->prefix}easymail_subscribers",
array ( 'active' => 1, 'email' => $user_email, 'lang' => "en"), // or cs 'name' => $name, ), // 1 = subscribe
array ( 'ID' => $user_id)
);
// code copyied from aol_easymail_function.alo_em_add_subscriber_to_list ( $subscriber, $list ) {
$list = 1;
$mailinglists = alo_em_get_mailinglists( 'public' );
$subscriber = $user_id;
foreach ($mailinglists as $l => $val) {
error_log("* * * * * * * * * * * * " . $l . "->" .$val );
foreach ($val as $k => $v){
error_log($k . "->" .$v );
error_log(implode(",", $v));
}
}
$user_lists = alo_em_get_user_mailinglists ( $subscriber );
if ( $user_lists && in_array($list, $user_lists) ) return; // if already, exit
$user_lists[] = $list; // add the list
asort ( $user_lists ); // order id from min to max, 1->9
$updated_lists = implode ( "|", $user_lists );
$updated_lists = "|".$updated_lists."|";
$wpdb->update( "{$wpdb->prefix}easymail_subscribers", array ( 'lists' => $mailinglists ), array ( 'ID' => $subscriber ) );
p.s Great plugin ;) Thanks
Neil
