diff --git a/changelog.txt b/changelog.txt index 236b950..0294c3a 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,5 +1,105 @@ == Changelog == += 1.1.4 = + +_Release date: 2026-08-20_ + +**Highlights** + +* Security and compatibility review of the whole code base, with static analysis raised to PHPStan level 9 + +**Added** + +* Development: PHPStan (level 9) with the WordPress stubs and the wp-compat rules, PHPUnit with the polyfills, and the missing PHPCS utilities; `bin/preflight.sh` runs every automatable pre-deploy check +* Tests: plugin header test suite (15 tests) verifying the required headers, the readme consistency (Stable tag, Requires at least, Requires PHP, Tested up to, License), the contributor order, the changelog URL, and the absence of the removed self-updater files + +**Changed** + +* Development: the full code base passes WordPress Coding Standards with zero errors and warnings, PHPStan level 9 with zero errors, and PHPCompatibilityWP for PHP 5.6 - 8.5 with zero errors +* Type safety: every parameter and return type documented (PHP 5.6-compatible phpDoc generics), all input paths narrowed before sanitization, and two always-dead branches removed (the logs list parameters column helper and the caller backtrace object check) +* License header of the main plugin file aligned with readme.txt ("GPL-3.0-or-later") + +**Fixed** + +* The User-Agent masking keeps the previous value when the regular expression replacement fails instead of returning null +* The Multisite main-site fallback (WordPress 4.8 and older) reads the network's blog_id only when it is set + +**Security** + +* Full review following OWASP and WordPress Plugin Security guidelines: capabilities, nonces, validation, sanitization, output escaping, database access, and uninstall cleanup re-audited with the new tooling; no vulnerabilities found, and the type hardening above was applied + +**Compatibility** + +* WordPress: 4.0 - 7.1 +* PHP: 5.6 - 8.5 +* MariaDB: 10.6+ +* Multisite: compatible (Per-site and Global modes) + +**Tests** + +* WordPress 7.2-alpha-63320, PHP 8.5.9, MariaDB 11.8.8 +* Verified live: plugin active on the staging site with no PHP notices, warnings, or deprecated messages +* PHP Coding Standards: 3.13.6 +* WordPress Coding Standards: 3.4.1 +* PHPCompatibilityWP (PHP 5.6 - 8.5) and wp-since (WordPress 4.0) static reviews for the floor versions +* PHPStan level 9 with the WordPress stubs: zero errors + += 1.1.3 = + +_Release date: 2026-08-20_ + +**Highlights** + +* Security and compatibility review of the 1.1.2 settings-save rewrite + +**Security** + +* Full review of the tab-scoped save handler (per-site and Network Admin) following OWASP and WordPress Plugin Security guidelines: nonce pairing, capability ordering (the capability check precedes every save branch, so site administrators cannot write network options in Global mode), tab whitelisting, hardcoded option names, per-value sanitization, and safe redirects with no open-redirect surface; all areas passed with no findings + +**Compatibility** + +* WordPress: 4.0 - 7.1 +* PHP: 5.6 - 8.5 +* MariaDB: 10.6+ +* Multisite: compatible (Per-site and Global modes) + +**Tests** + +* WordPress 7.2-alpha-63320, PHP 8.5.9, MariaDB 11.8.8 +* PHP Coding Standards: 3.13.6 +* WordPress Coding Standards: 3.4.1 +* PHPCompatibilityWP (PHP 5.6 - 8.5) and wp-since (WordPress 4.0) static reviews for the floor versions + += 1.1.2 = + +_Release date: 2026-08-18_ + +**Highlights** + +* Cross-tab settings saves fixed on the per-site Settings screen + +**Fixed** + +* Saving one tab of the per-site Settings screen no longer resets the other tabs: WordPress core sets every unposted option of a settings group to null since WordPress 5.5, so saving any tab was wiping the options of the other tabs back to their defaults (or, for the User-Agent mode, to the legacy pre-0.9 value). Each tab now saves through its own tab-scoped, nonce- and capability-protected handler shared with the Network Admin screen, updating only the options of the tab being saved + +**Changed** + +* The per-site Settings screen no longer posts through options.php; the Settings API registration of the options was removed along with it (the sanitizers are unchanged and still applied by the save handler) + +**Compatibility** + +* WordPress: 4.0 - 7.1 +* PHP: 5.6 - 8.5 +* MariaDB: 10.6+ +* Multisite: compatible (Per-site and Global modes) + +**Tests** + +* WordPress 7.2-alpha-63320, PHP 8.5.9, MariaDB 11.8.8 +* Verified live: main tab values survive saves of the Plugins, Logs, and General tabs and vice versa; hidden plugins, retention, and uninstall options each preserved +* PHP Coding Standards: 3.13.6 +* WordPress Coding Standards: 3.4.1 + = 1.1.1 = _Release date: 2026-08-18_ diff --git a/includes/class-robotstxt-telemetry-admin.php b/includes/class-robotstxt-telemetry-admin.php index 5dd1ea6..d771e7e 100644 --- a/includes/class-robotstxt-telemetry-admin.php +++ b/includes/class-robotstxt-telemetry-admin.php @@ -17,11 +17,12 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Admin' ) ) { /** * Register hooks. + * + * @return void */ public function register() { add_action( 'admin_menu', array( $this, 'register_menu' ) ); add_action( 'network_admin_menu', array( $this, 'register_network_menu' ) ); - add_action( 'admin_init', array( $this, 'register_settings' ) ); add_action( 'admin_init', array( $this, 'handle_actions' ) ); add_action( 'admin_notices', array( $this, 'render_saved_notice' ) ); add_action( 'network_admin_notices', array( $this, 'render_saved_notice' ) ); @@ -32,6 +33,8 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Admin' ) ) { * * In global mode the per-site screens are replaced by the * Network Admin ones. + * + * @return void */ public function register_menu() { if ( Robotstxt_Telemetry_Network::is_global() ) { @@ -47,33 +50,33 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Admin' ) ) { 'dashicons-admin-generic' ); - add_submenu_page( - 'robotstxt-telemetry', - __( 'Settings', 'robotstxt-telemetry' ), - __( 'Settings', 'robotstxt-telemetry' ), - 'manage_options', - 'robotstxt-telemetry', - array( $this, 'render_settings_page' ) - ); + add_submenu_page( + 'robotstxt-telemetry', + __( 'Settings', 'robotstxt-telemetry' ), + __( 'Settings', 'robotstxt-telemetry' ), + 'manage_options', + 'robotstxt-telemetry', + array( $this, 'render_settings_page' ) + ); - add_submenu_page( - 'robotstxt-telemetry', - __( 'Plugins', 'robotstxt-telemetry' ), - __( 'Plugins', 'robotstxt-telemetry' ), - 'manage_options', - 'robotstxt-telemetry-plugins', - array( $this, 'render_plugins_page' ) - ); + add_submenu_page( + 'robotstxt-telemetry', + __( 'Plugins', 'robotstxt-telemetry' ), + __( 'Plugins', 'robotstxt-telemetry' ), + 'manage_options', + 'robotstxt-telemetry-plugins', + array( $this, 'render_plugins_page' ) + ); - add_submenu_page( - 'robotstxt-telemetry', - __( 'Logs', 'robotstxt-telemetry' ), - __( 'Logs', 'robotstxt-telemetry' ), - 'manage_options', - 'robotstxt-telemetry-logs', - array( $this, 'render_logs_page' ) - ); - } + add_submenu_page( + 'robotstxt-telemetry', + __( 'Logs', 'robotstxt-telemetry' ), + __( 'Logs', 'robotstxt-telemetry' ), + 'manage_options', + 'robotstxt-telemetry-logs', + array( $this, 'render_logs_page' ) + ); + } /** * Register the Network Admin menus (Multisite only). @@ -81,6 +84,8 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Admin' ) ) { * The Network Settings screen always exposes the configuration * mode; when the network runs in global mode it also hosts the * shared settings and the central Logs screen. + * + * @return void */ public function register_network_menu() { if ( ! is_multisite() ) { @@ -96,25 +101,25 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Admin' ) ) { 'dashicons-admin-generic' ); - add_submenu_page( - 'robotstxt-telemetry', - __( 'Settings', 'robotstxt-telemetry' ), - __( 'Settings', 'robotstxt-telemetry' ), - 'manage_network_options', - 'robotstxt-telemetry', - array( $this, 'render_network_settings_page' ) - ); + add_submenu_page( + 'robotstxt-telemetry', + __( 'Settings', 'robotstxt-telemetry' ), + __( 'Settings', 'robotstxt-telemetry' ), + 'manage_network_options', + 'robotstxt-telemetry', + array( $this, 'render_network_settings_page' ) + ); - add_submenu_page( - 'robotstxt-telemetry', - __( 'Plugins', 'robotstxt-telemetry' ), - __( 'Plugins', 'robotstxt-telemetry' ), - 'manage_network_options', - 'robotstxt-telemetry-plugins', - array( $this, 'render_plugins_page' ) - ); + add_submenu_page( + 'robotstxt-telemetry', + __( 'Plugins', 'robotstxt-telemetry' ), + __( 'Plugins', 'robotstxt-telemetry' ), + 'manage_network_options', + 'robotstxt-telemetry-plugins', + array( $this, 'render_plugins_page' ) + ); - if ( Robotstxt_Telemetry_Network::is_global() ) { + if ( Robotstxt_Telemetry_Network::is_global() ) { add_submenu_page( 'robotstxt-telemetry', __( 'Logs', 'robotstxt-telemetry' ), @@ -127,31 +132,54 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Admin' ) ) { } /** - * Register the plugin settings. + * Save the settings of a single tab (per-site and network screens). + * + * Only the options of the given tab are read from the POST and + * updated, so the other tabs keep their values. WordPress core + * options.php cannot be used for this: it updates every registered + * option of the group, setting the ones missing from the POST to null. + * + * @param string $tab Settings tab: 'main', 'plugins', 'logs', or 'general'. + * @return void */ - public function register_settings() { - $settings = array( - 'robotstxt_telemetry_useragent_url' => array( 'string', 'hash', 'sanitize_useragent_mode' ), - 'robotstxt_telemetry_wp_version' => array( 'string', 'actual', 'sanitize_version_mode' ), - 'robotstxt_telemetry_mask_locale' => array( 'boolean', false, 'sanitize_checkbox' ), - 'robotstxt_telemetry_replace_news_feed' => array( 'boolean', true, 'sanitize_checkbox' ), - 'robotstxt_telemetry_replace_events_api' => array( 'boolean', true, 'sanitize_checkbox' ), - 'robotstxt_telemetry_disable_browse_happy' => array( 'boolean', true, 'sanitize_checkbox' ), - 'robotstxt_telemetry_wp_core_check' => array( 'string', 'safe', 'sanitize_mode' ), - 'robotstxt_telemetry_wp_themes_check' => array( 'string', 'safe', 'sanitize_mode' ), - 'robotstxt_telemetry_wp_plugins_check' => array( 'string', 'safe', 'sanitize_mode' ), - 'robotstxt_telemetry_hidden_plugins' => array( 'array', array(), 'sanitize_hidden_plugins' ), - 'robotstxt_telemetry_retention_period' => array( 'string', '12hours', 'sanitize_retention' ), - 'robotstxt_telemetry_delete_on_uninstall' => array( 'boolean', false, 'sanitize_checkbox' ), - ); + private function save_tab_settings( $tab ) { + // phpcs:disable WordPress.Security.NonceVerification.Missing -- Callers verified the nonce. + if ( 'logs' === $tab ) { + $retention = isset( $_POST['robotstxt_telemetry_retention_period'] ) && is_string( $_POST['robotstxt_telemetry_retention_period'] ) ? sanitize_key( wp_unslash( $_POST['robotstxt_telemetry_retention_period'] ) ) : '12hours'; + Robotstxt_Telemetry_Network::update_setting( 'robotstxt_telemetry_retention_period', $this->sanitize_retention( $retention ) ); + } elseif ( 'plugins' === $tab ) { + $hidden = isset( $_POST['robotstxt_telemetry_hidden_plugins'] ) ? array_map( + function ( $value ) { + return is_string( $value ) ? sanitize_text_field( $value ) : ''; + }, + (array) wp_unslash( $_POST['robotstxt_telemetry_hidden_plugins'] ) // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- Each value is sanitized in the callback above. + ) : array(); + Robotstxt_Telemetry_Network::update_setting( 'robotstxt_telemetry_hidden_plugins', $this->sanitize_hidden_plugins( $hidden ) ); + } elseif ( 'general' === $tab ) { + $delete = ! empty( $_POST['robotstxt_telemetry_delete_on_uninstall'] ); + Robotstxt_Telemetry_Network::update_setting( 'robotstxt_telemetry_delete_on_uninstall', $delete ); + } else { + $useragent_mode = isset( $_POST['robotstxt_telemetry_useragent_url'] ) && is_string( $_POST['robotstxt_telemetry_useragent_url'] ) ? sanitize_key( wp_unslash( $_POST['robotstxt_telemetry_useragent_url'] ) ) : 'hash'; + $version_mode = isset( $_POST['robotstxt_telemetry_wp_version'] ) && is_string( $_POST['robotstxt_telemetry_wp_version'] ) ? sanitize_key( wp_unslash( $_POST['robotstxt_telemetry_wp_version'] ) ) : 'actual'; + $mask_locale = ! empty( $_POST['robotstxt_telemetry_mask_locale'] ); + $replace_news = ! empty( $_POST['robotstxt_telemetry_replace_news_feed'] ); + $replace_events = ! empty( $_POST['robotstxt_telemetry_replace_events_api'] ); + $disable_browse_happy = ! empty( $_POST['robotstxt_telemetry_disable_browse_happy'] ); + $core = isset( $_POST['robotstxt_telemetry_wp_core_check'] ) && is_string( $_POST['robotstxt_telemetry_wp_core_check'] ) ? sanitize_key( wp_unslash( $_POST['robotstxt_telemetry_wp_core_check'] ) ) : 'safe'; + $themes = isset( $_POST['robotstxt_telemetry_wp_themes_check'] ) && is_string( $_POST['robotstxt_telemetry_wp_themes_check'] ) ? sanitize_key( wp_unslash( $_POST['robotstxt_telemetry_wp_themes_check'] ) ) : 'safe'; + $plugins = isset( $_POST['robotstxt_telemetry_wp_plugins_check'] ) && is_string( $_POST['robotstxt_telemetry_wp_plugins_check'] ) ? sanitize_key( wp_unslash( $_POST['robotstxt_telemetry_wp_plugins_check'] ) ) : 'safe'; - foreach ( $settings as $name => $config ) { - register_setting( - 'robotstxt_telemetry_settings', - $name, - array( $this, $config[2] ) - ); + Robotstxt_Telemetry_Network::update_setting( 'robotstxt_telemetry_useragent_url', $this->sanitize_useragent_mode( $useragent_mode ) ); + Robotstxt_Telemetry_Network::update_setting( 'robotstxt_telemetry_wp_version', $this->sanitize_version_mode( $version_mode ) ); + Robotstxt_Telemetry_Network::update_setting( 'robotstxt_telemetry_mask_locale', $mask_locale ); + Robotstxt_Telemetry_Network::update_setting( 'robotstxt_telemetry_replace_news_feed', $replace_news ); + Robotstxt_Telemetry_Network::update_setting( 'robotstxt_telemetry_replace_events_api', $replace_events ); + Robotstxt_Telemetry_Network::update_setting( 'robotstxt_telemetry_disable_browse_happy', $disable_browse_happy ); + Robotstxt_Telemetry_Network::update_setting( 'robotstxt_telemetry_wp_core_check', $this->sanitize_mode( $core ) ); + Robotstxt_Telemetry_Network::update_setting( 'robotstxt_telemetry_wp_themes_check', $this->sanitize_mode( $themes ) ); + Robotstxt_Telemetry_Network::update_setting( 'robotstxt_telemetry_wp_plugins_check', $this->sanitize_mode( $plugins ) ); } + // phpcs:enable } /** @@ -206,7 +234,11 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Admin' ) ) { $hidden = array(); foreach ( $value as $basename ) { - $basename = sanitize_text_field( (string) $basename ); + if ( ! is_string( $basename ) ) { + continue; + } + + $basename = sanitize_text_field( $basename ); if ( in_array( $basename, $installed, true ) ) { $hidden[] = $basename; @@ -230,23 +262,15 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Admin' ) ) { return in_array( $value, $valid, true ) ? $value : '12hours'; } - /** - * Sanitize a checkbox value. - * - * @param mixed $value Raw input value. - * @return bool - */ - public function sanitize_checkbox( $value ) { - return (bool) $value; - } - /** * Handle admin actions. + * + * @return void */ public function handle_actions() { // phpcs:disable WordPress.Security.NonceVerification.Recommended -- State changes are protected by check_admin_referer() below. - $page = isset( $_GET['page'] ) ? sanitize_key( wp_unslash( $_GET['page'] ) ) : ''; - $action = isset( $_REQUEST['action'] ) ? sanitize_key( wp_unslash( $_REQUEST['action'] ) ) : ''; + $page = isset( $_GET['page'] ) && is_string( $_GET['page'] ) ? sanitize_key( wp_unslash( $_GET['page'] ) ) : ''; + $action = isset( $_REQUEST['action'] ) && is_string( $_REQUEST['action'] ) ? sanitize_key( wp_unslash( $_REQUEST['action'] ) ) : ''; // Network-level actions are always restricted to super administrators. if ( 'save_network_mode' === $action || 'save_network_settings' === $action ) { @@ -270,6 +294,13 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Admin' ) ) { return; } + if ( 'save_site_settings' === $action ) { + if ( 'robotstxt-telemetry' === $page ) { + $this->handle_site_settings_save(); + } + return; + } + if ( 'robotstxt-telemetry-logs' !== $page ) { return; } @@ -295,7 +326,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Admin' ) ) { return; } - $log_id = isset( $_GET['log'] ) ? absint( wp_unslash( $_GET['log'] ) ) : 0; + $log_id = isset( $_GET['log'] ) && is_string( $_GET['log'] ) ? absint( wp_unslash( $_GET['log'] ) ) : 0; // phpcs:enable if ( 0 === $log_id ) { return; @@ -321,13 +352,14 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Admin' ) ) { * Handle Network Admin settings actions. * * @param string $action Action name. + * @return void */ private function handle_network_actions( $action ) { if ( 'save_network_mode' === $action ) { check_admin_referer( 'robotstxt_telemetry_network_mode' ); // phpcs:ignore WordPress.Security.NonceVerification.Missing -- Verified by check_admin_referer() above. - $new_mode = isset( $_POST['robotstxt_telemetry_config_mode'] ) ? sanitize_key( wp_unslash( $_POST['robotstxt_telemetry_config_mode'] ) ) : 'per-site'; + $new_mode = isset( $_POST['robotstxt_telemetry_config_mode'] ) && is_string( $_POST['robotstxt_telemetry_config_mode'] ) ? sanitize_key( wp_unslash( $_POST['robotstxt_telemetry_config_mode'] ) ) : 'per-site'; $new_mode = Robotstxt_Telemetry_Network::sanitize_mode( $new_mode ); $old_mode = get_site_option( Robotstxt_Telemetry_Network::MODE_OPTION, 'per-site' ); @@ -343,41 +375,11 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Admin' ) ) { if ( 'save_network_settings' === $action ) { check_admin_referer( 'robotstxt_telemetry_network_settings' ); - // phpcs:disable WordPress.Security.NonceVerification.Missing -- Verified by check_admin_referer() above. - $tab = isset( $_POST['tab'] ) ? sanitize_key( wp_unslash( $_POST['tab'] ) ) : 'main'; + // phpcs:ignore WordPress.Security.NonceVerification.Missing -- Verified by check_admin_referer() above. + $tab = isset( $_POST['tab'] ) && is_string( $_POST['tab'] ) ? sanitize_key( wp_unslash( $_POST['tab'] ) ) : 'main'; $tab = in_array( $tab, array( 'main', 'plugins', 'logs', 'general' ), true ) ? $tab : 'main'; - if ( 'logs' === $tab ) { - $retention = isset( $_POST['robotstxt_telemetry_retention_period'] ) ? sanitize_key( wp_unslash( $_POST['robotstxt_telemetry_retention_period'] ) ) : '12hours'; - Robotstxt_Telemetry_Network::update_setting( 'robotstxt_telemetry_retention_period', $this->sanitize_retention( $retention ) ); - } elseif ( 'plugins' === $tab ) { - $hidden = isset( $_POST['robotstxt_telemetry_hidden_plugins'] ) ? array_map( 'sanitize_text_field', (array) wp_unslash( $_POST['robotstxt_telemetry_hidden_plugins'] ) ) : array(); - Robotstxt_Telemetry_Network::update_setting( 'robotstxt_telemetry_hidden_plugins', $this->sanitize_hidden_plugins( $hidden ) ); - } elseif ( 'general' === $tab ) { - $delete = ! empty( $_POST['robotstxt_telemetry_delete_on_uninstall'] ); - Robotstxt_Telemetry_Network::update_setting( 'robotstxt_telemetry_delete_on_uninstall', $delete ); - } else { - $useragent_mode = isset( $_POST['robotstxt_telemetry_useragent_url'] ) ? sanitize_key( wp_unslash( $_POST['robotstxt_telemetry_useragent_url'] ) ) : 'hash'; - $version_mode = isset( $_POST['robotstxt_telemetry_wp_version'] ) ? sanitize_key( wp_unslash( $_POST['robotstxt_telemetry_wp_version'] ) ) : 'actual'; - $mask_locale = ! empty( $_POST['robotstxt_telemetry_mask_locale'] ); - $replace_news = ! empty( $_POST['robotstxt_telemetry_replace_news_feed'] ); - $replace_events = ! empty( $_POST['robotstxt_telemetry_replace_events_api'] ); - $disable_browse_happy = ! empty( $_POST['robotstxt_telemetry_disable_browse_happy'] ); - $core = isset( $_POST['robotstxt_telemetry_wp_core_check'] ) ? sanitize_key( wp_unslash( $_POST['robotstxt_telemetry_wp_core_check'] ) ) : 'safe'; - $themes = isset( $_POST['robotstxt_telemetry_wp_themes_check'] ) ? sanitize_key( wp_unslash( $_POST['robotstxt_telemetry_wp_themes_check'] ) ) : 'safe'; - $plugins = isset( $_POST['robotstxt_telemetry_wp_plugins_check'] ) ? sanitize_key( wp_unslash( $_POST['robotstxt_telemetry_wp_plugins_check'] ) ) : 'safe'; - - Robotstxt_Telemetry_Network::update_setting( 'robotstxt_telemetry_useragent_url', $this->sanitize_useragent_mode( $useragent_mode ) ); - Robotstxt_Telemetry_Network::update_setting( 'robotstxt_telemetry_wp_version', $this->sanitize_version_mode( $version_mode ) ); - Robotstxt_Telemetry_Network::update_setting( 'robotstxt_telemetry_mask_locale', $mask_locale ); - Robotstxt_Telemetry_Network::update_setting( 'robotstxt_telemetry_replace_news_feed', $replace_news ); - Robotstxt_Telemetry_Network::update_setting( 'robotstxt_telemetry_replace_events_api', $replace_events ); - Robotstxt_Telemetry_Network::update_setting( 'robotstxt_telemetry_disable_browse_happy', $disable_browse_happy ); - Robotstxt_Telemetry_Network::update_setting( 'robotstxt_telemetry_wp_core_check', $this->sanitize_mode( $core ) ); - Robotstxt_Telemetry_Network::update_setting( 'robotstxt_telemetry_wp_themes_check', $this->sanitize_mode( $themes ) ); - Robotstxt_Telemetry_Network::update_setting( 'robotstxt_telemetry_wp_plugins_check', $this->sanitize_mode( $plugins ) ); - } - // phpcs:enable + $this->save_tab_settings( $tab ); $this->redirect_network_settings( 'settings-updated', $tab ); } @@ -388,6 +390,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Admin' ) ) { * * @param string $flag Query flag to append. * @param string $tab Settings tab to return to. + * @return void */ private function redirect_network_settings( $flag, $tab = 'main' ) { wp_safe_redirect( @@ -405,6 +408,8 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Admin' ) ) { /** * Render the settings saved notice. + * + * @return void */ public function render_saved_notice() { if ( ! current_user_can( Robotstxt_Telemetry_Network::manage_capability() ) ) { @@ -412,9 +417,9 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Admin' ) ) { } // phpcs:disable WordPress.Security.NonceVerification.Recommended -- Read-only rendering of an admin screen. - $settings_updated = isset( $_GET['settings-updated'] ) ? sanitize_key( wp_unslash( $_GET['settings-updated'] ) ) : ''; - $mode_updated = isset( $_GET['mode-updated'] ) ? sanitize_key( wp_unslash( $_GET['mode-updated'] ) ) : ''; - $page = isset( $_GET['page'] ) ? sanitize_key( wp_unslash( $_GET['page'] ) ) : ''; + $settings_updated = isset( $_GET['settings-updated'] ) && is_string( $_GET['settings-updated'] ) ? sanitize_key( wp_unslash( $_GET['settings-updated'] ) ) : ''; + $mode_updated = isset( $_GET['mode-updated'] ) && is_string( $_GET['mode-updated'] ) ? sanitize_key( wp_unslash( $_GET['mode-updated'] ) ) : ''; + $page = isset( $_GET['page'] ) && is_string( $_GET['page'] ) ? sanitize_key( wp_unslash( $_GET['page'] ) ) : ''; // phpcs:enable if ( 'robotstxt-telemetry' !== $page ) { @@ -432,6 +437,8 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Admin' ) ) { /** * Render the Network Admin settings page (Multisite only). + * + * @return void */ public function render_network_settings_page() { if ( ! current_user_can( 'manage_network_options' ) ) { @@ -501,7 +508,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Admin' ) ) { */ private function get_current_tab() { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Read-only navigation state. - $tab = isset( $_GET['tab'] ) ? sanitize_key( wp_unslash( $_GET['tab'] ) ) : 'main'; + $tab = isset( $_GET['tab'] ) && is_string( $_GET['tab'] ) ? sanitize_key( wp_unslash( $_GET['tab'] ) ) : 'main'; return in_array( $tab, array( 'main', 'plugins', 'logs', 'general' ), true ) ? $tab : 'main'; } @@ -510,6 +517,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Admin' ) ) { * Render the settings screen tabs. * * @param string $current_tab Current tab slug. + * @return void */ private function render_tabs( $current_tab ) { $tabs = array( @@ -544,6 +552,8 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Admin' ) ) { /** * Render settings page. + * + * @return void */ public function render_settings_page() { if ( ! current_user_can( Robotstxt_Telemetry_Network::manage_capability() ) ) { @@ -560,8 +570,11 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Admin' ) ) { $this->render_tabs( $tab ); - echo '