public static function validate_settings($input, $options = null, $do_errors = false)
 {
     $null_options = false;
     if (is_null($options)) {
         $null_options = true;
         $defaults = static::get_defaults();
         $options = static::form_parts();
         if (is_admin()) {
             if (!empty($input['reset_defaults'])) {
                 foreach ($defaults as $id => $std) {
                     $input[$id] = $std;
                 }
                 unset($input['reset_defaults']);
                 $input['resetted'] = true;
             }
         }
     }
     return Aihrus_Settings::do_validate_settings($input, $options, $do_errors);
 }
 /**
  *
  *
  * @SuppressWarnings(PHPMD.Superglobals)
  */
 public static function validate_settings($input, $options = null, $do_errors = false)
 {
     $validated = parent::validate_settings($input, $options, $do_errors);
     if (empty($do_errors)) {
         $input = $validated;
         $errors = array();
     } else {
         $input = $validated['input'];
         $errors = $validated['errors'];
     }
     $defaults = self::get_defaults();
     if (!empty($_REQUEST['page']) && 'testimonialswidget_settings' == $_REQUEST['page']) {
         if (!empty($input['has_archive'])) {
             $input['has_archive'] = self::prevent_slug_conflict($input['has_archive']);
         } else {
             $input['has_archive'] = $defaults['has_archive'];
         }
         if (!empty($input['rewrite_slug'])) {
             $input['rewrite_slug'] = self::prevent_slug_conflict($input['rewrite_slug']);
         } else {
             $input['rewrite_slug'] = $defaults['rewrite_slug'];
         }
         $flush_rewrite_rules = false;
         // same has_archive and rewrite_slug causes problems
         if ($input['has_archive'] == $input['rewrite_slug']) {
             $input['has_archive'] = $defaults['has_archive'];
             $input['rewrite_slug'] = $defaults['rewrite_slug'];
             $flush_rewrite_rules = true;
         }
         // did URL slugs or taxonomy change?
         $has_archive = tw_get_option('has_archive');
         $rewrite_slug = tw_get_option('rewrite_slug');
         $use_cpt_taxonomy = tw_get_option('use_cpt_taxonomy');
         if ($has_archive != $input['has_archive'] || $rewrite_slug != $input['rewrite_slug'] || $use_cpt_taxonomy != $input['use_cpt_taxonomy']) {
             $flush_rewrite_rules = true;
         }
         if ($flush_rewrite_rules) {
             flush_rewrite_rules();
         }
     }
     $input['version'] = self::$version;
     $input['donate_version'] = Axl_Testimonials_Widget::VERSION;
     $input = apply_filters('tw_validate_settings', $input, $errors);
     if (empty($do_errors)) {
         $validated = $input;
     } else {
         $validated = array('input' => $input, 'errors' => $errors);
     }
     return $validated;
 }
 /**
  *
  *
  * @SuppressWarnings(PHPMD.UnusedLocalVariable)
  */
 public static function display_setting($args = array(), $do_echo = true, $input = null)
 {
     $content = apply_filters('wps_display_setting', '', $args, $input);
     if (empty($content)) {
         $content = parent::display_setting($args, false, $input);
     }
     if (!$do_echo) {
         return $content;
     }
     echo $content;
 }
 public static function define_options_value($setting, $parts)
 {
     $value = $parts['std'];
     switch ($parts['type']) {
         case 'checkbox':
             if (Aihrus_Settings::is_false($value)) {
                 $value = 'false';
             } elseif (Aihrus_Settings::is_true($value)) {
                 $value = 'true';
             } elseif (empty($value)) {
                 $value = esc_html__('TBD empty ') . $parts['type'];
             }
             break;
         case 'select':
             if (empty($value)) {
                 $value = esc_html__('Pick an option');
             }
             break;
         case 'text':
         case 'textarea':
             if (empty($value)) {
                 if ('absint' == self::$value_check) {
                     $value = 10;
                 } elseif ('ids' == self::$value_check) {
                     $value = '3,1,2';
                 } elseif ('intval' == self::$value_check) {
                     $value = 10;
                 } elseif ('min1' == self::$value_check) {
                     $value = 5;
                 } elseif ('nozero' == self::$value_check) {
                     $value = 10;
                 } elseif ('slug' == self::$value_check) {
                     $value = 'slug-name';
                 } elseif ('term' == self::$value_check) {
                     $value = 'termname';
                 } elseif ('terms' == self::$value_check) {
                     if (preg_match('#category|categories#i', $setting)) {
                         $value = esc_html__('Category A, Another category, 123');
                     } else {
                         $value = esc_html__('Tag A, Another tag, 123');
                     }
                 } else {
                     $value = esc_html__('You decide…');
                 }
             }
             break;
         default:
             break;
     }
     self::$value_check = null;
     return $value;
 }
 /**
  *
  *
  * @SuppressWarnings(PHPMD.Superglobals)
  */
 public static function do_validate_settings($input, $options = null, $do_errors = false, $null_options = true)
 {
     $errors = array();
     foreach ($options as $id => $parts) {
         $default = $parts['std'];
         $type = $parts['type'];
         $validations = !empty($parts['validate']) ? $parts['validate'] : array();
         if (!empty($validations)) {
             $validations = explode(',', $validations);
         }
         if (!isset($input[$id])) {
             if ('checkbox' != $type) {
                 $input[$id] = $default;
             } else {
                 $input[$id] = 0;
             }
         }
         if ($default == $input[$id] && !in_array('required', $validations)) {
             continue;
         }
         if ('checkbox' == $type) {
             if (self::is_true($input[$id])) {
                 $input[$id] = 1;
             } else {
                 $input[$id] = 0;
             }
         } elseif (in_array($type, array('radio', 'select'))) {
             // single choices only
             $keys = array_keys($parts['choices']);
             if (!in_array($input[$id], $keys)) {
                 if (self::is_true($input[$id])) {
                     $input[$id] = 1;
                 } else {
                     $input[$id] = 0;
                 }
             }
         }
         if (!empty($validations)) {
             foreach ($validations as $validate) {
                 self::validators($validate, $id, $input, $default, $errors);
             }
         }
     }
     unset($input['export']);
     unset($input['import']);
     $hide_update_notice = false;
     if (isset(static::$hide_update_notice) && !empty(static::$hide_update_notice)) {
         $hide_update_notice = true;
     }
     if ($null_options && empty($errors) && !$hide_update_notice && !empty($_REQUEST['option_page'])) {
         add_settings_error(static::ID, 'settings_updated', esc_html__('Settings saved.'), 'updated');
         if (empty(self::$settings_saved)) {
             self::$settings_saved = true;
             set_transient('settings_errors', get_settings_errors(), 30);
         }
     }
     if (empty($do_errors)) {
         $validated = $input;
     } else {
         $validated = array('input' => $input, 'errors' => $errors);
     }
     return $validated;
 }