Example #1
0
function mystique_verify_options()
{
    $default_settings = mystique_default_settings();
    $current_settings = get_option('mystique');
    if (!$current_settings) {
        mystique_setup_options();
        add_action('admin_notices', 'mystique_theme_install_notification');
    } else {
        // only go further if the theme version from the database differs from the one in the theme files
        if (version_compare($current_settings['theme_version'], THEME_VERSION, '!=')) {
            // check for new options
            foreach ($default_settings as $option => $value) {
                if (!array_key_exists($option, $current_settings)) {
                    $current_settings[$option] = $default_settings[$option];
                }
            }
            // delete the old twitter cache option (<2.3.1)
            delete_option('mystique-twitter');
            // update theme version
            $current_settings['theme_version'] = THEME_VERSION;
            update_option('mystique', $current_settings);
            do_action('mystique_verify_options');
        }
    }
}
Example #2
0
function mystique_update_options()
{
    check_admin_referer('theme-settings');
    // enable theme settings for lower level users, but with limitations
    if (!current_user_can('switch_themes')) {
        wp_die(__('You are not authorised to perform this operation.', 'mystique'));
    }
    $options = get_option('mystique');
    foreach (mystique_default_settings() as $key => $value) {
        $options[$key] = stripslashes((string) $_POST[$key]);
        if ($key == 'exclude_pages' && $_POST[$key] != '') {
            $options[$key] = implode(',', $_POST[$key]);
        }
        // else $options['exclude_pages'] = '';
        if ($key == 'exclude_categories' && $_POST[$key] != '') {
            $options[$key] = implode(',', $_POST[$key]);
        }
        // else $options['exclude_categories'] = '';
        // filter potentially malicious html/css (eg <script>, onclick, css expressions etc)
        if (!current_user_can('unfiltered_html')) {
            $options[$key] = mystique_strip_tags_attributes($options[$key]);
        }
    }
    // build dimensions array
    $dimensions = get_mystique_option('dimensions');
    foreach ($dimensions as $layout_size => $layout_types) {
        foreach ($layout_types as $layout => $values) {
            $options['dimensions'][$layout_size][$layout] = $_POST['dimensions_' . $layout_size . '_' . $layout];
        }
    }
    if (isset($_POST['remove-logo'])) {
        $options['logo'] = '';
        $options['logo_size'] = '';
    } elseif ($_FILES["file-logo"]["type"]) {
        $valid = is_valid_image('file-logo');
        if ($valid) {
            $options['logo'] = get_upload_dir('baseurl') . "/" . $_FILES["file-logo"]["name"];
            $options['logo_size'] = $valid;
        }
    }
    if (isset($_POST['remove-background'])) {
        $options['background'] = '';
    } elseif ($_FILES["file-background"]["type"]) {
        $valid = is_valid_image('file-background');
        if ($valid) {
            $options['background'] = get_upload_dir('baseurl') . "/" . $_FILES["file-background"]["name"];
        }
    }
    update_option('mystique', $options);
    // reset?
    if (isset($_POST['reset'])) {
        mystique_setup_options();
    }
    wp_redirect(admin_url('themes.php?page=theme-settings&updated=true'));
}