コード例 #1
0
ファイル: theme-options.php プロジェクト: navitronic/_s
/**
 * Sanitize and validate form input. Accepts an array, return a sanitized array.
 *
 * @see _s_theme_options_init()
 * @todo set up Reset Options action
 *
 * @param array $input Unknown values.
 * @return array Sanitized theme options ready to be stored in the database.
 *
 * @since _s 1.0
 */
function _s_theme_options_validate($input)
{
    $output = array();
    // Checkboxes will only be present if checked.
    if (isset($input['sample_checkbox'])) {
        $output['sample_checkbox'] = 'on';
    }
    // The sample text input must be safe text with no HTML tags
    if (isset($input['sample_text_input']) && !empty($input['sample_text_input'])) {
        $output['sample_text_input'] = wp_filter_nohtml_kses($input['sample_text_input']);
    }
    // The sample select option must actually be in the array of select options
    if (isset($input['sample_select_options']) && array_key_exists($input['sample_select_options'], _s_sample_select_options())) {
        $output['sample_select_options'] = $input['sample_select_options'];
    }
    // The sample radio button value must be in our array of radio button values
    if (isset($input['sample_radio_buttons']) && array_key_exists($input['sample_radio_buttons'], _s_sample_radio_buttons())) {
        $output['sample_radio_buttons'] = $input['sample_radio_buttons'];
    }
    // The sample textarea must be safe text with the allowed tags for posts
    if (isset($input['sample_textarea']) && !empty($input['sample_textarea'])) {
        $output['sample_textarea'] = wp_filter_post_kses($input['sample_textarea']);
    }
    return apply_filters('_s_theme_options_validate', $output, $input);
}
コード例 #2
0
/**
 * Sanitize and validate form input. Accepts an array, return a sanitized array.
 *
 * @see _s_theme_options_init()
 * @todo set up Reset Options action
 *
 * @since _s 1.0
 */
function _s_theme_options_validate($input)
{
    $output = $defaults = _s_get_default_theme_options();
    // The sample checkbox should either be on or off
    if (!isset($input['sample_checkbox'])) {
        $input['sample_checkbox'] = 'off';
    }
    $output['sample_checkbox'] = $input['sample_checkbox'] == 'on' ? 'on' : 'off';
    // The sample text input must be safe text with no HTML tags
    if (isset($input['sample_text_input'])) {
        $output['sample_text_input'] = wp_filter_nohtml_kses($input['sample_text_input']);
    }
    // The sample select option must actually be in the array of select options
    if (array_key_exists($input['sample_select_options'], _s_sample_select_options())) {
        $output['sample_select_options'] = $input['sample_select_options'];
    }
    // The sample radio button value must be in our array of radio button values
    if (isset($input['sample_radio_buttons']) && array_key_exists($input['sample_radio_buttons'], _s_sample_radio_buttons())) {
        $output['sample_radio_buttons'] = $input['sample_radio_buttons'];
    }
    // The sample textarea must be safe text with the allowed tags for posts
    if (isset($input['sample_textarea'])) {
        $output['sample_textarea'] = wp_filter_post_kses($input['sample_textarea']);
    }
    return apply_filters('_s_theme_options_validate', $output, $input, $defaults);
}