Example #1
0
/**
 * Sanitize a value from a list of allowed values.
 *
 * @since 2.0.0
 * @param mixed $value The value to sanitize.
 * @param mixed $setting The setting for which the sanitizing is occurring.
 * @return mixed The sanitized value.
 */
function hoot_customizer_sanitize_choices($value, $setting)
{
    if (is_object($setting)) {
        $setting = $setting->id;
    }
    $choices = hoot_customizer_get_choices($setting);
    if (!array_key_exists($value, $choices)) {
        $value = hoot_customizer_get_default($setting);
    }
    return $value;
}
Example #2
0
/**
 * Sanitize multicheckbox value to allow only allowed choices.
 *
 * @since 2.0.0
 * @param string $value The unsanitized string.
 * @param mixed $setting The setting for which the sanitizing is occurring.
 * @return string The sanitized value.
 */
function hoot_customizer_sanitize_multicheckbox($value, $setting)
{
    if (is_object($setting)) {
        $setting = $setting->id;
    }
    $choices = hoot_customizer_get_choices($setting);
    $multi_values = array_map('trim', explode(',', $value));
    $return = array();
    foreach ($multi_values as $key) {
        if (array_key_exists($key, $choices)) {
            $return[] = $key;
        }
    }
    return implode(',', $return);
}