public function populate_defaults()
 {
     include_once ABSPATH . 'wp-admin/includes/screen.php';
     include_once dirname(dirname(__DIR__)) . '/options.php';
     // Suppress notices resulting from call to of_get_default_values.
     // We're not testing the options framework here.
     $this->options = array_merge($this->options, @of_get_default_values());
 }
/**
 * Validate Options.
 *
 * This runs after the submit/reset button has been clicked and
 * validates the inputs.
 *
 * @uses $_POST['reset'] to restore default options
 */
function optionsframework_validate($input)
{
    /*
     * Restore Defaults.
     *
     * In the event that the user clicked the "Restore Defaults"
     * button, the options defined in the theme's options.php
     * file will be added to the option for the active theme.
     */
    if (isset($_POST['reset'])) {
        add_settings_error('options-framework', 'restore_defaults', __('Default options restored.', 'options_framework_theme'), 'updated fade');
        return of_get_default_values();
    }
    /*
     * Update Settings
     *
     * This used to check for $_POST['update'], but has been updated
     * to be compatible with the theme customizer introduced in WordPress 3.4
     */
    $clean = array();
    $options =& _optionsframework_options();
    foreach ($options as $option) {
        if (!isset($option['id'])) {
            continue;
        }
        if (!isset($option['type'])) {
            continue;
        }
        $id = preg_replace('/[^a-zA-Z0-9._\\-]/', '', strtolower($option['id']));
        // Set checkbox to false if it wasn't sent in the $_POST
        if ('checkbox' == $option['type'] && !isset($input[$id])) {
            $input[$id] = false;
        }
        // Set each item in the multicheck to false if it wasn't sent in the $_POST
        if ('multicheck' == $option['type'] && !isset($input[$id])) {
            foreach ($option['options'] as $key => $value) {
                $input[$id][$key] = false;
            }
        }
        // For a value to be submitted to database it must pass through a sanitization filter
        if (has_filter('of_sanitize_' . $option['type'])) {
            $clean[$id] = apply_filters('of_sanitize_' . $option['type'], $input[$id], $option);
        }
    }
    // Hook to run after validation
    do_action('optionsframework_after_validate', $clean);
    return $clean;
}
Example #3
0
/** 
 * Validate Options.
 *
 * This runs after the submit/reset button has been clicked and
 * validates the inputs.
 *
 * @uses $_POST['reset']
 * @uses $_POST['update']
 */
function optionsframework_validate($input)
{
    /*
     * Restore Defaults.
     *
     * In the event that the user clicked the "Restore Defaults"
     * button, the options defined in the theme's options.php
     * file will be added to the option for the active theme.
     */
    if (isset($_POST['reset'])) {
        add_settings_error('options-framework', 'restore_defaults', __('Default options restored.', 'optionsframework'), 'updated fade');
        return of_get_default_values();
    }
    /*
     * Udpdate Settings.
     */
    if (isset($_POST['update'])) {
        $clean = array();
        $options = optionsframework_options();
        foreach ($options as $option) {
            if (!isset($option['id'])) {
                continue;
            }
            if (!isset($option['type'])) {
                continue;
            }
            $id = preg_replace('/[^a-zA-Z0-9._\\-]/', '', strtolower($option['id']));
            // Set checkbox to false if it wasn't sent in the $_POST
            if ('checkbox' == $option['type'] && !isset($input[$id])) {
                $input[$id] = '0';
            }
            // Set each item in the multicheck to false if it wasn't sent in the $_POST
            if ('multicheck' == $option['type'] && !isset($input[$id])) {
                foreach ($option['options'] as $key => $value) {
                    $input[$id][$key] = '0';
                }
            }
            // For a value to be submitted to database it must pass through a sanitization filter
            if (has_filter('of_sanitize_' . $option['type'])) {
                $clean[$id] = apply_filters('of_sanitize_' . $option['type'], $input[$id], $option);
            }
        }
        add_settings_error('options-framework', 'save_options', __('Options saved.', 'optionsframework'), 'updated fade');
        return $clean;
    }
    /*
     * Request Not Recognized.
     */
    return of_get_default_values();
}
Example #4
0
/**
 * Save default values for any newly introduced options to the database
 *
 * Note: this must be called before any other update function calls `of_set_option`,
 * as `of_set_uption` defaults all values to null.
 *
 * @since 0.5.1
 */
