v1.1.4
This commit is contained in:
parent
7ae471e27f
commit
e4518812c3
18 changed files with 1800 additions and 1093 deletions
100
changelog.txt
100
changelog.txt
|
|
@ -1,5 +1,105 @@
|
||||||
== Changelog ==
|
== 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 =
|
= 1.1.1 =
|
||||||
|
|
||||||
_Release date: 2026-08-18_
|
_Release date: 2026-08-18_
|
||||||
|
|
|
||||||
|
|
@ -17,11 +17,12 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Admin' ) ) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register hooks.
|
* Register hooks.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function register() {
|
public function register() {
|
||||||
add_action( 'admin_menu', array( $this, 'register_menu' ) );
|
add_action( 'admin_menu', array( $this, 'register_menu' ) );
|
||||||
add_action( 'network_admin_menu', array( $this, 'register_network_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_init', array( $this, 'handle_actions' ) );
|
||||||
add_action( 'admin_notices', array( $this, 'render_saved_notice' ) );
|
add_action( 'admin_notices', array( $this, 'render_saved_notice' ) );
|
||||||
add_action( 'network_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
|
* In global mode the per-site screens are replaced by the
|
||||||
* Network Admin ones.
|
* Network Admin ones.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function register_menu() {
|
public function register_menu() {
|
||||||
if ( Robotstxt_Telemetry_Network::is_global() ) {
|
if ( Robotstxt_Telemetry_Network::is_global() ) {
|
||||||
|
|
@ -81,6 +84,8 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Admin' ) ) {
|
||||||
* The Network Settings screen always exposes the configuration
|
* The Network Settings screen always exposes the configuration
|
||||||
* mode; when the network runs in global mode it also hosts the
|
* mode; when the network runs in global mode it also hosts the
|
||||||
* shared settings and the central Logs screen.
|
* shared settings and the central Logs screen.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function register_network_menu() {
|
public function register_network_menu() {
|
||||||
if ( ! is_multisite() ) {
|
if ( ! is_multisite() ) {
|
||||||
|
|
@ -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() {
|
private function save_tab_settings( $tab ) {
|
||||||
$settings = array(
|
// phpcs:disable WordPress.Security.NonceVerification.Missing -- Callers verified the nonce.
|
||||||
'robotstxt_telemetry_useragent_url' => array( 'string', 'hash', 'sanitize_useragent_mode' ),
|
if ( 'logs' === $tab ) {
|
||||||
'robotstxt_telemetry_wp_version' => array( 'string', 'actual', 'sanitize_version_mode' ),
|
$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_mask_locale' => array( 'boolean', false, 'sanitize_checkbox' ),
|
Robotstxt_Telemetry_Network::update_setting( 'robotstxt_telemetry_retention_period', $this->sanitize_retention( $retention ) );
|
||||||
'robotstxt_telemetry_replace_news_feed' => array( 'boolean', true, 'sanitize_checkbox' ),
|
} elseif ( 'plugins' === $tab ) {
|
||||||
'robotstxt_telemetry_replace_events_api' => array( 'boolean', true, 'sanitize_checkbox' ),
|
$hidden = isset( $_POST['robotstxt_telemetry_hidden_plugins'] ) ? array_map(
|
||||||
'robotstxt_telemetry_disable_browse_happy' => array( 'boolean', true, 'sanitize_checkbox' ),
|
function ( $value ) {
|
||||||
'robotstxt_telemetry_wp_core_check' => array( 'string', 'safe', 'sanitize_mode' ),
|
return is_string( $value ) ? sanitize_text_field( $value ) : '';
|
||||||
'robotstxt_telemetry_wp_themes_check' => array( 'string', 'safe', 'sanitize_mode' ),
|
},
|
||||||
'robotstxt_telemetry_wp_plugins_check' => array( 'string', 'safe', 'sanitize_mode' ),
|
(array) wp_unslash( $_POST['robotstxt_telemetry_hidden_plugins'] ) // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- Each value is sanitized in the callback above.
|
||||||
'robotstxt_telemetry_hidden_plugins' => array( 'array', array(), 'sanitize_hidden_plugins' ),
|
) : array();
|
||||||
'robotstxt_telemetry_retention_period' => array( 'string', '12hours', 'sanitize_retention' ),
|
Robotstxt_Telemetry_Network::update_setting( 'robotstxt_telemetry_hidden_plugins', $this->sanitize_hidden_plugins( $hidden ) );
|
||||||
'robotstxt_telemetry_delete_on_uninstall' => array( 'boolean', false, 'sanitize_checkbox' ),
|
} 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 ) {
|
Robotstxt_Telemetry_Network::update_setting( 'robotstxt_telemetry_useragent_url', $this->sanitize_useragent_mode( $useragent_mode ) );
|
||||||
register_setting(
|
Robotstxt_Telemetry_Network::update_setting( 'robotstxt_telemetry_wp_version', $this->sanitize_version_mode( $version_mode ) );
|
||||||
'robotstxt_telemetry_settings',
|
Robotstxt_Telemetry_Network::update_setting( 'robotstxt_telemetry_mask_locale', $mask_locale );
|
||||||
$name,
|
Robotstxt_Telemetry_Network::update_setting( 'robotstxt_telemetry_replace_news_feed', $replace_news );
|
||||||
array( $this, $config[2] )
|
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();
|
$hidden = array();
|
||||||
|
|
||||||
foreach ( $value as $basename ) {
|
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 ) ) {
|
if ( in_array( $basename, $installed, true ) ) {
|
||||||
$hidden[] = $basename;
|
$hidden[] = $basename;
|
||||||
|
|
@ -230,23 +262,15 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Admin' ) ) {
|
||||||
return in_array( $value, $valid, true ) ? $value : '12hours';
|
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.
|
* Handle admin actions.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function handle_actions() {
|
public function handle_actions() {
|
||||||
// phpcs:disable WordPress.Security.NonceVerification.Recommended -- State changes are protected by check_admin_referer() below.
|
// 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'] ) ) : '';
|
$page = isset( $_GET['page'] ) && is_string( $_GET['page'] ) ? sanitize_key( wp_unslash( $_GET['page'] ) ) : '';
|
||||||
$action = isset( $_REQUEST['action'] ) ? sanitize_key( wp_unslash( $_REQUEST['action'] ) ) : '';
|
$action = isset( $_REQUEST['action'] ) && is_string( $_REQUEST['action'] ) ? sanitize_key( wp_unslash( $_REQUEST['action'] ) ) : '';
|
||||||
|
|
||||||
// Network-level actions are always restricted to super administrators.
|
// Network-level actions are always restricted to super administrators.
|
||||||
if ( 'save_network_mode' === $action || 'save_network_settings' === $action ) {
|
if ( 'save_network_mode' === $action || 'save_network_settings' === $action ) {
|
||||||
|
|
@ -270,6 +294,13 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Admin' ) ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( 'save_site_settings' === $action ) {
|
||||||
|
if ( 'robotstxt-telemetry' === $page ) {
|
||||||
|
$this->handle_site_settings_save();
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if ( 'robotstxt-telemetry-logs' !== $page ) {
|
if ( 'robotstxt-telemetry-logs' !== $page ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -295,7 +326,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Admin' ) ) {
|
||||||
return;
|
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
|
// phpcs:enable
|
||||||
if ( 0 === $log_id ) {
|
if ( 0 === $log_id ) {
|
||||||
return;
|
return;
|
||||||
|
|
@ -321,13 +352,14 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Admin' ) ) {
|
||||||
* Handle Network Admin settings actions.
|
* Handle Network Admin settings actions.
|
||||||
*
|
*
|
||||||
* @param string $action Action name.
|
* @param string $action Action name.
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
private function handle_network_actions( $action ) {
|
private function handle_network_actions( $action ) {
|
||||||
if ( 'save_network_mode' === $action ) {
|
if ( 'save_network_mode' === $action ) {
|
||||||
check_admin_referer( 'robotstxt_telemetry_network_mode' );
|
check_admin_referer( 'robotstxt_telemetry_network_mode' );
|
||||||
|
|
||||||
// phpcs:ignore WordPress.Security.NonceVerification.Missing -- Verified by check_admin_referer() above.
|
// 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 );
|
$new_mode = Robotstxt_Telemetry_Network::sanitize_mode( $new_mode );
|
||||||
$old_mode = get_site_option( Robotstxt_Telemetry_Network::MODE_OPTION, 'per-site' );
|
$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 ) {
|
if ( 'save_network_settings' === $action ) {
|
||||||
check_admin_referer( 'robotstxt_telemetry_network_settings' );
|
check_admin_referer( 'robotstxt_telemetry_network_settings' );
|
||||||
|
|
||||||
// phpcs:disable WordPress.Security.NonceVerification.Missing -- Verified by check_admin_referer() above.
|
// phpcs:ignore WordPress.Security.NonceVerification.Missing -- Verified by check_admin_referer() above.
|
||||||
$tab = isset( $_POST['tab'] ) ? sanitize_key( wp_unslash( $_POST['tab'] ) ) : 'main';
|
$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';
|
$tab = in_array( $tab, array( 'main', 'plugins', 'logs', 'general' ), true ) ? $tab : 'main';
|
||||||
|
|
||||||
if ( 'logs' === $tab ) {
|
$this->save_tab_settings( $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->redirect_network_settings( 'settings-updated', $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 $flag Query flag to append.
|
||||||
* @param string $tab Settings tab to return to.
|
* @param string $tab Settings tab to return to.
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
private function redirect_network_settings( $flag, $tab = 'main' ) {
|
private function redirect_network_settings( $flag, $tab = 'main' ) {
|
||||||
wp_safe_redirect(
|
wp_safe_redirect(
|
||||||
|
|
@ -405,6 +408,8 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Admin' ) ) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Render the settings saved notice.
|
* Render the settings saved notice.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function render_saved_notice() {
|
public function render_saved_notice() {
|
||||||
if ( ! current_user_can( Robotstxt_Telemetry_Network::manage_capability() ) ) {
|
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.
|
// 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'] ) ) : '';
|
$settings_updated = isset( $_GET['settings-updated'] ) && is_string( $_GET['settings-updated'] ) ? sanitize_key( wp_unslash( $_GET['settings-updated'] ) ) : '';
|
||||||
$mode_updated = isset( $_GET['mode-updated'] ) ? sanitize_key( wp_unslash( $_GET['mode-updated'] ) ) : '';
|
$mode_updated = isset( $_GET['mode-updated'] ) && is_string( $_GET['mode-updated'] ) ? sanitize_key( wp_unslash( $_GET['mode-updated'] ) ) : '';
|
||||||
$page = isset( $_GET['page'] ) ? sanitize_key( wp_unslash( $_GET['page'] ) ) : '';
|
$page = isset( $_GET['page'] ) && is_string( $_GET['page'] ) ? sanitize_key( wp_unslash( $_GET['page'] ) ) : '';
|
||||||
// phpcs:enable
|
// phpcs:enable
|
||||||
|
|
||||||
if ( 'robotstxt-telemetry' !== $page ) {
|
if ( 'robotstxt-telemetry' !== $page ) {
|
||||||
|
|
@ -432,6 +437,8 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Admin' ) ) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Render the Network Admin settings page (Multisite only).
|
* Render the Network Admin settings page (Multisite only).
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function render_network_settings_page() {
|
public function render_network_settings_page() {
|
||||||
if ( ! current_user_can( 'manage_network_options' ) ) {
|
if ( ! current_user_can( 'manage_network_options' ) ) {
|
||||||
|
|
@ -501,7 +508,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Admin' ) ) {
|
||||||
*/
|
*/
|
||||||
private function get_current_tab() {
|
private function get_current_tab() {
|
||||||
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Read-only navigation state.
|
// 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';
|
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.
|
* Render the settings screen tabs.
|
||||||
*
|
*
|
||||||
* @param string $current_tab Current tab slug.
|
* @param string $current_tab Current tab slug.
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
private function render_tabs( $current_tab ) {
|
private function render_tabs( $current_tab ) {
|
||||||
$tabs = array(
|
$tabs = array(
|
||||||
|
|
@ -544,6 +552,8 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Admin' ) ) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Render settings page.
|
* Render settings page.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function render_settings_page() {
|
public function render_settings_page() {
|
||||||
if ( ! current_user_can( Robotstxt_Telemetry_Network::manage_capability() ) ) {
|
if ( ! current_user_can( Robotstxt_Telemetry_Network::manage_capability() ) ) {
|
||||||
|
|
@ -560,8 +570,11 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Admin' ) ) {
|
||||||
|
|
||||||
$this->render_tabs( $tab );
|
$this->render_tabs( $tab );
|
||||||
|
|
||||||
echo '<form method="post" action="options.php">';
|
echo '<form method="post" action="">';
|
||||||
settings_fields( 'robotstxt_telemetry_settings' );
|
wp_nonce_field( 'robotstxt_telemetry_settings' );
|
||||||
|
echo '<input type="hidden" name="action" value="save_site_settings" />';
|
||||||
|
echo '<input type="hidden" name="page" value="robotstxt-telemetry" />';
|
||||||
|
echo '<input type="hidden" name="tab" value="' . esc_attr( $tab ) . '" />';
|
||||||
|
|
||||||
$this->render_settings_fields( $tab );
|
$this->render_settings_fields( $tab );
|
||||||
|
|
||||||
|
|
@ -578,6 +591,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Admin' ) ) {
|
||||||
* given tab are rendered, so each tab saves independently.
|
* given tab are rendered, so each tab saves independently.
|
||||||
*
|
*
|
||||||
* @param string $tab Tab slug: 'main', 'logs', or 'general'.
|
* @param string $tab Tab slug: 'main', 'logs', or 'general'.
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
private function render_settings_fields( $tab = 'main' ) {
|
private function render_settings_fields( $tab = 'main' ) {
|
||||||
echo '<table class="form-table" role="presentation">';
|
echo '<table class="form-table" role="presentation">';
|
||||||
|
|
@ -760,6 +774,8 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Admin' ) ) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Render the Plugins page.
|
* Render the Plugins page.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function render_plugins_page() {
|
public function render_plugins_page() {
|
||||||
$capability = Robotstxt_Telemetry_Network::is_global() ? 'manage_network_options' : Robotstxt_Telemetry_Network::manage_capability();
|
$capability = Robotstxt_Telemetry_Network::is_global() ? 'manage_network_options' : Robotstxt_Telemetry_Network::manage_capability();
|
||||||
|
|
@ -833,8 +849,37 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Admin' ) ) {
|
||||||
<?php
|
<?php
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Save the per-site settings screen form.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
private function handle_site_settings_save() {
|
||||||
|
check_admin_referer( 'robotstxt_telemetry_settings' );
|
||||||
|
|
||||||
|
// 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';
|
||||||
|
|
||||||
|
$this->save_tab_settings( $tab );
|
||||||
|
|
||||||
|
wp_safe_redirect(
|
||||||
|
add_query_arg(
|
||||||
|
array(
|
||||||
|
'page' => 'robotstxt-telemetry',
|
||||||
|
'tab' => $tab,
|
||||||
|
'settings-updated' => 'true',
|
||||||
|
),
|
||||||
|
Robotstxt_Telemetry_Network::base_url()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Save the per-plugin safe-mode settings.
|
* Save the per-plugin safe-mode settings.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
private function handle_plugin_modes_save() {
|
private function handle_plugin_modes_save() {
|
||||||
check_admin_referer( 'robotstxt_telemetry_plugin_modes' );
|
check_admin_referer( 'robotstxt_telemetry_plugin_modes' );
|
||||||
|
|
@ -894,6 +939,8 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Admin' ) ) {
|
||||||
* A widefat table lists every installed plugin with a hide checkbox
|
* A widefat table lists every installed plugin with a hide checkbox
|
||||||
* (disabled and checked for this plugin), its status, its name,
|
* (disabled and checked for this plugin), its status, its name,
|
||||||
* and its version.
|
* and its version.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
private function render_plugins_tab() {
|
private function render_plugins_tab() {
|
||||||
if ( ! function_exists( 'get_plugins' ) ) {
|
if ( ! function_exists( 'get_plugins' ) ) {
|
||||||
|
|
@ -956,6 +1003,8 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Admin' ) ) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Render logs page.
|
* Render logs page.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function render_logs_page() {
|
public function render_logs_page() {
|
||||||
$capability = Robotstxt_Telemetry_Network::is_global() ? 'manage_network_options' : Robotstxt_Telemetry_Network::manage_capability();
|
$capability = Robotstxt_Telemetry_Network::is_global() ? 'manage_network_options' : Robotstxt_Telemetry_Network::manage_capability();
|
||||||
|
|
@ -967,8 +1016,8 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Admin' ) ) {
|
||||||
require_once ROBOTSTXT_TELEMETRY_PLUGIN_DIR . '/includes/class-robotstxt-telemetry-logs-table.php';
|
require_once ROBOTSTXT_TELEMETRY_PLUGIN_DIR . '/includes/class-robotstxt-telemetry-logs-table.php';
|
||||||
|
|
||||||
// phpcs:disable WordPress.Security.NonceVerification.Recommended -- Read-only rendering of an admin screen.
|
// phpcs:disable WordPress.Security.NonceVerification.Recommended -- Read-only rendering of an admin screen.
|
||||||
$view_action = isset( $_GET['action'] ) ? sanitize_key( wp_unslash( $_GET['action'] ) ) : '';
|
$view_action = isset( $_GET['action'] ) && is_string( $_GET['action'] ) ? sanitize_key( wp_unslash( $_GET['action'] ) ) : '';
|
||||||
$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;
|
||||||
|
|
||||||
echo '<div class="wrap">';
|
echo '<div class="wrap">';
|
||||||
echo '<h1>' . esc_html__( 'Telemetry Logs', 'robotstxt-telemetry' ) . '</h1>';
|
echo '<h1>' . esc_html__( 'Telemetry Logs', 'robotstxt-telemetry' ) . '</h1>';
|
||||||
|
|
@ -988,7 +1037,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Admin' ) ) {
|
||||||
// Apply the retention policy before listing.
|
// Apply the retention policy before listing.
|
||||||
Robotstxt_Telemetry_DB::cleanup();
|
Robotstxt_Telemetry_DB::cleanup();
|
||||||
|
|
||||||
$deleted_notice = isset( $_GET['deleted'] ) ? sanitize_key( wp_unslash( $_GET['deleted'] ) ) : '';
|
$deleted_notice = isset( $_GET['deleted'] ) && is_string( $_GET['deleted'] ) ? sanitize_key( wp_unslash( $_GET['deleted'] ) ) : '';
|
||||||
// phpcs:enable
|
// phpcs:enable
|
||||||
if ( 'all' === $deleted_notice ) {
|
if ( 'all' === $deleted_notice ) {
|
||||||
echo '<div class="notice notice-success is-dismissible"><p>' . esc_html__( 'All log entries deleted.', 'robotstxt-telemetry' ) . '</p></div>';
|
echo '<div class="notice notice-success is-dismissible"><p>' . esc_html__( 'All log entries deleted.', 'robotstxt-telemetry' ) . '</p></div>';
|
||||||
|
|
@ -1021,6 +1070,8 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Admin' ) ) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Render the delete-all confirmation screen.
|
* Render the delete-all confirmation screen.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
private function render_delete_all_confirm() {
|
private function render_delete_all_confirm() {
|
||||||
check_admin_referer( 'robotstxt_telemetry_delete_all_confirm' );
|
check_admin_referer( 'robotstxt_telemetry_delete_all_confirm' );
|
||||||
|
|
@ -1042,6 +1093,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Admin' ) ) {
|
||||||
* Render a single log entry.
|
* Render a single log entry.
|
||||||
*
|
*
|
||||||
* @param int $log_id Log ID.
|
* @param int $log_id Log ID.
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
private function render_single_log( $log_id ) {
|
private function render_single_log( $log_id ) {
|
||||||
$log = Robotstxt_Telemetry_DB::get_log( $log_id );
|
$log = Robotstxt_Telemetry_DB::get_log( $log_id );
|
||||||
|
|
@ -1061,7 +1113,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Admin' ) ) {
|
||||||
$this->render_log_row( __( 'Host', 'robotstxt-telemetry' ), $log['host'] );
|
$this->render_log_row( __( 'Host', 'robotstxt-telemetry' ), $log['host'] );
|
||||||
$this->render_log_row( __( 'Path', 'robotstxt-telemetry' ), $log['path'] );
|
$this->render_log_row( __( 'Path', 'robotstxt-telemetry' ), $log['path'] );
|
||||||
$this->render_log_row( __( 'Body Params', 'robotstxt-telemetry' ), $this->format_params_field( $log, 'body' ) );
|
$this->render_log_row( __( 'Body Params', 'robotstxt-telemetry' ), $this->format_params_field( $log, 'body' ) );
|
||||||
$this->render_log_row( __( 'Headers', 'robotstxt-telemetry' ), $this->format_json_field( $log['headers_json'] ) );
|
$this->render_log_row( __( 'Headers', 'robotstxt-telemetry' ), $this->format_json_field( is_string( $log['headers_json'] ) ? $log['headers_json'] : null ) );
|
||||||
$this->render_log_row( __( 'User Agent', 'robotstxt-telemetry' ), $log['user_agent'] );
|
$this->render_log_row( __( 'User Agent', 'robotstxt-telemetry' ), $log['user_agent'] );
|
||||||
$this->render_log_row( __( 'Raw Body', 'robotstxt-telemetry' ), $log['raw_body'] );
|
$this->render_log_row( __( 'Raw Body', 'robotstxt-telemetry' ), $log['raw_body'] );
|
||||||
$this->render_log_row( __( 'Caller', 'robotstxt-telemetry' ), $log['caller'] );
|
$this->render_log_row( __( 'Caller', 'robotstxt-telemetry' ), $log['caller'] );
|
||||||
|
|
@ -1075,7 +1127,8 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Admin' ) ) {
|
||||||
/**
|
/**
|
||||||
* Render telemetry analysis section.
|
* Render telemetry analysis section.
|
||||||
*
|
*
|
||||||
* @param array $log Log data.
|
* @param array<string,mixed> $log Log data.
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
private function render_telemetry_analysis( $log ) {
|
private function render_telemetry_analysis( $log ) {
|
||||||
$sections = Robotstxt_Telemetry_Analysis::build_sections( $log );
|
$sections = Robotstxt_Telemetry_Analysis::build_sections( $log );
|
||||||
|
|
@ -1100,12 +1153,13 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Admin' ) ) {
|
||||||
* Render a table row.
|
* Render a table row.
|
||||||
*
|
*
|
||||||
* @param string $label Label.
|
* @param string $label Label.
|
||||||
* @param string $value Value.
|
* @param mixed $value Value.
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
private function render_log_row( $label, $value ) {
|
private function render_log_row( $label, $value ) {
|
||||||
echo '<tr>';
|
echo '<tr>';
|
||||||
echo '<th scope="row" style="width: 180px; vertical-align: top;">' . esc_html( $label ) . '</th>';
|
echo '<th scope="row" style="width: 180px; vertical-align: top;">' . esc_html( $label ) . '</th>';
|
||||||
echo '<td><pre style="white-space: pre-wrap; margin: 0;">' . esc_html( (string) $value ) . '</pre></td>';
|
echo '<td><pre style="white-space: pre-wrap; margin: 0;">' . esc_html( is_string( $value ) ? $value : '' ) . '</pre></td>';
|
||||||
echo '</tr>';
|
echo '</tr>';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1131,7 +1185,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Admin' ) ) {
|
||||||
/**
|
/**
|
||||||
* Format query/body params as line-per-parameter output.
|
* Format query/body params as line-per-parameter output.
|
||||||
*
|
*
|
||||||
* @param array $log Log data.
|
* @param array<string,mixed> $log Log data.
|
||||||
* @param string $type Param source.
|
* @param string $type Param source.
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -18,8 +18,8 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Analysis_Api_WordPress_Org' ) ) {
|
||||||
/**
|
/**
|
||||||
* Build analysis sections for api.wordpress.org.
|
* Build analysis sections for api.wordpress.org.
|
||||||
*
|
*
|
||||||
* @param array $log Log data.
|
* @param array<string,mixed> $log Log data.
|
||||||
* @return array
|
* @return array<string,string>
|
||||||
*/
|
*/
|
||||||
public static function build_sections( $log ) {
|
public static function build_sections( $log ) {
|
||||||
$sections = array();
|
$sections = array();
|
||||||
|
|
@ -40,8 +40,8 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Analysis_Api_WordPress_Org' ) ) {
|
||||||
/**
|
/**
|
||||||
* Group query parameters.
|
* Group query parameters.
|
||||||
*
|
*
|
||||||
* @param array $params Query parameters.
|
* @param array<int|string,mixed> $params Query parameters.
|
||||||
* @return array
|
* @return array<string,string>
|
||||||
*/
|
*/
|
||||||
private static function group_query_params( $params ) {
|
private static function group_query_params( $params ) {
|
||||||
$sections = array();
|
$sections = array();
|
||||||
|
|
@ -96,8 +96,8 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Analysis_Api_WordPress_Org' ) ) {
|
||||||
/**
|
/**
|
||||||
* Group body parameters.
|
* Group body parameters.
|
||||||
*
|
*
|
||||||
* @param array $params Body parameters.
|
* @param array<int|string,mixed> $params Body parameters.
|
||||||
* @return array
|
* @return array<string,string>
|
||||||
*/
|
*/
|
||||||
private static function group_body_params( $params ) {
|
private static function group_body_params( $params ) {
|
||||||
$sections = array();
|
$sections = array();
|
||||||
|
|
@ -114,8 +114,8 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Analysis_Api_WordPress_Org' ) ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( is_array( $translations ) ) {
|
if ( is_array( $translations ) ) {
|
||||||
$sections[ __( 'Translations', 'robotstxt-telemetry' ) ] = Robotstxt_Telemetry_Analysis::format_params_lines( $translations );
|
$sections[ __( 'Translations', 'robotstxt-telemetry' ) ] = Robotstxt_Telemetry_Analysis::format_params_lines( Robotstxt_Telemetry_Analysis::normalize_params( $translations ) );
|
||||||
} else {
|
} elseif ( is_scalar( $translations ) ) {
|
||||||
$sections[ __( 'Translations', 'robotstxt-telemetry' ) ] = (string) $translations;
|
$sections[ __( 'Translations', 'robotstxt-telemetry' ) ] = (string) $translations;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -130,14 +130,16 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Analysis_Api_WordPress_Org' ) ) {
|
||||||
/**
|
/**
|
||||||
* Extract bracketed parameters into a nested array.
|
* Extract bracketed parameters into a nested array.
|
||||||
*
|
*
|
||||||
* @param array $params Parameters (will be mutated).
|
* @param array<int|string,mixed> $params Parameters (will be mutated).
|
||||||
* @param string $prefix Prefix name.
|
* @param string $prefix Prefix name.
|
||||||
* @return array
|
* @return array<string,mixed>
|
||||||
*/
|
*/
|
||||||
private static function pluck_bracketed( &$params, $prefix ) {
|
private static function pluck_bracketed( &$params, $prefix ) {
|
||||||
$result = array();
|
$result = array();
|
||||||
|
|
||||||
foreach ( $params as $key => $value ) {
|
foreach ( $params as $key => $value ) {
|
||||||
|
$key = (string) $key;
|
||||||
|
|
||||||
if ( 0 !== strpos( $key, $prefix . '[' ) ) {
|
if ( 0 !== strpos( $key, $prefix . '[' ) ) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,11 +18,11 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Analysis' ) ) {
|
||||||
/**
|
/**
|
||||||
* Build analysis sections for a log entry.
|
* Build analysis sections for a log entry.
|
||||||
*
|
*
|
||||||
* @param array $log Log data.
|
* @param array<string,mixed> $log Log data.
|
||||||
* @return array
|
* @return array<string,string>
|
||||||
*/
|
*/
|
||||||
public static function build_sections( $log ) {
|
public static function build_sections( $log ) {
|
||||||
$host = isset( $log['host'] ) ? strtolower( (string) $log['host'] ) : '';
|
$host = isset( $log['host'] ) && is_string( $log['host'] ) ? strtolower( $log['host'] ) : '';
|
||||||
|
|
||||||
if ( 'api.wordpress.org' === $host ) {
|
if ( 'api.wordpress.org' === $host ) {
|
||||||
return Robotstxt_Telemetry_Analysis_Api_WordPress_Org::build_sections( $log );
|
return Robotstxt_Telemetry_Analysis_Api_WordPress_Org::build_sections( $log );
|
||||||
|
|
@ -34,8 +34,8 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Analysis' ) ) {
|
||||||
/**
|
/**
|
||||||
* Build generic analysis sections.
|
* Build generic analysis sections.
|
||||||
*
|
*
|
||||||
* @param array $log Log data.
|
* @param array<string,mixed> $log Log data.
|
||||||
* @return array
|
* @return array<string,string>
|
||||||
*/
|
*/
|
||||||
private static function build_generic_sections( $log ) {
|
private static function build_generic_sections( $log ) {
|
||||||
$sections = array();
|
$sections = array();
|
||||||
|
|
@ -58,22 +58,25 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Analysis' ) ) {
|
||||||
*
|
*
|
||||||
* Prefers the redacted query_json column over re-parsing the raw URL.
|
* Prefers the redacted query_json column over re-parsing the raw URL.
|
||||||
*
|
*
|
||||||
* @param array $log Log data.
|
* @param array<string,mixed> $log Log data.
|
||||||
* @return array
|
* @return array<int|string,mixed>
|
||||||
*/
|
*/
|
||||||
public static function extract_query_params( $log ) {
|
public static function extract_query_params( $log ) {
|
||||||
if ( empty( $log['url'] ) && empty( $log['query_json'] ) ) {
|
$url = isset( $log['url'] ) && is_string( $log['url'] ) ? $log['url'] : '';
|
||||||
|
$query_json = isset( $log['query_json'] ) && is_string( $log['query_json'] ) ? $log['query_json'] : '';
|
||||||
|
|
||||||
|
if ( '' === $url && '' === $query_json ) {
|
||||||
return array();
|
return array();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ! empty( $log['query_json'] ) ) {
|
if ( '' !== $query_json ) {
|
||||||
$decoded = json_decode( $log['query_json'], true );
|
$decoded = json_decode( $query_json, true );
|
||||||
if ( is_array( $decoded ) && ! empty( $decoded ) ) {
|
if ( is_array( $decoded ) && ! empty( $decoded ) ) {
|
||||||
return $decoded;
|
return self::normalize_params( $decoded );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$parts = explode( '?', (string) $log['url'], 2 );
|
$parts = explode( '?', $url, 2 );
|
||||||
$query = isset( $parts[1] ) ? $parts[1] : '';
|
$query = isset( $parts[1] ) ? $parts[1] : '';
|
||||||
|
|
||||||
if ( '' === $query ) {
|
if ( '' === $query ) {
|
||||||
|
|
@ -86,14 +89,17 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Analysis' ) ) {
|
||||||
/**
|
/**
|
||||||
* Extract parameters from the body.
|
* Extract parameters from the body.
|
||||||
*
|
*
|
||||||
* @param array $log Log data.
|
* @param array<string,mixed> $log Log data.
|
||||||
* @return array
|
* @return array<int|string,mixed>
|
||||||
*/
|
*/
|
||||||
public static function extract_body_params( $log ) {
|
public static function extract_body_params( $log ) {
|
||||||
if ( ! empty( $log['body_json'] ) ) {
|
$body_json = isset( $log['body_json'] ) && is_string( $log['body_json'] ) ? $log['body_json'] : '';
|
||||||
$decoded = json_decode( $log['body_json'], true );
|
$raw_body = isset( $log['raw_body'] ) && is_string( $log['raw_body'] ) ? $log['raw_body'] : '';
|
||||||
|
|
||||||
|
if ( '' !== $body_json ) {
|
||||||
|
$decoded = json_decode( $body_json, true );
|
||||||
if ( is_array( $decoded ) ) {
|
if ( is_array( $decoded ) ) {
|
||||||
return $decoded;
|
return self::normalize_params( $decoded );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( is_string( $decoded ) ) {
|
if ( is_string( $decoded ) ) {
|
||||||
|
|
@ -101,18 +107,34 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Analysis' ) ) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ! empty( $log['raw_body'] ) ) {
|
if ( '' !== $raw_body ) {
|
||||||
return self::parse_query_string_flat( $log['raw_body'] );
|
return self::parse_query_string_flat( $raw_body );
|
||||||
}
|
}
|
||||||
|
|
||||||
return array();
|
return array();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Normalize a decoded parameter array to integer or string keys.
|
||||||
|
*
|
||||||
|
* @param array<mixed,mixed> $params Decoded parameters.
|
||||||
|
* @return array<int|string,mixed>
|
||||||
|
*/
|
||||||
|
public static function normalize_params( array $params ) {
|
||||||
|
$normalized = array();
|
||||||
|
|
||||||
|
foreach ( $params as $key => $value ) {
|
||||||
|
$normalized[ $key ] = $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $normalized;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse a query string into a flat key/value array.
|
* Parse a query string into a flat key/value array.
|
||||||
*
|
*
|
||||||
* @param string $query Query string.
|
* @param string $query Query string.
|
||||||
* @return array
|
* @return array<string,string|array<int,string>>
|
||||||
*/
|
*/
|
||||||
public static function parse_query_string_flat( $query ) {
|
public static function parse_query_string_flat( $query ) {
|
||||||
$params = array();
|
$params = array();
|
||||||
|
|
@ -149,7 +171,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Analysis' ) ) {
|
||||||
/**
|
/**
|
||||||
* Format parameters as line-per-entry output.
|
* Format parameters as line-per-entry output.
|
||||||
*
|
*
|
||||||
* @param array $params Parameters.
|
* @param array<int|string,mixed> $params Parameters.
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public static function format_params_lines( $params ) {
|
public static function format_params_lines( $params ) {
|
||||||
|
|
@ -161,8 +183,16 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Analysis' ) ) {
|
||||||
$value = wp_json_encode( $value );
|
$value = wp_json_encode( $value );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( null === $value ) {
|
||||||
|
$value = '';
|
||||||
|
} elseif ( is_scalar( $value ) ) {
|
||||||
|
$value = (string) $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( is_string( $value ) ) {
|
||||||
$lines[] = sprintf( '%s=%s', $key, $value );
|
$lines[] = sprintf( '%s=%s', $key, $value );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return implode( "\n", $lines );
|
return implode( "\n", $lines );
|
||||||
}
|
}
|
||||||
|
|
@ -170,9 +200,9 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Analysis' ) ) {
|
||||||
/**
|
/**
|
||||||
* Flatten nested parameters into bracketed keys.
|
* Flatten nested parameters into bracketed keys.
|
||||||
*
|
*
|
||||||
* @param array $params Parameters to flatten.
|
* @param array<int|string,mixed> $params Parameters to flatten.
|
||||||
* @param string|null $prefix Current prefix.
|
* @param string|null $prefix Current prefix.
|
||||||
* @return array
|
* @return array<string,mixed>
|
||||||
*/
|
*/
|
||||||
public static function flatten_params( $params, $prefix = null ) {
|
public static function flatten_params( $params, $prefix = null ) {
|
||||||
$flat = array();
|
$flat = array();
|
||||||
|
|
|
||||||
|
|
@ -48,6 +48,8 @@ if ( ! class_exists( 'Robotstxt_Telemetry_DB' ) ) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Activation hook.
|
* Activation hook.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
public static function activate() {
|
public static function activate() {
|
||||||
self::create_table();
|
self::create_table();
|
||||||
|
|
@ -56,6 +58,8 @@ if ( ! class_exists( 'Robotstxt_Telemetry_DB' ) ) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ensure the database schema is up to date.
|
* Ensure the database schema is up to date.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
public static function maybe_upgrade() {
|
public static function maybe_upgrade() {
|
||||||
if ( self::$did_check ) {
|
if ( self::$did_check ) {
|
||||||
|
|
@ -78,6 +82,8 @@ if ( ! class_exists( 'Robotstxt_Telemetry_DB' ) ) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create or update the logs table.
|
* Create or update the logs table.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
public static function create_table() {
|
public static function create_table() {
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
|
|
@ -115,7 +121,8 @@ if ( ! class_exists( 'Robotstxt_Telemetry_DB' ) ) {
|
||||||
/**
|
/**
|
||||||
* Insert a log row.
|
* Insert a log row.
|
||||||
*
|
*
|
||||||
* @param array $data Log data.
|
* @param array<string,mixed> $data Log data.
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
public static function insert_log( array $data ) {
|
public static function insert_log( array $data ) {
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
|
|
@ -144,7 +151,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_DB' ) ) {
|
||||||
* Fetch a single log row.
|
* Fetch a single log row.
|
||||||
*
|
*
|
||||||
* @param int $log_id Log ID.
|
* @param int $log_id Log ID.
|
||||||
* @return array|null
|
* @return array<string,mixed>|null
|
||||||
*/
|
*/
|
||||||
public static function get_log( $log_id ) {
|
public static function get_log( $log_id ) {
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
|
|
@ -221,7 +228,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_DB' ) ) {
|
||||||
'3days' => 3 * DAY_IN_SECONDS,
|
'3days' => 3 * DAY_IN_SECONDS,
|
||||||
);
|
);
|
||||||
|
|
||||||
if ( isset( $periods[ $retention ] ) ) {
|
if ( is_string( $retention ) && isset( $periods[ $retention ] ) ) {
|
||||||
$cutoff = gmdate( 'Y-m-d H:i:s', time() - $periods[ $retention ] );
|
$cutoff = gmdate( 'Y-m-d H:i:s', time() - $periods[ $retention ] );
|
||||||
|
|
||||||
$wpdb->query( // phpcs:ignore WordPress.DB.DirectDatabaseQuery -- Delete from the plugin's custom table via the wpdb API.
|
$wpdb->query( // phpcs:ignore WordPress.DB.DirectDatabaseQuery -- Delete from the plugin's custom table via the wpdb API.
|
||||||
|
|
|
||||||
|
|
@ -44,6 +44,8 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Endpoints' ) ) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register hooks.
|
* Register hooks.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function register() {
|
public function register() {
|
||||||
add_filter( 'pre_http_request', array( $this, 'intercept' ), 10, 3 );
|
add_filter( 'pre_http_request', array( $this, 'intercept' ), 10, 3 );
|
||||||
|
|
@ -52,10 +54,10 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Endpoints' ) ) {
|
||||||
/**
|
/**
|
||||||
* Intercept outbound WordPress.org requests.
|
* Intercept outbound WordPress.org requests.
|
||||||
*
|
*
|
||||||
* @param false|array|WP_Error $preempt Short-circuit value from other filters.
|
* @param false|array<string,mixed>|WP_Error $preempt Short-circuit value from other filters.
|
||||||
* @param array $args HTTP request arguments.
|
* @param array{body?:string|array<mixed,mixed>,headers?:string|array<mixed,mixed>} $args HTTP request arguments.
|
||||||
* @param string $url Request URL.
|
* @param string $url Request URL.
|
||||||
* @return false|array|WP_Error
|
* @return false|array<string,mixed>|WP_Error
|
||||||
*/
|
*/
|
||||||
public function intercept( $preempt, $args, $url ) {
|
public function intercept( $preempt, $args, $url ) {
|
||||||
if ( false !== $preempt ) {
|
if ( false !== $preempt ) {
|
||||||
|
|
@ -112,7 +114,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Endpoints' ) ) {
|
||||||
* Build a successful Browse Happy response marking the browser
|
* Build a successful Browse Happy response marking the browser
|
||||||
* as up to date and secure, so no browser nag is shown.
|
* as up to date and secure, so no browser nag is shown.
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array<string,mixed>
|
||||||
*/
|
*/
|
||||||
private function mock_browse_happy_response() {
|
private function mock_browse_happy_response() {
|
||||||
$body = wp_json_encode(
|
$body = wp_json_encode(
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,8 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Logger' ) ) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register hooks.
|
* Register hooks.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function register() {
|
public function register() {
|
||||||
add_filter( 'http_request_args', array( $this, 'capture_request' ), 10, 2 );
|
add_filter( 'http_request_args', array( $this, 'capture_request' ), 10, 2 );
|
||||||
|
|
@ -46,12 +48,12 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Logger' ) ) {
|
||||||
/**
|
/**
|
||||||
* Capture outbound request arguments.
|
* Capture outbound request arguments.
|
||||||
*
|
*
|
||||||
* @param array $args HTTP request arguments.
|
* @param array<string,mixed> $args HTTP request arguments.
|
||||||
* @param string $url Request URL.
|
* @param string $url Request URL.
|
||||||
* @return array
|
* @return array<string,mixed>
|
||||||
*/
|
*/
|
||||||
public function capture_request( $args, $url ) {
|
public function capture_request( $args, $url ) {
|
||||||
if ( empty( $url ) || ! is_array( $args ) ) {
|
if ( empty( $url ) ) {
|
||||||
return $args;
|
return $args;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -72,21 +74,25 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Logger' ) ) {
|
||||||
/**
|
/**
|
||||||
* Prepare log data for storage.
|
* Prepare log data for storage.
|
||||||
*
|
*
|
||||||
* @param array $args Request args.
|
* @param array<string,mixed> $args Request args.
|
||||||
* @param string $url Request URL.
|
* @param string $url Request URL.
|
||||||
* @return array
|
* @return array<string,mixed>
|
||||||
*/
|
*/
|
||||||
private function prepare_log_data( $args, $url ) {
|
private function prepare_log_data( $args, $url ) {
|
||||||
$method = isset( $args['method'] ) ? strtoupper( sanitize_text_field( (string) $args['method'] ) ) : 'GET';
|
$method = isset( $args['method'] ) && is_string( $args['method'] ) ? strtoupper( sanitize_text_field( $args['method'] ) ) : 'GET';
|
||||||
$url = esc_url_raw( $url );
|
$url = esc_url_raw( $url );
|
||||||
|
|
||||||
$parsed_url = wp_parse_url( $url );
|
$parsed_url = wp_parse_url( $url );
|
||||||
|
if ( ! is_array( $parsed_url ) ) {
|
||||||
|
$parsed_url = array();
|
||||||
|
}
|
||||||
|
|
||||||
$host = isset( $parsed_url['host'] ) ? sanitize_text_field( $parsed_url['host'] ) : '';
|
$host = isset( $parsed_url['host'] ) ? sanitize_text_field( $parsed_url['host'] ) : '';
|
||||||
$path = isset( $parsed_url['path'] ) ? sanitize_text_field( $parsed_url['path'] ) : '';
|
$path = isset( $parsed_url['path'] ) ? sanitize_text_field( $parsed_url['path'] ) : '';
|
||||||
|
|
||||||
$query_params = array();
|
$query_params = array();
|
||||||
if ( ! empty( $parsed_url['query'] ) ) {
|
if ( ! empty( $parsed_url['query'] ) ) {
|
||||||
$query_params = wp_parse_args( $parsed_url['query'] );
|
$query_params = $this->normalize_keys( wp_parse_args( $parsed_url['query'] ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
$query_params = $this->redact_array( $query_params );
|
$query_params = $this->redact_array( $query_params );
|
||||||
|
|
@ -110,7 +116,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Logger' ) ) {
|
||||||
if ( isset( $args['body'] ) ) {
|
if ( isset( $args['body'] ) ) {
|
||||||
$body_data = $args['body'];
|
$body_data = $args['body'];
|
||||||
if ( is_array( $body_data ) ) {
|
if ( is_array( $body_data ) ) {
|
||||||
$redacted_body = $this->redact_array( $body_data );
|
$redacted_body = $this->redact_array( $this->normalize_keys( $body_data ) );
|
||||||
$body_json = $this->encode_json_limited( $redacted_body, $this->max_json_bytes );
|
$body_json = $this->encode_json_limited( $redacted_body, $this->max_json_bytes );
|
||||||
|
|
||||||
if ( empty( $body_json ) ) {
|
if ( empty( $body_json ) ) {
|
||||||
|
|
@ -147,11 +153,8 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Logger' ) ) {
|
||||||
|
|
||||||
// phpcs:ignore WordPress.PHP.DevelopmentFunctions -- Needed for caller context logging.
|
// phpcs:ignore WordPress.PHP.DevelopmentFunctions -- Needed for caller context logging.
|
||||||
$caller = wp_debug_backtrace_summary( null, 0, false );
|
$caller = wp_debug_backtrace_summary( null, 0, false );
|
||||||
if ( is_array( $caller ) || is_object( $caller ) ) {
|
|
||||||
$caller = wp_json_encode( $caller );
|
$caller = wp_json_encode( $caller );
|
||||||
}
|
$caller = $this->truncate_string( is_string( $caller ) ? $caller : '', $this->max_caller_bytes );
|
||||||
|
|
||||||
$caller = $this->truncate_string( (string) $caller, $this->max_caller_bytes );
|
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
'created_at' => current_time( 'mysql', true ),
|
'created_at' => current_time( 'mysql', true ),
|
||||||
|
|
@ -172,30 +175,31 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Logger' ) ) {
|
||||||
/**
|
/**
|
||||||
* Rebuild a URL with a redacted query string and without credentials.
|
* Rebuild a URL with a redacted query string and without credentials.
|
||||||
*
|
*
|
||||||
* @param array $parts URL parts from wp_parse_url().
|
* @param array<string,mixed> $parts URL parts from wp_parse_url().
|
||||||
* @param string $query Redacted query string.
|
* @param string $query Redacted query string.
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
private function build_redacted_url( $parts, $query ) {
|
private function build_redacted_url( $parts, $query ) {
|
||||||
$url = '';
|
$scheme = isset( $parts['scheme'] ) && is_string( $parts['scheme'] ) ? $parts['scheme'] : '';
|
||||||
|
$host = isset( $parts['host'] ) && is_string( $parts['host'] ) ? $parts['host'] : '';
|
||||||
|
|
||||||
if ( ! empty( $parts['scheme'] ) && ! empty( $parts['host'] ) ) {
|
if ( '' === $scheme || '' === $host ) {
|
||||||
$url = $parts['scheme'] . '://' . $parts['host'];
|
|
||||||
} else {
|
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ! empty( $parts['port'] ) ) {
|
$url = $scheme . '://' . $host;
|
||||||
$url .= ':' . (int) $parts['port'];
|
|
||||||
|
if ( isset( $parts['port'] ) && is_int( $parts['port'] ) ) {
|
||||||
|
$url .= ':' . $parts['port'];
|
||||||
}
|
}
|
||||||
|
|
||||||
$url .= isset( $parts['path'] ) ? $parts['path'] : '';
|
$url .= isset( $parts['path'] ) && is_string( $parts['path'] ) ? $parts['path'] : '';
|
||||||
|
|
||||||
if ( '' !== $query ) {
|
if ( '' !== $query ) {
|
||||||
$url .= '?' . $query;
|
$url .= '?' . $query;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ! empty( $parts['fragment'] ) ) {
|
if ( isset( $parts['fragment'] ) && is_string( $parts['fragment'] ) ) {
|
||||||
$url .= '#' . $parts['fragment'];
|
$url .= '#' . $parts['fragment'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -206,7 +210,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Logger' ) ) {
|
||||||
* Normalize request headers into a simple array.
|
* Normalize request headers into a simple array.
|
||||||
*
|
*
|
||||||
* @param mixed $headers Headers value.
|
* @param mixed $headers Headers value.
|
||||||
* @return array
|
* @return array<string,mixed>
|
||||||
*/
|
*/
|
||||||
private function normalize_headers( $headers ) {
|
private function normalize_headers( $headers ) {
|
||||||
if ( is_object( $headers ) && method_exists( $headers, 'getAll' ) ) {
|
if ( is_object( $headers ) && method_exists( $headers, 'getAll' ) ) {
|
||||||
|
|
@ -230,20 +234,24 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Logger' ) ) {
|
||||||
/**
|
/**
|
||||||
* Extract the user agent from request args.
|
* Extract the user agent from request args.
|
||||||
*
|
*
|
||||||
* @param array $args Request args.
|
* @param array<string,mixed> $args Request args.
|
||||||
* @return string|null
|
* @return string|null
|
||||||
*/
|
*/
|
||||||
private function extract_user_agent( $args ) {
|
private function extract_user_agent( $args ) {
|
||||||
$user_agent = '';
|
$user_agent = '';
|
||||||
|
|
||||||
if ( isset( $args['user-agent'] ) ) {
|
if ( isset( $args['user-agent'] ) && is_string( $args['user-agent'] ) ) {
|
||||||
$user_agent = (string) $args['user-agent'];
|
$user_agent = $args['user-agent'];
|
||||||
} elseif ( isset( $args['user_agent'] ) ) {
|
} elseif ( isset( $args['user_agent'] ) && is_string( $args['user_agent'] ) ) {
|
||||||
$user_agent = (string) $args['user_agent'];
|
$user_agent = $args['user_agent'];
|
||||||
} elseif ( isset( $args['headers']['user-agent'] ) ) {
|
} elseif ( isset( $args['headers'] ) && is_array( $args['headers'] ) ) {
|
||||||
$user_agent = (string) $args['headers']['user-agent'];
|
$headers = $args['headers'];
|
||||||
} elseif ( isset( $args['headers']['User-Agent'] ) ) {
|
|
||||||
$user_agent = (string) $args['headers']['User-Agent'];
|
if ( isset( $headers['user-agent'] ) && is_string( $headers['user-agent'] ) ) {
|
||||||
|
$user_agent = $headers['user-agent'];
|
||||||
|
} elseif ( isset( $headers['User-Agent'] ) && is_string( $headers['User-Agent'] ) ) {
|
||||||
|
$user_agent = $headers['User-Agent'];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( '' === $user_agent ) {
|
if ( '' === $user_agent ) {
|
||||||
|
|
@ -257,33 +265,49 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Logger' ) ) {
|
||||||
* Parse body strings into arrays when possible.
|
* Parse body strings into arrays when possible.
|
||||||
*
|
*
|
||||||
* @param string $body Raw body.
|
* @param string $body Raw body.
|
||||||
* @return array|null
|
* @return array<int|string,mixed>|null
|
||||||
*/
|
*/
|
||||||
private function parse_body_string( $body ) {
|
private function parse_body_string( $body ) {
|
||||||
$decoded = json_decode( $body, true );
|
$decoded = json_decode( $body, true );
|
||||||
if ( is_array( $decoded ) ) {
|
if ( is_array( $decoded ) ) {
|
||||||
return $decoded;
|
return $this->normalize_keys( $decoded );
|
||||||
}
|
}
|
||||||
|
|
||||||
$parsed = wp_parse_args( $body );
|
$parsed = wp_parse_args( $body );
|
||||||
if ( ! empty( $parsed ) ) {
|
if ( ! empty( $parsed ) ) {
|
||||||
return $parsed;
|
return $this->normalize_keys( $parsed );
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Normalize an array to integer or string keys.
|
||||||
|
*
|
||||||
|
* @param array<mixed,mixed> $data Input array.
|
||||||
|
* @return array<int|string,mixed>
|
||||||
|
*/
|
||||||
|
private function normalize_keys( array $data ) {
|
||||||
|
$normalized = array();
|
||||||
|
|
||||||
|
foreach ( $data as $key => $value ) {
|
||||||
|
$normalized[ $key ] = $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $normalized;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Redact sensitive keys in arrays.
|
* Redact sensitive keys in arrays.
|
||||||
*
|
*
|
||||||
* @param array $data Data to sanitize.
|
* @param array<int|string,mixed> $data Data to sanitize.
|
||||||
* @return array
|
* @return array<int|string,mixed>
|
||||||
*/
|
*/
|
||||||
private function redact_array( $data ) {
|
private function redact_array( $data ) {
|
||||||
$redacted = array();
|
$redacted = array();
|
||||||
|
|
||||||
foreach ( $data as $key => $value ) {
|
foreach ( $data as $key => $value ) {
|
||||||
$normalized_key = is_string( $key ) ? strtolower( $key ) : (string) $key;
|
$normalized_key = strtolower( (string) $key );
|
||||||
|
|
||||||
if ( $this->is_sensitive_key( $normalized_key ) ) {
|
if ( $this->is_sensitive_key( $normalized_key ) ) {
|
||||||
$redacted[ $key ] = '[redacted]';
|
$redacted[ $key ] = '[redacted]';
|
||||||
|
|
@ -348,13 +372,15 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Logger' ) ) {
|
||||||
return $value;
|
return $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
return sanitize_text_field( wp_json_encode( $value ) );
|
$encoded = wp_json_encode( $value );
|
||||||
|
|
||||||
|
return false === $encoded ? '' : sanitize_text_field( $encoded );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Encode JSON with size limits.
|
* Encode JSON with size limits.
|
||||||
*
|
*
|
||||||
* @param array $data Data to encode.
|
* @param array<int|string,mixed> $data Data to encode.
|
||||||
* @param int $limit Max size in bytes.
|
* @param int $limit Max size in bytes.
|
||||||
* @return string|null
|
* @return string|null
|
||||||
*/
|
*/
|
||||||
|
|
@ -375,9 +401,9 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Logger' ) ) {
|
||||||
/**
|
/**
|
||||||
* Truncate array values to keep payloads manageable.
|
* Truncate array values to keep payloads manageable.
|
||||||
*
|
*
|
||||||
* @param array $data Data to trim.
|
* @param array<int|string,mixed> $data Data to trim.
|
||||||
* @param int $max_len Max length per string value.
|
* @param int $max_len Max length per string value.
|
||||||
* @return array
|
* @return array<int|string,mixed>
|
||||||
*/
|
*/
|
||||||
private function truncate_array_values( $data, $max_len ) {
|
private function truncate_array_values( $data, $max_len ) {
|
||||||
$trimmed = array();
|
$trimmed = array();
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Logs_Table' ) ) {
|
||||||
/**
|
/**
|
||||||
* Get columns.
|
* Get columns.
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array<string,string>
|
||||||
*/
|
*/
|
||||||
public function get_columns() {
|
public function get_columns() {
|
||||||
return array(
|
return array(
|
||||||
|
|
@ -55,6 +55,8 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Logs_Table' ) ) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prepare items for display.
|
* Prepare items for display.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function prepare_items() {
|
public function prepare_items() {
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
|
|
@ -119,18 +121,19 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Logs_Table' ) ) {
|
||||||
/**
|
/**
|
||||||
* Render default column output.
|
* Render default column output.
|
||||||
*
|
*
|
||||||
* @param array $item Column data.
|
* @param array<string,mixed> $item Column data.
|
||||||
* @param string $column_name Column name.
|
* @param string $column_name Column name.
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function column_default( $item, $column_name ) {
|
public function column_default( $item, $column_name ) {
|
||||||
switch ( $column_name ) {
|
switch ( $column_name ) {
|
||||||
case 'created_at':
|
case 'created_at':
|
||||||
return esc_html( isset( $item[ $column_name ] ) ? $item[ $column_name ] : '' );
|
|
||||||
case 'method':
|
case 'method':
|
||||||
case 'host':
|
case 'host':
|
||||||
case 'path':
|
case 'path':
|
||||||
return esc_html( isset( $item[ $column_name ] ) ? $item[ $column_name ] : '' );
|
$value = isset( $item[ $column_name ] ) && is_string( $item[ $column_name ] ) ? $item[ $column_name ] : '';
|
||||||
|
|
||||||
|
return esc_html( $value );
|
||||||
default:
|
default:
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
@ -139,11 +142,11 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Logs_Table' ) ) {
|
||||||
/**
|
/**
|
||||||
* Add row actions.
|
* Add row actions.
|
||||||
*
|
*
|
||||||
* @param array $item Item data.
|
* @param array<string,mixed> $item Item data.
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function column_created_at( $item ) {
|
public function column_created_at( $item ) {
|
||||||
$log_id = (int) $item['id'];
|
$log_id = isset( $item['id'] ) && is_numeric( $item['id'] ) ? (int) $item['id'] : 0;
|
||||||
|
|
||||||
$view_url = add_query_arg(
|
$view_url = add_query_arg(
|
||||||
array(
|
array(
|
||||||
|
|
@ -171,23 +174,27 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Logs_Table' ) ) {
|
||||||
'delete' => '<a href="' . esc_url( $delete_url ) . '">' . esc_html__( 'Delete', 'robotstxt-telemetry' ) . '</a>',
|
'delete' => '<a href="' . esc_url( $delete_url ) . '">' . esc_html__( 'Delete', 'robotstxt-telemetry' ) . '</a>',
|
||||||
);
|
);
|
||||||
|
|
||||||
return esc_html( $item['created_at'] ) . $this->row_actions( $actions );
|
$created_at = isset( $item['created_at'] ) && is_string( $item['created_at'] ) ? $item['created_at'] : '';
|
||||||
|
|
||||||
|
return esc_html( $created_at ) . $this->row_actions( $actions );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Render the URL column without query parameters.
|
* Render the URL column without query parameters.
|
||||||
*
|
*
|
||||||
* @param array $item Item data.
|
* @param array<string,mixed> $item Item data.
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function column_url( $item ) {
|
public function column_url( $item ) {
|
||||||
if ( empty( $item['url'] ) ) {
|
$url = isset( $item['url'] ) && is_string( $item['url'] ) ? $item['url'] : '';
|
||||||
|
|
||||||
|
if ( '' === $url ) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
$parsed_url = wp_parse_url( $item['url'] );
|
$parsed_url = wp_parse_url( $url );
|
||||||
if ( empty( $parsed_url ) || empty( $parsed_url['host'] ) ) {
|
if ( ! is_array( $parsed_url ) || empty( $parsed_url['host'] ) ) {
|
||||||
return esc_html( $item['url'] );
|
return esc_html( $url );
|
||||||
}
|
}
|
||||||
|
|
||||||
$scheme = isset( $parsed_url['scheme'] ) ? $parsed_url['scheme'] : 'https';
|
$scheme = isset( $parsed_url['scheme'] ) ? $parsed_url['scheme'] : 'https';
|
||||||
|
|
@ -198,91 +205,11 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Logs_Table' ) ) {
|
||||||
return esc_html( $base );
|
return esc_html( $base );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Format parameters column output.
|
|
||||||
*
|
|
||||||
* @param array $item Item data.
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
private function format_params_column( $item ) {
|
|
||||||
$params = array();
|
|
||||||
|
|
||||||
if ( ! empty( $item['url'] ) ) {
|
|
||||||
$parsed_url = wp_parse_url( $item['url'] );
|
|
||||||
if ( ! empty( $parsed_url['query'] ) ) {
|
|
||||||
$fallback_query = wp_parse_args( $parsed_url['query'] );
|
|
||||||
$params = array_merge( $params, $fallback_query );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$query_params = $this->decode_json_params( isset( $item['query_json'] ) ? $item['query_json'] : '' );
|
|
||||||
if ( ! empty( $query_params ) ) {
|
|
||||||
$params = array_merge( $params, $query_params );
|
|
||||||
}
|
|
||||||
|
|
||||||
$body_params = $this->decode_json_params( isset( $item['body_json'] ) ? $item['body_json'] : '' );
|
|
||||||
if ( ! empty( $body_params ) ) {
|
|
||||||
$params = array_merge( $params, $body_params );
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( empty( $body_params ) && ! empty( $item['raw_body'] ) ) {
|
|
||||||
$fallback_body = wp_parse_args( $item['raw_body'] );
|
|
||||||
if ( ! empty( $fallback_body ) ) {
|
|
||||||
$params = array_merge( $params, $fallback_body );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( empty( $params ) ) {
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
|
|
||||||
$lines = array();
|
|
||||||
foreach ( $params as $key => $value ) {
|
|
||||||
if ( is_array( $value ) ) {
|
|
||||||
$value = wp_json_encode( $value );
|
|
||||||
}
|
|
||||||
|
|
||||||
$lines[] = sprintf( '%s=%s', $key, $value );
|
|
||||||
}
|
|
||||||
|
|
||||||
return '<pre style="white-space: pre-wrap; margin: 0;">' . esc_html( implode( "\n", $lines ) ) . '</pre>';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Decode JSON parameters into arrays.
|
|
||||||
*
|
|
||||||
* @param string $value JSON string.
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
private function decode_json_params( $value ) {
|
|
||||||
if ( empty( $value ) ) {
|
|
||||||
return array();
|
|
||||||
}
|
|
||||||
|
|
||||||
$decoded = json_decode( $value, true );
|
|
||||||
if ( is_array( $decoded ) ) {
|
|
||||||
return $decoded;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( is_string( $decoded ) ) {
|
|
||||||
$parsed = wp_parse_args( $decoded );
|
|
||||||
if ( ! empty( $parsed ) ) {
|
|
||||||
return $parsed;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$parsed = wp_parse_args( $value );
|
|
||||||
if ( ! empty( $parsed ) ) {
|
|
||||||
return $parsed;
|
|
||||||
}
|
|
||||||
|
|
||||||
return array();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extra controls for filtering.
|
* Extra controls for filtering.
|
||||||
*
|
*
|
||||||
* @param string $which Top or bottom.
|
* @param string $which Top or bottom.
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function extra_tablenav( $which ) {
|
public function extra_tablenav( $which ) {
|
||||||
if ( 'top' !== $which ) {
|
if ( 'top' !== $which ) {
|
||||||
|
|
@ -344,7 +271,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Logs_Table' ) ) {
|
||||||
*/
|
*/
|
||||||
private function get_filter_value( $key ) {
|
private function get_filter_value( $key ) {
|
||||||
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Read-only list filters.
|
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Read-only list filters.
|
||||||
if ( ! isset( $_GET[ $key ] ) ) {
|
if ( ! isset( $_GET[ $key ] ) || ! is_string( $_GET[ $key ] ) ) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,8 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Manager_Notice' ) ) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register hooks.
|
* Register hooks.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function register() {
|
public function register() {
|
||||||
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
|
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
|
||||||
|
|
@ -58,6 +60,8 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Manager_Notice' ) ) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enqueue the inline dismissal script on the plugins list screen.
|
* Enqueue the inline dismissal script on the plugins list screen.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function enqueue_scripts() {
|
public function enqueue_scripts() {
|
||||||
if ( ! $this->should_show_notice() ) {
|
if ( ! $this->should_show_notice() ) {
|
||||||
|
|
@ -93,6 +97,8 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Manager_Notice' ) ) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Render the dismissible notice on the plugins list screen.
|
* Render the dismissible notice on the plugins list screen.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function render_plugins_page_notice() {
|
public function render_plugins_page_notice() {
|
||||||
if ( ! $this->should_show_notice() ) {
|
if ( ! $this->should_show_notice() ) {
|
||||||
|
|
@ -104,6 +110,8 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Manager_Notice' ) ) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Render a permanent notice for the settings screen.
|
* Render a permanent notice for the settings screen.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function render_settings_notice() {
|
public function render_settings_notice() {
|
||||||
$this->render_notice( 'notice-info', '' );
|
$this->render_notice( 'notice-info', '' );
|
||||||
|
|
@ -114,6 +122,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Manager_Notice' ) ) {
|
||||||
*
|
*
|
||||||
* @param string $classes Extra CSS classes.
|
* @param string $classes Extra CSS classes.
|
||||||
* @param string $id Optional DOM id for the notice container.
|
* @param string $id Optional DOM id for the notice container.
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
private function render_notice( $classes, $id ) {
|
private function render_notice( $classes, $id ) {
|
||||||
if ( self::is_manager_active() ) {
|
if ( self::is_manager_active() ) {
|
||||||
|
|
@ -159,6 +168,8 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Manager_Notice' ) ) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Persist the notice dismissal for the current user.
|
* Persist the notice dismissal for the current user.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function handle_dismiss() {
|
public function handle_dismiss() {
|
||||||
check_ajax_referer( 'robotstxt_telemetry_manager_notice' );
|
check_ajax_referer( 'robotstxt_telemetry_manager_notice' );
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Network' ) ) {
|
||||||
/**
|
/**
|
||||||
* Plugin settings and their defaults.
|
* Plugin settings and their defaults.
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array<string,mixed>
|
||||||
*/
|
*/
|
||||||
const SETTINGS = array(
|
const SETTINGS = array(
|
||||||
'robotstxt_telemetry_useragent_url' => 'hash',
|
'robotstxt_telemetry_useragent_url' => 'hash',
|
||||||
|
|
@ -134,6 +134,9 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Network' ) ) {
|
||||||
/**
|
/**
|
||||||
* The main site ID of the current network.
|
* The main site ID of the current network.
|
||||||
*
|
*
|
||||||
|
* On WordPress 4.8 and older the current network object exposes the
|
||||||
|
* main site ID through its magic "blog_id" property.
|
||||||
|
*
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
public static function main_site_id() {
|
public static function main_site_id() {
|
||||||
|
|
@ -143,7 +146,9 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Network' ) ) {
|
||||||
|
|
||||||
$current_site = get_current_site();
|
$current_site = get_current_site();
|
||||||
|
|
||||||
return max( 1, (int) $current_site->blog_id );
|
$blog_id = isset( $current_site->blog_id ) ? (int) $current_site->blog_id : 0;
|
||||||
|
|
||||||
|
return max( 1, $blog_id );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -194,10 +199,15 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Network' ) ) {
|
||||||
* @return string[]
|
* @return string[]
|
||||||
*/
|
*/
|
||||||
public static function get_hidden_plugins() {
|
public static function get_hidden_plugins() {
|
||||||
$hidden = self::get_setting( 'robotstxt_telemetry_hidden_plugins', array() );
|
$stored = self::get_setting( 'robotstxt_telemetry_hidden_plugins', array() );
|
||||||
|
|
||||||
if ( ! is_array( $hidden ) ) {
|
|
||||||
$hidden = array();
|
$hidden = array();
|
||||||
|
|
||||||
|
if ( is_array( $stored ) ) {
|
||||||
|
foreach ( $stored as $basename ) {
|
||||||
|
if ( is_string( $basename ) ) {
|
||||||
|
$hidden[] = $basename;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$hidden[] = 'robotstxt-telemetry/robotstxt-telemetry.php';
|
$hidden[] = 'robotstxt-telemetry/robotstxt-telemetry.php';
|
||||||
|
|
@ -208,12 +218,24 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Network' ) ) {
|
||||||
/**
|
/**
|
||||||
* Get the per-plugin safe-mode map (slug => safe|original).
|
* Get the per-plugin safe-mode map (slug => safe|original).
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array<string,string>
|
||||||
*/
|
*/
|
||||||
public static function get_plugin_modes() {
|
public static function get_plugin_modes() {
|
||||||
$modes = self::get_setting( 'robotstxt_telemetry_plugin_modes', array() );
|
$stored = self::get_setting( 'robotstxt_telemetry_plugin_modes', array() );
|
||||||
|
|
||||||
return is_array( $modes ) ? $modes : array();
|
if ( ! is_array( $stored ) ) {
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
|
||||||
|
$modes = array();
|
||||||
|
|
||||||
|
foreach ( $stored as $slug => $mode ) {
|
||||||
|
if ( is_string( $slug ) && is_string( $mode ) ) {
|
||||||
|
$modes[ $slug ] = $mode;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $modes;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,8 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Plugin_Guards' ) ) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register hooks.
|
* Register hooks.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function register() {
|
public function register() {
|
||||||
add_filter( 'pre_http_request', array( $this, 'apply_guards' ), 4, 3 );
|
add_filter( 'pre_http_request', array( $this, 'apply_guards' ), 4, 3 );
|
||||||
|
|
@ -37,10 +39,10 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Plugin_Guards' ) ) {
|
||||||
/**
|
/**
|
||||||
* Apply the Safe profiles to an outbound request.
|
* Apply the Safe profiles to an outbound request.
|
||||||
*
|
*
|
||||||
* @param false|array|WP_Error $preempt Preempt value.
|
* @param false|array<string,mixed>|WP_Error $preempt Preempt value.
|
||||||
* @param array $args Request arguments.
|
* @param array{body?:string|array<mixed,mixed>,headers?:string|array<mixed,mixed>,user-agent?:string} $args Request arguments.
|
||||||
* @param string $url Request URL.
|
* @param string $url Request URL.
|
||||||
* @return false|array|WP_Error
|
* @return false|array<string,mixed>|WP_Error
|
||||||
*/
|
*/
|
||||||
public function apply_guards( $preempt, $args, $url ) {
|
public function apply_guards( $preempt, $args, $url ) {
|
||||||
if ( false !== $preempt || self::$busy ) {
|
if ( false !== $preempt || self::$busy ) {
|
||||||
|
|
@ -75,7 +77,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Plugin_Guards' ) ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( 'strip_query' === $action ) {
|
if ( 'strip_query' === $action ) {
|
||||||
$new_url = $this->strip_query_keys( $url, $matcher['keys'] );
|
$new_url = $this->strip_query_keys( $url, isset( $matcher['keys'] ) ? $matcher['keys'] : array() );
|
||||||
if ( $new_url !== $url ) {
|
if ( $new_url !== $url ) {
|
||||||
$url = $new_url;
|
$url = $new_url;
|
||||||
$modified = true;
|
$modified = true;
|
||||||
|
|
@ -84,8 +86,8 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Plugin_Guards' ) ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( 'strip_body' === $action ) {
|
if ( 'strip_body' === $action ) {
|
||||||
$new_body = $this->strip_body_keys( $args, $matcher['keys'] );
|
$new_body = $this->strip_body_keys( $args, isset( $matcher['keys'] ) ? $matcher['keys'] : array() );
|
||||||
if ( null !== $new_body ) {
|
if ( is_string( $new_body ) || is_array( $new_body ) ) {
|
||||||
$args['body'] = $new_body;
|
$args['body'] = $new_body;
|
||||||
$modified = true;
|
$modified = true;
|
||||||
}
|
}
|
||||||
|
|
@ -93,7 +95,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Plugin_Guards' ) ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( 'strip_headers' === $action ) {
|
if ( 'strip_headers' === $action ) {
|
||||||
$new_headers = $this->strip_header_keys( $args, $matcher['headers'] );
|
$new_headers = $this->strip_header_keys( $args, isset( $matcher['headers'] ) ? $matcher['headers'] : array() );
|
||||||
if ( null !== $new_headers ) {
|
if ( null !== $new_headers ) {
|
||||||
$args['headers'] = $new_headers;
|
$args['headers'] = $new_headers;
|
||||||
$modified = true;
|
$modified = true;
|
||||||
|
|
@ -127,7 +129,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Plugin_Guards' ) ) {
|
||||||
*
|
*
|
||||||
* @param string $host Request host.
|
* @param string $host Request host.
|
||||||
* @param string $path Request path.
|
* @param string $path Request path.
|
||||||
* @return array Slug => list of matching matchers.
|
* @return array<string,array<int,array{host?:string,host_contains?:string,path?:string,do?:string,keys?:string[],headers?:string[],mock?:string}>> Slug => list of matching matchers.
|
||||||
*/
|
*/
|
||||||
private function match_profiles( $host, $path ) {
|
private function match_profiles( $host, $path ) {
|
||||||
$candidates = array();
|
$candidates = array();
|
||||||
|
|
@ -161,7 +163,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Plugin_Guards' ) ) {
|
||||||
* the caller attribution keeps them scoped to their own plugin.
|
* the caller attribution keeps them scoped to their own plugin.
|
||||||
*
|
*
|
||||||
* @param string $host Request host.
|
* @param string $host Request host.
|
||||||
* @param array $matcher Matcher.
|
* @param array{host?:string,host_contains?:string} $matcher Matcher.
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
private function host_matches( $host, $matcher ) {
|
private function host_matches( $host, $matcher ) {
|
||||||
|
|
@ -179,7 +181,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Plugin_Guards' ) ) {
|
||||||
/**
|
/**
|
||||||
* Find which of the candidate plugins issued the request.
|
* Find which of the candidate plugins issued the request.
|
||||||
*
|
*
|
||||||
* @param array $slugs Candidate plugin slugs.
|
* @param array<int,string> $slugs Candidate plugin slugs.
|
||||||
* @return string Plugin slug or an empty string.
|
* @return string Plugin slug or an empty string.
|
||||||
*/
|
*/
|
||||||
private function find_calling_plugin( $slugs ) {
|
private function find_calling_plugin( $slugs ) {
|
||||||
|
|
@ -187,7 +189,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Plugin_Guards' ) ) {
|
||||||
$backtrace = debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS );
|
$backtrace = debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS );
|
||||||
|
|
||||||
foreach ( $backtrace as $frame ) {
|
foreach ( $backtrace as $frame ) {
|
||||||
if ( empty( $frame['file'] ) || ! is_string( $frame['file'] ) ) {
|
if ( empty( $frame['file'] ) ) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -207,7 +209,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Plugin_Guards' ) ) {
|
||||||
* Build a mock response for a blocked endpoint.
|
* Build a mock response for a blocked endpoint.
|
||||||
*
|
*
|
||||||
* @param string $body Mock body.
|
* @param string $body Mock body.
|
||||||
* @return array
|
* @return array<string,mixed>
|
||||||
*/
|
*/
|
||||||
private function mock_response( $body ) {
|
private function mock_response( $body ) {
|
||||||
return array(
|
return array(
|
||||||
|
|
@ -226,7 +228,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Plugin_Guards' ) ) {
|
||||||
* Remove keys from the URL query string.
|
* Remove keys from the URL query string.
|
||||||
*
|
*
|
||||||
* @param string $url Request URL.
|
* @param string $url Request URL.
|
||||||
* @param array $keys Keys to remove.
|
* @param array<int,string> $keys Keys to remove.
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
private function strip_query_keys( $url, $keys ) {
|
private function strip_query_keys( $url, $keys ) {
|
||||||
|
|
@ -256,8 +258,8 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Plugin_Guards' ) ) {
|
||||||
*
|
*
|
||||||
* Returns null when nothing changed.
|
* Returns null when nothing changed.
|
||||||
*
|
*
|
||||||
* @param array $args Request arguments.
|
* @param array<string,mixed> $args Request arguments.
|
||||||
* @param array $keys Keys to remove.
|
* @param array<int,string> $keys Keys to remove.
|
||||||
* @return mixed|null
|
* @return mixed|null
|
||||||
*/
|
*/
|
||||||
private function strip_body_keys( $args, $keys ) {
|
private function strip_body_keys( $args, $keys ) {
|
||||||
|
|
@ -300,9 +302,9 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Plugin_Guards' ) ) {
|
||||||
/**
|
/**
|
||||||
* Remove keys from an array (case-insensitive).
|
* Remove keys from an array (case-insensitive).
|
||||||
*
|
*
|
||||||
* @param array $data Source array.
|
* @param array<mixed> $data Source array.
|
||||||
* @param array $keys Keys to remove.
|
* @param array<int,string> $keys Keys to remove.
|
||||||
* @return array
|
* @return array<mixed>
|
||||||
*/
|
*/
|
||||||
private function remove_keys( $data, $keys ) {
|
private function remove_keys( $data, $keys ) {
|
||||||
$lower = array_map( 'strtolower', array_values( $keys ) );
|
$lower = array_map( 'strtolower', array_values( $keys ) );
|
||||||
|
|
@ -321,9 +323,9 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Plugin_Guards' ) ) {
|
||||||
/**
|
/**
|
||||||
* Remove headers from the request arguments.
|
* Remove headers from the request arguments.
|
||||||
*
|
*
|
||||||
* @param array $args Request arguments.
|
* @param array<string,mixed> $args Request arguments.
|
||||||
* @param array $headers Header names to remove.
|
* @param array<int,string> $headers Header names to remove.
|
||||||
* @return array|null
|
* @return array<mixed>|null
|
||||||
*/
|
*/
|
||||||
private function strip_header_keys( $args, $headers ) {
|
private function strip_header_keys( $args, $headers ) {
|
||||||
if ( ! isset( $args['headers'] ) || ! is_array( $args['headers'] ) ) {
|
if ( ! isset( $args['headers'] ) || ! is_array( $args['headers'] ) ) {
|
||||||
|
|
@ -350,7 +352,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Plugin_Guards' ) ) {
|
||||||
*
|
*
|
||||||
* Returns null when there is nothing to strip.
|
* Returns null when there is nothing to strip.
|
||||||
*
|
*
|
||||||
* @param array $args Request arguments.
|
* @param array<string,mixed> $args Request arguments.
|
||||||
* @return string|null
|
* @return string|null
|
||||||
*/
|
*/
|
||||||
private function strip_user_agent( $args ) {
|
private function strip_user_agent( $args ) {
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load diff
|
|
@ -42,6 +42,8 @@ if ( ! class_exists( 'Robotstxt_Telemetry_WordPress_Api' ) ) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register hooks.
|
* Register hooks.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function register() {
|
public function register() {
|
||||||
add_filter( 'core_version_check_query_args', array( $this, 'filter_core_query_args' ) );
|
add_filter( 'core_version_check_query_args', array( $this, 'filter_core_query_args' ) );
|
||||||
|
|
@ -51,8 +53,8 @@ if ( ! class_exists( 'Robotstxt_Telemetry_WordPress_Api' ) ) {
|
||||||
/**
|
/**
|
||||||
* Limit the core version check query arguments in safe mode.
|
* Limit the core version check query arguments in safe mode.
|
||||||
*
|
*
|
||||||
* @param array $query Query arguments.
|
* @param array<string,mixed> $query Query arguments.
|
||||||
* @return array
|
* @return array<string,mixed>
|
||||||
*/
|
*/
|
||||||
public function filter_core_query_args( $query ) {
|
public function filter_core_query_args( $query ) {
|
||||||
if ( ! $this->is_safe( self::OPT_CORE ) ) {
|
if ( ! $this->is_safe( self::OPT_CORE ) ) {
|
||||||
|
|
@ -74,9 +76,9 @@ if ( ! class_exists( 'Robotstxt_Telemetry_WordPress_Api' ) ) {
|
||||||
/**
|
/**
|
||||||
* Filter update check request arguments.
|
* Filter update check request arguments.
|
||||||
*
|
*
|
||||||
* @param array $args HTTP request arguments.
|
* @param array<string,mixed> $args HTTP request arguments.
|
||||||
* @param string $url Request URL.
|
* @param string $url Request URL.
|
||||||
* @return array
|
* @return array<string,mixed>
|
||||||
*/
|
*/
|
||||||
public function filter_request_args( $args, $url ) {
|
public function filter_request_args( $args, $url ) {
|
||||||
$parsed = wp_parse_url( $url );
|
$parsed = wp_parse_url( $url );
|
||||||
|
|
@ -115,17 +117,19 @@ if ( ! class_exists( 'Robotstxt_Telemetry_WordPress_Api' ) ) {
|
||||||
* Removes the wp_install/wp_blog headers and reduces the translations
|
* Removes the wp_install/wp_blog headers and reduces the translations
|
||||||
* payload to its project dates.
|
* payload to its project dates.
|
||||||
*
|
*
|
||||||
* @param array $args HTTP request arguments.
|
* @param array<string,mixed> $args HTTP request arguments.
|
||||||
* @return array
|
* @return array<string,mixed>
|
||||||
*/
|
*/
|
||||||
private function filter_core_request( $args ) {
|
private function filter_core_request( $args ) {
|
||||||
if ( ! $this->is_safe( self::OPT_CORE ) ) {
|
if ( ! $this->is_safe( self::OPT_CORE ) ) {
|
||||||
return $args;
|
return $args;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( isset( $args['headers'] ) && is_array( $args['headers'] ) ) {
|
||||||
unset( $args['headers']['wp_install'], $args['headers']['wp_blog'] );
|
unset( $args['headers']['wp_install'], $args['headers']['wp_blog'] );
|
||||||
|
}
|
||||||
|
|
||||||
if ( isset( $args['body']['translations'] ) && is_string( $args['body']['translations'] ) ) {
|
if ( isset( $args['body'] ) && is_array( $args['body'] ) && isset( $args['body']['translations'] ) && is_string( $args['body']['translations'] ) ) {
|
||||||
$args['body']['translations'] = $this->filter_translations( $args['body']['translations'] );
|
$args['body']['translations'] = $this->filter_translations( $args['body']['translations'] );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -135,15 +139,15 @@ if ( ! class_exists( 'Robotstxt_Telemetry_WordPress_Api' ) ) {
|
||||||
/**
|
/**
|
||||||
* Limit the themes update check payload in safe mode.
|
* Limit the themes update check payload in safe mode.
|
||||||
*
|
*
|
||||||
* @param array $args HTTP request arguments.
|
* @param array<string,mixed> $args HTTP request arguments.
|
||||||
* @return array
|
* @return array<string,mixed>
|
||||||
*/
|
*/
|
||||||
private function filter_themes_request( $args ) {
|
private function filter_themes_request( $args ) {
|
||||||
if ( ! $this->is_safe( self::OPT_THEMES ) ) {
|
if ( ! $this->is_safe( self::OPT_THEMES ) ) {
|
||||||
return $args;
|
return $args;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ! isset( $args['body']['themes'] ) || ! is_string( $args['body']['themes'] ) ) {
|
if ( ! isset( $args['body'] ) || ! is_array( $args['body'] ) || ! isset( $args['body']['themes'] ) || ! is_string( $args['body']['themes'] ) ) {
|
||||||
return $args;
|
return $args;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -180,15 +184,15 @@ if ( ! class_exists( 'Robotstxt_Telemetry_WordPress_Api' ) ) {
|
||||||
/**
|
/**
|
||||||
* Limit the plugins update check payload in safe mode.
|
* Limit the plugins update check payload in safe mode.
|
||||||
*
|
*
|
||||||
* @param array $args HTTP request arguments.
|
* @param array<string,mixed> $args HTTP request arguments.
|
||||||
* @return array
|
* @return array<string,mixed>
|
||||||
*/
|
*/
|
||||||
private function filter_plugins_request( $args ) {
|
private function filter_plugins_request( $args ) {
|
||||||
if ( ! $this->is_safe( self::OPT_PLUGINS ) ) {
|
if ( ! $this->is_safe( self::OPT_PLUGINS ) ) {
|
||||||
return $args;
|
return $args;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ! isset( $args['body']['plugins'] ) || ! is_string( $args['body']['plugins'] ) ) {
|
if ( ! isset( $args['body'] ) || ! is_array( $args['body'] ) || ! isset( $args['body']['plugins'] ) || ! is_string( $args['body']['plugins'] ) ) {
|
||||||
return $args;
|
return $args;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -231,13 +235,13 @@ if ( ! class_exists( 'Robotstxt_Telemetry_WordPress_Api' ) ) {
|
||||||
* the active list, nor their translation projects), which also
|
* the active list, nor their translation projects), which also
|
||||||
* means they stop receiving WordPress.org update notifications.
|
* means they stop receiving WordPress.org update notifications.
|
||||||
*
|
*
|
||||||
* @param array $args HTTP request arguments.
|
* @param array<string,mixed> $args HTTP request arguments.
|
||||||
* @return array
|
* @return array<string,mixed>
|
||||||
*/
|
*/
|
||||||
private function exclude_hidden_plugins( $args ) {
|
private function exclude_hidden_plugins( $args ) {
|
||||||
$hidden = Robotstxt_Telemetry_Network::get_hidden_plugins();
|
$hidden = Robotstxt_Telemetry_Network::get_hidden_plugins();
|
||||||
|
|
||||||
if ( empty( $hidden ) || empty( $args['body']['plugins'] ) || ! is_string( $args['body']['plugins'] ) ) {
|
if ( empty( $hidden ) || ! isset( $args['body'] ) || ! is_array( $args['body'] ) || empty( $args['body']['plugins'] ) || ! is_string( $args['body']['plugins'] ) ) {
|
||||||
return $args;
|
return $args;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -253,7 +257,13 @@ if ( ! class_exists( 'Robotstxt_Telemetry_WordPress_Api' ) ) {
|
||||||
$slug = dirname( $basename );
|
$slug = dirname( $basename );
|
||||||
$hidden_slugs[ $slug ] = true;
|
$hidden_slugs[ $slug ] = true;
|
||||||
|
|
||||||
unset( $data['plugins'][ $basename ], $data['active'][ $basename ] );
|
if ( isset( $data['plugins'] ) && is_array( $data['plugins'] ) ) {
|
||||||
|
unset( $data['plugins'][ $basename ] );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( isset( $data['active'] ) && is_array( $data['active'] ) ) {
|
||||||
|
unset( $data['active'][ $basename ] );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( isset( $args['body']['translations'] ) && is_string( $args['body']['translations'] ) ) {
|
if ( isset( $args['body']['translations'] ) && is_string( $args['body']['translations'] ) ) {
|
||||||
|
|
@ -290,11 +300,11 @@ if ( ! class_exists( 'Robotstxt_Telemetry_WordPress_Api' ) ) {
|
||||||
* Handles the JSON-encoded locale arrays of the update checks
|
* Handles the JSON-encoded locale arrays of the update checks
|
||||||
* (for example `["es_ES","en_US"]`) and plain locale strings.
|
* (for example `["es_ES","en_US"]`) and plain locale strings.
|
||||||
*
|
*
|
||||||
* @param array $args HTTP request arguments.
|
* @param array<string,mixed> $args HTTP request arguments.
|
||||||
* @return array
|
* @return array<string,mixed>
|
||||||
*/
|
*/
|
||||||
private function mask_locale_in_body( $args ) {
|
private function mask_locale_in_body( $args ) {
|
||||||
if ( ! isset( $args['body']['locale'] ) || ! is_array( $args['body'] ) ) {
|
if ( ! isset( $args['body'] ) || ! is_array( $args['body'] ) || ! isset( $args['body']['locale'] ) ) {
|
||||||
return $args;
|
return $args;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -324,13 +334,13 @@ if ( ! class_exists( 'Robotstxt_Telemetry_WordPress_Api' ) ) {
|
||||||
/**
|
/**
|
||||||
* Read a string field from the request body arguments.
|
* Read a string field from the request body arguments.
|
||||||
*
|
*
|
||||||
* @param array $args HTTP request arguments.
|
* @param array<string,mixed> $args HTTP request arguments.
|
||||||
* @param string $key Body field name.
|
* @param string $key Body field name.
|
||||||
* @param string $fallback_value Default value when missing.
|
* @param string $fallback_value Default value when missing.
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
private function body_field( $args, $key, $fallback_value ) {
|
private function body_field( $args, $key, $fallback_value ) {
|
||||||
if ( isset( $args['body'][ $key ] ) && is_string( $args['body'][ $key ] ) ) {
|
if ( isset( $args['body'] ) && is_array( $args['body'] ) && isset( $args['body'][ $key ] ) && is_string( $args['body'][ $key ] ) ) {
|
||||||
return $args['body'][ $key ];
|
return $args['body'][ $key ];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -377,7 +387,13 @@ if ( ! class_exists( 'Robotstxt_Telemetry_WordPress_Api' ) ) {
|
||||||
return $json;
|
return $json;
|
||||||
}
|
}
|
||||||
|
|
||||||
return wp_json_encode( $filtered );
|
$encoded = wp_json_encode( $filtered );
|
||||||
|
|
||||||
|
if ( false === $encoded ) {
|
||||||
|
return $json;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $encoded;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -385,9 +401,9 @@ if ( ! class_exists( 'Robotstxt_Telemetry_WordPress_Api' ) ) {
|
||||||
*
|
*
|
||||||
* Matching is case-insensitive; original keys are preserved.
|
* Matching is case-insensitive; original keys are preserved.
|
||||||
*
|
*
|
||||||
* @param array $fields Fields of the entry.
|
* @param array<mixed,mixed> $fields Fields of the entry.
|
||||||
* @param array $allowed Lowercase allowed field names.
|
* @param array<int,string> $allowed Lowercase allowed field names.
|
||||||
* @return array
|
* @return array<mixed,mixed>
|
||||||
*/
|
*/
|
||||||
private function keep_fields( $fields, $allowed ) {
|
private function keep_fields( $fields, $allowed ) {
|
||||||
$kept = array();
|
$kept = array();
|
||||||
|
|
@ -409,8 +425,8 @@ if ( ! class_exists( 'Robotstxt_Telemetry_WordPress_Api' ) ) {
|
||||||
* SHA-256 truncation of the URI, so the plugin or theme source is
|
* SHA-256 truncation of the URI, so the plugin or theme source is
|
||||||
* no longer identifiable while staying consistent across requests.
|
* no longer identifiable while staying consistent across requests.
|
||||||
*
|
*
|
||||||
* @param array $fields Fields of a plugin or theme entry.
|
* @param array<mixed,mixed> $fields Fields of a plugin or theme entry.
|
||||||
* @return array
|
* @return array<mixed,mixed>
|
||||||
*/
|
*/
|
||||||
private function hash_update_uri( $fields ) {
|
private function hash_update_uri( $fields ) {
|
||||||
foreach ( $fields as $key => $value ) {
|
foreach ( $fields as $key => $value ) {
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,8 @@ if ( ! class_exists( 'Robotstxt_Telemetry' ) ) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize the plugin.
|
* Initialize the plugin.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
public static function init() {
|
public static function init() {
|
||||||
$instance = new self();
|
$instance = new self();
|
||||||
|
|
@ -25,6 +27,8 @@ if ( ! class_exists( 'Robotstxt_Telemetry' ) ) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register hooks.
|
* Register hooks.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
private function register_hooks() {
|
private function register_hooks() {
|
||||||
add_action( 'plugins_loaded', array( $this, 'load_textdomain' ) );
|
add_action( 'plugins_loaded', array( $this, 'load_textdomain' ) );
|
||||||
|
|
@ -67,9 +71,9 @@ if ( ! class_exists( 'Robotstxt_Telemetry' ) ) {
|
||||||
* Runs at priority 9 so the telemetry logger records the value that
|
* Runs at priority 9 so the telemetry logger records the value that
|
||||||
* is actually sent on the wire.
|
* is actually sent on the wire.
|
||||||
*
|
*
|
||||||
* @param array $args HTTP request arguments.
|
* @param array<string,mixed> $args HTTP request arguments.
|
||||||
* @param string $url Request URL.
|
* @param string $url Request URL.
|
||||||
* @return array
|
* @return array<string,mixed>
|
||||||
*/
|
*/
|
||||||
public function filter_useragent( $args, $url ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter -- Second argument required by the http_request_args filter signature.
|
public function filter_useragent( $args, $url ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter -- Second argument required by the http_request_args filter signature.
|
||||||
$url_mode = Robotstxt_Telemetry_Network::get_useragent_url_mode();
|
$url_mode = Robotstxt_Telemetry_Network::get_useragent_url_mode();
|
||||||
|
|
@ -85,11 +89,13 @@ if ( ! class_exists( 'Robotstxt_Telemetry' ) ) {
|
||||||
$args['user-agent'] = $this->mask_user_agent( $args['user-agent'], $url_mode, $version_mode, $site_url );
|
$args['user-agent'] = $this->mask_user_agent( $args['user-agent'], $url_mode, $version_mode, $site_url );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( isset( $args['headers'] ) && is_array( $args['headers'] ) ) {
|
||||||
foreach ( array( 'User-Agent', 'user-agent' ) as $header ) {
|
foreach ( array( 'User-Agent', 'user-agent' ) as $header ) {
|
||||||
if ( isset( $args['headers'][ $header ] ) && is_string( $args['headers'][ $header ] ) ) {
|
if ( isset( $args['headers'][ $header ] ) && is_string( $args['headers'][ $header ] ) ) {
|
||||||
$args['headers'][ $header ] = $this->mask_user_agent( $args['headers'][ $header ], $url_mode, $version_mode, $site_url );
|
$args['headers'][ $header ] = $this->mask_user_agent( $args['headers'][ $header ], $url_mode, $version_mode, $site_url );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return $args;
|
return $args;
|
||||||
}
|
}
|
||||||
|
|
@ -128,11 +134,15 @@ if ( ! class_exists( 'Robotstxt_Telemetry' ) ) {
|
||||||
$user_agent = trim( $user_agent );
|
$user_agent = trim( $user_agent );
|
||||||
|
|
||||||
if ( 'actual' !== $version_mode && preg_match( '#^WordPress/(\d+[^\s;]*)#', $user_agent, $matches ) ) {
|
if ( 'actual' !== $version_mode && preg_match( '#^WordPress/(\d+[^\s;]*)#', $user_agent, $matches ) ) {
|
||||||
$user_agent = preg_replace(
|
$masked = preg_replace(
|
||||||
'#^WordPress/[^\s;]+#',
|
'#^WordPress/[^\s;]+#',
|
||||||
'WordPress/' . Robotstxt_Telemetry_Network::mask_wp_version( $matches[1], $version_mode ),
|
'WordPress/' . Robotstxt_Telemetry_Network::mask_wp_version( $matches[1], $version_mode ),
|
||||||
$user_agent
|
$user_agent
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if ( null !== $masked ) {
|
||||||
|
$user_agent = $masked;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $user_agent;
|
return $user_agent;
|
||||||
|
|
@ -142,6 +152,8 @@ if ( ! class_exists( 'Robotstxt_Telemetry' ) ) {
|
||||||
*
|
*
|
||||||
* In global mode the shared table is cleaned from the main site
|
* In global mode the shared table is cleaned from the main site
|
||||||
* only, so subsites do not schedule the event.
|
* only, so subsites do not schedule the event.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function schedule_cleanup() {
|
public function schedule_cleanup() {
|
||||||
if ( Robotstxt_Telemetry_Network::is_global() && ! is_main_site() ) {
|
if ( Robotstxt_Telemetry_Network::is_global() && ! is_main_site() ) {
|
||||||
|
|
@ -155,6 +167,8 @@ if ( ! class_exists( 'Robotstxt_Telemetry' ) ) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deactivation handler: clear the scheduled cleanup event.
|
* Deactivation handler: clear the scheduled cleanup event.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
public static function deactivate() {
|
public static function deactivate() {
|
||||||
wp_clear_scheduled_hook( 'robotstxt_telemetry_cleanup' );
|
wp_clear_scheduled_hook( 'robotstxt_telemetry_cleanup' );
|
||||||
|
|
@ -170,6 +184,8 @@ if ( ! class_exists( 'Robotstxt_Telemetry' ) ) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load plugin translations.
|
* Load plugin translations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function load_textdomain() {
|
public function load_textdomain() {
|
||||||
load_plugin_textdomain(
|
load_plugin_textdomain(
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load diff
22
readme.txt
22
readme.txt
|
|
@ -3,9 +3,9 @@ Contributors: robotstxt, javiercasares
|
||||||
Tags: telemetry, privacy, http, requests, logging
|
Tags: telemetry, privacy, http, requests, logging
|
||||||
Requires at least: 4.0
|
Requires at least: 4.0
|
||||||
Tested up to: 7.1
|
Tested up to: 7.1
|
||||||
Stable tag: 1.1.1
|
Stable tag: 1.1.4
|
||||||
Requires PHP: 5.6
|
Requires PHP: 5.6
|
||||||
Version: 1.1.1
|
Version: 1.1.4
|
||||||
License: GPL-3.0-or-later
|
License: GPL-3.0-or-later
|
||||||
License URI: https://www.gnu.org/licenses/gpl-3.0.txt
|
License URI: https://www.gnu.org/licenses/gpl-3.0.txt
|
||||||
|
|
||||||
|
|
@ -148,23 +148,17 @@ On WordPress versions older than 5.1, the Core update check Safe mode cannot red
|
||||||
|
|
||||||
Only the 3 last versions. The full changelog will be at changelog.txt
|
Only the 3 last versions. The full changelog will be at changelog.txt
|
||||||
|
|
||||||
= 1.1.1 =
|
= 1.1.4 =
|
||||||
|
|
||||||
* Added: "Safe Mode" checkbox column in the Plugins screen (with accessible hidden labels per row)
|
* Security and compatibility review of the 1.1.3 code base: PHPStan level 9 with the WordPress stubs introduced (and every finding fixed), WordPress Coding Standards fixes applied across all files, and the real compatibility floors re-verified (WordPress 4.0 - 7.1, PHP 5.6 - 8.5)
|
||||||
* Fixed: the StellarWP telemetry blocks (iThemes Security, Kadence Blocks, The Events Calendar) are now actually applied (path-only matchers were never reached)
|
|
||||||
* Changed: the profile registry is built once per request instead of on every outbound call
|
|
||||||
|
|
||||||
= 1.1.0 =
|
= 1.1.3 =
|
||||||
|
|
||||||
* Added: "Plugins" settings screen (Telemetry → Plugins) with a Safe/Original mode per plugin; in Safe mode the known telemetry endpoints are blocked and the environment data is reduced to what each service needs, and every row explains what is truncated and what is kept
|
* Security and compatibility review of the 1.1.2 tab-scoped settings save: nonce and capability checks, tab whitelisting, option-name whitelisting, per-value sanitization, and redirect hardening all verified; no changes needed
|
||||||
* Added: safe profiles for 99 popular plugins, covering the common telemetry SDKs (Freemius, BSF analytics, Themeisle, Mixpanel, Appsero, StellarWP, WPMU DEV Hub) and the individual trackers, license-update extras, feedback surveys, and User-Agent/headers of each plugin
|
|
||||||
|
|
||||||
= 1.0.1 =
|
= 1.1.2 =
|
||||||
|
|
||||||
* Fixed: saving the "Plugins" tab from the Network Admin no longer resets the other network settings to their defaults (and the hidden plugins list can now be saved in Global mode)
|
* Fixed: saving one Settings tab 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 settings of the other tabs back to their defaults; each tab now saves through its own tab-scoped, nonce-protected handler)
|
||||||
* Fixed: credentials embedded in URLs are now always stripped, including URLs without query strings
|
|
||||||
* Changed: the redaction of sensitive keys now also covers "api-key", "cookie", "session", "private-key", and "private_key"
|
|
||||||
* Changed: documentation clarified — the WordPress version masking applies to the User-Agent only, and the query parameters always send the real version
|
|
||||||
|
|
||||||
= Previous versions =
|
= Previous versions =
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
* Plugin URI: https://www.robotstxt.software/plugins/robotstxt-telemetry/
|
* Plugin URI: https://www.robotstxt.software/plugins/robotstxt-telemetry/
|
||||||
* Update URI: https://www.robotstxt.software/plugins/robotstxt-telemetry/
|
* Update URI: https://www.robotstxt.software/plugins/robotstxt-telemetry/
|
||||||
* Description: Reduces the telemetry WordPress sends out and logs every outbound HTTP request, so your site shares less and you can see everything.
|
* Description: Reduces the telemetry WordPress sends out and logs every outbound HTTP request, so your site shares less and you can see everything.
|
||||||
* Version: 1.1.1
|
* Version: 1.1.4
|
||||||
* Author: ROBOTSTXT
|
* Author: ROBOTSTXT
|
||||||
* Author URI: https://www.robotstxt.software/
|
* Author URI: https://www.robotstxt.software/
|
||||||
* Text Domain: robotstxt-telemetry
|
* Text Domain: robotstxt-telemetry
|
||||||
|
|
@ -13,8 +13,8 @@
|
||||||
* Requires PHP: 5.6
|
* Requires PHP: 5.6
|
||||||
* Tested up to: 7.1
|
* Tested up to: 7.1
|
||||||
* Network: true
|
* Network: true
|
||||||
* License: GPL v3 or later
|
* License: GPL-3.0-or-later
|
||||||
* License URI: https://www.gnu.org/licenses/gpl-3.0.html
|
* License URI: https://www.gnu.org/licenses/gpl-3.0.txt
|
||||||
*
|
*
|
||||||
* @package RobotstxtTelemetry
|
* @package RobotstxtTelemetry
|
||||||
*/
|
*/
|
||||||
|
|
@ -23,7 +23,7 @@ if ( ! defined( 'ABSPATH' ) ) {
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
define( 'ROBOTSTXT_TELEMETRY_VERSION', '1.1.1' );
|
define( 'ROBOTSTXT_TELEMETRY_VERSION', '1.1.4' );
|
||||||
define( 'ROBOTSTXT_TELEMETRY_DB_VERSION', '1.1.0' );
|
define( 'ROBOTSTXT_TELEMETRY_DB_VERSION', '1.1.0' );
|
||||||
define( 'ROBOTSTXT_TELEMETRY_PLUGIN_FILE', __FILE__ );
|
define( 'ROBOTSTXT_TELEMETRY_PLUGIN_FILE', __FILE__ );
|
||||||
define( 'ROBOTSTXT_TELEMETRY_PLUGIN_DIR', __DIR__ );
|
define( 'ROBOTSTXT_TELEMETRY_PLUGIN_DIR', __DIR__ );
|
||||||
|
|
@ -53,7 +53,7 @@ if ( ! function_exists( 'wp_json_encode' ) ) {
|
||||||
* @return string|false
|
* @return string|false
|
||||||
*/
|
*/
|
||||||
function wp_json_encode( $data, $options = 0 ) {
|
function wp_json_encode( $data, $options = 0 ) {
|
||||||
return json_encode( $data, $options ); // phpcs:ignore WordPress.WP.AlternativeFunctions.json_encode_json_decode -- Native call is the purpose of this compatibility shim for WordPress 4.0.
|
return json_encode( $data, $options ); // phpcs:ignore WordPress.WP.AlternativeFunctions.json_encode_json_encode -- Native call is the purpose of this compatibility shim for WordPress 4.0.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -70,7 +70,7 @@ function robotstxt_telemetry_uninstall_site( $force_drop = null ) {
|
||||||
|
|
||||||
if ( $drop ) {
|
if ( $drop ) {
|
||||||
$table_name = $wpdb->prefix . 'robotstxt_telemetry_logs';
|
$table_name = $wpdb->prefix . 'robotstxt_telemetry_logs';
|
||||||
$wpdb->query( "DROP TABLE IF EXISTS {$table_name}" ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- Table name is internal; the %i placeholder requires WordPress 6.2. // phpcs:ignore WordPress.DB.DirectDatabaseQuery, WordPress.DB.DirectDatabaseQuery.SchemaChange, WordPress.DB.DirectDatabaseQuery.NoCaching
|
$wpdb->query( "DROP TABLE IF EXISTS {$table_name}" ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.DirectDatabaseQuery.SchemaChange -- Table name is internal (%i requires WordPress 6.2); dropping the table on uninstall is the intended, opt-in behavior.
|
||||||
}
|
}
|
||||||
|
|
||||||
delete_option( 'robotstxt_telemetry_delete_on_uninstall' );
|
delete_option( 'robotstxt_telemetry_delete_on_uninstall' );
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue