/** * Stores the localization object to localize theme options' scripts. * @since 1.6 */ function ar2_theme_options_localize_vars() { $current = isset($_GET['opt_type']) ? esc_attr($_GET['opt_type']) : ''; $_vars = array('changedConfirmation' => __('If you have made any changes in the fields without submitting, all changes will be lost.', 'ar2'), 'ajaxurl' => admin_url('admin-ajax.php'), 'hintText' => __('Start by entering a term here.', 'ar2'), 'noResultsText' => __('No results.', 'ar2'), 'searchingText' => __('Searching...', 'ar2'), 'uploadMediaTitle' => __('Upload Media', 'ar2'), 'isNewMediaManager' => false); if (function_exists('wp_enqueue_media')) { $_vars['isNewMediaManager'] = true; } $_fields = ar2_theme_options_default_fields(); foreach ($_fields as $id => $args) { if ($args['type'] == 'cat-dropdown') { $_taxonomy_id = isset($args['taxonomy_id']) ? $args['taxonomy_id'] : str_replace('[terms]', '[taxonomy]', $args['setting']); $_vars[$id] = ar2_prep_term_js_vars($args['setting'], $_taxonomy_id); } } return apply_filters('ar2_theme_options_localize_vars', $_vars); }
/** * Sanitize and validate form input. Accepts an array, return a sanitized array. * @todo: Needs cleaning up. * @since 1.6 */ function ar2_theme_options_validate($input) { $output = ar2_flush_theme_options(); $defaults = ar2_get_default_theme_options(); if (isset($input['reset'])) { // Reset theme options to default settings. ar2_reset_theme_options(); add_settings_error('reset', 'ar2-theme-options-reset', __('Your settings have been reverted to the defaults.', 'ar2'), 'updated'); return $defaults; } else { if (isset($input['import_theme_options']) && $input['import_theme_options'] != '') { // Import theme options from user input. $output = json_decode($input['import_theme_options'], true); add_settings_error('import_theme_options', 'ar2-theme-options-import', __('Your settings have been successfully imported.', 'ar2'), 'updated'); return $output; } else { if (isset($input['submit'])) { /* Validation for theme options page. Refer to WordPress Codex on Data Validation: * http://codex.wordpress.org/Data_Validation */ $setting_fields = ar2_theme_options_default_fields(); unset($input['export_theme_options']); unset($input['import_theme_options']); foreach ($input as $id => $value) { if (isset($setting_fields[$id])) { switch ($setting_fields[$id]['type']) { case 'thumbnail-size': $sanitized_val = array('w' => is_numeric($value['w']) ? absint($value['w']) : 0, 'h' => is_numeric($value['h']) ? absint($value['h']) : 0); break; case 'cat-dropdown': $sanitized_val = ar2_theme_options_validate_terms_input($value); break; case 'taxonomies-dropdown': if (taxonomy_exists($value)) { $sanitized_val = $value; } break; case 'posttype-dropdown': if (post_type_exists($value)) { $sanitized_val = $value; } break; case 'color-switcher': $sanitized_val = $value; // do nothing break; case 'textarea_html': $sanitized_val = esc_html($value); break; case 'wp_editor': $sanitized_val = esc_html($value); break; case 'dropdown': if (in_array($value, array_keys($setting_fields[$id]['options']))) { $sanitized_val = $value; } break; case 'checkbox': $sanitized_val = 1 == $value ? true : false; break; case 'switch': $sanitized_val = 1 == $value ? true : false; break; case 'custom': $sanitized_val = $value; // do nothing break; default: $sanitized_val = esc_attr($value); } $sanitized_val = apply_filters('ar2_theme_options_validate_setting-' . $id, $sanitized_val, $value, $output); $output = ar2_multidimensional_replace($output, $setting_fields[$id]['_id_data']['keys'], $sanitized_val); } } add_settings_error('submit', 'ar2-theme-options-submit', __('Your settings have been successfully saved.', 'ar2'), 'updated'); } else { // Input from WP Customize $output = apply_filters('ar2_theme_customize_validate', $output, $input, $defaults); } } } // Leave for debugging purposes. /* echo '<pre><code>'; print_r( $input ); echo '</code></pre>'; echo '<pre><code>'; print_r( $output ); echo '</code></pre>'; */ return apply_filters('ar2_theme_options_validate', $output, $input, $defaults); }