function alo_em_save_profile_optin($user_id) { if (!current_user_can('edit_user', $user_id)) { return false; } $user_info = get_userdata($user_id); $user_email = $user_info->user_email; if (isset($_POST['alo_easymail_option'])) { if ($_POST['alo_easymail_option'] == "yes") { // if changed name and lastname if (isset($_POST['first_name']) && $user_info->first_name != $_POST['first_name']) { $user_first_name = stripslashes(trim($_POST['first_name'])); } else { $user_first_name = $user_info->first_name; } if (isset($_POST['last_name']) && $user_info->last_name != $_POST['last_name']) { $user_last_name = stripslashes(trim($_POST['last_name'])); } else { $user_last_name = $user_info->last_name; } $fullname = $user_first_name . " " . $user_last_name; // if changed email if (isset($_POST['email']) && is_email($_POST['email']) && $user_email != $_POST['email']) { $user_email = stripslashes(trim($_POST['email'])); } $fields = array(); //edit : added all this foreach $alo_em_cf = alo_easymail_get_custom_fields(); if ($alo_em_cf) { foreach ($alo_em_cf as $key => $value) { //check if custom fields have been changed if (isset($_POST["alo_em_" . $key])) { $fields[$key] = stripslashes(trim($_POST["alo_em_" . $key])); } } } // Is already subscriber? update or insert $todo_update = alo_em_is_subscriber($user_info->user_email) > 0 ? true : false; if ($todo_update) { //alo_em_update_subscriber_by_email ( $user_info->user_email, $user_email, $fullname, 1, alo_em_get_language(true) ); //$fields['old_email'] = $user_info->user_email; //edit : added all this line $fields['email'] = $user_email; //edit : added all this line $fields['name'] = $fullname; //edit : added all this line if (alo_em_update_subscriber_by_email($user_info->user_email, $fields, 1, alo_em_get_language(true))) { //edit : orig : if ( alo_em_update_subscriber_by_email ( $user_info->user_email, $user_email, $fullname, 1, alo_em_get_language(true) ) ) { $subscriber = alo_em_get_subscriber($user_email); alo_em_update_subscriber_last_act($user_email); do_action('alo_easymail_subscriber_updated', $subscriber, $user_info->user_email); } } else { $fields['email'] = $user_email; //edit : added all this line $fields['name'] = $fullname; //edit : added all this line alo_em_add_subscriber($fields, 1, alo_em_get_language(true)); //edit : orig: alo_em_add_subscriber( $user_email, $fullname, 1, alo_em_get_language(true) ); do_action('alo_easymail_new_subscriber_added', alo_em_is_subscriber($user_email), $user_id); } // if subscribing, save also lists $mailinglists = alo_em_get_mailinglists('public'); if ($mailinglists) { $subscriber_id = alo_em_is_subscriber($user_email); foreach ($mailinglists as $mailinglist => $val) { if (isset($_POST['alo_em_profile_lists']) && is_array($_POST['alo_em_profile_lists']) && in_array($mailinglist, $_POST['alo_em_profile_lists'])) { alo_em_add_subscriber_to_list($subscriber_id, $mailinglist); // add to list } else { alo_em_delete_subscriber_from_list($subscriber_id, $mailinglist); // remove from list } } } } else { alo_em_delete_subscriber_by_id(alo_em_is_subscriber($user_email)); alo_em_add_email_in_unsubscribed($user_email); } } }