示例#1
0
/**
 * Get Default Options
 *
 * @since  1.3
 */
function dedo_get_default_options()
{
    // Get registered settings
    $options = dedo_get_options();
    // Loop through and find default value
    foreach ($options as $key => $value) {
        $default_options[$key] = $value['default'];
        // Add sub options
        if (isset($value['sub_option'])) {
            foreach ($value['sub_option'] as $key2 => $value2) {
                $default_options[$key . '_' . $key2] = $value2;
            }
        }
    }
    return $default_options;
}
/**
 * Validate settings callback
 *
 * @since  1.3
 */
function dedo_validate_settings($input)
{
    global $dedo_options, $dedo_default_options;
    // Registered options
    $options = dedo_get_options();
    // Ensure text fields are not blank
    foreach ($options as $key => $value) {
        if ('text' === $options[$key]['type'] && '' === trim($input[$key])) {
            $input[$key] = $dedo_default_options[$key];
        }
    }
    // Ensure download URL does not contain illegal characters
    $input['download_url'] = strtolower(preg_replace('/[^A-Za-z0-9_-]/', '', $input['download_url']));
    // Run folder protection if option changed
    if ($input['folder_protection'] != $dedo_options['folder_protection']) {
        dedo_folder_protection($input['folder_protection']);
    }
    // Clear transients
    dedo_delete_all_transients();
    return $input;
}