function largo_set_new_option_defaults()
{
    // Gets the unique id, returning a default if it isn't defined
    $config = get_option('optionsframework');
    if (isset($config['id'])) {
        $options = get_option($config['id']);
        // a list of saved options
        $defaults = of_get_default_values();
        // the list of default values.
        $options = wp_parse_args($options, $defaults);
        // merge 'em.
        update_option($config['id'], $options);
    }
}
Example #5
0
/**
 * Validate Options.
 *
 * This runs after the submit/reset button has been clicked and
 * validates the inputs.
 *
 * @uses $_POST['reset'] to restore default options
 */
function optionsframework_validate($input)
{
    /*
     * Restore Defaults.
     *
     * In the event that the user clicked the "Restore Defaults"
     * button, the options defined in the theme's options.php
     * file will be added to the option for the active theme.
     */
    if (isset($_POST['reset'])) {
        add_settings_error('options-framework', 'restore_defaults', __('Default options restored.', LANGUAGE_ZONE), 'updated fade');
        $current = null;
        if (isset($_POST['_wp_http_referer'])) {
            $arr = array();
            wp_parse_str($_POST['_wp_http_referer'], $arr);
            $current = current($arr);
        }
        return of_get_default_values($current);
    }
    /*
     * Update Settings
     *
     * This used to check for $_POST['update'], but has been updated
     * to be compatible with the theme customizer introduced in WordPress 3.4
     */
    // Get all defined options
    $options_orig =& _optionsframework_options();
    // Get all saved options
    $known_options = get_option('optionsframework', array());
    $saved_options = get_option($known_options['id'], array());
    $clean = array();
    $preserve = apply_filters('optionsframework_validate_preserve_fields', array());
    $presets_list = optionsframework_get_presets_list();
    // If there are preset option on this page - use this options instead saved
    if (isset($input['preset']) && in_array($input['preset'], array_keys($presets_list))) {
        // Get preset options
        $preset_options = optionsframework_presets_data($input['preset']);
        // Ignore preserved options
        foreach ($preserve as $option) {
            if (isset($preset_options[$option])) {
                unset($preset_options[$option]);
            }
        }
        if (!isset($preset_options['preset'])) {
            $preset_options['preset'] = $input['preset'];
        }
        // Use all options for sanitazing
        $options = $options_orig;
        // Merge options, use preset options
        $saved_options = $used_options = array_merge((array) $saved_options, $preset_options);
        $is_preset = true;
        // If regular page
    } else {
        // Get kurrent preset options
        $preset_options = optionsframework_presets_data($saved_options['preset']);
        // Options only for current page
        $options = array_filter($options_orig, 'optionsframework_options_for_page_filter');
        // Defune options data with which we will work
        $used_options = $input;
        $is_preset = false;
    }
    // Sanitize options
    foreach ($options as $option) {
        if (!isset($option['id'])) {
            continue;
        }
        if (!isset($option['type'])) {
            continue;
        }
        $id = preg_replace('/(\\W!-)/', '', strtolower($option['id']));
        // Set checkbox to false if it wasn't sent in the $_POST
        if ('checkbox' == $option['type'] && !isset($used_options[$id])) {
            $used_options[$id] = false;
        }
        // Set each item in the multicheck to false if it wasn't sent in the $_POST
        if ('multicheck' == $option['type'] && !isset($used_options[$id])) {
            foreach ($option['options'] as $key => $value) {
                $used_options[$id][$key] = false;
            }
        }
        // Use preset value instead native std
        if (isset($preset_options[$id])) {
            $option['std'] = $preset_options[$id];
        }
        if ($is_preset) {
            if ('upload' == $option['type'] && isset($used_options[$id]) && is_array($used_options[$id])) {
                $used_options[$id] = array_reverse($used_options[$id]);
            }
        }
        // For a value to be submitted to database it must pass through a sanitization filter
        if (!empty($option['sanitize']) && has_filter('of_sanitize_' . $option['sanitize'])) {
            $clean[$id] = apply_filters('of_sanitize_' . $option['sanitize'], $used_options[$id], $option);
        } elseif (has_filter('of_sanitize_' . $option['type'])) {
            $clean[$id] = apply_filters('of_sanitize_' . $option['type'], $used_options[$id], $option);
        }
    }
    // Merge current options and saved ones
    $clean = array_merge($saved_options, $clean);
    // Hook to run after validation
    do_action('optionsframework_after_validate', $clean, $input);
    return $clean;
}
Example #6
0
/**
 * Save default values for any newly introduced options to the database
 *
 * Note: this must be called before any other update function calls `of_set_option`,
 * as `of_set_uption` defaults all values to null.
 *
 * @since 0.5.1
 */
