コード例 #1
0
 public function sanitize($input)
 {
     $new_input = array();
     if (!empty($input['from_email'])) {
         $new_input['from_email'] = sanitize_text_field($input['from_email']);
     }
     if (!empty($input['from_name'])) {
         $new_input['from_name'] = sanitize_text_field($input['from_name']);
     }
     if (!empty($input['template'])) {
         $new_input['template'] = sanitize_text_field($input['template']);
     }
     if (empty($input['password'])) {
         add_settings_error('Password', esc_attr('password'), 'API Key is required', 'error');
     } else {
         if (SparkPost::is_key_obfuscated(esc_attr($input['password']))) {
             //do not change password
             $new_input['password'] = $this->settings['password'];
         } else {
             $new_input['password'] = sanitize_text_field($input['password']);
         }
     }
     if (isset($input['enable_sparkpost'])) {
         $new_input['enable_sparkpost'] = true;
     } else {
         $new_input['enable_sparkpost'] = false;
     }
     if (empty($input['password']) && $new_input['enable_sparkpost']) {
         add_settings_error('Enable', esc_attr('enable_sparkpost'), 'You must enter API key to enable sending via SparkPost', 'error');
         $new_input['enable_sparkpost'] = false;
     }
     switch (esc_attr($input['sending_method'])) {
         case 'smtp587':
             $new_input['port'] = 587;
             $new_input['sending_method'] = 'smtp';
             break;
         case 'smtp2525':
             $new_input['port'] = 2525;
             $new_input['sending_method'] = 'smtp';
             break;
         default:
             unset($new_input['port']);
             $new_input['sending_method'] = 'api';
             break;
     }
     if (!empty($input['enable_tracking'])) {
         $new_input['enable_tracking'] = true;
     } else {
         $new_input['enable_tracking'] = false;
     }
     if (!empty($input['transactional'])) {
         $new_input['transactional'] = true;
     } else {
         $new_input['transactional'] = false;
     }
     return $new_input;
 }