function mystique_setup_options() { mystique_remove_options(); $default_settings = mystique_default_settings(); update_option('mystique', $default_settings); do_action('mystique_setup_options'); }
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')); }