function largo_set_new_option_defaults()
{
    // Gets the unique id, returning a default if it isn't defined
    $config = get_option('optionsframework');
    if (isset($config['id'])) {
        $defaults = of_get_default_values();
        // the list of default values.
        $previous_options = largo_retrieve_previous_options();
        $options = wp_parse_args($previous_options, $defaults);
        update_option($config['id'], $options);
    }
}
Example #7
0
/** 
 * Validate Options.
 *
 * This runs after the submit/reset button has been clicked and
 * validates the inputs.
 *
 * @uses $_POST['reset']
 * @uses $_POST['update']
 */
function optionsframework_validate($input)
{
    /*
     * Restore Defaults.
     *
     * In the event that the user clicked the "Restore Defaults"
     * button, the options defined in the theme's options.php
     * file will be added to the option for the active theme.
     */
    if (isset($_POST['reset'])) {
        add_settings_error('options-framework', 'restore_defaults', _x('Default options restored.', 'optionsframework', LANGUAGE_ZONE), 'updated fade');
        $current = null;
        if (isset($_POST['_wp_http_referer'])) {
            $arr = array();
            wp_parse_str($_POST['_wp_http_referer'], $arr);
            $current = current($arr);
        }
        return of_get_default_values($current);
    }
    /*
     * Udpdate Settings.
     */
    $clean = array();
    $options_orig = optionsframework_options();
    $options = array_filter($options_orig, 'optionsframework_options_for_page_filter');
    foreach ($options as $option) {
        if (!isset($option['id'])) {
            continue;
        }
        if (!isset($option['type'])) {
            continue;
        }
        $sanitize = isset($option['sanitize']) ? $option['sanitize'] : true;
        $id = preg_replace('/(\\W!-)/', '', strtolower($option['id']));
        // Set checkbox to false if it wasn't sent in the $_POST
        if ('checkbox' == $option['type'] && !isset($input[$id])) {
            $input[$id] = '0';
        }
        // Set each item in the multicheck to false if it wasn't sent in the $_POST
        if ('multicheck' == $option['type'] && !isset($input[$id])) {
            foreach ($option['options'] as $key => $value) {
                $input[$id][$key] = '0';
            }
        }
        if (!isset($input[$id])) {
            continue;
        }
        // For a value to be submitted to database it must pass through a sanitization filter
        if (!has_filter('of_sanitize_' . $option['type'])) {
            continue;
        }
        if ($sanitize) {
            $clean[$id] = apply_filters('of_sanitize_' . $option['type'], $input[$id], $option);
        } else {
            $clean[$id] = $input[$id];
        }
    }
    unset($option);
    $known_options = get_option('optionsframework', array());
    $saved_options = get_option($known_options['id'], array());
    if (isset($clean['of-preset'])) {
        $preserve = array('of_generatortest2', 'social_icons', 'branding-header_logo', 'branding-retina_header_logo', 'branding-header_mobile_logo', 'branding-retina_header_mobile_logo', 'branding-footer_logo', 'branding-retina_footer_logo', 'branding-favicon', "branding-copyrights", 'branding-dt_credits', 'misc-static_css', 'misc-rollover_blur', 'misc-show_header_contacts', 'misc-contact_address', 'misc-contact_phone', 'misc-contact_email', 'misc-contact_skype', 'misc-contact_work_hours', 'misc-show_next_prev_post', 'misc-show_next_prev_portfolio', 'misc-show_top_line', 'misc-show_search_top', 'misc-show_author_details', 'misc-analitics_code', 'menu-parent_menu_clickable', 'social-like_post', 'social-like_portfolio', 'social-like_catalog', 'social-like_gallery', 'social-like_photo', 'social-like_video', 'social-like_button_google_plus', 'social-like_button_twitter', 'social-like_button_faceboock');
        $preset_options = optionsframework_presets_data($clean['of-preset']);
        foreach ($preserve as $pres) {
            if (isset($preset_options[$pres])) {
                unset($preset_options[$pres]);
            }
        }
        $saved_options = array_merge((array) $saved_options, $preset_options);
    }
    $clean = array_merge($saved_options, $clean);
    add_settings_error('options-framework', 'save_options', _x('Options saved.', 'optionsframework', LANGUAGE_ZONE), 'updated fade');
    return $clean;
}