/** * Settings Sanitization * * Adds a settings error (for the updated message) * At some point this will validate input. * * Note: All sanitized settings will be saved. * Thus, no error messages will be produced. * * Filters in order: * - plugin_name_settings_sanitize_<tab_slug> * - plugin_name_settings_sanitize_<type> * - plugin_name_settings_sanitize * - plugin_name_settings_on_change_<tab_slug> * - plugin_name_settings_on_change_<field_key> * * @since 1.0.0 * @param array $input The value inputted in the field * @return string $input Sanitizied value */ public function settings_sanitize($input = array()) { if (empty($_POST['_wp_http_referer'])) { return $input; } parse_str($_POST['_wp_http_referer'], $referrer); $tab = isset($referrer['tab']) ? $referrer['tab'] : Plugin_Name_Settings_Definition::get_default_tab_slug(); // Tab filter $input = apply_filters('plugin_name_settings_sanitize_' . $tab, $input); // Trigger action hook for general settings update for $tab $this->do_settings_on_change_hook($input, $tab); // Loop through each setting being saved and pass it through a sanitization filter foreach ($input as $key => $value) { $new_value = $value; // set value of $value in $new_value $input[$key] = $this->apply_type_filter($input, $tab, $key); $input[$key] = $this->apply_general_filter($input, $key); $this->do_settings_on_key_change_hook($key, $new_value); } add_settings_error($this->plugin_name . '-notices', $this->plugin_name, __('Settings updated.', $this->plugin_name), 'updated'); return $this->get_output($tab, $input); }
/** * Render the settings page for this plugin. * * @since 1.0.0 */ public function display_plugin_admin_page() { $tabs = Plugin_Name_Settings_Definition::get_tabs(); $default_tab = Plugin_Name_Settings_Definition::get_default_tab_slug(); $active_tab = isset($_GET['tab']) && array_key_exists($_GET['tab'], $tabs) ? $_GET['tab'] : $default_tab; include_once 'partials/' . $this->plugin_name . '-admin-display.php'; }