diff --git a/changelog.txt b/changelog.txt index ac2381c..9085ba9 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,5 +1,234 @@ == Changelog == += 1.1.5 = + +_Release date: 2026-08-24_ + +**Changed** + +* Manager (by ROBOTSTXT) detection uses the ecosystem presence constant `ROBOTSTXT_MANAGER_NOTICED` (Manager 1.6.2+) instead of scanning the installed-plugin list on every check; the plugin-list scan is kept as a fallback for older Manager versions and now also matches single-file Manager installs by basename + +**Compatibility** + +* WordPress: 4.0 - 7.1 +* PHP: 5.6 - 8.5 +* MariaDB: 10.6+ +* Multisite: compatible (Per-site and Global modes) + +**Tests** + +* PHPUnit: 22 tests, 53 assertions (6 new tests covering both Manager-detection paths: presence constant and plugin-list fallback) +* WordPress Coding Standards, PHPCompatibilityWP (PHP 5.6 - 8.5), and PHPStan level 9: zero errors +* Environment: PHP 8.5.9, MariaDB 11.8.8 + += 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_ + +**Highlights** + +* Security and reliability review of the 1.1.0 per-plugin Safe modes + +**Added** + +* The Plugins screen mode column is now a "Safe Mode" checkbox (checked = Safe, unchecked = Original) with an accessible hidden label and aria-label per row + +**Fixed** + +* The StellarWP telemetry blocks (iThemes Security, Kadence Blocks, The Events Calendar) are now actually applied: matchers without a host restriction were never reached, so those telemetry reports were silently sent despite Safe mode + +**Changed** + +* The profile registry is built once per request and cached, instead of being rebuilt on every outbound HTTP call + +**Security** + +* Full review of the new Plugins screen and Safe-mode guards (capabilities, nonces, multisite global-mode isolation, input whitelisting, output escaping, mock responses, caller attribution, uninstall cleanup) following OWASP and WordPress Plugin Security guidelines; no vulnerabilities found, and the findings above were addressed + +**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: path-only matcher application, host scoping, path constraints, per-request cache +* 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.0 = + +_Release date: 2026-08-18_ + +**Highlights** + +* Per-plugin Safe modes: the privacy reduction now extends beyond WordPress.org to the other installed plugins + +**Added** + +* "Plugins" screen (Telemetry → Plugins, and Network Admin → Telemetry → Plugins in Multisite global mode) listing every installed plugin with a known telemetry behavior in a table with the mode (Safe/Original per plugin, Safe by default), the plugin name, the installed version, the version the Safe profile was tested against, and the description of what is truncated; saved with a nonce- and capability-protected action +* Safe profiles for 99 popular plugins: usage trackers, analytics SDKs (Freemius, BSF analytics, Themeisle, Mixpanel, Appsero, StellarWP, WPMU DEV Hub), deactivation feedback surveys, and license-update extras are blocked or reduced to the minimum each service needs (license keys and account identifiers are kept), and the specific truncation is explained on every row +* Requests are attributed to the plugin that issues them through the caller backtrace, so endpoints shared by several plugins (api.wordpress.org, public-api.wordpress.com) never affect the others + +**Changed** + +* The Settings tab formerly shown as "Plugins" is now described as "Hidden plugins" to distinguish it from the new Plugins screen + +**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: blocking, query/body/header/User-Agent stripping, caller attribution, Original mode bypass, fake-slug rejection in the save handler +* PHP Coding Standards: 3.13.6 +* WordPress Coding Standards: 3.4.1 + += 1.0.1 = + +_Release date: 2026-08-18_ + +**Highlights** + +* Security and reliability review of the 1.0.0 feature set + +**Fixed** + +* Saving the "Plugins" tab from the Network Admin no longer resets the other network settings to their defaults; the hidden plugins list can now actually be saved in Global mode +* Credentials embedded in URLs are now always stripped from the logs, including URLs without query strings + +**Changed** + +* The redaction of sensitive keys in the logs now also covers "api-key", "cookie", "session", "private-key", and "private_key" +* Documentation clarified: the WordPress version masking applies to the User-Agent only, and the version query parameters always send the real version +* Development: the Composer manifest now declares name, description, and license (dev tooling only; the plugin has no runtime dependencies) + +**Security** + +* Full review of capabilities, nonces, sanitization, escaping, uninstall cleanup, and log redaction following OWASP and WordPress Plugin Security guidelines; no vulnerabilities found in the audited areas, and the findings above were addressed + +**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.0.0 = _Release date: 2026-08-18_ diff --git a/includes/class-robotstxt-telemetry-admin.php b/includes/class-robotstxt-telemetry-admin.php index df83ac3..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() ) { @@ -56,6 +59,15 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Admin' ) ) { 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', __( 'Logs', 'robotstxt-telemetry' ), @@ -72,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,6 +110,15 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Admin' ) ) { 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' ) + ); + if ( Robotstxt_Telemetry_Network::is_global() ) { add_submenu_page( 'robotstxt-telemetry', @@ -109,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 } /** @@ -188,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; @@ -212,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 ) { @@ -245,6 +287,20 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Admin' ) ) { return; } + if ( 'save_plugin_modes' === $action ) { + if ( 'robotstxt-telemetry-plugins' === $page ) { + $this->handle_plugin_modes_save(); + } + return; + } + + if ( 'save_site_settings' === $action ) { + if ( 'robotstxt-telemetry' === $page ) { + $this->handle_site_settings_save(); + } + return; + } + if ( 'robotstxt-telemetry-logs' !== $page ) { return; } @@ -270,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; @@ -296,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' ); @@ -318,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'; - $tab = in_array( $tab, array( 'main', 'logs', 'general' ), true ) ? $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 ); } @@ -363,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( @@ -380,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() ) ) { @@ -387,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 ) { @@ -407,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' ) ) { @@ -476,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'; } @@ -485,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( @@ -519,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() ) ) { @@ -535,8 +570,11 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Admin' ) ) { $this->render_tabs( $tab ); - echo '