コード例 #1
0
 public static function add_new_subscriber($friendly_name, $email_address)
 {
     $error_text = null;
     $friendly_name = sanitize_text_field($friendly_name);
     $email_address = sanitize_text_field($email_address);
     if (strlen($friendly_name) > 255) {
         $error_text = EZP_CS_Utility::__('Name is too long') . '.';
     }
     if (!is_email($email_address) || strlen($email_address) > 255) {
         $error_text = EZP_CS_Utility::__('Email address is not valid') . '.';
     }
     // Note: If error with entity, silently let it go. No sense telling user, just admin.
     if ($error_text == null) {
         $contact = new EZP_Contact_Entity();
         $contact->friendly_name = $friendly_name;
         if ($contact->save()) {
             $email = new EZP_Email_Entity();
             $email->email_address = $email_address;
             $email->contact_id = $contact->id;
             if ($email->save()) {
                 $cse = new EZP_CS_Subscriber_Entity();
                 $cse->contact_id = $contact->id;
                 if (!$cse->save()) {
                     EZP_CS_Utility::debug('add_new_subscriber:Error saving subscriber entity to deleting email and contact');
                     $email->delete();
                     $contact->delete();
                 }
             } else {
                 EZP_CS_Utility::debug('add_new_subscriber:Error saving email entity so deleting contact');
                 $contact->delete();
             }
         } else {
             EZP_CS_Utility::debug('add_new_subscriber:Error saving contact entity');
         }
     }
     return $error_text;
 }