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 ==
|
||||
|
||||
= 1.1.4 =
|
||||
|
||||
_Release date: 2026-08-20_
|
||||
|
||||
**Highlights**
|
||||
|
||||
* Security and compatibility review of the whole code base, with static analysis raised to PHPStan level 9
|
||||
|
||||
**Added**
|
||||
|
||||
* Development: PHPStan (level 9) with the WordPress stubs and the wp-compat rules, PHPUnit with the polyfills, and the missing PHPCS utilities; `bin/preflight.sh` runs every automatable pre-deploy check
|
||||
* Tests: plugin header test suite (15 tests) verifying the required headers, the readme consistency (Stable tag, Requires at least, Requires PHP, Tested up to, License), the contributor order, the changelog URL, and the absence of the removed self-updater files
|
||||
|
||||
**Changed**
|
||||
|
||||
* Development: the full code base passes WordPress Coding Standards with zero errors and warnings, PHPStan level 9 with zero errors, and PHPCompatibilityWP for PHP 5.6 - 8.5 with zero errors
|
||||
* Type safety: every parameter and return type documented (PHP 5.6-compatible phpDoc generics), all input paths narrowed before sanitization, and two always-dead branches removed (the logs list parameters column helper and the caller backtrace object check)
|
||||
* License header of the main plugin file aligned with readme.txt ("GPL-3.0-or-later")
|
||||
|
||||
**Fixed**
|
||||
|
||||
* The User-Agent masking keeps the previous value when the regular expression replacement fails instead of returning null
|
||||
* The Multisite main-site fallback (WordPress 4.8 and older) reads the network's blog_id only when it is set
|
||||
|
||||
**Security**
|
||||
|
||||
* Full review following OWASP and WordPress Plugin Security guidelines: capabilities, nonces, validation, sanitization, output escaping, database access, and uninstall cleanup re-audited with the new tooling; no vulnerabilities found, and the type hardening above was applied
|
||||
|
||||
**Compatibility**
|
||||
|
||||
* WordPress: 4.0 - 7.1
|
||||
* PHP: 5.6 - 8.5
|
||||
* MariaDB: 10.6+
|
||||
* Multisite: compatible (Per-site and Global modes)
|
||||
|
||||
**Tests**
|
||||
|
||||
* WordPress 7.2-alpha-63320, PHP 8.5.9, MariaDB 11.8.8
|
||||
* Verified live: plugin active on the staging site with no PHP notices, warnings, or deprecated messages
|
||||
* PHP Coding Standards: 3.13.6
|
||||
* WordPress Coding Standards: 3.4.1
|
||||
* PHPCompatibilityWP (PHP 5.6 - 8.5) and wp-since (WordPress 4.0) static reviews for the floor versions
|
||||
* PHPStan level 9 with the WordPress stubs: zero errors
|
||||
|
||||
= 1.1.3 =
|
||||
|
||||
_Release date: 2026-08-20_
|
||||
|
||||
**Highlights**
|
||||
|
||||
* Security and compatibility review of the 1.1.2 settings-save rewrite
|
||||
|
||||
**Security**
|
||||
|
||||
* Full review of the tab-scoped save handler (per-site and Network Admin) following OWASP and WordPress Plugin Security guidelines: nonce pairing, capability ordering (the capability check precedes every save branch, so site administrators cannot write network options in Global mode), tab whitelisting, hardcoded option names, per-value sanitization, and safe redirects with no open-redirect surface; all areas passed with no findings
|
||||
|
||||
**Compatibility**
|
||||
|
||||
* WordPress: 4.0 - 7.1
|
||||
* PHP: 5.6 - 8.5
|
||||
* MariaDB: 10.6+
|
||||
* Multisite: compatible (Per-site and Global modes)
|
||||
|
||||
**Tests**
|
||||
|
||||
* WordPress 7.2-alpha-63320, PHP 8.5.9, MariaDB 11.8.8
|
||||
* PHP Coding Standards: 3.13.6
|
||||
* WordPress Coding Standards: 3.4.1
|
||||
* PHPCompatibilityWP (PHP 5.6 - 8.5) and wp-since (WordPress 4.0) static reviews for the floor versions
|
||||
|
||||
= 1.1.2 =
|
||||
|
||||
_Release date: 2026-08-18_
|
||||
|
||||
**Highlights**
|
||||
|
||||
* Cross-tab settings saves fixed on the per-site Settings screen
|
||||
|
||||
**Fixed**
|
||||
|
||||
* Saving one tab of the per-site Settings screen no longer resets the other tabs: WordPress core sets every unposted option of a settings group to null since WordPress 5.5, so saving any tab was wiping the options of the other tabs back to their defaults (or, for the User-Agent mode, to the legacy pre-0.9 value). Each tab now saves through its own tab-scoped, nonce- and capability-protected handler shared with the Network Admin screen, updating only the options of the tab being saved
|
||||
|
||||
**Changed**
|
||||
|
||||
* The per-site Settings screen no longer posts through options.php; the Settings API registration of the options was removed along with it (the sanitizers are unchanged and still applied by the save handler)
|
||||
|
||||
**Compatibility**
|
||||
|
||||
* WordPress: 4.0 - 7.1
|
||||
* PHP: 5.6 - 8.5
|
||||
* MariaDB: 10.6+
|
||||
* Multisite: compatible (Per-site and Global modes)
|
||||
|
||||
**Tests**
|
||||
|
||||
* WordPress 7.2-alpha-63320, PHP 8.5.9, MariaDB 11.8.8
|
||||
* Verified live: main tab values survive saves of the Plugins, Logs, and General tabs and vice versa; hidden plugins, retention, and uninstall options each preserved
|
||||
* PHP Coding Standards: 3.13.6
|
||||
* WordPress Coding Standards: 3.4.1
|
||||
|
||||
= 1.1.1 =
|
||||
|
||||
_Release date: 2026-08-18_
|
||||
|
|
|
|||
|
|
@ -17,11 +17,12 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Admin' ) ) {
|
|||
|
||||
/**
|
||||
* Register hooks.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register() {
|
||||
add_action( 'admin_menu', array( $this, 'register_menu' ) );
|
||||
add_action( 'network_admin_menu', array( $this, 'register_network_menu' ) );
|
||||
add_action( 'admin_init', array( $this, 'register_settings' ) );
|
||||
add_action( 'admin_init', array( $this, 'handle_actions' ) );
|
||||
add_action( 'admin_notices', array( $this, 'render_saved_notice' ) );
|
||||
add_action( 'network_admin_notices', array( $this, 'render_saved_notice' ) );
|
||||
|
|
@ -32,6 +33,8 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Admin' ) ) {
|
|||
*
|
||||
* In global mode the per-site screens are replaced by the
|
||||
* Network Admin ones.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register_menu() {
|
||||
if ( Robotstxt_Telemetry_Network::is_global() ) {
|
||||
|
|
@ -47,33 +50,33 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Admin' ) ) {
|
|||
'dashicons-admin-generic'
|
||||
);
|
||||
|
||||
add_submenu_page(
|
||||
'robotstxt-telemetry',
|
||||
__( 'Settings', 'robotstxt-telemetry' ),
|
||||
__( 'Settings', 'robotstxt-telemetry' ),
|
||||
'manage_options',
|
||||
'robotstxt-telemetry',
|
||||
array( $this, 'render_settings_page' )
|
||||
);
|
||||
add_submenu_page(
|
||||
'robotstxt-telemetry',
|
||||
__( 'Settings', 'robotstxt-telemetry' ),
|
||||
__( 'Settings', 'robotstxt-telemetry' ),
|
||||
'manage_options',
|
||||
'robotstxt-telemetry',
|
||||
array( $this, 'render_settings_page' )
|
||||
);
|
||||
|
||||
add_submenu_page(
|
||||
'robotstxt-telemetry',
|
||||
__( 'Plugins', 'robotstxt-telemetry' ),
|
||||
__( 'Plugins', 'robotstxt-telemetry' ),
|
||||
'manage_options',
|
||||
'robotstxt-telemetry-plugins',
|
||||
array( $this, 'render_plugins_page' )
|
||||
);
|
||||
add_submenu_page(
|
||||
'robotstxt-telemetry',
|
||||
__( 'Plugins', 'robotstxt-telemetry' ),
|
||||
__( 'Plugins', 'robotstxt-telemetry' ),
|
||||
'manage_options',
|
||||
'robotstxt-telemetry-plugins',
|
||||
array( $this, 'render_plugins_page' )
|
||||
);
|
||||
|
||||
add_submenu_page(
|
||||
'robotstxt-telemetry',
|
||||
__( 'Logs', 'robotstxt-telemetry' ),
|
||||
__( 'Logs', 'robotstxt-telemetry' ),
|
||||
'manage_options',
|
||||
'robotstxt-telemetry-logs',
|
||||
array( $this, 'render_logs_page' )
|
||||
);
|
||||
}
|
||||
add_submenu_page(
|
||||
'robotstxt-telemetry',
|
||||
__( 'Logs', 'robotstxt-telemetry' ),
|
||||
__( 'Logs', 'robotstxt-telemetry' ),
|
||||
'manage_options',
|
||||
'robotstxt-telemetry-logs',
|
||||
array( $this, 'render_logs_page' )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the Network Admin menus (Multisite only).
|
||||
|
|
@ -81,6 +84,8 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Admin' ) ) {
|
|||
* The Network Settings screen always exposes the configuration
|
||||
* mode; when the network runs in global mode it also hosts the
|
||||
* shared settings and the central Logs screen.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register_network_menu() {
|
||||
if ( ! is_multisite() ) {
|
||||
|
|
@ -96,25 +101,25 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Admin' ) ) {
|
|||
'dashicons-admin-generic'
|
||||
);
|
||||
|
||||
add_submenu_page(
|
||||
'robotstxt-telemetry',
|
||||
__( 'Settings', 'robotstxt-telemetry' ),
|
||||
__( 'Settings', 'robotstxt-telemetry' ),
|
||||
'manage_network_options',
|
||||
'robotstxt-telemetry',
|
||||
array( $this, 'render_network_settings_page' )
|
||||
);
|
||||
add_submenu_page(
|
||||
'robotstxt-telemetry',
|
||||
__( 'Settings', 'robotstxt-telemetry' ),
|
||||
__( 'Settings', 'robotstxt-telemetry' ),
|
||||
'manage_network_options',
|
||||
'robotstxt-telemetry',
|
||||
array( $this, 'render_network_settings_page' )
|
||||
);
|
||||
|
||||
add_submenu_page(
|
||||
'robotstxt-telemetry',
|
||||
__( 'Plugins', 'robotstxt-telemetry' ),
|
||||
__( 'Plugins', 'robotstxt-telemetry' ),
|
||||
'manage_network_options',
|
||||
'robotstxt-telemetry-plugins',
|
||||
array( $this, 'render_plugins_page' )
|
||||
);
|
||||
add_submenu_page(
|
||||
'robotstxt-telemetry',
|
||||
__( 'Plugins', 'robotstxt-telemetry' ),
|
||||
__( 'Plugins', 'robotstxt-telemetry' ),
|
||||
'manage_network_options',
|
||||
'robotstxt-telemetry-plugins',
|
||||
array( $this, 'render_plugins_page' )
|
||||
);
|
||||
|
||||
if ( Robotstxt_Telemetry_Network::is_global() ) {
|
||||
if ( Robotstxt_Telemetry_Network::is_global() ) {
|
||||
add_submenu_page(
|
||||
'robotstxt-telemetry',
|
||||
__( 'Logs', 'robotstxt-telemetry' ),
|
||||
|
|
@ -127,31 +132,54 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Admin' ) ) {
|
|||
}
|
||||
|
||||
/**
|
||||
* Register the plugin settings.
|
||||
* Save the settings of a single tab (per-site and network screens).
|
||||
*
|
||||
* Only the options of the given tab are read from the POST and
|
||||
* updated, so the other tabs keep their values. WordPress core
|
||||
* options.php cannot be used for this: it updates every registered
|
||||
* option of the group, setting the ones missing from the POST to null.
|
||||
*
|
||||
* @param string $tab Settings tab: 'main', 'plugins', 'logs', or 'general'.
|
||||
* @return void
|
||||
*/
|
||||
public function register_settings() {
|
||||
$settings = array(
|
||||
'robotstxt_telemetry_useragent_url' => array( 'string', 'hash', 'sanitize_useragent_mode' ),
|
||||
'robotstxt_telemetry_wp_version' => array( 'string', 'actual', 'sanitize_version_mode' ),
|
||||
'robotstxt_telemetry_mask_locale' => array( 'boolean', false, 'sanitize_checkbox' ),
|
||||
'robotstxt_telemetry_replace_news_feed' => array( 'boolean', true, 'sanitize_checkbox' ),
|
||||
'robotstxt_telemetry_replace_events_api' => array( 'boolean', true, 'sanitize_checkbox' ),
|
||||
'robotstxt_telemetry_disable_browse_happy' => array( 'boolean', true, 'sanitize_checkbox' ),
|
||||
'robotstxt_telemetry_wp_core_check' => array( 'string', 'safe', 'sanitize_mode' ),
|
||||
'robotstxt_telemetry_wp_themes_check' => array( 'string', 'safe', 'sanitize_mode' ),
|
||||
'robotstxt_telemetry_wp_plugins_check' => array( 'string', 'safe', 'sanitize_mode' ),
|
||||
'robotstxt_telemetry_hidden_plugins' => array( 'array', array(), 'sanitize_hidden_plugins' ),
|
||||
'robotstxt_telemetry_retention_period' => array( 'string', '12hours', 'sanitize_retention' ),
|
||||
'robotstxt_telemetry_delete_on_uninstall' => array( 'boolean', false, 'sanitize_checkbox' ),
|
||||
);
|
||||
private function save_tab_settings( $tab ) {
|
||||
// phpcs:disable WordPress.Security.NonceVerification.Missing -- Callers verified the nonce.
|
||||
if ( 'logs' === $tab ) {
|
||||
$retention = isset( $_POST['robotstxt_telemetry_retention_period'] ) && is_string( $_POST['robotstxt_telemetry_retention_period'] ) ? sanitize_key( wp_unslash( $_POST['robotstxt_telemetry_retention_period'] ) ) : '12hours';
|
||||
Robotstxt_Telemetry_Network::update_setting( 'robotstxt_telemetry_retention_period', $this->sanitize_retention( $retention ) );
|
||||
} elseif ( 'plugins' === $tab ) {
|
||||
$hidden = isset( $_POST['robotstxt_telemetry_hidden_plugins'] ) ? array_map(
|
||||
function ( $value ) {
|
||||
return is_string( $value ) ? sanitize_text_field( $value ) : '';
|
||||
},
|
||||
(array) wp_unslash( $_POST['robotstxt_telemetry_hidden_plugins'] ) // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- Each value is sanitized in the callback above.
|
||||
) : array();
|
||||
Robotstxt_Telemetry_Network::update_setting( 'robotstxt_telemetry_hidden_plugins', $this->sanitize_hidden_plugins( $hidden ) );
|
||||
} elseif ( 'general' === $tab ) {
|
||||
$delete = ! empty( $_POST['robotstxt_telemetry_delete_on_uninstall'] );
|
||||
Robotstxt_Telemetry_Network::update_setting( 'robotstxt_telemetry_delete_on_uninstall', $delete );
|
||||
} else {
|
||||
$useragent_mode = isset( $_POST['robotstxt_telemetry_useragent_url'] ) && is_string( $_POST['robotstxt_telemetry_useragent_url'] ) ? sanitize_key( wp_unslash( $_POST['robotstxt_telemetry_useragent_url'] ) ) : 'hash';
|
||||
$version_mode = isset( $_POST['robotstxt_telemetry_wp_version'] ) && is_string( $_POST['robotstxt_telemetry_wp_version'] ) ? sanitize_key( wp_unslash( $_POST['robotstxt_telemetry_wp_version'] ) ) : 'actual';
|
||||
$mask_locale = ! empty( $_POST['robotstxt_telemetry_mask_locale'] );
|
||||
$replace_news = ! empty( $_POST['robotstxt_telemetry_replace_news_feed'] );
|
||||
$replace_events = ! empty( $_POST['robotstxt_telemetry_replace_events_api'] );
|
||||
$disable_browse_happy = ! empty( $_POST['robotstxt_telemetry_disable_browse_happy'] );
|
||||
$core = isset( $_POST['robotstxt_telemetry_wp_core_check'] ) && is_string( $_POST['robotstxt_telemetry_wp_core_check'] ) ? sanitize_key( wp_unslash( $_POST['robotstxt_telemetry_wp_core_check'] ) ) : 'safe';
|
||||
$themes = isset( $_POST['robotstxt_telemetry_wp_themes_check'] ) && is_string( $_POST['robotstxt_telemetry_wp_themes_check'] ) ? sanitize_key( wp_unslash( $_POST['robotstxt_telemetry_wp_themes_check'] ) ) : 'safe';
|
||||
$plugins = isset( $_POST['robotstxt_telemetry_wp_plugins_check'] ) && is_string( $_POST['robotstxt_telemetry_wp_plugins_check'] ) ? sanitize_key( wp_unslash( $_POST['robotstxt_telemetry_wp_plugins_check'] ) ) : 'safe';
|
||||
|
||||
foreach ( $settings as $name => $config ) {
|
||||
register_setting(
|
||||
'robotstxt_telemetry_settings',
|
||||
$name,
|
||||
array( $this, $config[2] )
|
||||
);
|
||||
Robotstxt_Telemetry_Network::update_setting( 'robotstxt_telemetry_useragent_url', $this->sanitize_useragent_mode( $useragent_mode ) );
|
||||
Robotstxt_Telemetry_Network::update_setting( 'robotstxt_telemetry_wp_version', $this->sanitize_version_mode( $version_mode ) );
|
||||
Robotstxt_Telemetry_Network::update_setting( 'robotstxt_telemetry_mask_locale', $mask_locale );
|
||||
Robotstxt_Telemetry_Network::update_setting( 'robotstxt_telemetry_replace_news_feed', $replace_news );
|
||||
Robotstxt_Telemetry_Network::update_setting( 'robotstxt_telemetry_replace_events_api', $replace_events );
|
||||
Robotstxt_Telemetry_Network::update_setting( 'robotstxt_telemetry_disable_browse_happy', $disable_browse_happy );
|
||||
Robotstxt_Telemetry_Network::update_setting( 'robotstxt_telemetry_wp_core_check', $this->sanitize_mode( $core ) );
|
||||
Robotstxt_Telemetry_Network::update_setting( 'robotstxt_telemetry_wp_themes_check', $this->sanitize_mode( $themes ) );
|
||||
Robotstxt_Telemetry_Network::update_setting( 'robotstxt_telemetry_wp_plugins_check', $this->sanitize_mode( $plugins ) );
|
||||
}
|
||||
// phpcs:enable
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -206,7 +234,11 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Admin' ) ) {
|
|||
$hidden = array();
|
||||
|
||||
foreach ( $value as $basename ) {
|
||||
$basename = sanitize_text_field( (string) $basename );
|
||||
if ( ! is_string( $basename ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$basename = sanitize_text_field( $basename );
|
||||
|
||||
if ( in_array( $basename, $installed, true ) ) {
|
||||
$hidden[] = $basename;
|
||||
|
|
@ -230,23 +262,15 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Admin' ) ) {
|
|||
return in_array( $value, $valid, true ) ? $value : '12hours';
|
||||
}
|
||||
|
||||
/**
|
||||
* Sanitize a checkbox value.
|
||||
*
|
||||
* @param mixed $value Raw input value.
|
||||
* @return bool
|
||||
*/
|
||||
public function sanitize_checkbox( $value ) {
|
||||
return (bool) $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle admin actions.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle_actions() {
|
||||
// phpcs:disable WordPress.Security.NonceVerification.Recommended -- State changes are protected by check_admin_referer() below.
|
||||
$page = isset( $_GET['page'] ) ? sanitize_key( wp_unslash( $_GET['page'] ) ) : '';
|
||||
$action = isset( $_REQUEST['action'] ) ? sanitize_key( wp_unslash( $_REQUEST['action'] ) ) : '';
|
||||
$page = isset( $_GET['page'] ) && is_string( $_GET['page'] ) ? sanitize_key( wp_unslash( $_GET['page'] ) ) : '';
|
||||
$action = isset( $_REQUEST['action'] ) && is_string( $_REQUEST['action'] ) ? sanitize_key( wp_unslash( $_REQUEST['action'] ) ) : '';
|
||||
|
||||
// Network-level actions are always restricted to super administrators.
|
||||
if ( 'save_network_mode' === $action || 'save_network_settings' === $action ) {
|
||||
|
|
@ -270,6 +294,13 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Admin' ) ) {
|
|||
return;
|
||||
}
|
||||
|
||||
if ( 'save_site_settings' === $action ) {
|
||||
if ( 'robotstxt-telemetry' === $page ) {
|
||||
$this->handle_site_settings_save();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if ( 'robotstxt-telemetry-logs' !== $page ) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -295,7 +326,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Admin' ) ) {
|
|||
return;
|
||||
}
|
||||
|
||||
$log_id = isset( $_GET['log'] ) ? absint( wp_unslash( $_GET['log'] ) ) : 0;
|
||||
$log_id = isset( $_GET['log'] ) && is_string( $_GET['log'] ) ? absint( wp_unslash( $_GET['log'] ) ) : 0;
|
||||
// phpcs:enable
|
||||
if ( 0 === $log_id ) {
|
||||
return;
|
||||
|
|
@ -321,13 +352,14 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Admin' ) ) {
|
|||
* Handle Network Admin settings actions.
|
||||
*
|
||||
* @param string $action Action name.
|
||||
* @return void
|
||||
*/
|
||||
private function handle_network_actions( $action ) {
|
||||
if ( 'save_network_mode' === $action ) {
|
||||
check_admin_referer( 'robotstxt_telemetry_network_mode' );
|
||||
|
||||
// phpcs:ignore WordPress.Security.NonceVerification.Missing -- Verified by check_admin_referer() above.
|
||||
$new_mode = isset( $_POST['robotstxt_telemetry_config_mode'] ) ? sanitize_key( wp_unslash( $_POST['robotstxt_telemetry_config_mode'] ) ) : 'per-site';
|
||||
$new_mode = isset( $_POST['robotstxt_telemetry_config_mode'] ) && is_string( $_POST['robotstxt_telemetry_config_mode'] ) ? sanitize_key( wp_unslash( $_POST['robotstxt_telemetry_config_mode'] ) ) : 'per-site';
|
||||
$new_mode = Robotstxt_Telemetry_Network::sanitize_mode( $new_mode );
|
||||
$old_mode = get_site_option( Robotstxt_Telemetry_Network::MODE_OPTION, 'per-site' );
|
||||
|
||||
|
|
@ -343,41 +375,11 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Admin' ) ) {
|
|||
if ( 'save_network_settings' === $action ) {
|
||||
check_admin_referer( 'robotstxt_telemetry_network_settings' );
|
||||
|
||||
// phpcs:disable WordPress.Security.NonceVerification.Missing -- Verified by check_admin_referer() above.
|
||||
$tab = isset( $_POST['tab'] ) ? sanitize_key( wp_unslash( $_POST['tab'] ) ) : 'main';
|
||||
// phpcs:ignore WordPress.Security.NonceVerification.Missing -- Verified by check_admin_referer() above.
|
||||
$tab = isset( $_POST['tab'] ) && is_string( $_POST['tab'] ) ? sanitize_key( wp_unslash( $_POST['tab'] ) ) : 'main';
|
||||
$tab = in_array( $tab, array( 'main', 'plugins', 'logs', 'general' ), true ) ? $tab : 'main';
|
||||
|
||||
if ( 'logs' === $tab ) {
|
||||
$retention = isset( $_POST['robotstxt_telemetry_retention_period'] ) ? sanitize_key( wp_unslash( $_POST['robotstxt_telemetry_retention_period'] ) ) : '12hours';
|
||||
Robotstxt_Telemetry_Network::update_setting( 'robotstxt_telemetry_retention_period', $this->sanitize_retention( $retention ) );
|
||||
} elseif ( 'plugins' === $tab ) {
|
||||
$hidden = isset( $_POST['robotstxt_telemetry_hidden_plugins'] ) ? array_map( 'sanitize_text_field', (array) wp_unslash( $_POST['robotstxt_telemetry_hidden_plugins'] ) ) : array();
|
||||
Robotstxt_Telemetry_Network::update_setting( 'robotstxt_telemetry_hidden_plugins', $this->sanitize_hidden_plugins( $hidden ) );
|
||||
} elseif ( 'general' === $tab ) {
|
||||
$delete = ! empty( $_POST['robotstxt_telemetry_delete_on_uninstall'] );
|
||||
Robotstxt_Telemetry_Network::update_setting( 'robotstxt_telemetry_delete_on_uninstall', $delete );
|
||||
} else {
|
||||
$useragent_mode = isset( $_POST['robotstxt_telemetry_useragent_url'] ) ? sanitize_key( wp_unslash( $_POST['robotstxt_telemetry_useragent_url'] ) ) : 'hash';
|
||||
$version_mode = isset( $_POST['robotstxt_telemetry_wp_version'] ) ? sanitize_key( wp_unslash( $_POST['robotstxt_telemetry_wp_version'] ) ) : 'actual';
|
||||
$mask_locale = ! empty( $_POST['robotstxt_telemetry_mask_locale'] );
|
||||
$replace_news = ! empty( $_POST['robotstxt_telemetry_replace_news_feed'] );
|
||||
$replace_events = ! empty( $_POST['robotstxt_telemetry_replace_events_api'] );
|
||||
$disable_browse_happy = ! empty( $_POST['robotstxt_telemetry_disable_browse_happy'] );
|
||||
$core = isset( $_POST['robotstxt_telemetry_wp_core_check'] ) ? sanitize_key( wp_unslash( $_POST['robotstxt_telemetry_wp_core_check'] ) ) : 'safe';
|
||||
$themes = isset( $_POST['robotstxt_telemetry_wp_themes_check'] ) ? sanitize_key( wp_unslash( $_POST['robotstxt_telemetry_wp_themes_check'] ) ) : 'safe';
|
||||
$plugins = isset( $_POST['robotstxt_telemetry_wp_plugins_check'] ) ? sanitize_key( wp_unslash( $_POST['robotstxt_telemetry_wp_plugins_check'] ) ) : 'safe';
|
||||
|
||||
Robotstxt_Telemetry_Network::update_setting( 'robotstxt_telemetry_useragent_url', $this->sanitize_useragent_mode( $useragent_mode ) );
|
||||
Robotstxt_Telemetry_Network::update_setting( 'robotstxt_telemetry_wp_version', $this->sanitize_version_mode( $version_mode ) );
|
||||
Robotstxt_Telemetry_Network::update_setting( 'robotstxt_telemetry_mask_locale', $mask_locale );
|
||||
Robotstxt_Telemetry_Network::update_setting( 'robotstxt_telemetry_replace_news_feed', $replace_news );
|
||||
Robotstxt_Telemetry_Network::update_setting( 'robotstxt_telemetry_replace_events_api', $replace_events );
|
||||
Robotstxt_Telemetry_Network::update_setting( 'robotstxt_telemetry_disable_browse_happy', $disable_browse_happy );
|
||||
Robotstxt_Telemetry_Network::update_setting( 'robotstxt_telemetry_wp_core_check', $this->sanitize_mode( $core ) );
|
||||
Robotstxt_Telemetry_Network::update_setting( 'robotstxt_telemetry_wp_themes_check', $this->sanitize_mode( $themes ) );
|
||||
Robotstxt_Telemetry_Network::update_setting( 'robotstxt_telemetry_wp_plugins_check', $this->sanitize_mode( $plugins ) );
|
||||
}
|
||||
// phpcs:enable
|
||||
$this->save_tab_settings( $tab );
|
||||
|
||||
$this->redirect_network_settings( 'settings-updated', $tab );
|
||||
}
|
||||
|
|
@ -388,6 +390,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Admin' ) ) {
|
|||
*
|
||||
* @param string $flag Query flag to append.
|
||||
* @param string $tab Settings tab to return to.
|
||||
* @return void
|
||||
*/
|
||||
private function redirect_network_settings( $flag, $tab = 'main' ) {
|
||||
wp_safe_redirect(
|
||||
|
|
@ -405,6 +408,8 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Admin' ) ) {
|
|||
|
||||
/**
|
||||
* Render the settings saved notice.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function render_saved_notice() {
|
||||
if ( ! current_user_can( Robotstxt_Telemetry_Network::manage_capability() ) ) {
|
||||
|
|
@ -412,9 +417,9 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Admin' ) ) {
|
|||
}
|
||||
|
||||
// phpcs:disable WordPress.Security.NonceVerification.Recommended -- Read-only rendering of an admin screen.
|
||||
$settings_updated = isset( $_GET['settings-updated'] ) ? sanitize_key( wp_unslash( $_GET['settings-updated'] ) ) : '';
|
||||
$mode_updated = isset( $_GET['mode-updated'] ) ? sanitize_key( wp_unslash( $_GET['mode-updated'] ) ) : '';
|
||||
$page = isset( $_GET['page'] ) ? sanitize_key( wp_unslash( $_GET['page'] ) ) : '';
|
||||
$settings_updated = isset( $_GET['settings-updated'] ) && is_string( $_GET['settings-updated'] ) ? sanitize_key( wp_unslash( $_GET['settings-updated'] ) ) : '';
|
||||
$mode_updated = isset( $_GET['mode-updated'] ) && is_string( $_GET['mode-updated'] ) ? sanitize_key( wp_unslash( $_GET['mode-updated'] ) ) : '';
|
||||
$page = isset( $_GET['page'] ) && is_string( $_GET['page'] ) ? sanitize_key( wp_unslash( $_GET['page'] ) ) : '';
|
||||
// phpcs:enable
|
||||
|
||||
if ( 'robotstxt-telemetry' !== $page ) {
|
||||
|
|
@ -432,6 +437,8 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Admin' ) ) {
|
|||
|
||||
/**
|
||||
* Render the Network Admin settings page (Multisite only).
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function render_network_settings_page() {
|
||||
if ( ! current_user_can( 'manage_network_options' ) ) {
|
||||
|
|
@ -501,7 +508,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Admin' ) ) {
|
|||
*/
|
||||
private function get_current_tab() {
|
||||
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Read-only navigation state.
|
||||
$tab = isset( $_GET['tab'] ) ? sanitize_key( wp_unslash( $_GET['tab'] ) ) : 'main';
|
||||
$tab = isset( $_GET['tab'] ) && is_string( $_GET['tab'] ) ? sanitize_key( wp_unslash( $_GET['tab'] ) ) : 'main';
|
||||
|
||||
return in_array( $tab, array( 'main', 'plugins', 'logs', 'general' ), true ) ? $tab : 'main';
|
||||
}
|
||||
|
|
@ -510,6 +517,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Admin' ) ) {
|
|||
* Render the settings screen tabs.
|
||||
*
|
||||
* @param string $current_tab Current tab slug.
|
||||
* @return void
|
||||
*/
|
||||
private function render_tabs( $current_tab ) {
|
||||
$tabs = array(
|
||||
|
|
@ -544,6 +552,8 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Admin' ) ) {
|
|||
|
||||
/**
|
||||
* Render settings page.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function render_settings_page() {
|
||||
if ( ! current_user_can( Robotstxt_Telemetry_Network::manage_capability() ) ) {
|
||||
|
|
@ -560,8 +570,11 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Admin' ) ) {
|
|||
|
||||
$this->render_tabs( $tab );
|
||||
|
||||
echo '<form method="post" action="options.php">';
|
||||
settings_fields( 'robotstxt_telemetry_settings' );
|
||||
echo '<form method="post" action="">';
|
||||
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 );
|
||||
|
||||
|
|
@ -578,6 +591,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Admin' ) ) {
|
|||
* given tab are rendered, so each tab saves independently.
|
||||
*
|
||||
* @param string $tab Tab slug: 'main', 'logs', or 'general'.
|
||||
* @return void
|
||||
*/
|
||||
private function render_settings_fields( $tab = 'main' ) {
|
||||
echo '<table class="form-table" role="presentation">';
|
||||
|
|
@ -585,126 +599,126 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Admin' ) ) {
|
|||
|
||||
if ( 'main' === $tab ) {
|
||||
|
||||
$url_mode = Robotstxt_Telemetry_Network::get_useragent_url_mode();
|
||||
$url_mode = Robotstxt_Telemetry_Network::get_useragent_url_mode();
|
||||
|
||||
echo '<tr>';
|
||||
echo '<th scope="row">' . esc_html__( 'Outbound requests', 'robotstxt-telemetry' ) . '</th>';
|
||||
echo '<td>';
|
||||
echo '<fieldset>';
|
||||
echo '<legend class="screen-reader-text">' . esc_html__( 'Outbound requests', 'robotstxt-telemetry' ) . '</legend>';
|
||||
echo '<p style="margin: 0;">';
|
||||
|
||||
$useragent_options = array(
|
||||
'url' => __( 'Send your URL', 'robotstxt-telemetry' ),
|
||||
'hash' => __( 'Send a hash', 'robotstxt-telemetry' ),
|
||||
'none' => __( 'Do not send anything', 'robotstxt-telemetry' ),
|
||||
);
|
||||
|
||||
foreach ( $useragent_options as $value => $label ) {
|
||||
echo '<label style="display: block; margin: 0;"><input type="radio" name="robotstxt_telemetry_useragent_url" value="' . esc_attr( $value ) . '" ' . checked( $url_mode, $value, false ) . '/> ' . esc_html( $label ) . '</label>';
|
||||
}
|
||||
|
||||
echo '</p>';
|
||||
echo '<p class="description">' . esc_html__( 'Outbound requests normally identify this site in the User-Agent with its URL (for example "WordPress/6.9; https://example.com/"). "Send a hash" (default) replaces it with a fixed hash so the site is no longer identifiable; "Do not send anything" removes it completely.', 'robotstxt-telemetry' ) . '</p>';
|
||||
echo '</fieldset>';
|
||||
echo '</td>';
|
||||
echo '</tr>';
|
||||
|
||||
$version_mode = Robotstxt_Telemetry_Network::get_wp_version_mode();
|
||||
|
||||
echo '<tr>';
|
||||
echo '<th scope="row">' . esc_html__( 'WordPress version', 'robotstxt-telemetry' ) . '</th>';
|
||||
echo '<td>';
|
||||
echo '<fieldset>';
|
||||
echo '<legend class="screen-reader-text">' . esc_html__( 'WordPress version', 'robotstxt-telemetry' ) . '</legend>';
|
||||
echo '<p style="margin: 0;">';
|
||||
|
||||
$version_options = array(
|
||||
'actual' => __( 'Actual version', 'robotstxt-telemetry' ),
|
||||
'major' => __( 'Major version', 'robotstxt-telemetry' ),
|
||||
'nulled' => __( 'Nulled version', 'robotstxt-telemetry' ),
|
||||
);
|
||||
|
||||
foreach ( $version_options as $value => $label ) {
|
||||
echo '<label style="display: block; margin: 0;"><input type="radio" name="robotstxt_telemetry_wp_version" value="' . esc_attr( $value ) . '" ' . checked( $version_mode, $value, false ) . '/> ' . esc_html( $label ) . '</label>';
|
||||
}
|
||||
|
||||
echo '</p>';
|
||||
echo '<p class="description">' . esc_html__( 'The version reported in the User-Agent and in the WordPress.org version fields: the actual version (default), the major version with the rest masked (for example "7.2.n"), or a nulled version ("0.0.0"). The checksum and translation requests always use the real version so updates keep working.', 'robotstxt-telemetry' ) . '</p>';
|
||||
echo '</fieldset>';
|
||||
echo '</td>';
|
||||
echo '</tr>';
|
||||
|
||||
echo '<tr>';
|
||||
echo '<th scope="row">' . esc_html__( 'Installation language', 'robotstxt-telemetry' ) . '</th>';
|
||||
echo '<td>';
|
||||
echo '<label for="robotstxt-telemetry-mask-locale">';
|
||||
echo '<input type="checkbox" id="robotstxt-telemetry-mask-locale" name="robotstxt_telemetry_mask_locale" value="1" ' . checked( (bool) Robotstxt_Telemetry_Network::get_setting( 'robotstxt_telemetry_mask_locale', false ), true, false ) . '/>';
|
||||
echo '<span>' . esc_html__( 'Send en_US as the language of outbound requests', 'robotstxt-telemetry' ) . '</span>';
|
||||
echo '</label>';
|
||||
echo '<p class="description">' . esc_html__( 'When enabled, requests to WordPress.org report English (United States) instead of the installation language. The translation endpoints keep using the real language so installed language packs keep receiving updates.', 'robotstxt-telemetry' ) . '</p>';
|
||||
echo '</td>';
|
||||
echo '</tr>';
|
||||
|
||||
$dashboard_services = array(
|
||||
'robotstxt_telemetry_replace_news_feed' => array(
|
||||
'label' => __( 'Replace the WordPress News feed', 'robotstxt-telemetry' ),
|
||||
'title' => __( 'Use WordPress Planet by Fair (planet.fair.pm) instead of wordpress.org/news for the Events and News dashboard widget', 'robotstxt-telemetry' ),
|
||||
),
|
||||
'robotstxt_telemetry_replace_events_api' => array(
|
||||
'label' => __( 'Replace the WordPress Events service', 'robotstxt-telemetry' ),
|
||||
'title' => __( 'Use WordPress Events by The WP World (api.fair.pm) instead of api.wordpress.org/events, sending the same request data', 'robotstxt-telemetry' ),
|
||||
),
|
||||
'robotstxt_telemetry_disable_browse_happy' => array(
|
||||
'label' => __( 'Disable the WordPress browser check', 'robotstxt-telemetry' ),
|
||||
'title' => __( 'Do not send the browser version to api.wordpress.org/core/browse-happy; the browser is always reported as compatible', 'robotstxt-telemetry' ),
|
||||
),
|
||||
);
|
||||
|
||||
foreach ( $dashboard_services as $option_name => $service ) {
|
||||
echo '<tr>';
|
||||
echo '<th scope="row">' . esc_html( $service['label'] ) . '</th>';
|
||||
echo '<td>';
|
||||
echo '<label for="robotstxt-telemetry-' . esc_attr( str_replace( 'robotstxt_telemetry_', '', $option_name ) ) . '">';
|
||||
echo '<input type="checkbox" id="robotstxt-telemetry-' . esc_attr( str_replace( 'robotstxt_telemetry_', '', $option_name ) ) . '" name="' . esc_attr( $option_name ) . '" value="1" ' . checked( (bool) Robotstxt_Telemetry_Network::get_setting( $option_name, true ), true, false ) . '/>';
|
||||
echo '<span>' . esc_html( $service['title'] ) . '</span>';
|
||||
echo '</label>';
|
||||
echo '</td>';
|
||||
echo '</tr>';
|
||||
}
|
||||
|
||||
$wp_checks = array(
|
||||
'robotstxt_telemetry_wp_core_check' => array(
|
||||
'label' => __( 'WordPress Core version check', 'robotstxt-telemetry' ),
|
||||
'desc' => __( 'Safe sends only the WordPress version, PHP version, locale, MySQL version, and update channel. Original also sends site counts, database history, PHP extensions, and platform details.', 'robotstxt-telemetry' ),
|
||||
),
|
||||
'robotstxt_telemetry_wp_themes_check' => array(
|
||||
'label' => __( 'WordPress Themes version check', 'robotstxt-telemetry' ),
|
||||
'desc' => __( 'Safe sends only the theme name, version, update URI, template, and stylesheet, plus the translation revision date and site locale. Original also sends author details and other theme metadata.', 'robotstxt-telemetry' ),
|
||||
),
|
||||
'robotstxt_telemetry_wp_plugins_check' => array(
|
||||
'label' => __( 'WordPress Plugins version check', 'robotstxt-telemetry' ),
|
||||
'desc' => __( 'Safe sends only the plugin version, update URI, and requirements, plus the translation revision date, locale, and the "all" flag. Original also sends names, descriptions, authors, and other plugin metadata.', 'robotstxt-telemetry' ),
|
||||
),
|
||||
);
|
||||
|
||||
foreach ( $wp_checks as $option_name => $check ) {
|
||||
$mode = Robotstxt_Telemetry_Network::get_setting( $option_name, 'safe' );
|
||||
echo '<tr>';
|
||||
echo '<th scope="row">' . esc_html( $check['label'] ) . '</th>';
|
||||
echo '<th scope="row">' . esc_html__( 'Outbound requests', 'robotstxt-telemetry' ) . '</th>';
|
||||
echo '<td>';
|
||||
echo '<fieldset>';
|
||||
echo '<legend class="screen-reader-text">' . esc_html( $check['label'] ) . '</legend>';
|
||||
echo '<legend class="screen-reader-text">' . esc_html__( 'Outbound requests', 'robotstxt-telemetry' ) . '</legend>';
|
||||
echo '<p style="margin: 0;">';
|
||||
echo '<label><input type="radio" name="' . esc_attr( $option_name ) . '" value="original" ' . checked( $mode, 'original', false ) . '/> ' . esc_html__( 'Original', 'robotstxt-telemetry' ) . '</label>';
|
||||
echo ' ';
|
||||
echo '<label><input type="radio" name="' . esc_attr( $option_name ) . '" value="safe" ' . checked( $mode, 'safe', false ) . '/> ' . esc_html__( 'Safe', 'robotstxt-telemetry' ) . '</label>';
|
||||
|
||||
$useragent_options = array(
|
||||
'url' => __( 'Send your URL', 'robotstxt-telemetry' ),
|
||||
'hash' => __( 'Send a hash', 'robotstxt-telemetry' ),
|
||||
'none' => __( 'Do not send anything', 'robotstxt-telemetry' ),
|
||||
);
|
||||
|
||||
foreach ( $useragent_options as $value => $label ) {
|
||||
echo '<label style="display: block; margin: 0;"><input type="radio" name="robotstxt_telemetry_useragent_url" value="' . esc_attr( $value ) . '" ' . checked( $url_mode, $value, false ) . '/> ' . esc_html( $label ) . '</label>';
|
||||
}
|
||||
|
||||
echo '</p>';
|
||||
echo '<p class="description">' . esc_html( $check['desc'] ) . '</p>';
|
||||
echo '<p class="description">' . esc_html__( 'Outbound requests normally identify this site in the User-Agent with its URL (for example "WordPress/6.9; https://example.com/"). "Send a hash" (default) replaces it with a fixed hash so the site is no longer identifiable; "Do not send anything" removes it completely.', 'robotstxt-telemetry' ) . '</p>';
|
||||
echo '</fieldset>';
|
||||
echo '</td>';
|
||||
echo '</tr>';
|
||||
}
|
||||
|
||||
$version_mode = Robotstxt_Telemetry_Network::get_wp_version_mode();
|
||||
|
||||
echo '<tr>';
|
||||
echo '<th scope="row">' . esc_html__( 'WordPress version', 'robotstxt-telemetry' ) . '</th>';
|
||||
echo '<td>';
|
||||
echo '<fieldset>';
|
||||
echo '<legend class="screen-reader-text">' . esc_html__( 'WordPress version', 'robotstxt-telemetry' ) . '</legend>';
|
||||
echo '<p style="margin: 0;">';
|
||||
|
||||
$version_options = array(
|
||||
'actual' => __( 'Actual version', 'robotstxt-telemetry' ),
|
||||
'major' => __( 'Major version', 'robotstxt-telemetry' ),
|
||||
'nulled' => __( 'Nulled version', 'robotstxt-telemetry' ),
|
||||
);
|
||||
|
||||
foreach ( $version_options as $value => $label ) {
|
||||
echo '<label style="display: block; margin: 0;"><input type="radio" name="robotstxt_telemetry_wp_version" value="' . esc_attr( $value ) . '" ' . checked( $version_mode, $value, false ) . '/> ' . esc_html( $label ) . '</label>';
|
||||
}
|
||||
|
||||
echo '</p>';
|
||||
echo '<p class="description">' . esc_html__( 'The version reported in the User-Agent and in the WordPress.org version fields: the actual version (default), the major version with the rest masked (for example "7.2.n"), or a nulled version ("0.0.0"). The checksum and translation requests always use the real version so updates keep working.', 'robotstxt-telemetry' ) . '</p>';
|
||||
echo '</fieldset>';
|
||||
echo '</td>';
|
||||
echo '</tr>';
|
||||
|
||||
echo '<tr>';
|
||||
echo '<th scope="row">' . esc_html__( 'Installation language', 'robotstxt-telemetry' ) . '</th>';
|
||||
echo '<td>';
|
||||
echo '<label for="robotstxt-telemetry-mask-locale">';
|
||||
echo '<input type="checkbox" id="robotstxt-telemetry-mask-locale" name="robotstxt_telemetry_mask_locale" value="1" ' . checked( (bool) Robotstxt_Telemetry_Network::get_setting( 'robotstxt_telemetry_mask_locale', false ), true, false ) . '/>';
|
||||
echo '<span>' . esc_html__( 'Send en_US as the language of outbound requests', 'robotstxt-telemetry' ) . '</span>';
|
||||
echo '</label>';
|
||||
echo '<p class="description">' . esc_html__( 'When enabled, requests to WordPress.org report English (United States) instead of the installation language. The translation endpoints keep using the real language so installed language packs keep receiving updates.', 'robotstxt-telemetry' ) . '</p>';
|
||||
echo '</td>';
|
||||
echo '</tr>';
|
||||
|
||||
$dashboard_services = array(
|
||||
'robotstxt_telemetry_replace_news_feed' => array(
|
||||
'label' => __( 'Replace the WordPress News feed', 'robotstxt-telemetry' ),
|
||||
'title' => __( 'Use WordPress Planet by Fair (planet.fair.pm) instead of wordpress.org/news for the Events and News dashboard widget', 'robotstxt-telemetry' ),
|
||||
),
|
||||
'robotstxt_telemetry_replace_events_api' => array(
|
||||
'label' => __( 'Replace the WordPress Events service', 'robotstxt-telemetry' ),
|
||||
'title' => __( 'Use WordPress Events by The WP World (api.fair.pm) instead of api.wordpress.org/events, sending the same request data', 'robotstxt-telemetry' ),
|
||||
),
|
||||
'robotstxt_telemetry_disable_browse_happy' => array(
|
||||
'label' => __( 'Disable the WordPress browser check', 'robotstxt-telemetry' ),
|
||||
'title' => __( 'Do not send the browser version to api.wordpress.org/core/browse-happy; the browser is always reported as compatible', 'robotstxt-telemetry' ),
|
||||
),
|
||||
);
|
||||
|
||||
foreach ( $dashboard_services as $option_name => $service ) {
|
||||
echo '<tr>';
|
||||
echo '<th scope="row">' . esc_html( $service['label'] ) . '</th>';
|
||||
echo '<td>';
|
||||
echo '<label for="robotstxt-telemetry-' . esc_attr( str_replace( 'robotstxt_telemetry_', '', $option_name ) ) . '">';
|
||||
echo '<input type="checkbox" id="robotstxt-telemetry-' . esc_attr( str_replace( 'robotstxt_telemetry_', '', $option_name ) ) . '" name="' . esc_attr( $option_name ) . '" value="1" ' . checked( (bool) Robotstxt_Telemetry_Network::get_setting( $option_name, true ), true, false ) . '/>';
|
||||
echo '<span>' . esc_html( $service['title'] ) . '</span>';
|
||||
echo '</label>';
|
||||
echo '</td>';
|
||||
echo '</tr>';
|
||||
}
|
||||
|
||||
$wp_checks = array(
|
||||
'robotstxt_telemetry_wp_core_check' => array(
|
||||
'label' => __( 'WordPress Core version check', 'robotstxt-telemetry' ),
|
||||
'desc' => __( 'Safe sends only the WordPress version, PHP version, locale, MySQL version, and update channel. Original also sends site counts, database history, PHP extensions, and platform details.', 'robotstxt-telemetry' ),
|
||||
),
|
||||
'robotstxt_telemetry_wp_themes_check' => array(
|
||||
'label' => __( 'WordPress Themes version check', 'robotstxt-telemetry' ),
|
||||
'desc' => __( 'Safe sends only the theme name, version, update URI, template, and stylesheet, plus the translation revision date and site locale. Original also sends author details and other theme metadata.', 'robotstxt-telemetry' ),
|
||||
),
|
||||
'robotstxt_telemetry_wp_plugins_check' => array(
|
||||
'label' => __( 'WordPress Plugins version check', 'robotstxt-telemetry' ),
|
||||
'desc' => __( 'Safe sends only the plugin version, update URI, and requirements, plus the translation revision date, locale, and the "all" flag. Original also sends names, descriptions, authors, and other plugin metadata.', 'robotstxt-telemetry' ),
|
||||
),
|
||||
);
|
||||
|
||||
foreach ( $wp_checks as $option_name => $check ) {
|
||||
$mode = Robotstxt_Telemetry_Network::get_setting( $option_name, 'safe' );
|
||||
echo '<tr>';
|
||||
echo '<th scope="row">' . esc_html( $check['label'] ) . '</th>';
|
||||
echo '<td>';
|
||||
echo '<fieldset>';
|
||||
echo '<legend class="screen-reader-text">' . esc_html( $check['label'] ) . '</legend>';
|
||||
echo '<p style="margin: 0;">';
|
||||
echo '<label><input type="radio" name="' . esc_attr( $option_name ) . '" value="original" ' . checked( $mode, 'original', false ) . '/> ' . esc_html__( 'Original', 'robotstxt-telemetry' ) . '</label>';
|
||||
echo ' ';
|
||||
echo '<label><input type="radio" name="' . esc_attr( $option_name ) . '" value="safe" ' . checked( $mode, 'safe', false ) . '/> ' . esc_html__( 'Safe', 'robotstxt-telemetry' ) . '</label>';
|
||||
echo '</p>';
|
||||
echo '<p class="description">' . esc_html( $check['desc'] ) . '</p>';
|
||||
echo '</fieldset>';
|
||||
echo '</td>';
|
||||
echo '</tr>';
|
||||
}
|
||||
} // End of the 'main' tab.
|
||||
|
||||
if ( 'plugins' === $tab ) {
|
||||
|
|
@ -714,44 +728,44 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Admin' ) ) {
|
|||
$retention = Robotstxt_Telemetry_Network::get_setting( 'robotstxt_telemetry_retention_period', '12hours' );
|
||||
|
||||
if ( 'logs' === $tab ) {
|
||||
echo '<tr>';
|
||||
echo '<th scope="row">' . esc_html__( 'Log retention', 'robotstxt-telemetry' ) . '</th>';
|
||||
echo '<td>';
|
||||
echo '<label class="screen-reader-text" for="robotstxt-telemetry-retention">' . esc_html__( 'Log retention', 'robotstxt-telemetry' ) . '</label>';
|
||||
echo '<select id="robotstxt-telemetry-retention" name="robotstxt_telemetry_retention_period">';
|
||||
echo '<tr>';
|
||||
echo '<th scope="row">' . esc_html__( 'Log retention', 'robotstxt-telemetry' ) . '</th>';
|
||||
echo '<td>';
|
||||
echo '<label class="screen-reader-text" for="robotstxt-telemetry-retention">' . esc_html__( 'Log retention', 'robotstxt-telemetry' ) . '</label>';
|
||||
echo '<select id="robotstxt-telemetry-retention" name="robotstxt_telemetry_retention_period">';
|
||||
|
||||
$retention_options = array(
|
||||
'12hours' => __( '12 hours', 'robotstxt-telemetry' ),
|
||||
'1day' => __( '1 day', 'robotstxt-telemetry' ),
|
||||
'3days' => __( '3 days', 'robotstxt-telemetry' ),
|
||||
);
|
||||
|
||||
foreach ( $retention_options as $value => $label ) {
|
||||
printf(
|
||||
'<option value="%s" %s>%s</option>',
|
||||
esc_attr( $value ),
|
||||
selected( $retention, $value, false ),
|
||||
esc_html( $label )
|
||||
$retention_options = array(
|
||||
'12hours' => __( '12 hours', 'robotstxt-telemetry' ),
|
||||
'1day' => __( '1 day', 'robotstxt-telemetry' ),
|
||||
'3days' => __( '3 days', 'robotstxt-telemetry' ),
|
||||
);
|
||||
}
|
||||
|
||||
echo '</select>';
|
||||
echo '<p class="description">' . esc_html__( 'Logs older than the selected period are deleted (12 hours by default). A maximum of 1000 entries is always kept; the cleanup runs when browsing the logs and twice a day automatically.', 'robotstxt-telemetry' ) . '</p>';
|
||||
echo '</td>';
|
||||
echo '</tr>';
|
||||
foreach ( $retention_options as $value => $label ) {
|
||||
printf(
|
||||
'<option value="%s" %s>%s</option>',
|
||||
esc_attr( $value ),
|
||||
selected( $retention, $value, false ),
|
||||
esc_html( $label )
|
||||
);
|
||||
}
|
||||
|
||||
echo '</select>';
|
||||
echo '<p class="description">' . esc_html__( 'Logs older than the selected period are deleted (12 hours by default). A maximum of 1000 entries is always kept; the cleanup runs when browsing the logs and twice a day automatically.', 'robotstxt-telemetry' ) . '</p>';
|
||||
echo '</td>';
|
||||
echo '</tr>';
|
||||
} // End of the 'logs' tab.
|
||||
|
||||
if ( 'general' === $tab ) {
|
||||
echo '<tr>';
|
||||
echo '<th scope="row">' . esc_html__( 'Uninstall behavior', 'robotstxt-telemetry' ) . '</th>';
|
||||
echo '<td>';
|
||||
echo '<label for="robotstxt-telemetry-delete-on-uninstall">';
|
||||
echo '<input type="checkbox" id="robotstxt-telemetry-delete-on-uninstall" name="robotstxt_telemetry_delete_on_uninstall" value="1" ' . checked( (bool) Robotstxt_Telemetry_Network::get_setting( 'robotstxt_telemetry_delete_on_uninstall', false ), true, false ) . '/>';
|
||||
echo '<span>' . esc_html__( 'Delete all telemetry logs and plugin options on uninstall', 'robotstxt-telemetry' ) . '</span>';
|
||||
echo '</label>';
|
||||
echo '<p class="description">' . esc_html__( 'By default, all telemetry logs are preserved when the plugin is uninstalled.', 'robotstxt-telemetry' ) . '</p>';
|
||||
echo '</td>';
|
||||
echo '</tr>';
|
||||
echo '<tr>';
|
||||
echo '<th scope="row">' . esc_html__( 'Uninstall behavior', 'robotstxt-telemetry' ) . '</th>';
|
||||
echo '<td>';
|
||||
echo '<label for="robotstxt-telemetry-delete-on-uninstall">';
|
||||
echo '<input type="checkbox" id="robotstxt-telemetry-delete-on-uninstall" name="robotstxt_telemetry_delete_on_uninstall" value="1" ' . checked( (bool) Robotstxt_Telemetry_Network::get_setting( 'robotstxt_telemetry_delete_on_uninstall', false ), true, false ) . '/>';
|
||||
echo '<span>' . esc_html__( 'Delete all telemetry logs and plugin options on uninstall', 'robotstxt-telemetry' ) . '</span>';
|
||||
echo '</label>';
|
||||
echo '<p class="description">' . esc_html__( 'By default, all telemetry logs are preserved when the plugin is uninstalled.', 'robotstxt-telemetry' ) . '</p>';
|
||||
echo '</td>';
|
||||
echo '</tr>';
|
||||
} // End of the 'general' tab.
|
||||
|
||||
echo '</tbody>';
|
||||
|
|
@ -760,6 +774,8 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Admin' ) ) {
|
|||
|
||||
/**
|
||||
* Render the Plugins page.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function render_plugins_page() {
|
||||
$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
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function handle_plugin_modes_save() {
|
||||
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
|
||||
* (disabled and checked for this plugin), its status, its name,
|
||||
* and its version.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function render_plugins_tab() {
|
||||
if ( ! function_exists( 'get_plugins' ) ) {
|
||||
|
|
@ -956,6 +1003,8 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Admin' ) ) {
|
|||
|
||||
/**
|
||||
* Render logs page.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function render_logs_page() {
|
||||
$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';
|
||||
|
||||
// phpcs:disable WordPress.Security.NonceVerification.Recommended -- Read-only rendering of an admin screen.
|
||||
$view_action = isset( $_GET['action'] ) ? sanitize_key( wp_unslash( $_GET['action'] ) ) : '';
|
||||
$log_id = isset( $_GET['log'] ) ? absint( wp_unslash( $_GET['log'] ) ) : 0;
|
||||
$view_action = isset( $_GET['action'] ) && is_string( $_GET['action'] ) ? sanitize_key( wp_unslash( $_GET['action'] ) ) : '';
|
||||
$log_id = isset( $_GET['log'] ) && is_string( $_GET['log'] ) ? absint( wp_unslash( $_GET['log'] ) ) : 0;
|
||||
|
||||
echo '<div class="wrap">';
|
||||
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.
|
||||
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
|
||||
if ( 'all' === $deleted_notice ) {
|
||||
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.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function render_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.
|
||||
*
|
||||
* @param int $log_id Log ID.
|
||||
* @return void
|
||||
*/
|
||||
private function render_single_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( __( 'Path', 'robotstxt-telemetry' ), $log['path'] );
|
||||
$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( __( 'Raw Body', 'robotstxt-telemetry' ), $log['raw_body'] );
|
||||
$this->render_log_row( __( 'Caller', 'robotstxt-telemetry' ), $log['caller'] );
|
||||
|
|
@ -1075,7 +1127,8 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Admin' ) ) {
|
|||
/**
|
||||
* Render telemetry analysis section.
|
||||
*
|
||||
* @param array $log Log data.
|
||||
* @param array<string,mixed> $log Log data.
|
||||
* @return void
|
||||
*/
|
||||
private function render_telemetry_analysis( $log ) {
|
||||
$sections = Robotstxt_Telemetry_Analysis::build_sections( $log );
|
||||
|
|
@ -1100,12 +1153,13 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Admin' ) ) {
|
|||
* Render a table row.
|
||||
*
|
||||
* @param string $label Label.
|
||||
* @param string $value Value.
|
||||
* @param mixed $value Value.
|
||||
* @return void
|
||||
*/
|
||||
private function render_log_row( $label, $value ) {
|
||||
echo '<tr>';
|
||||
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>';
|
||||
}
|
||||
|
||||
|
|
@ -1131,8 +1185,8 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Admin' ) ) {
|
|||
/**
|
||||
* Format query/body params as line-per-parameter output.
|
||||
*
|
||||
* @param array $log Log data.
|
||||
* @param string $type Param source.
|
||||
* @param array<string,mixed> $log Log data.
|
||||
* @param string $type Param source.
|
||||
* @return string
|
||||
*/
|
||||
private function format_params_field( $log, $type ) {
|
||||
|
|
|
|||
|
|
@ -18,8 +18,8 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Analysis_Api_WordPress_Org' ) ) {
|
|||
/**
|
||||
* Build analysis sections for api.wordpress.org.
|
||||
*
|
||||
* @param array $log Log data.
|
||||
* @return array
|
||||
* @param array<string,mixed> $log Log data.
|
||||
* @return array<string,string>
|
||||
*/
|
||||
public static function build_sections( $log ) {
|
||||
$sections = array();
|
||||
|
|
@ -40,8 +40,8 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Analysis_Api_WordPress_Org' ) ) {
|
|||
/**
|
||||
* Group query parameters.
|
||||
*
|
||||
* @param array $params Query parameters.
|
||||
* @return array
|
||||
* @param array<int|string,mixed> $params Query parameters.
|
||||
* @return array<string,string>
|
||||
*/
|
||||
private static function group_query_params( $params ) {
|
||||
$sections = array();
|
||||
|
|
@ -96,8 +96,8 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Analysis_Api_WordPress_Org' ) ) {
|
|||
/**
|
||||
* Group body parameters.
|
||||
*
|
||||
* @param array $params Body parameters.
|
||||
* @return array
|
||||
* @param array<int|string,mixed> $params Body parameters.
|
||||
* @return array<string,string>
|
||||
*/
|
||||
private static function group_body_params( $params ) {
|
||||
$sections = array();
|
||||
|
|
@ -114,8 +114,8 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Analysis_Api_WordPress_Org' ) ) {
|
|||
}
|
||||
|
||||
if ( is_array( $translations ) ) {
|
||||
$sections[ __( 'Translations', 'robotstxt-telemetry' ) ] = Robotstxt_Telemetry_Analysis::format_params_lines( $translations );
|
||||
} else {
|
||||
$sections[ __( 'Translations', 'robotstxt-telemetry' ) ] = Robotstxt_Telemetry_Analysis::format_params_lines( Robotstxt_Telemetry_Analysis::normalize_params( $translations ) );
|
||||
} elseif ( is_scalar( $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.
|
||||
*
|
||||
* @param array $params Parameters (will be mutated).
|
||||
* @param string $prefix Prefix name.
|
||||
* @return array
|
||||
* @param array<int|string,mixed> $params Parameters (will be mutated).
|
||||
* @param string $prefix Prefix name.
|
||||
* @return array<string,mixed>
|
||||
*/
|
||||
private static function pluck_bracketed( &$params, $prefix ) {
|
||||
$result = array();
|
||||
|
||||
foreach ( $params as $key => $value ) {
|
||||
$key = (string) $key;
|
||||
|
||||
if ( 0 !== strpos( $key, $prefix . '[' ) ) {
|
||||
continue;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,11 +18,11 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Analysis' ) ) {
|
|||
/**
|
||||
* Build analysis sections for a log entry.
|
||||
*
|
||||
* @param array $log Log data.
|
||||
* @return array
|
||||
* @param array<string,mixed> $log Log data.
|
||||
* @return array<string,string>
|
||||
*/
|
||||
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 ) {
|
||||
return Robotstxt_Telemetry_Analysis_Api_WordPress_Org::build_sections( $log );
|
||||
|
|
@ -34,8 +34,8 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Analysis' ) ) {
|
|||
/**
|
||||
* Build generic analysis sections.
|
||||
*
|
||||
* @param array $log Log data.
|
||||
* @return array
|
||||
* @param array<string,mixed> $log Log data.
|
||||
* @return array<string,string>
|
||||
*/
|
||||
private static function build_generic_sections( $log ) {
|
||||
$sections = array();
|
||||
|
|
@ -58,22 +58,25 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Analysis' ) ) {
|
|||
*
|
||||
* Prefers the redacted query_json column over re-parsing the raw URL.
|
||||
*
|
||||
* @param array $log Log data.
|
||||
* @return array
|
||||
* @param array<string,mixed> $log Log data.
|
||||
* @return array<int|string,mixed>
|
||||
*/
|
||||
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();
|
||||
}
|
||||
|
||||
if ( ! empty( $log['query_json'] ) ) {
|
||||
$decoded = json_decode( $log['query_json'], true );
|
||||
if ( '' !== $query_json ) {
|
||||
$decoded = json_decode( $query_json, true );
|
||||
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] : '';
|
||||
|
||||
if ( '' === $query ) {
|
||||
|
|
@ -86,14 +89,17 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Analysis' ) ) {
|
|||
/**
|
||||
* Extract parameters from the body.
|
||||
*
|
||||
* @param array $log Log data.
|
||||
* @return array
|
||||
* @param array<string,mixed> $log Log data.
|
||||
* @return array<int|string,mixed>
|
||||
*/
|
||||
public static function extract_body_params( $log ) {
|
||||
if ( ! empty( $log['body_json'] ) ) {
|
||||
$decoded = json_decode( $log['body_json'], true );
|
||||
$body_json = isset( $log['body_json'] ) && is_string( $log['body_json'] ) ? $log['body_json'] : '';
|
||||
$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 ) ) {
|
||||
return $decoded;
|
||||
return self::normalize_params( $decoded );
|
||||
}
|
||||
|
||||
if ( is_string( $decoded ) ) {
|
||||
|
|
@ -101,18 +107,34 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Analysis' ) ) {
|
|||
}
|
||||
}
|
||||
|
||||
if ( ! empty( $log['raw_body'] ) ) {
|
||||
return self::parse_query_string_flat( $log['raw_body'] );
|
||||
if ( '' !== $raw_body ) {
|
||||
return self::parse_query_string_flat( $raw_body );
|
||||
}
|
||||
|
||||
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.
|
||||
*
|
||||
* @param string $query Query string.
|
||||
* @return array
|
||||
* @return array<string,string|array<int,string>>
|
||||
*/
|
||||
public static function parse_query_string_flat( $query ) {
|
||||
$params = array();
|
||||
|
|
@ -149,7 +171,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Analysis' ) ) {
|
|||
/**
|
||||
* Format parameters as line-per-entry output.
|
||||
*
|
||||
* @param array $params Parameters.
|
||||
* @param array<int|string,mixed> $params Parameters.
|
||||
* @return string
|
||||
*/
|
||||
public static function format_params_lines( $params ) {
|
||||
|
|
@ -161,7 +183,15 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Analysis' ) ) {
|
|||
$value = wp_json_encode( $value );
|
||||
}
|
||||
|
||||
$lines[] = sprintf( '%s=%s', $key, $value );
|
||||
if ( null === $value ) {
|
||||
$value = '';
|
||||
} elseif ( is_scalar( $value ) ) {
|
||||
$value = (string) $value;
|
||||
}
|
||||
|
||||
if ( is_string( $value ) ) {
|
||||
$lines[] = sprintf( '%s=%s', $key, $value );
|
||||
}
|
||||
}
|
||||
|
||||
return implode( "\n", $lines );
|
||||
|
|
@ -170,9 +200,9 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Analysis' ) ) {
|
|||
/**
|
||||
* Flatten nested parameters into bracketed keys.
|
||||
*
|
||||
* @param array $params Parameters to flatten.
|
||||
* @param string|null $prefix Current prefix.
|
||||
* @return array
|
||||
* @param array<int|string,mixed> $params Parameters to flatten.
|
||||
* @param string|null $prefix Current prefix.
|
||||
* @return array<string,mixed>
|
||||
*/
|
||||
public static function flatten_params( $params, $prefix = null ) {
|
||||
$flat = array();
|
||||
|
|
|
|||
|
|
@ -48,6 +48,8 @@ if ( ! class_exists( 'Robotstxt_Telemetry_DB' ) ) {
|
|||
|
||||
/**
|
||||
* Activation hook.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function activate() {
|
||||
self::create_table();
|
||||
|
|
@ -56,6 +58,8 @@ if ( ! class_exists( 'Robotstxt_Telemetry_DB' ) ) {
|
|||
|
||||
/**
|
||||
* Ensure the database schema is up to date.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function maybe_upgrade() {
|
||||
if ( self::$did_check ) {
|
||||
|
|
@ -78,6 +82,8 @@ if ( ! class_exists( 'Robotstxt_Telemetry_DB' ) ) {
|
|||
|
||||
/**
|
||||
* Create or update the logs table.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function create_table() {
|
||||
global $wpdb;
|
||||
|
|
@ -115,7 +121,8 @@ if ( ! class_exists( 'Robotstxt_Telemetry_DB' ) ) {
|
|||
/**
|
||||
* 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 ) {
|
||||
global $wpdb;
|
||||
|
|
@ -144,7 +151,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_DB' ) ) {
|
|||
* Fetch a single log row.
|
||||
*
|
||||
* @param int $log_id Log ID.
|
||||
* @return array|null
|
||||
* @return array<string,mixed>|null
|
||||
*/
|
||||
public static function get_log( $log_id ) {
|
||||
global $wpdb;
|
||||
|
|
@ -221,7 +228,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_DB' ) ) {
|
|||
'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 ] );
|
||||
|
||||
$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.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register() {
|
||||
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.
|
||||
*
|
||||
* @param false|array|WP_Error $preempt Short-circuit value from other filters.
|
||||
* @param array $args HTTP request arguments.
|
||||
* @param string $url Request URL.
|
||||
* @return false|array|WP_Error
|
||||
* @param false|array<string,mixed>|WP_Error $preempt Short-circuit value from other filters.
|
||||
* @param array{body?:string|array<mixed,mixed>,headers?:string|array<mixed,mixed>} $args HTTP request arguments.
|
||||
* @param string $url Request URL.
|
||||
* @return false|array<string,mixed>|WP_Error
|
||||
*/
|
||||
public function intercept( $preempt, $args, $url ) {
|
||||
if ( false !== $preempt ) {
|
||||
|
|
@ -112,20 +114,20 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Endpoints' ) ) {
|
|||
* Build a successful Browse Happy response marking the browser
|
||||
* as up to date and secure, so no browser nag is shown.
|
||||
*
|
||||
* @return array
|
||||
* @return array<string,mixed>
|
||||
*/
|
||||
private function mock_browse_happy_response() {
|
||||
$body = wp_json_encode(
|
||||
array(
|
||||
'platform' => 'other',
|
||||
'name' => 'Browser',
|
||||
'version' => '1.0',
|
||||
'platform' => 'other',
|
||||
'name' => 'Browser',
|
||||
'version' => '1.0',
|
||||
'current_version' => '1.0',
|
||||
'upgrade' => false,
|
||||
'insecure' => false,
|
||||
'update_url' => '',
|
||||
'img_src' => '',
|
||||
'img_src_ssl' => '',
|
||||
'upgrade' => false,
|
||||
'insecure' => false,
|
||||
'update_url' => '',
|
||||
'img_src' => '',
|
||||
'img_src_ssl' => '',
|
||||
)
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -38,6 +38,8 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Logger' ) ) {
|
|||
|
||||
/**
|
||||
* Register hooks.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register() {
|
||||
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.
|
||||
*
|
||||
* @param array $args HTTP request arguments.
|
||||
* @param string $url Request URL.
|
||||
* @return array
|
||||
* @param array<string,mixed> $args HTTP request arguments.
|
||||
* @param string $url Request URL.
|
||||
* @return array<string,mixed>
|
||||
*/
|
||||
public function capture_request( $args, $url ) {
|
||||
if ( empty( $url ) || ! is_array( $args ) ) {
|
||||
if ( empty( $url ) ) {
|
||||
return $args;
|
||||
}
|
||||
|
||||
|
|
@ -72,21 +74,25 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Logger' ) ) {
|
|||
/**
|
||||
* Prepare log data for storage.
|
||||
*
|
||||
* @param array $args Request args.
|
||||
* @param string $url Request URL.
|
||||
* @return array
|
||||
* @param array<string,mixed> $args Request args.
|
||||
* @param string $url Request URL.
|
||||
* @return array<string,mixed>
|
||||
*/
|
||||
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 );
|
||||
|
||||
$parsed_url = wp_parse_url( $url );
|
||||
$host = isset( $parsed_url['host'] ) ? sanitize_text_field( $parsed_url['host'] ) : '';
|
||||
$path = isset( $parsed_url['path'] ) ? sanitize_text_field( $parsed_url['path'] ) : '';
|
||||
if ( ! is_array( $parsed_url ) ) {
|
||||
$parsed_url = array();
|
||||
}
|
||||
|
||||
$host = isset( $parsed_url['host'] ) ? sanitize_text_field( $parsed_url['host'] ) : '';
|
||||
$path = isset( $parsed_url['path'] ) ? sanitize_text_field( $parsed_url['path'] ) : '';
|
||||
|
||||
$query_params = array();
|
||||
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 );
|
||||
|
|
@ -110,7 +116,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Logger' ) ) {
|
|||
if ( isset( $args['body'] ) ) {
|
||||
$body_data = $args['body'];
|
||||
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 );
|
||||
|
||||
if ( empty( $body_json ) ) {
|
||||
|
|
@ -147,11 +153,8 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Logger' ) ) {
|
|||
|
||||
// phpcs:ignore WordPress.PHP.DevelopmentFunctions -- Needed for caller context logging.
|
||||
$caller = wp_debug_backtrace_summary( null, 0, false );
|
||||
if ( is_array( $caller ) || is_object( $caller ) ) {
|
||||
$caller = wp_json_encode( $caller );
|
||||
}
|
||||
|
||||
$caller = $this->truncate_string( (string) $caller, $this->max_caller_bytes );
|
||||
$caller = wp_json_encode( $caller );
|
||||
$caller = $this->truncate_string( is_string( $caller ) ? $caller : '', $this->max_caller_bytes );
|
||||
|
||||
return array(
|
||||
'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.
|
||||
*
|
||||
* @param array $parts URL parts from wp_parse_url().
|
||||
* @param string $query Redacted query string.
|
||||
* @param array<string,mixed> $parts URL parts from wp_parse_url().
|
||||
* @param string $query Redacted query string.
|
||||
* @return string
|
||||
*/
|
||||
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'] ) ) {
|
||||
$url = $parts['scheme'] . '://' . $parts['host'];
|
||||
} else {
|
||||
if ( '' === $scheme || '' === $host ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
if ( ! empty( $parts['port'] ) ) {
|
||||
$url .= ':' . (int) $parts['port'];
|
||||
$url = $scheme . '://' . $host;
|
||||
|
||||
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 ) {
|
||||
$url .= '?' . $query;
|
||||
}
|
||||
|
||||
if ( ! empty( $parts['fragment'] ) ) {
|
||||
if ( isset( $parts['fragment'] ) && is_string( $parts['fragment'] ) ) {
|
||||
$url .= '#' . $parts['fragment'];
|
||||
}
|
||||
|
||||
|
|
@ -206,7 +210,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Logger' ) ) {
|
|||
* Normalize request headers into a simple array.
|
||||
*
|
||||
* @param mixed $headers Headers value.
|
||||
* @return array
|
||||
* @return array<string,mixed>
|
||||
*/
|
||||
private function normalize_headers( $headers ) {
|
||||
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.
|
||||
*
|
||||
* @param array $args Request args.
|
||||
* @param array<string,mixed> $args Request args.
|
||||
* @return string|null
|
||||
*/
|
||||
private function extract_user_agent( $args ) {
|
||||
$user_agent = '';
|
||||
|
||||
if ( isset( $args['user-agent'] ) ) {
|
||||
$user_agent = (string) $args['user-agent'];
|
||||
} elseif ( isset( $args['user_agent'] ) ) {
|
||||
$user_agent = (string) $args['user_agent'];
|
||||
} elseif ( isset( $args['headers']['user-agent'] ) ) {
|
||||
$user_agent = (string) $args['headers']['user-agent'];
|
||||
} elseif ( isset( $args['headers']['User-Agent'] ) ) {
|
||||
$user_agent = (string) $args['headers']['User-Agent'];
|
||||
if ( isset( $args['user-agent'] ) && is_string( $args['user-agent'] ) ) {
|
||||
$user_agent = $args['user-agent'];
|
||||
} elseif ( isset( $args['user_agent'] ) && is_string( $args['user_agent'] ) ) {
|
||||
$user_agent = $args['user_agent'];
|
||||
} elseif ( isset( $args['headers'] ) && is_array( $args['headers'] ) ) {
|
||||
$headers = $args['headers'];
|
||||
|
||||
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 ) {
|
||||
|
|
@ -257,33 +265,49 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Logger' ) ) {
|
|||
* Parse body strings into arrays when possible.
|
||||
*
|
||||
* @param string $body Raw body.
|
||||
* @return array|null
|
||||
* @return array<int|string,mixed>|null
|
||||
*/
|
||||
private function parse_body_string( $body ) {
|
||||
$decoded = json_decode( $body, true );
|
||||
if ( is_array( $decoded ) ) {
|
||||
return $decoded;
|
||||
return $this->normalize_keys( $decoded );
|
||||
}
|
||||
|
||||
$parsed = wp_parse_args( $body );
|
||||
if ( ! empty( $parsed ) ) {
|
||||
return $parsed;
|
||||
return $this->normalize_keys( $parsed );
|
||||
}
|
||||
|
||||
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.
|
||||
*
|
||||
* @param array $data Data to sanitize.
|
||||
* @return array
|
||||
* @param array<int|string,mixed> $data Data to sanitize.
|
||||
* @return array<int|string,mixed>
|
||||
*/
|
||||
private function redact_array( $data ) {
|
||||
$redacted = array();
|
||||
|
||||
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 ) ) {
|
||||
$redacted[ $key ] = '[redacted]';
|
||||
|
|
@ -348,14 +372,16 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Logger' ) ) {
|
|||
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.
|
||||
*
|
||||
* @param array $data Data to encode.
|
||||
* @param int $limit Max size in bytes.
|
||||
* @param array<int|string,mixed> $data Data to encode.
|
||||
* @param int $limit Max size in bytes.
|
||||
* @return string|null
|
||||
*/
|
||||
private function encode_json_limited( $data, $limit ) {
|
||||
|
|
@ -375,9 +401,9 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Logger' ) ) {
|
|||
/**
|
||||
* Truncate array values to keep payloads manageable.
|
||||
*
|
||||
* @param array $data Data to trim.
|
||||
* @param int $max_len Max length per string value.
|
||||
* @return array
|
||||
* @param array<int|string,mixed> $data Data to trim.
|
||||
* @param int $max_len Max length per string value.
|
||||
* @return array<int|string,mixed>
|
||||
*/
|
||||
private function truncate_array_values( $data, $max_len ) {
|
||||
$trimmed = array();
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Logs_Table' ) ) {
|
|||
/**
|
||||
* Get columns.
|
||||
*
|
||||
* @return array
|
||||
* @return array<string,string>
|
||||
*/
|
||||
public function get_columns() {
|
||||
return array(
|
||||
|
|
@ -55,6 +55,8 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Logs_Table' ) ) {
|
|||
|
||||
/**
|
||||
* Prepare items for display.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function prepare_items() {
|
||||
global $wpdb;
|
||||
|
|
@ -119,18 +121,19 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Logs_Table' ) ) {
|
|||
/**
|
||||
* Render default column output.
|
||||
*
|
||||
* @param array $item Column data.
|
||||
* @param string $column_name Column name.
|
||||
* @param array<string,mixed> $item Column data.
|
||||
* @param string $column_name Column name.
|
||||
* @return string
|
||||
*/
|
||||
public function column_default( $item, $column_name ) {
|
||||
switch ( $column_name ) {
|
||||
case 'created_at':
|
||||
return esc_html( isset( $item[ $column_name ] ) ? $item[ $column_name ] : '' );
|
||||
case 'method':
|
||||
case 'host':
|
||||
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:
|
||||
return '';
|
||||
}
|
||||
|
|
@ -139,11 +142,11 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Logs_Table' ) ) {
|
|||
/**
|
||||
* Add row actions.
|
||||
*
|
||||
* @param array $item Item data.
|
||||
* @param array<string,mixed> $item Item data.
|
||||
* @return string
|
||||
*/
|
||||
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(
|
||||
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>',
|
||||
);
|
||||
|
||||
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.
|
||||
*
|
||||
* @param array $item Item data.
|
||||
* @param array<string,mixed> $item Item data.
|
||||
* @return string
|
||||
*/
|
||||
public function column_url( $item ) {
|
||||
if ( empty( $item['url'] ) ) {
|
||||
$url = isset( $item['url'] ) && is_string( $item['url'] ) ? $item['url'] : '';
|
||||
|
||||
if ( '' === $url ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$parsed_url = wp_parse_url( $item['url'] );
|
||||
if ( empty( $parsed_url ) || empty( $parsed_url['host'] ) ) {
|
||||
return esc_html( $item['url'] );
|
||||
$parsed_url = wp_parse_url( $url );
|
||||
if ( ! is_array( $parsed_url ) || empty( $parsed_url['host'] ) ) {
|
||||
return esc_html( $url );
|
||||
}
|
||||
|
||||
$scheme = isset( $parsed_url['scheme'] ) ? $parsed_url['scheme'] : 'https';
|
||||
|
|
@ -198,91 +205,11 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Logs_Table' ) ) {
|
|||
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.
|
||||
*
|
||||
* @param string $which Top or bottom.
|
||||
* @return void
|
||||
*/
|
||||
public function extra_tablenav( $which ) {
|
||||
if ( 'top' !== $which ) {
|
||||
|
|
@ -344,7 +271,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Logs_Table' ) ) {
|
|||
*/
|
||||
private function get_filter_value( $key ) {
|
||||
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Read-only list filters.
|
||||
if ( ! isset( $_GET[ $key ] ) ) {
|
||||
if ( ! isset( $_GET[ $key ] ) || ! is_string( $_GET[ $key ] ) ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -34,6 +34,8 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Manager_Notice' ) ) {
|
|||
|
||||
/**
|
||||
* Register hooks.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register() {
|
||||
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.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function enqueue_scripts() {
|
||||
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.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function render_plugins_page_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.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function render_settings_notice() {
|
||||
$this->render_notice( 'notice-info', '' );
|
||||
|
|
@ -114,6 +122,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Manager_Notice' ) ) {
|
|||
*
|
||||
* @param string $classes Extra CSS classes.
|
||||
* @param string $id Optional DOM id for the notice container.
|
||||
* @return void
|
||||
*/
|
||||
private function render_notice( $classes, $id ) {
|
||||
if ( self::is_manager_active() ) {
|
||||
|
|
@ -159,6 +168,8 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Manager_Notice' ) ) {
|
|||
|
||||
/**
|
||||
* Persist the notice dismissal for the current user.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle_dismiss() {
|
||||
check_ajax_referer( 'robotstxt_telemetry_manager_notice' );
|
||||
|
|
|
|||
|
|
@ -33,22 +33,22 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Network' ) ) {
|
|||
/**
|
||||
* Plugin settings and their defaults.
|
||||
*
|
||||
* @var array
|
||||
* @var array<string,mixed>
|
||||
*/
|
||||
const SETTINGS = array(
|
||||
'robotstxt_telemetry_useragent_url' => 'hash',
|
||||
'robotstxt_telemetry_wp_version' => 'actual',
|
||||
'robotstxt_telemetry_mask_locale' => false,
|
||||
'robotstxt_telemetry_replace_news_feed' => true,
|
||||
'robotstxt_telemetry_replace_events_api' => true,
|
||||
'robotstxt_telemetry_disable_browse_happy' => true,
|
||||
'robotstxt_telemetry_wp_core_check' => 'safe',
|
||||
'robotstxt_telemetry_wp_themes_check' => 'safe',
|
||||
'robotstxt_telemetry_wp_plugins_check' => 'safe',
|
||||
'robotstxt_telemetry_hidden_plugins' => array(),
|
||||
'robotstxt_telemetry_plugin_modes' => array(),
|
||||
'robotstxt_telemetry_retention_period' => '12hours',
|
||||
'robotstxt_telemetry_delete_on_uninstall' => false,
|
||||
'robotstxt_telemetry_useragent_url' => 'hash',
|
||||
'robotstxt_telemetry_wp_version' => 'actual',
|
||||
'robotstxt_telemetry_mask_locale' => false,
|
||||
'robotstxt_telemetry_replace_news_feed' => true,
|
||||
'robotstxt_telemetry_replace_events_api' => true,
|
||||
'robotstxt_telemetry_disable_browse_happy' => true,
|
||||
'robotstxt_telemetry_wp_core_check' => 'safe',
|
||||
'robotstxt_telemetry_wp_themes_check' => 'safe',
|
||||
'robotstxt_telemetry_wp_plugins_check' => 'safe',
|
||||
'robotstxt_telemetry_hidden_plugins' => array(),
|
||||
'robotstxt_telemetry_plugin_modes' => array(),
|
||||
'robotstxt_telemetry_retention_period' => '12hours',
|
||||
'robotstxt_telemetry_delete_on_uninstall' => false,
|
||||
);
|
||||
|
||||
/**
|
||||
|
|
@ -134,6 +134,9 @@ if ( ! class_exists( 'Robotstxt_Telemetry_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
|
||||
*/
|
||||
public static function main_site_id() {
|
||||
|
|
@ -143,7 +146,9 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Network' ) ) {
|
|||
|
||||
$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[]
|
||||
*/
|
||||
public static function get_hidden_plugins() {
|
||||
$hidden = self::get_setting( 'robotstxt_telemetry_hidden_plugins', array() );
|
||||
$stored = self::get_setting( 'robotstxt_telemetry_hidden_plugins', array() );
|
||||
$hidden = array();
|
||||
|
||||
if ( ! is_array( $hidden ) ) {
|
||||
$hidden = array();
|
||||
if ( is_array( $stored ) ) {
|
||||
foreach ( $stored as $basename ) {
|
||||
if ( is_string( $basename ) ) {
|
||||
$hidden[] = $basename;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$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).
|
||||
*
|
||||
* @return array
|
||||
* @return array<string,string>
|
||||
*/
|
||||
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.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register() {
|
||||
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.
|
||||
*
|
||||
* @param false|array|WP_Error $preempt Preempt value.
|
||||
* @param array $args Request arguments.
|
||||
* @param string $url Request URL.
|
||||
* @return false|array|WP_Error
|
||||
* @param false|array<string,mixed>|WP_Error $preempt Preempt value.
|
||||
* @param array{body?:string|array<mixed,mixed>,headers?:string|array<mixed,mixed>,user-agent?:string} $args Request arguments.
|
||||
* @param string $url Request URL.
|
||||
* @return false|array<string,mixed>|WP_Error
|
||||
*/
|
||||
public function apply_guards( $preempt, $args, $url ) {
|
||||
if ( false !== $preempt || self::$busy ) {
|
||||
|
|
@ -75,7 +77,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Plugin_Guards' ) ) {
|
|||
}
|
||||
|
||||
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 ) {
|
||||
$url = $new_url;
|
||||
$modified = true;
|
||||
|
|
@ -84,8 +86,8 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Plugin_Guards' ) ) {
|
|||
}
|
||||
|
||||
if ( 'strip_body' === $action ) {
|
||||
$new_body = $this->strip_body_keys( $args, $matcher['keys'] );
|
||||
if ( null !== $new_body ) {
|
||||
$new_body = $this->strip_body_keys( $args, isset( $matcher['keys'] ) ? $matcher['keys'] : array() );
|
||||
if ( is_string( $new_body ) || is_array( $new_body ) ) {
|
||||
$args['body'] = $new_body;
|
||||
$modified = true;
|
||||
}
|
||||
|
|
@ -93,7 +95,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Plugin_Guards' ) ) {
|
|||
}
|
||||
|
||||
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 ) {
|
||||
$args['headers'] = $new_headers;
|
||||
$modified = true;
|
||||
|
|
@ -127,7 +129,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Plugin_Guards' ) ) {
|
|||
*
|
||||
* @param string $host Request host.
|
||||
* @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 ) {
|
||||
$candidates = array();
|
||||
|
|
@ -160,8 +162,8 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Plugin_Guards' ) ) {
|
|||
* Matchers without a host restriction (path-only) apply to any host;
|
||||
* the caller attribution keeps them scoped to their own plugin.
|
||||
*
|
||||
* @param string $host Request host.
|
||||
* @param array $matcher Matcher.
|
||||
* @param string $host Request host.
|
||||
* @param array{host?:string,host_contains?:string} $matcher Matcher.
|
||||
* @return bool
|
||||
*/
|
||||
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.
|
||||
*
|
||||
* @param array $slugs Candidate plugin slugs.
|
||||
* @param array<int,string> $slugs Candidate plugin slugs.
|
||||
* @return string Plugin slug or an empty string.
|
||||
*/
|
||||
private function find_calling_plugin( $slugs ) {
|
||||
|
|
@ -187,7 +189,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Plugin_Guards' ) ) {
|
|||
$backtrace = debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS );
|
||||
|
||||
foreach ( $backtrace as $frame ) {
|
||||
if ( empty( $frame['file'] ) || ! is_string( $frame['file'] ) ) {
|
||||
if ( empty( $frame['file'] ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
@ -207,7 +209,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Plugin_Guards' ) ) {
|
|||
* Build a mock response for a blocked endpoint.
|
||||
*
|
||||
* @param string $body Mock body.
|
||||
* @return array
|
||||
* @return array<string,mixed>
|
||||
*/
|
||||
private function mock_response( $body ) {
|
||||
return array(
|
||||
|
|
@ -225,8 +227,8 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Plugin_Guards' ) ) {
|
|||
/**
|
||||
* Remove keys from the URL query string.
|
||||
*
|
||||
* @param string $url Request URL.
|
||||
* @param array $keys Keys to remove.
|
||||
* @param string $url Request URL.
|
||||
* @param array<int,string> $keys Keys to remove.
|
||||
* @return string
|
||||
*/
|
||||
private function strip_query_keys( $url, $keys ) {
|
||||
|
|
@ -256,8 +258,8 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Plugin_Guards' ) ) {
|
|||
*
|
||||
* Returns null when nothing changed.
|
||||
*
|
||||
* @param array $args Request arguments.
|
||||
* @param array $keys Keys to remove.
|
||||
* @param array<string,mixed> $args Request arguments.
|
||||
* @param array<int,string> $keys Keys to remove.
|
||||
* @return mixed|null
|
||||
*/
|
||||
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).
|
||||
*
|
||||
* @param array $data Source array.
|
||||
* @param array $keys Keys to remove.
|
||||
* @return array
|
||||
* @param array<mixed> $data Source array.
|
||||
* @param array<int,string> $keys Keys to remove.
|
||||
* @return array<mixed>
|
||||
*/
|
||||
private function remove_keys( $data, $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.
|
||||
*
|
||||
* @param array $args Request arguments.
|
||||
* @param array $headers Header names to remove.
|
||||
* @return array|null
|
||||
* @param array<string,mixed> $args Request arguments.
|
||||
* @param array<int,string> $headers Header names to remove.
|
||||
* @return array<mixed>|null
|
||||
*/
|
||||
private function strip_header_keys( $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.
|
||||
*
|
||||
* @param array $args Request arguments.
|
||||
* @param array<string,mixed> $args Request arguments.
|
||||
* @return string|null
|
||||
*/
|
||||
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.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register() {
|
||||
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.
|
||||
*
|
||||
* @param array $query Query arguments.
|
||||
* @return array
|
||||
* @param array<string,mixed> $query Query arguments.
|
||||
* @return array<string,mixed>
|
||||
*/
|
||||
public function filter_core_query_args( $query ) {
|
||||
if ( ! $this->is_safe( self::OPT_CORE ) ) {
|
||||
|
|
@ -74,9 +76,9 @@ if ( ! class_exists( 'Robotstxt_Telemetry_WordPress_Api' ) ) {
|
|||
/**
|
||||
* Filter update check request arguments.
|
||||
*
|
||||
* @param array $args HTTP request arguments.
|
||||
* @param string $url Request URL.
|
||||
* @return array
|
||||
* @param array<string,mixed> $args HTTP request arguments.
|
||||
* @param string $url Request URL.
|
||||
* @return array<string,mixed>
|
||||
*/
|
||||
public function filter_request_args( $args, $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
|
||||
* payload to its project dates.
|
||||
*
|
||||
* @param array $args HTTP request arguments.
|
||||
* @return array
|
||||
* @param array<string,mixed> $args HTTP request arguments.
|
||||
* @return array<string,mixed>
|
||||
*/
|
||||
private function filter_core_request( $args ) {
|
||||
if ( ! $this->is_safe( self::OPT_CORE ) ) {
|
||||
return $args;
|
||||
}
|
||||
|
||||
unset( $args['headers']['wp_install'], $args['headers']['wp_blog'] );
|
||||
if ( isset( $args['headers'] ) && is_array( $args['headers'] ) ) {
|
||||
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'] );
|
||||
}
|
||||
|
||||
|
|
@ -135,15 +139,15 @@ if ( ! class_exists( 'Robotstxt_Telemetry_WordPress_Api' ) ) {
|
|||
/**
|
||||
* Limit the themes update check payload in safe mode.
|
||||
*
|
||||
* @param array $args HTTP request arguments.
|
||||
* @return array
|
||||
* @param array<string,mixed> $args HTTP request arguments.
|
||||
* @return array<string,mixed>
|
||||
*/
|
||||
private function filter_themes_request( $args ) {
|
||||
if ( ! $this->is_safe( self::OPT_THEMES ) ) {
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
@ -180,15 +184,15 @@ if ( ! class_exists( 'Robotstxt_Telemetry_WordPress_Api' ) ) {
|
|||
/**
|
||||
* Limit the plugins update check payload in safe mode.
|
||||
*
|
||||
* @param array $args HTTP request arguments.
|
||||
* @return array
|
||||
* @param array<string,mixed> $args HTTP request arguments.
|
||||
* @return array<string,mixed>
|
||||
*/
|
||||
private function filter_plugins_request( $args ) {
|
||||
if ( ! $this->is_safe( self::OPT_PLUGINS ) ) {
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
@ -231,13 +235,13 @@ if ( ! class_exists( 'Robotstxt_Telemetry_WordPress_Api' ) ) {
|
|||
* the active list, nor their translation projects), which also
|
||||
* means they stop receiving WordPress.org update notifications.
|
||||
*
|
||||
* @param array $args HTTP request arguments.
|
||||
* @return array
|
||||
* @param array<string,mixed> $args HTTP request arguments.
|
||||
* @return array<string,mixed>
|
||||
*/
|
||||
private function exclude_hidden_plugins( $args ) {
|
||||
$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;
|
||||
}
|
||||
|
||||
|
|
@ -250,10 +254,16 @@ if ( ! class_exists( 'Robotstxt_Telemetry_WordPress_Api' ) ) {
|
|||
$hidden_slugs = array();
|
||||
|
||||
foreach ( $hidden as $basename ) {
|
||||
$slug = dirname( $basename );
|
||||
$slug = dirname( $basename );
|
||||
$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'] ) ) {
|
||||
|
|
@ -290,11 +300,11 @@ if ( ! class_exists( 'Robotstxt_Telemetry_WordPress_Api' ) ) {
|
|||
* Handles the JSON-encoded locale arrays of the update checks
|
||||
* (for example `["es_ES","en_US"]`) and plain locale strings.
|
||||
*
|
||||
* @param array $args HTTP request arguments.
|
||||
* @return array
|
||||
* @param array<string,mixed> $args HTTP request arguments.
|
||||
* @return array<string,mixed>
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
@ -324,13 +334,13 @@ if ( ! class_exists( 'Robotstxt_Telemetry_WordPress_Api' ) ) {
|
|||
/**
|
||||
* Read a string field from the request body arguments.
|
||||
*
|
||||
* @param array $args HTTP request arguments.
|
||||
* @param string $key Body field name.
|
||||
* @param string $fallback_value Default value when missing.
|
||||
* @param array<string,mixed> $args HTTP request arguments.
|
||||
* @param string $key Body field name.
|
||||
* @param string $fallback_value Default value when missing.
|
||||
* @return string
|
||||
*/
|
||||
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 ];
|
||||
}
|
||||
|
||||
|
|
@ -377,7 +387,13 @@ if ( ! class_exists( 'Robotstxt_Telemetry_WordPress_Api' ) ) {
|
|||
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.
|
||||
*
|
||||
* @param array $fields Fields of the entry.
|
||||
* @param array $allowed Lowercase allowed field names.
|
||||
* @return array
|
||||
* @param array<mixed,mixed> $fields Fields of the entry.
|
||||
* @param array<int,string> $allowed Lowercase allowed field names.
|
||||
* @return array<mixed,mixed>
|
||||
*/
|
||||
private function keep_fields( $fields, $allowed ) {
|
||||
$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
|
||||
* no longer identifiable while staying consistent across requests.
|
||||
*
|
||||
* @param array $fields Fields of a plugin or theme entry.
|
||||
* @return array
|
||||
* @param array<mixed,mixed> $fields Fields of a plugin or theme entry.
|
||||
* @return array<mixed,mixed>
|
||||
*/
|
||||
private function hash_update_uri( $fields ) {
|
||||
foreach ( $fields as $key => $value ) {
|
||||
|
|
|
|||
|
|
@ -17,6 +17,8 @@ if ( ! class_exists( 'Robotstxt_Telemetry' ) ) {
|
|||
|
||||
/**
|
||||
* Initialize the plugin.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function init() {
|
||||
$instance = new self();
|
||||
|
|
@ -25,6 +27,8 @@ if ( ! class_exists( 'Robotstxt_Telemetry' ) ) {
|
|||
|
||||
/**
|
||||
* Register hooks.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function register_hooks() {
|
||||
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
|
||||
* is actually sent on the wire.
|
||||
*
|
||||
* @param array $args HTTP request arguments.
|
||||
* @param string $url Request URL.
|
||||
* @return array
|
||||
* @param array<string,mixed> $args HTTP request arguments.
|
||||
* @param string $url Request URL.
|
||||
* @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.
|
||||
$url_mode = Robotstxt_Telemetry_Network::get_useragent_url_mode();
|
||||
|
|
@ -85,9 +89,11 @@ if ( ! class_exists( 'Robotstxt_Telemetry' ) ) {
|
|||
$args['user-agent'] = $this->mask_user_agent( $args['user-agent'], $url_mode, $version_mode, $site_url );
|
||||
}
|
||||
|
||||
foreach ( array( 'User-Agent', 'user-agent' ) as $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 );
|
||||
if ( isset( $args['headers'] ) && is_array( $args['headers'] ) ) {
|
||||
foreach ( array( 'User-Agent', 'user-agent' ) as $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 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -128,11 +134,15 @@ if ( ! class_exists( 'Robotstxt_Telemetry' ) ) {
|
|||
$user_agent = trim( $user_agent );
|
||||
|
||||
if ( 'actual' !== $version_mode && preg_match( '#^WordPress/(\d+[^\s;]*)#', $user_agent, $matches ) ) {
|
||||
$user_agent = preg_replace(
|
||||
$masked = preg_replace(
|
||||
'#^WordPress/[^\s;]+#',
|
||||
'WordPress/' . Robotstxt_Telemetry_Network::mask_wp_version( $matches[1], $version_mode ),
|
||||
$user_agent
|
||||
);
|
||||
|
||||
if ( null !== $masked ) {
|
||||
$user_agent = $masked;
|
||||
}
|
||||
}
|
||||
|
||||
return $user_agent;
|
||||
|
|
@ -142,6 +152,8 @@ if ( ! class_exists( 'Robotstxt_Telemetry' ) ) {
|
|||
*
|
||||
* In global mode the shared table is cleaned from the main site
|
||||
* only, so subsites do not schedule the event.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function schedule_cleanup() {
|
||||
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.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function deactivate() {
|
||||
wp_clear_scheduled_hook( 'robotstxt_telemetry_cleanup' );
|
||||
|
|
@ -170,6 +184,8 @@ if ( ! class_exists( 'Robotstxt_Telemetry' ) ) {
|
|||
|
||||
/**
|
||||
* Load plugin translations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function load_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
|
||||
Requires at least: 4.0
|
||||
Tested up to: 7.1
|
||||
Stable tag: 1.1.1
|
||||
Stable tag: 1.1.4
|
||||
Requires PHP: 5.6
|
||||
Version: 1.1.1
|
||||
Version: 1.1.4
|
||||
License: GPL-3.0-or-later
|
||||
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
|
||||
|
||||
= 1.1.1 =
|
||||
= 1.1.4 =
|
||||
|
||||
* Added: "Safe Mode" checkbox column in the Plugins screen (with accessible hidden labels per row)
|
||||
* 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
|
||||
* 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)
|
||||
|
||||
= 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
|
||||
* 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
|
||||
* 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
|
||||
|
||||
= 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: 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
|
||||
* 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)
|
||||
|
||||
= Previous versions =
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
* Plugin 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.
|
||||
* Version: 1.1.1
|
||||
* Version: 1.1.4
|
||||
* Author: ROBOTSTXT
|
||||
* Author URI: https://www.robotstxt.software/
|
||||
* Text Domain: robotstxt-telemetry
|
||||
|
|
@ -13,8 +13,8 @@
|
|||
* Requires PHP: 5.6
|
||||
* Tested up to: 7.1
|
||||
* Network: true
|
||||
* License: GPL v3 or later
|
||||
* License URI: https://www.gnu.org/licenses/gpl-3.0.html
|
||||
* License: GPL-3.0-or-later
|
||||
* License URI: https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
*
|
||||
* @package RobotstxtTelemetry
|
||||
*/
|
||||
|
|
@ -23,7 +23,7 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|||
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_PLUGIN_FILE', __FILE__ );
|
||||
define( 'ROBOTSTXT_TELEMETRY_PLUGIN_DIR', __DIR__ );
|
||||
|
|
@ -53,7 +53,7 @@ if ( ! function_exists( 'wp_json_encode' ) ) {
|
|||
* @return string|false
|
||||
*/
|
||||
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 ) {
|
||||
$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' );
|
||||
|
|
|
|||
Loading…
Reference in a new issue