/** * Theme register_setting() sanitize callback * * Validate and whitelist user-input data before updating Theme * Options in the database. Only whitelisted options are passed * back to the database, and user-input data for all whitelisted * options are sanitized. * * @link http://codex.wordpress.org/Data_Validation Codex Reference: Data Validation * * @param array $input Raw user-input data submitted via the Theme Settings page * @return array $input Sanitized user-input data passed to the database */ function cleanyetibasic_options_validate($input) { // This is the "whitelist": current settings $valid_input = cleanyetibasic_get_options(); // Get the array of Theme settings, by Settings Page tab $settingsbytab = cleanyetibasic_get_settings_by_tab(); // Get the array of option parameters $option_parameters = cleanyetibasic_get_option_parameters(); // Get the array of option defaults $option_defaults = cleanyetibasic_get_option_defaults(); // Get list of tabs $tabs = cleanyetibasic_get_settings_page_tabs(); // Determine what type of submit was input $submittype = 'submit'; foreach ($tabs as $tab) { $resetname = 'reset-' . $tab['name']; if (!empty($input[$resetname])) { $submittype = 'reset'; } } // Determine what tab was input $submittab = cleanyetibasic_get_current_tab(); foreach ($tabs as $tab) { $submitname = 'submit-' . $tab['name']; $resetname = 'reset-' . $tab['name']; if (!empty($input[$submitname]) || !empty($input[$resetname])) { $submittab = $tab['name']; } } global $wp_customize; // Get settings by tab $tabsettings = isset($wp_customize) ? $settingsbytab['all'] : $settingsbytab[$submittab]; // Loop through each tab setting foreach ($tabsettings as $setting) { // If no option is selected, set the default $valid_input[$setting] = !isset($input[$setting]) ? $option_defaults[$setting] : $input[$setting]; // If submit, validate/sanitize $input if ('submit' == $submittype) { // Get the setting details from the defaults array $optiondetails = $option_parameters[$setting]; // Get the array of valid options, if applicable $valid_options = isset($optiondetails['valid_options']) ? $optiondetails['valid_options'] : false; // Validate checkbox fields if ('checkbox' == $optiondetails['type']) { // If input value is set and is true, return true; otherwise return false $valid_input[$setting] = isset($input[$setting]) && true == $input[$setting] ? true : false; } else { if ('radio' == $optiondetails['type']) { // Only update setting if input value is in the list of valid options $valid_input[$setting] = array_key_exists($input[$setting], $valid_options) ? $input[$setting] : $valid_input[$setting]; } else { if ('select' == $optiondetails['type']) { // Only update setting if input value is in the list of valid options $valid_input[$setting] = array_key_exists($input[$setting], $valid_options) ? $input[$setting] : $valid_input[$setting]; } else { if ('text' == $optiondetails['type'] || 'textarea' == $optiondetails['type']) { // Validate no-HTML content if ('nohtml' == $optiondetails['sanitize']) { // Pass input data through the wp_filter_nohtml_kses filter $valid_input[$setting] = wp_filter_nohtml_kses($input[$setting]); } // Validate HTML content if ('html' == $optiondetails['sanitize']) { // Pass input data through the wp_filter_kses filter $valid_input[$setting] = wp_filter_kses($input[$setting]); } } else { if ('color-picker' == $optiondetails['type']) { $colorCode = $input[$setting]; $colorCode = ltrim($colorCode, '#'); $valid_input[$setting] = ctype_xdigit($colorCode) ? $input[$setting] : $valid_input[$setting]; } else { if ('custom' == $optiondetails['type']) { } } } } } } } elseif ('reset' == $submittype) { // Set $setting to the default value $valid_input[$setting] = $option_defaults[$setting]; } } return $valid_input; }
/** * Clean Yeti Basic Theme Settings Page Markup * * @uses cleanyetibasic_get_current_tab() defined in \functions\custom.php * @uses cleanyetibasic_get_page_tab_markup() defined in \functions\custom.php */ function cleanyetibasic_admin_options_page() { // Determine the current page tab $currenttab = cleanyetibasic_get_current_tab(); // Define the page section accordingly $settings_section = 'cleanyetibasic_' . $currenttab . '_tab'; ?> <div class="wrap"> <?php cleanyetibasic_get_page_tab_markup(); if (isset($_GET['settings-updated'])) { echo '<div class="updated"><p>'; echo __('Theme settings updated successfully.', 'cleanyeti'); echo '</p></div>'; } ?> <form action="options.php" method="post"> <?php // Implement settings field security, nonces, etc. settings_fields('theme_cleanyetibasic_options'); // Output each settings section, and each // Settings field in each section do_settings_sections($settings_section); ?> <?php submit_button(__('Save Settings', 'cleanyetibasic'), 'primary', 'theme_cleanyetibasic_options[submit-' . $currenttab . ']', false); ?> <?php submit_button(__('Reset Defaults', 'cleanyetibasic'), 'secondary', 'theme_cleanyetibasic_options[reset-' . $currenttab . ']', false); ?> </form> </div> <?php }