コード例 #1
0
 /**
  * Validate the option
  *
  * @param  array $dirty New value for the option
  * @param  array $clean Clean value for the option, normally the defaults
  * @param  array $old   Old value of the option
  *
  * @todo remove code using $short, there is no "short form" anymore.
  *
  * @return  array      Validated clean value for the option to be saved to the database
  */
 protected function validate_option($dirty, $clean, $old)
 {
     // Have we receive input from a short (license only) form ?
     $short = isset($dirty['short_form']) && $dirty['short_form'] === 'on' ? true : false;
     // Prepare an array of valid data types and taxonomies to validate against
     $valid_data_types = array_keys($this->valid_data_types);
     $valid_taxonomies = array();
     $taxonomies = get_object_taxonomies('product', 'objects');
     if (is_array($taxonomies) && $taxonomies !== array()) {
         foreach ($taxonomies as $tax) {
             $tax_name = strtolower($tax->name);
             $valid_data_types[] = $tax_name;
             $valid_taxonomies[] = $tax_name;
         }
     }
     unset($taxonomies, $tax, $tax_name);
     foreach ($clean as $key => $value) {
         switch ($key) {
             case 'dbversion':
                 $clean[$key] = $this->db_version;
                 break;
             case 'data1_type':
             case 'data2_type':
                 if (isset($dirty[$key])) {
                     if (in_array($dirty[$key], $valid_data_types, true)) {
                         $clean[$key] = $dirty[$key];
                     } else {
                         if (sanitize_title_with_dashes($dirty[$key]) === $dirty[$key]) {
                             // Allow taxonomies which may not be registered yet
                             $clean[$key] = $dirty[$key];
                         }
                     }
                 } else {
                     if ($short && isset($old[$key])) {
                         if (in_array($old[$key], $valid_data_types, true)) {
                             $clean[$key] = $old[$key];
                         } else {
                             if (sanitize_title_with_dashes($old[$key]) === $old[$key]) {
                                 // Allow taxonomies which may not be registered yet
                                 $clean[$key] = $old[$key];
                             }
                         }
                     }
                 }
                 break;
             case 'schema_brand':
             case 'schema_manufacturer':
                 if (isset($dirty[$key])) {
                     if (in_array($dirty[$key], $valid_taxonomies, true)) {
                         $clean[$key] = $dirty[$key];
                     } else {
                         if (sanitize_title_with_dashes($dirty[$key]) === $dirty[$key]) {
                             // Allow taxonomies which may not be registered yet
                             $clean[$key] = $dirty[$key];
                         }
                     }
                 } else {
                     if ($short && isset($old[$key])) {
                         if (in_array($old[$key], $valid_taxonomies, true)) {
                             $clean[$key] = $old[$key];
                         } else {
                             if (sanitize_title_with_dashes($old[$key]) === $old[$key]) {
                                 // Allow taxonomies which may not be registered yet
                                 $clean[$key] = $old[$key];
                             }
                         }
                     }
                 }
                 break;
                 /* boolean (checkbox) field - may not be in form */
             /* boolean (checkbox) field - may not be in form */
             case 'breadcrumbs':
             case 'hide_columns':
             case 'metabox_woo_top':
                 if (isset($dirty[$key])) {
                     $clean[$key] = WPSEO_WooCommerce_Wrappers::validate_bool($dirty[$key]);
                 } else {
                     if ($short && isset($old[$key])) {
                         $clean[$key] = WPSEO_WooCommerce_Wrappers::validate_bool($old[$key]);
                     } else {
                         $clean[$key] = false;
                     }
                 }
                 break;
         }
     }
     return $clean;
 }