add_error() 공개 메소드

Add an error to this form
public add_error ( string $error_code )
$error_code string
 /**
  * @param MC4WP_Form $form
  */
 public function process_unsubscribe_form(MC4WP_Form $form)
 {
     $api = $this->get_api();
     $result = null;
     foreach ($form->get_lists() as $list_id) {
         $result = $api->unsubscribe($list_id, $form->data['EMAIL']);
     }
     if (!$result) {
         // not subscribed is a soft-error
         if (in_array($api->get_error_code(), array(215, 232))) {
             $form->add_error('not_subscribed');
             $this->get_log()->info(sprintf('Form %d > %s is not subscribed to the selected list(s)', $form->ID, $form->data['EMAIL']));
         } else {
             $form->add_error('error');
             $this->get_log()->error(sprintf('Form %d > MailChimp API error: %s', $form->ID, $api->get_error_message()));
         }
     }
     /**
      * Fires right after a form was used to unsubscribe.
      *
      * @since 3.0
      *
      * @param MC4WP_Form $form Instance of the submitted form.
      */
     do_action('mc4wp_form_unsubscribed', $form);
 }
 /**
  * @param MC4WP_Form $form
  */
 public function process_unsubscribe_form(MC4WP_Form $form)
 {
     $api = $this->get_api();
     $result = null;
     foreach ($form->get_lists() as $list_id) {
         $result = $api->unsubscribe($list_id, $form->data['EMAIL']);
     }
     if (!$result) {
         $form->add_error(in_array($api->get_error_code(), array(215, 232)) ? 'not_subscribed' : 'error');
     }
     /**
      * Fires right after a form was used to unsubscribe.
      *
      * @since 3.0
      *
      * @param MC4WP_Form $form Instance of the submitted form.
      */
     do_action('mc4wp_form_unsubscribed', $form);
 }
예제 #3
0
 /**
  * @param MC4WP_Form $form
  * @param MC4WP_Request $request
  */
 public function process_unsubscribe_form(MC4WP_Form $form, MC4WP_Request $request = null)
 {
     $mailchimp = new MC4WP_MailChimp();
     $log = $this->get_log();
     $result = null;
     $data = $form->get_data();
     // unsubscribe from each list
     foreach ($form->get_lists() as $list_id) {
         // TODO: Check if on list before proceeding with unsubscribe call?
         $result = $mailchimp->list_unsubscribe($list_id, $data['EMAIL']);
     }
     if (!$result) {
         $form->add_error('error');
         $log->error(sprintf('Form %d > MailChimp API error: %s', $form->ID, $mailchimp->get_error_message()));
         // bail
         return;
     }
     // Success! Unsubscribed.
     $form->add_message('unsubscribed');
     $log->info(sprintf("Form %d > Successfully unsubscribed %s", $form->ID, $data['EMAIL']));
     /**
      * Fires right after a form was used to unsubscribe.
      *
      * @since 3.0
      *
      * @param MC4WP_Form $form Instance of the submitted form.
      */
     do_action('mc4wp_form_unsubscribed', $form);
 }