public function update_license($value = null) { $license = $this->get_license(); if ($license === $value) { return $value; } $deactivate_license = false; if ($this->valid_hash($value)) { $this->set_license($value); $value = $this->activate_license(); $this->set_license($value); } else { $this->deactivate_license(); $this->delete_license(); $deactivate_license = true; $value = ''; } if ($this->valid_license()) { $text = esc_html__('%s license saved.'); $text = sprintf($text, $this->item_name); add_settings_error(static::$settings_id, 'license_saved', $text, 'updated'); } elseif (empty($deactivate_license)) { $text = esc_html__('%s license not saved.'); $text = sprintf($text, $this->item_name); add_settings_error(static::$settings_id, 'license_not_saved', $text, 'error'); } if (empty(self::$settings_saved)) { self::$settings_saved = true; set_transient('settings_errors', get_settings_errors(), 30); } return $value; }
function presscore_ubermenu_generate_less_css_file_after_options_save() { $set = get_settings_errors('options-framework'); if (!empty($set)) { presscore_generate_less_css_file('the7-ubermenu.less', PRESSCORE_THEME_URI . '/css/the7-uber-menu.less'); } }
/** * Callback for the 'admin_init' action; used to initialize settings APIs */ public function init_settings() { if (isset($_GET['settings-updated'])) { $err = get_settings_errors(); $errors = array(); foreach ($err as $msg) { if ('general' !== $msg['setting'] && 'settings_updated' !== $msg['code']) { $errors[] = $msg; } } $this->_errors = $errors; global $wp_settings_errors; $wp_settings_errors = array(); if (0 == count($this->_errors)) { add_action('admin_notices', array(&$this, 'saved_notice')); } else { add_action('admin_notices', array($this, 'error_notice')); } } register_setting($this->get_group(), $this->get_option(), array(&$this, 'validate_options')); foreach ($this->_args['sections'] as $section_id => $section) { add_settings_section($section_id, $section['title'], array(&$this, 'section_callback'), $this->get_page()); // page // add all the fields foreach ($section['fields'] as $field_id => $field) { $label = '<label for="' . $field_id . '"' . (isset($field['tooltip']) ? ' title="' . esc_attr($field['tooltip']) . '" ' : '') . '>' . esc_html($field['title']) . ($this->_is_required($field) ? '<span class="required">*</span>' : '') . '</label>'; add_settings_field($field_id, $label, array(&$this, 'display_field'), $this->get_page(), $section_id, array($section_id, $field_id)); } } }
/** * Add settings for the RSS feed * + also regenerates the secret if requested */ public function add_settings() { //we register a setting to keep track of the RSS feed status (enabled/disabled) register_setting('simple_history_settings_group', 'simple_history_enable_rss_feed', array($this, 'update_rss_status')); /** * Start new section for RSS feed */ $settings_section_rss_id = "simple_history_settings_section_rss"; add_settings_section($settings_section_rss_id, _x("RSS feed", "rss settings headline", "simple-history"), array($this, "settings_section_output"), SimpleHistory::SETTINGS_MENU_SLUG); // Enable/Disabled RSS feed add_settings_field("simple_history_enable_rss_feed", __("Enable", "simple-history"), array($this, "settings_field_rss_enable"), SimpleHistory::SETTINGS_MENU_SLUG, $settings_section_rss_id); //if RSS is activated we display other fields if ($this->is_rss_enabled()) { // RSS address add_settings_field("simple_history_rss_feed", __("Address", "simple-history"), array($this, "settings_field_rss"), SimpleHistory::SETTINGS_MENU_SLUG, $settings_section_rss_id); // Regnerate address add_settings_field("simple_history_rss_feed_regenerate_secret", __("Regenerate", "simple-history"), array($this, "settings_field_rss_regenerate"), SimpleHistory::SETTINGS_MENU_SLUG, $settings_section_rss_id); } // Create new RSS secret $create_new_secret = false; $create_secret_nonce_name = "simple_history_rss_secret_regenerate_nonce"; if (isset($_GET[$create_secret_nonce_name]) && wp_verify_nonce($_GET[$create_secret_nonce_name], 'simple_history_rss_update_secret')) { $create_new_secret = true; $this->update_rss_secret(); // Add updated-message and store in transient and then redirect // This is the way options.php does it. $msg = __("Created new secret RSS address", 'simple-history'); add_settings_error("simple_history_rss_feed_regenerate_secret", "simple_history_rss_feed_regenerate_secret", $msg, "updated"); set_transient('settings_errors', get_settings_errors(), 30); $goback = esc_url_raw(add_query_arg('settings-updated', 'true', wp_get_referer())); wp_redirect($goback); exit; } }
function redirect_to_settings() { //First preserve all errors that have been generated set_transient('settings_errors', get_settings_errors(), 30); //Call settings url wp_redirect($this->get_redirect_url() . '&settings-updated=true'); }
public function post_restore() { if (isset($_POST['job_id']) && isset($_POST['backup_uniqid']) && isset($_POST['_wpnonce']) && isset($_POST['method'])) { $nonce = filter_input(INPUT_POST, '_wpnonce', FILTER_SANITIZE_STRING); if (!wp_verify_nonce($nonce, 'my-wp-backup-restore-backup')) { wp_die(esc_html__('Nope! Security check failed!', 'my-wp-backup')); } $id = absint($_POST['job_id']); $uniqid = sanitize_key($_POST['backup_uniqid']); $method = filter_input(INPUT_POST, 'method', FILTER_SANITIZE_STRING); $backup = self::get($id, $uniqid); if (!isset($backup['duration'])) { add_settings_error('', '', __('Invalid backup id/uniqid.', 'my-wp-backup')); set_transient('settings_errors', get_settings_errors()); wp_safe_redirect($this->admin->get_page_url('backup', array('settings-updated' => 1))); } if (!$backup->has_archives()) { // No local copy and no remote copy === DEAD END. if (empty($backup['destinations'])) { add_settings_error('', '', __('Backup files missing.', 'my-wp-backup')); set_transient('settings_errors', get_settings_errors()); wp_safe_redirect($this->admin->get_page_url('backup', array('settings-updated' => 1))); } if (!isset($backup['destinations'][$method])) { add_settings_error('', '', sprintf(__('No backup files from %s.', 'my-wp-backup'), Job::$destinations[$method])); set_transient('settings_errors', get_settings_errors()); wp_safe_redirect($this->admin->get_page_url('backup', array('settings-updated' => 1))); } } wp_schedule_single_event(time(), 'wp_backup_restore_backup', array(array($id, $uniqid, $method))); wp_safe_redirect($this->admin->get_page_url('backup', array('uniqid' => $uniqid, 'action' => 'viewprogress', 'id' => $id))); } }
function ubermenu_migration_check() { if (isset($_GET['page']) && $_GET['page'] == 'ubermenu-settings') { if (isset($_GET['do'])) { if ($_GET['do'] == 'migration-check' || $_GET['do'] == 'migrate' || $_GET['do'] == 'reset-styles') { //If we're doing the migration check now, don't show this message return; } else { if ($_GET['do'] == 'no-migrate') { update_option(UBERMENU_PREFIX . 'migration_status', 'do-not-migrate'); } else { if ($_GET['do'] == 'reset-migration-check') { update_option(UBERMENU_PREFIX . 'migration_status', false); } } } } } $migration_status = get_option(UBERMENU_PREFIX . 'migration_status', false); //Have we already migrated, or determined we don't need to? if ($migration_status == 'complete' || $migration_status == 'n/a' || $migration_status == 'do-not-migrate') { return; } //We may need to migrate - do the old setting exist? $old_ops = get_option('wp-mega-menu-settings', false); // 'sparkops_ubermenu' ); //There are some old setting, offer migration if (is_array($old_ops)) { if ($migration_status == false) { $notice = __('Looks like you\'ve updated to UberMenu 3. Awesome! Would you like to migrate your settings?', 'ubermenu'); $notice .= ' <a class="button button-primary" href="' . admin_url('themes.php?page=ubermenu-settings&do=migration-check') . '">' . __('Begin Migration') . '</a>'; $notice .= ' <a class="button ubermenu-migrate-dismiss" href="' . admin_url('themes.php?page=ubermenu-settings&do=no-migrate') . '">' . __('No, thanks', 'ubermenu') . '</a>'; $add = true; //Avoid duplication $errors = get_settings_errors(); if (is_array($errors)) { foreach ($errors as $er) { if (is_array($er)) { if ($er['code'] == 'migration-notice') { $add = false; break; } } } } if ($add) { add_settings_error('menu-migration', 'migration-notice', $notice, 'updated'); add_action('admin_footer', 'ubermenu_migrate_nag_js'); } } else { if ($migration_status == 'in_progress') { $notice = __('Migration did not complete successfully', 'ubermenu'); add_settings_error('menu-migration', 'migration-notice-incomplete', $notice, 'error'); update_option(UBERMENU_PREFIX . 'migration_status', false); } } } else { update_option(UBERMENU_PREFIX . 'migration_status', 'n/a'); } }
function compiler_add_error() { if (get_settings_errors('options-framework')) { return; } add_settings_error('options-framework', 'lessc_error', _x('Attention! Theme Options will not be saved, because one of your plugins conflicts with the theme.<br /> How to make it work:<br /> 1. Deactivate all plugins.<br /> 2. Make required changes. Save Theme Options.<br /> 3. Activate the plugins back.', 'backend', LANGUAGE_ZONE), 'error'); }
/** * Update custom.less stylesheet. * */ function presscore_generate_less_css_file_after_options_save() { $css_is_writable = apply_filters('presscore_less_cache_writable', true); $set = get_settings_errors('options-framework'); if (!empty($set)) { $dynamic_stylesheets = presscore_get_dynamic_stylesheets_list(); foreach ($dynamic_stylesheets as $stylesheet_handle => $stylesheet) { presscore_generate_less_css_file($stylesheet_handle, $stylesheet['src']); } if ($css_is_writable) { add_settings_error('presscore-wp-less', 'save_stylesheet', _x('Stylesheet saved.', 'backend', 'the7mk2'), 'updated fade'); } } }
function handle_settings_save() { if (!isset($_REQUEST[$this->name()])) { wp_die(__('Settings could not be parsed — this may be caused by a plugin conflict.')); } $to_be_saved = $_REQUEST[$this->name()]; $option_page = $_REQUEST['option_page']; $is_network_wide = isset($_REQUEST['network_wide']) && $_REQUEST['network_wide']; if (!wp_verify_nonce($_REQUEST['_wpnonce'], $option_page . "-options")) { wp_die(__('Cheatin’ uh?')); } // if it's network request, we want to check that the current user is // a network admin if ($is_network_wide && !is_super_admin()) { wp_die(__('Cheatin’ uh?')); } // verify that the user has the permissions to edit the clef page $capability = 'manage_options'; $capability = apply_filters("option_page_capability_{$option_page}", $capability); if (!current_user_can($capability)) { wp_die(__('Cheatin’ uh?')); } $whitelist_options = apply_filters('whitelist_options', array()); $options = $whitelist_options[$option_page]; if (empty($options[0]) || $options[0] != $this->name()) { wp_die("You can't do that!"); } $to_be_saved = apply_filters('ajax_settings_pre_save', $to_be_saved); if ($is_network_wide) { update_site_option($this->name(), $to_be_saved); } else { update_option($this->name(), $to_be_saved); } $errors = get_settings_errors(); $response = array(); if (!empty($errors)) { $error_messages = array(); foreach ($errors as &$error) { $error_messages[$error['code']] = $error['message']; } $response['errors'] = $error_messages; header('HTTP/1.0 400'); wp_send_json_error($response); } else { $response['success'] = true; wp_send_json($response); } }
/** * @dataProvider permalink_structure_provider */ public function test_sanitize_permalink_structure($provided, $expected, $valid) { global $wp_settings_errors; $old_wp_settings_errors = (array) $wp_settings_errors; $actual = sanitize_option('permalink_structure', $provided); $errors = get_settings_errors('permalink_structure'); // Clear errors. $wp_settings_errors = $old_wp_settings_errors; if ($valid) { $this->assertEmpty($errors); } else { $this->assertNotEmpty($errors); $this->assertEquals('invalid_permalink_structure', $errors[0]['code']); } $this->assertEquals($expected, $actual); }
/** * Process the AJAX call to save/delete colour preset */ function graphene_ajax_update_preset_handler() { global $wpdb; check_ajax_referer('graphene_options-options', '_wpnonce'); if (!current_user_can('edit_theme_options')) { echo '<div class="error fade"><p>' . __("Sorry, but you don't have the necessary permission to modify theme options.", 'graphene') . '</p></div>'; die; } $action = $_POST['colour_preset_action']; $preset = $action == 'delete' ? trim($_POST['colour_preset_name']) : sanitize_title($_POST['colour_preset_name']); $data = $_POST['graphene_settings']; if ($action == 'delete') { unset($data['colour_presets'][$preset]); } if ($action == 'save') { $count = $dash = ''; while (array_key_exists($preset . $dash . $count, $data['colour_presets'])) { if (!$count) { $count = 0; $dash = '-'; } $count++; } if ($count) { $preset .= '-' . $count; } $colour_settings = $data; unset($colour_settings['colour_preset']); unset($colour_settings['colour_presets']); $colour_settings = json_encode($colour_settings); $data['colour_presets'][$preset]['name'] = trim($_POST['colour_preset_name']); $data['colour_presets'][$preset]['code'] = $colour_settings; $data['colour_preset'] = $preset; } $data = graphene_settings_validator($data); if (get_settings_errors('graphene_options')) { settings_errors('graphene_options'); } else { if ($data) { update_option('graphene_settings', stripslashes_deep($data)); } $message = $action == 'delete' ? __('Colour preset deleted.', 'graphene') : __('Colour preset saved.', 'graphene'); echo '<div class="updated fade"><p>' . $message . '</p></div>'; } die; }
/** * Update custom.less stylesheet. * */ function presscore_generate_less_css_file_after_options_save() { $css_is_writable = get_option('presscore_less_css_is_writable'); if (isset($_GET['page']) && 'options-framework' == $_GET['page'] && !$css_is_writable) { return; } $set = get_settings_errors('options-framework'); if (!empty($set)) { $dynamic_stylesheets = presscore_get_dynamic_stylesheets_list(); foreach ($dynamic_stylesheets as $stylesheet_handle => $stylesheet) { presscore_generate_less_css_file($stylesheet_handle, $stylesheet['src']); } if ($css_is_writable) { add_settings_error('presscore-wp-less', 'save_stylesheet', _x('Stylesheet saved.', 'backend', 'the7mk2'), 'updated fade'); } } }
/** * ---------------------------------------------------------------------- * Check if required plugins were manually installed */ function lbmn_required_plugins_install_check() { if (!get_option(LBMN_THEME_NAME . '_required_plugins_installed')) { // Proceed only if '_required_plugins_installed' not already market as true $current_tgmpa_message = ''; $current_tgmpa_messages = get_settings_errors('tgmpa'); foreach ($current_tgmpa_messages as $message) { $current_tgmpa_message = $message['message']; } // If message has no link to install-required-plugins page then all // required plugins has been installed if (!stristr($current_tgmpa_message, 'install-required-plugins')) { // Update theme option '_required_plugins_installed' update_option(LBMN_THEME_NAME . '_required_plugins_installed', true); } } }
/** * Process the AJAX call to save the theme's settings */ function franz_ajax_update_handler() { global $wpdb; check_ajax_referer('franz_options-options', '_wpnonce'); if (!current_user_can('edit_theme_options')) { echo '<div class="error fade"><p>' . __("Sorry, but you don't have the necessary permission to modify theme options.", 'franz-josef') . '</p></div>'; die; } $data = $_POST['franz_settings']; $data = franz_settings_validator($data); if (get_settings_errors('franz_options')) { settings_errors('franz_options'); } else { if ($data) { update_option('franz_settings', stripslashes_deep($data)); } echo '<div class="updated fade"><p>' . __('Options saved.', 'franz-josef') . '</p></div>'; } die; }
/** * Updates network options for a network settings page. * * This method relies on the settings page to use the `settings_fields()` function, similarly * to regular WordPress settings pages. * * @since 1.0.0 * @access public */ public function update_network_option() { if (!isset($_POST['option_page']) || !isset($_POST['action']) || 'update' !== $_POST['action']) { return; } $option_page = $_POST['option_page']; if ('wp_encrypt_settings' !== $option_page) { return; } check_admin_referer('wp_encrypt_settings-options'); if (isset($_POST['wp_encrypt_settings'])) { update_site_option('wp_encrypt_settings', wp_unslash($_POST['wp_encrypt_settings'])); } if (0 === count(get_settings_errors())) { add_settings_error('general', 'settings_updated', __('Settings saved.'), 'updated'); } set_site_transient('settings_errors', get_settings_errors(), 30); wp_redirect(add_query_arg('updated', 'true', network_admin_url('settings.php?page=wp_encrypt'))); exit; }
function adminNotices() { $settings = Settings\getSettings(); $errors = get_settings_errors(); foreach ($errors as $error) { if ($error["type"] != "error" && $error["type"] != "updated") { continue; } elseif ($error["code"] === $settings[Settings\S_PAGE_NAME]) { ?> <div class="<?php echo $error["type"]; ?> "><p><?php echo $error["message"]; ?> </p></div> <?php } } }
/** * Temporary workaround for wordpress bug #9296 http://core.trac.wordpress.org/ticket/9296 * Although there is a hook in the options-permalink.php to insert custom settings, * it does not actually save any custom setting which is added to that page. */ function _cp_enable_permalink_settings() { global $new_whitelist_options; // save hook for permalinks page if (isset($_POST['permalink_structure']) || isset($_POST['category_base'])) { check_admin_referer('update-permalink'); $option_page = 'permalink'; $capability = 'manage_options'; $capability = apply_filters("option_page_capability_{$option_page}", $capability); if (!current_user_can($capability)) { wp_die(__('Cheatin’ uh?', APP_TD)); } // get extra permalink options $options = $new_whitelist_options[$option_page]; if ($options) { foreach ($options as $option) { $option = trim($option); $value = null; if (isset($_POST[$option])) { $value = $_POST[$option]; } if (!is_array($value)) { $value = trim($value); } $value = stripslashes_deep($value); // get the old values to merge $db_option = get_option($option); if (is_array($db_option)) { update_option($option, array_merge($db_option, $value)); } else { update_option($option, $value); } } } /** * Handle settings errors */ set_transient('settings_errors', get_settings_errors(), 30); } }
/** * Admin page html * * @since 0.1 */ function admin_page() { $files = new WP_Parser_JSON_File(); // abort if we cannot access the WP_Filesystem API if ($files->generate_files() === true) { return; } echo '<div class="wrap">'; echo '<h2>' . __('WP Parser JSON', 'wp-parser-json') . '</h2>'; echo '<p>' . __('Generate json files from all functions, hooks, filters, actions and classes', 'wp-parser-json') . '</p>'; settings_errors(); // don't show the form if the post types from WP Parser don't exist if (!$files->post_types_exists()) { return; } echo '<form method="post" action="">'; wp_nonce_field('wp-parser-json_nonce'); echo get_submit_button(esc_html__('Generate json files!', 'wp-parser-json')); echo '</form>'; $errors = get_settings_errors(); $settings_updated = true; // Check if new files were generated. if (!(isset($errors[0]['code']) && 'wp_parser_json_updated' === $errors[0]['code'])) { // Offer download link to old zip file if it exists. $zip_dir = plugin_dir_path(__FILE__) . 'json-files/wp-parser-json.zip'; $version = plugin_dir_path(__FILE__) . 'json-files/version.json'; if (file_exists($zip_dir) && file_exists($version)) { $version = json_decode(file_get_contents($version)); $version = isset($version->version) ? '(WP ' . $version->version . ')' : ''; echo '<a href="' . plugins_url('wp-parser-json') . '/json-files/wp-parser-json.zip">'; printf(__('download %s files', 'wp-parser-json'), $version) . '</a>'; } $settings_updated = false; } if ($settings_updated) { do_action('wp_parser_json_afer_form'); } echo '</div>'; }
function bfox_ms_admin_page_save() { if ('bfox-ms' == $_GET['action']) { check_admin_referer('bfox-ms-admin-settings-options'); update_site_option('bfox-ms-allow-blog-options', $_POST['bfox-ms-allow-blog-options']); update_site_option('bfox-blog-options', $_POST['bfox-blog-options']); /** * Handle settings errors and return to options page */ // If no settings errors were registered add a general 'updated' message. if (!count(get_settings_errors())) { add_settings_error('general', 'settings_updated', __('Settings saved.', 'bfox'), 'updated'); } set_transient('settings_errors', get_settings_errors(), 30); /** * Redirect back to the settings page that was submitted */ $goback = add_query_arg('updated', 'true', wp_get_referer()); wp_redirect($goback); exit; } }
/** * Generates Backend Page for options * * @hook add_theme_page */ public function do_options_page() { ?> <div class="wrap"> <?php if (isset($_GET['settings-updated'])) { // input var okay echo "<div class='updated'><p>Theme settings updated successfully.</p></div>"; } ?> <?php // @todo http://codex.wordpress.org/Function_Reference/get_settings_errors $errors = get_settings_errors(); if ($errors) { echo "<div class='error'>"; foreach ($errors as $error) { echo esc_html($error['message']); } echo '</div>'; } ?> <form action="options.php" method="post"> <?php settings_fields('wp_light_options'); do_settings_sections('wp_light_settings'); ?> <br /> <input name="wp_light_options[submit]" type="submit" class="button-primary" value="<?php esc_attr_e('Save Settings', WP_LIGHT); ?> " /> </form> </div> <?php }
function theme_remove_sidebar() { $id = $_POST['sidebar_id']; global $wp_registered_sidebars; if (array_key_exists($id, $wp_registered_sidebars)) { $sidebars = get_option('generated_sidebars'); if (array_key_exists($id, $sidebars)) { unset($sidebars[$id]); unregister_sidebar($id); update_option('generated_sidebars', $sidebars); add_settings_error('general', 'settings_updated', __('Sidebar successfully removed.'), 'updated'); } else { add_settings_error('sidebars', 'name', __('This sidebar is not possible to remove.', TEMPLATENAME)); } } else { add_settings_error('sidebars', 'name', __('This sidebar does not exist.', TEMPLATENAME)); } set_transient('settings_errors', get_settings_errors(), 30); $goback = wp_get_referer(); wp_redirect($goback); exit; }
function my_admin_notice() { $set_errors = get_settings_errors(); if (!isset($_SESSION['page_for_posts']) || !isset($_SESSION['page_on_front'])) { $_SESSION['page_for_posts'] = get_option('page_for_posts'); $_SESSION['page_on_front'] = get_option('page_on_front'); } if (current_user_can('manage_options') && !empty($set_errors) && $_SERVER['PHP_SELF'] === '/wp-admin/options-reading.php') { if ($set_errors[0]['code'] == 'settings_updated' && isset($_GET['settings-updated']) && ($_SESSION['page_for_posts'] !== get_option('page_for_posts') || $_SESSION['page_on_front'] !== get_option('page_on_front'))) { $_SESSION['page_for_posts'] = get_option('page_for_posts'); $_SESSION['page_on_front'] = get_option('page_on_front'); if (get_option('show_on_front') == 'page') { echo '<div id="message" class="updated "> <p>Please, don\'t forget to update your Blog page. Click here: <a href="' . admin_url('edit.php?post_type=page') . '">Edit Pages</a> </p> </div>'; } else { echo '<div id="message" class="updated "> <p>Please, don\'t forget to update Front and Posts pages. Click here: <a href="' . admin_url('edit.php?post_type=page') . '">Edit Pages</a> </p> </div>'; } } } }
/** * Display settings errors registered by add_settings_error(). * * Part of the Settings API. Outputs a div for each error retrieved by * get_settings_errors(). * * This is called automatically after a settings page based on the * Settings API is submitted. Errors should be added during the validation * callback function for a setting defined in register_setting(). * * The $sanitize option is passed into get_settings_errors() and will * re-run the setting sanitization * on its current value. * * The $hide_on_update option will cause errors to only show when the settings * page is first loaded. if the user has already saved new values it will be * hidden to avoid repeating messages already shown in the default error * reporting after submission. This is useful to show general errors like * missing settings when the user arrives at the settings page. * * @since 3.0.0 * * @param string $setting Optional slug title of a specific setting who's errors you want. * @param bool $sanitize Whether to re-sanitize the setting value before returning errors. * @param bool $hide_on_update If set to true errors will not be shown if the settings page has * already been submitted. */ function settings_errors($setting = '', $sanitize = false, $hide_on_update = false) { if ($hide_on_update && !empty($_GET['settings-updated'])) { return; } $settings_errors = get_settings_errors($setting, $sanitize); if (empty($settings_errors)) { return; } $output = ''; foreach ($settings_errors as $key => $details) { $css_id = 'setting-error-' . $details['code']; $css_class = $details['type'] . ' settings-error notice is-dismissible'; $output .= "<div id='{$css_id}' class='{$css_class}'> \n"; $output .= "<p><strong>{$details['message']}</strong></p>"; $output .= "</div> \n"; } echo $output; }
/** * Sanitize and validate form input. Accepts an array, return a sanitized array. * * @see the_bootstrap_theme_options_init() * * @author Automattic * @since 1.3.0 - 06.04.2012 * * @return void */ function the_bootstrap_theme_options_validate($input) { $output = $defaults = the_bootstrap_get_default_theme_options(); if (isset($input['theme_layout']) and array_key_exists($input['theme_layout'], the_bootstrap_layouts())) { $output['theme_layout'] = $input['theme_layout']; } $output['navbar_site_name'] = (bool) $input['navbar_site_name']; $output['navbar_searchform'] = (bool) $input['navbar_searchform']; if (!get_settings_errors()) { add_settings_error('the-bootstrap-options', 'settings_updated', sprintf(__('Settings saved. <a href="%s">Visit your site</a> to see how it looks.', 'the-bootstrap'), home_url('/')), 'updated'); } return apply_filters('the_bootstrap_theme_options_validate', $output, $input, $defaults); }
} if (!is_array($value)) { $value = trim($value); } $value = stripslashes_deep($value); update_option($option, $value); } } /** * Handle settings errors and return to options page */ // If no settings errors were registered add a general 'updated' message. if (!count(get_settings_errors())) { add_settings_error('general', 'settings_updated', __('Settings saved.'), 'updated'); } set_transient('settings_errors', get_settings_errors(), 30); /** * Redirect back to the settings page that was submitted */ $goback = add_query_arg('updated', 'true', wp_get_referer()); wp_redirect($goback); exit; } include './admin-header.php'; ?> <div class="wrap"> <?php screen_icon(); ?> <h2><?php
function add_settings() { // Clear the log if clear button was clicked in settings if (isset($_GET["simple_history_clear_log_nonce"]) && wp_verify_nonce($_GET["simple_history_clear_log_nonce"], 'simple_history_clear_log')) { $this->clear_log(); $msg = __("Cleared database", 'simple-history'); add_settings_error("simple_history_rss_feed_regenerate_secret", "simple_history_rss_feed_regenerate_secret", $msg, "updated"); set_transient('settings_errors', get_settings_errors(), 30); $goback = esc_url_raw(add_query_arg('settings-updated', 'true', wp_get_referer())); wp_redirect($goback); exit; } // Section for general options // Will contain settings like where to show simple history and number of items $settings_section_general_id = self::SETTINGS_SECTION_GENERAL_ID; add_settings_section($settings_section_general_id, "", array($this, "settings_section_output"), SimpleHistory::SETTINGS_MENU_SLUG); // Settings for the general settings section // Each setting = one row in the settings section // add_settings_field( $id, $title, $callback, $page, $section, $args ); // Checkboxes for where to show simple history add_settings_field("simple_history_show_where", __("Show history", "simple-history"), array($this, "settings_field_where_to_show"), SimpleHistory::SETTINGS_MENU_SLUG, $settings_section_general_id); // Nonces for show where inputs register_setting("simple_history_settings_group", "simple_history_show_on_dashboard"); register_setting("simple_history_settings_group", "simple_history_show_as_page"); // Dropdown number if items to show add_settings_field("simple_history_number_of_items", __("Number of items per page", "simple-history"), array($this, "settings_field_number_of_items"), SimpleHistory::SETTINGS_MENU_SLUG, $settings_section_general_id); // Nonces for number of items inputs register_setting("simple_history_settings_group", "simple_history_pager_size"); // Link to clear log add_settings_field("simple_history_clear_log", __("Clear log", "simple-history"), array($this, "settings_field_clear_log"), SimpleHistory::SETTINGS_MENU_SLUG, $settings_section_general_id); }
/** * Displays plugin admin notices. * * @since 4.0 * * @return void */ public function admin_notices() { if (isset(get_current_screen()->id) && (strpos(get_current_screen()->id, 'security_page_toplevel_page_itsec_settings') !== false || strpos(get_current_screen()->id, 'security_page_toplevel_page_itsec_advanced') !== false || strpos(get_current_screen()->id, 'security_page_toplevel_page_itsec_pro') !== false)) { $errors = get_settings_errors('itsec'); $updated = ''; if (get_site_option('itsec_manual_update') == true) { delete_site_option('itsec_manual_update'); if (ITSEC_Lib::get_server() == 'nginx') { $server = __('NGINX conf file and/or restart your NGINX server', 'it-l10n-better-wp-security'); } else { $server = __('.htaccess file', 'it-l10n-better-wp-security'); } $updated = sprintf('<br />%s %s %s <a href="%s">%s</a> %s', __('As you have not allowed this plugin to update system files you must update your', 'it-l10n-better-wp-security'), $server, __('as well as your wp-config.php file manually. Rules to insert in both files can be found on the Dashboard page.', 'it-l10n-better-wp-security'), '?page=toplevel_page_itsec_settings#itsec_global_write_files', __('Click here', 'it-l10n-better-wp-security'), __('to allow this plugin to write to these files.', 'it-l10n-better-wp-security')); } if (sizeof($errors) === 0 && isset($_GET['settings-updated']) && sanitize_text_field($_GET['settings-updated']) == 'true') { add_settings_error('itsec', esc_attr('settings_updated'), __('Settings Updated', 'it-l10n-better-wp-security') . $updated, 'updated'); } } settings_errors('itsec'); }
/** * Display settings errors registered by add_settings_error() * * Part of the Settings API. Outputs a <div> for each error retrieved by get_settings_errors(). * * This is called automatically after a settings page based on the Settings API is submitted. * Errors should be added during the validation callback function for a setting defined in register_setting() * * The $sanitize option is passed into get_settings_errors() and will re-run the setting sanitization * on its current value. * * The $hide_on_update option will cause errors to only show when the settings page is first loaded. * if the user has already saved new values it will be hidden to avoid repeating messages already * shown in the default error reporting after submission. This is useful to show general errors like missing * settings when the user arrives at the settings page. * * @since 3.0.0 * * @param string $setting Optional slug title of a specific setting who's errors you want. * @param boolean $sanitize Whether to re-sanitize the setting value before returning errors. * @param boolean $hide_on_update If set to true errors will not be shown if the settings page has already been submitted. */ function settings_errors($setting = '', $sanitize = FALSE, $hide_on_update = FALSE) { if ($hide_on_update and $_GET['settings-updated']) { return; } $settings_errors = get_settings_errors($setting, $sanitize); if (!is_array($settings_errors)) { return; } $output = ''; foreach ($settings_errors as $key => $details) { $css_id = 'setting-error-' . $details['code']; $css_class = $details['type'] . ' settings-error'; $output .= "<div id='{$css_id}' class='{$css_class}'> \n"; $output .= "<p><strong>{$details['message']}</strong></p>"; $output .= "</div> \n"; } echo $output; }
$config->set_schedule($_POST['day'], $_POST['time'], $_POST['frequency'])->set_option('store_in_subfolder', $_POST['store_in_subfolder'] == "on")->set_option('dropbox_location', $_POST['dropbox_location']); add_settings_error('general', 'settings_updated', __('Settings saved.'), 'updated'); } } elseif (array_key_exists('unlink', $_POST)) { check_admin_referer('backup_to_dropbox_options_save'); $dropbox->unlink_account()->init(); } elseif (array_key_exists('clear_history', $_POST)) { check_admin_referer('backup_to_dropbox_options_save'); $config->clear_history(); } //Lets grab the schedule and the options to display to the user list($unixtime, $frequency) = $config->get_schedule(); if (!$frequency) { $frequency = 'weekly'; } if (!get_settings_errors('wpb2d_options')) { $dropbox_location = $config->get_option('dropbox_location'); $store_in_subfolder = $config->get_option('store_in_subfolder'); } $time = date('H:i', $unixtime); $day = date('D', $unixtime); ?> <link rel="stylesheet" type="text/css" href="<?php echo $uri; ?> /JQueryFileTree/jqueryFileTree.css"/> <script src="<?php echo $uri; ?> /JQueryFileTree/jqueryFileTree.js" type="text/javascript" language="javascript"></script> <script src="<?php