This commit is contained in:
Javier Casares 2026-08-18 16:28:38 +00:00
commit e9782eaa82
18 changed files with 1711 additions and 440 deletions

View file

@ -1,72 +0,0 @@
# Changelog
## [0.2.0] - 2026-08-18
### Highlights
* Settings screen and uninstall behavior (data preserved by default), Manager (by ROBOTSTXT) dependency notices, and lowered requirements to WordPress 6.2 / PHP 7.4
### Added
* Settings screen with the "Delete all telemetry logs and plugin options on uninstall" checkbox (unchecked by default).
* Manager (by ROBOTSTXT) dependency notice: dismissible on the plugins list screen, permanent on the plugin Settings screen.
* `uninstall.php` routine honoring the delete-data option, Multisite aware (per-site tables), using WordPress database APIs.
* `bin/deploy.sh` script that builds a distributable ZIP in the plugin's parent directory, reading the version from the plugin headers.
* `languages/robotstxt-telemetry.pot` translation template.
### Changed
* Minimum requirements lowered to WordPress 6.2 and PHP 7.4 (previously 6.7 / 8.2).
* Plugin URI and Update URI set to https://www.robotstxt.software/plugins/robotstxt-telemetry/
* Author URI set to https://www.robotstxt.software/
* Contributors ordered as robotstxt, javiercasares.
### Fixed
* Query parameters were not stored because the `wp_parse_args()` return value was discarded.
* Invalid UTF-8 no longer discards whole payloads; values are truncated first and then scrubbed.
### Security
* Query strings are redacted before the URL is stored; credentials embedded in URLs are stripped.
* Log detail view prefers the already-redacted stored parameters over re-parsing the raw URL.
* Removed the bundled self-updater (`robotstxt-updater.php`, `update.json`); updates are now handled by the Manager (by ROBOTSTXT) plugin.
### Removed
* Bundled updater files `robotstxt-updater.php` and `update.json`.
### Compatibility
* WordPress: 6.2 - 7.1
* PHP: 7.4 - 8.5
* MariaDB: 10.6+
* Multisite: compatible
### 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 7.4-8.5): 9.3.5
* wp-since (WordPress 6.2+): 1.5.0
## [0.1.0] - 2026-08-18
### Highlights
* Initial release: outbound HTTP request logging with an admin Logs screen
### Added
* Outbound HTTP capture through `http_request_args` storing method, URL, host, path, query parameters, body parameters/raw body, sanitized headers, user agent, and caller backtrace.
* Custom database table `{$wpdb->prefix}robotstxt_telemetry_logs` created with `dbDelta()` on activation, with lazy per-site schema upgrades on Multisite.
* Logs admin screen: paginated `WP_List_Table` with method, host, and date range filters, single entry view with pretty-printed JSON, and nonce-protected delete action.
* Secret redaction for sensitive keys (authorization, password, token, secret, api_key, nonce) applied before storing.
* Payload size limits: 64 KB per JSON blob, 64 KB raw body, 16 KB caller trace.
* Dedicated analysis view for `api.wordpress.org` requests grouping environment, extensions, platform flags, and image support parameters.
### Compatibility
* WordPress: 6.7 - 6.9
* PHP: 8.2 - 8.5

View file

@ -1,56 +0,0 @@
# Telemetry (by ROBOTSTXT)
Logs outbound HTTP requests made by WordPress for inspection. Every external call performed through the WordPress HTTP API is recorded — with sensitive values redacted — in a custom database table, and can be browsed from a dedicated admin panel with filters, detail views, and safe deletion.
* Plugin URI: https://www.robotstxt.software/plugins/robotstxt-telemetry/
* Author: [ROBOTSTXT](https://www.robotstxt.software/)
* License: GPL-3.0-or-later
## Features
* Captures GET, POST, HEAD, PUT, PATCH, and DELETE requests made via the WP HTTP API.
* Stores method, URL, host, path, query parameters, body parameters (or truncated raw body), sanitized headers, user agent, and caller backtrace.
* Redacts secrets (authorization, passwords, tokens, API keys, nonces) and strips URL credentials before anything is written to the database.
* Size-limited storage: 64 KB per JSON blob, 64 KB raw body, 16 KB caller trace.
* Logs admin screen with pagination, method/host/date filters, single-entry detail view, and nonce-protected deletion.
* Dedicated analysis view for `api.wordpress.org` calls (environment, extensions, platform flags, image support).
* Multisite compatible (`Network: true`), per-site tables.
## Compatibility
* WordPress: 6.2 - 7.1
* PHP: 7.4 - 8.5
* MariaDB: 10.6+
## Updates
Updates are delivered through the [Manager (by ROBOTSTXT)](https://www.robotstxt.software/plugins/robotstxt-manager/) plugin. If it is not installed and active, this plugin shows a dismissible reminder in the plugins list and a permanent notice on its Settings screen.
## Dependencies
* Runtime: none.
* Development only (not shipped): Composer with PHPCS, WordPress Coding Standards, PHPCompatibility, and wp-since for QA. See `composer.json`.
## Documentation
* User documentation: `readme.txt`
* Full changelog: `changelog.txt` and `CHANGELOG.md`
* Internal design notes: `docs/`
## Development QA
```bash
composer install
vendor/bin/phpcs --standard=WordPress --ignore=vendor .
vendor/bin/phpcs --standard=PHPCompatibilityWP --runtime-set testVersion 7.4- --ignore=vendor .
```
## Deployment
Builds are always executed manually:
```bash
./bin/deploy.sh
```
The script reads the version from the plugin headers and generates `robotstxt-telemetry-<version>.zip` in the parent directory of the plugin folder, excluding development files.

View file

@ -1,59 +0,0 @@
#!/usr/bin/env bash
#
# Build a distributable ZIP of the plugin.
#
# Reads the version from the plugin header and writes the artifact to the
# parent directory of the plugin folder. Deploys are always executed manually.
#
# Usage: ./bin/deploy.sh
set -euo pipefail
PLUGIN_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
PLUGIN_SLUG="$(basename "$PLUGIN_DIR")"
MAIN_FILE="$PLUGIN_DIR/$PLUGIN_SLUG.php"
if [[ ! -f "$MAIN_FILE" ]]; then
echo "Error: $MAIN_FILE not found." >&2
exit 1
fi
VERSION="$(awk -F': ' '/Version:/{gsub(/[[:space:]]/, "", $2); print $2; exit}' "$MAIN_FILE")"
if [[ -z "$VERSION" ]]; then
echo "Error: unable to read the plugin version from $MAIN_FILE." >&2
exit 1
fi
ARTIFACT="$PLUGIN_DIR/../$PLUGIN_SLUG-$VERSION.zip"
STAGING="$(mktemp -d)"
trap 'rm -rf "$STAGING"' EXIT
rsync -a \
--exclude '.git/' \
--exclude '.github/' \
--exclude '.claude/' \
--exclude '.codex/' \
--exclude 'vendor/' \
--exclude 'node_modules/' \
--exclude 'tests/' \
--exclude 'phpunit.xml*' \
--exclude 'phpstan.neon*' \
--exclude 'composer.json' \
--exclude 'composer.lock' \
--exclude 'package.json' \
--exclude 'package-lock.json' \
--exclude '.gitignore' \
--exclude '.wporg' \
--exclude 'AGENTS.md' \
--exclude 'CLAUDE.md' \
--exclude 'CHANGELOG-*.md' \
--exclude 'docs/' \
"$PLUGIN_DIR/" "$STAGING/$PLUGIN_SLUG/"
rm -f "$ARTIFACT"
(cd "$STAGING" && zip -r -q "$ARTIFACT" "$PLUGIN_SLUG")
echo "Built $ARTIFACT (version $VERSION)."

View file

@ -1,5 +1,169 @@
== Changelog ==
= 0.6.1 =
_Release date: 2026-08-18_
**Highlights**
* Compatibility lowered to WordPress 4.0 and PHP 5.6, keeping every feature available on modern versions
**Changed**
* Minimum requirements lowered to WordPress 4.0 (was 6.2) and PHP 5.6 (was 7.4)
* Removed PHP 7-only syntax (scalar type hints, return type declarations, null coalescing operators, typed properties)
* Replaced the `%i` placeholder of the WordPress database API (WordPress 6.2+) with interpolated internal table names
* Compatibility fallbacks for older WordPress APIs: `wp_json_encode()` and `wp_parse_url()` shims, `get_sites()` via `wp_get_sites()`, `get_main_site_id()` via `get_current_site()`, and an inline-script fallback for `wp_add_inline_script()`
* Settings registered with the WordPress 4.0 signature of `register_setting()`
* Plugin renamed to "Telemetry disabler (by ROBOTSTXT)" with a new description
* Improved readme.txt documentation structure
**Fixed**
* Duplicated "Save Changes" button on the Settings screen
**Compatibility**
* WordPress: 4.0 - 7.1
* PHP: 5.6 - 8.5
* MariaDB: 10.6+
* Multisite: compatible (Per-site and Global modes)
* Known limitation: on WordPress older than 5.1 the Core update check Safe mode cannot reduce the query arguments (the hook does not exist); headers and translations are still reduced
**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
= 0.6.0 =
_Release date: 2026-08-18_
**Highlights**
* Multisite configuration modes: run the plugin per site (default) or centrally for the whole network from the Network Admin
**Added**
* "Configuration mode" setting (Network Admin → Telemetry): "Per-site" (default) keeps separate settings and log tables per site, "Global" uses one shared configuration and one central log table on the main site
* Network Admin Telemetry screens (Settings, and Logs in Global mode) restricted to `manage_network_options`
* When switching to Global, the network settings are seeded from the main site values
* In Global mode the per-site Telemetry screens are removed, the cleanup cron runs on the main site only, and subsites do not create their own tables
* Uninstall honors the network-wide delete-data option in Global mode and removes the shared network options
* Deactivation clears the cleanup cron on every site
**Changed**
* Plugin renamed to "Telemetry disabler (by ROBOTSTXT)" with a new description
* Improved readme.txt documentation structure
**Compatibility**
* WordPress: 6.2 - 7.1
* PHP: 7.4 - 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
= 0.5.0 =
_Release date: 2026-08-18_
**Highlights**
* Log retention management: configurable retention periods, a 1000-entry cap, scheduled cleanup, and a double-checked bulk deletion
**Added**
* "Log retention" setting with three options: 12 hours (default), 1 day, and 3 days
* A hard cap of 1000 log entries applies to every retention option; only the newest entries are kept
* The database cleaner runs when the logs list is visited and via a "twicedaily" cron event (cleared on deactivation and uninstall)
* "Delete all logs" button on the Logs screen with a two-step confirmation (nonce-protected on both steps)
**Compatibility**
* WordPress: 6.2 - 7.1
* PHP: 7.4 - 8.5
* MariaDB: 10.6+
* Multisite: compatible
**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
= 0.4.0 =
_Release date: 2026-08-18_
**Highlights**
* Safe modes (default) for the WordPress.org Core, Themes, and Plugins update checks, limiting the data sent to the minimum required to keep receiving updates
**Added**
* WordPress Core version check mode (Safe by default): sends only version, PHP, locale, normalized MySQL/MariaDB version (without distribution or logging suffixes), and channel; strips site counts, database history, PHP extensions, platform details, and the site-identifying wp_install/wp_blog headers; translation payloads reduced to project dates (no Project-Id-Version or X-Generator metadata)
* WordPress Themes version check mode (Safe by default): reports each theme with only name, version, update URI, template, and stylesheet; translations reduced to project dates, plus locale
* WordPress Plugins version check mode (Safe by default): reports each plugin with only version, update URI, RequiresWP, RequiresPHP, and RequiresPlugins; translations reduced to project dates, plus locale and the "all" flag
* Update URIs pointing at wordpress.org are kept as-is; update URIs hosted elsewhere are replaced with a deterministic hash so external plugin and theme sources are not disclosed
* New "WordPress API calls" settings section with Original/Safe options for each check
* The new options are removed on uninstall together with the other plugin options
**Changed**
* Update check requests are logged after the Safe filters run, so the Telemetry logs show exactly what was transmitted
**Fixed**
* The User-Agent is now also hashed for the WordPress.org update checks, which send an explicit User-Agent that bypassed the default User-Agent filter
**Compatibility**
* WordPress: 6.2 - 7.1
* PHP: 7.4 - 8.5
* MariaDB: 10.6+
* Multisite: compatible
**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
= 0.3.0 =
_Release date: 2026-08-18_
**Highlights**
* New privacy setting that hashes the site URL in the User-Agent of outbound requests (enabled by default)
**Added**
* "Hash the site URL in the User-Agent of outbound requests" setting, enabled by default: the default outbound User-Agent "WordPress/<version>; <site URL>" becomes "WordPress/<version>; <hash>", where the hash is a deterministic SHA-256 truncation of the site URL, so the site is no longer identifiable while remaining consistent across requests
* The new option is removed on uninstall together with the other plugin options
**Compatibility**
* WordPress: 6.2 - 7.1
* PHP: 7.4 - 8.5
* MariaDB: 10.6+
* Multisite: compatible
**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
= 0.2.0 =
_Release date: 2026-08-18_

View file

@ -18,17 +18,26 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Admin' ) ) {
/**
* Register hooks.
*/
public function register(): 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' ) );
}
/**
* Register admin menus.
*
* In global mode the per-site screens are replaced by the
* Network Admin ones.
*/
public function register_menu(): void {
public function register_menu() {
if ( Robotstxt_Telemetry_Network::is_global() ) {
return;
}
add_menu_page(
__( 'Telemetry', 'robotstxt-telemetry' ),
__( 'Telemetry', 'robotstxt-telemetry' ),
@ -58,20 +67,90 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Admin' ) ) {
}
/**
* Register the uninstall behavior setting.
* Register the Network Admin menus (Multisite only).
*
* 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.
*/
public function register_settings(): void {
public function register_network_menu() {
if ( ! is_multisite() ) {
return;
}
add_menu_page(
__( 'Telemetry', 'robotstxt-telemetry' ),
__( 'Telemetry', 'robotstxt-telemetry' ),
'manage_network_options',
'robotstxt-telemetry',
array( $this, 'render_network_settings_page' ),
'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' )
);
if ( Robotstxt_Telemetry_Network::is_global() ) {
add_submenu_page(
'robotstxt-telemetry',
__( 'Logs', 'robotstxt-telemetry' ),
__( 'Logs', 'robotstxt-telemetry' ),
'manage_network_options',
'robotstxt-telemetry-logs',
array( $this, 'render_logs_page' )
);
}
}
/**
* Register the plugin settings.
*/
public function register_settings() {
$settings = array(
'robotstxt_telemetry_hash_useragent_url' => 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_retention_period' => array( 'string', '12hours', 'sanitize_retention' ),
'robotstxt_telemetry_delete_on_uninstall' => array( 'boolean', false, 'sanitize_checkbox' ),
);
foreach ( $settings as $name => $config ) {
register_setting(
'robotstxt_telemetry_settings',
'robotstxt_telemetry_delete_on_uninstall',
array(
'type' => 'boolean',
'default' => false,
'sanitize_callback' => array( $this, 'sanitize_checkbox' ),
'show_in_rest' => false,
)
$name,
array( $this, $config[2] )
);
}
}
/**
* Sanitize a mode setting.
*
* @param mixed $value Raw input value.
* @return string
*/
public function sanitize_mode( $value ) {
return 'original' === $value ? 'original' : 'safe';
}
/**
* Sanitize a retention period setting.
*
* @param mixed $value Raw input value.
* @return string
*/
public function sanitize_retention( $value ) {
$valid = array( '12hours', '1day', '3days' );
return in_array( $value, $valid, true ) ? $value : '12hours';
}
/**
* Sanitize a checkbox value.
@ -79,23 +158,55 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Admin' ) ) {
* @param mixed $value Raw input value.
* @return bool
*/
public function sanitize_checkbox( $value ): bool {
public function sanitize_checkbox( $value ) {
return (bool) $value;
}
/**
* Handle admin actions.
*/
public function handle_actions(): void {
if ( ! current_user_can( 'manage_options' ) ) {
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'] ) ) : '';
// Network-level actions are always restricted to super administrators.
if ( 'save_network_mode' === $action || 'save_network_settings' === $action ) {
if ( 'robotstxt-telemetry' === $page && current_user_can( 'manage_network_options' ) && is_multisite() ) {
$this->handle_network_actions( $action );
}
return;
}
// phpcs:disable WordPress.Security.NonceVerification.Recommended -- State change is protected by check_admin_referer() below.
$page = isset( $_GET['page'] ) ? sanitize_key( wp_unslash( $_GET['page'] ) ) : '';
$action = isset( $_GET['action'] ) ? sanitize_key( wp_unslash( $_GET['action'] ) ) : '';
// In global mode the shared logs belong to the Network Admin only.
$capability = Robotstxt_Telemetry_Network::is_global() ? 'manage_network_options' : 'manage_options';
if ( 'robotstxt-telemetry-logs' !== $page || 'delete' !== $action ) {
if ( ! current_user_can( $capability ) ) {
return;
}
if ( 'robotstxt-telemetry-logs' !== $page ) {
return;
}
if ( 'delete_all' === $action ) {
check_admin_referer( 'robotstxt_telemetry_delete_all_logs' );
Robotstxt_Telemetry_DB::delete_all_logs();
wp_safe_redirect(
add_query_arg(
array(
'page' => 'robotstxt-telemetry-logs',
'deleted' => 'all',
),
Robotstxt_Telemetry_Network::base_url()
)
);
exit;
}
if ( 'delete' !== $action ) {
return;
}
@ -115,7 +226,71 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Admin' ) ) {
'page' => 'robotstxt-telemetry-logs',
'deleted' => 1,
),
admin_url( 'admin.php' )
Robotstxt_Telemetry_Network::base_url()
)
);
exit;
}
/**
* Handle Network Admin settings actions.
*
* @param string $action Action name.
*/
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 = Robotstxt_Telemetry_Network::sanitize_mode( $new_mode );
$old_mode = get_site_option( Robotstxt_Telemetry_Network::MODE_OPTION, 'per-site' );
if ( 'global' === $new_mode && 'global' !== $old_mode ) {
Robotstxt_Telemetry_Network::seed_network_settings();
}
update_site_option( Robotstxt_Telemetry_Network::MODE_OPTION, $new_mode );
$this->redirect_network_settings( 'mode-updated' );
}
if ( 'save_network_settings' === $action ) {
check_admin_referer( 'robotstxt_telemetry_network_settings' );
// phpcs:disable WordPress.Security.NonceVerification.Missing -- Verified by check_admin_referer() above.
$hash = ! empty( $_POST['robotstxt_telemetry_hash_useragent_url'] );
$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';
$retention = isset( $_POST['robotstxt_telemetry_retention_period'] ) ? sanitize_key( wp_unslash( $_POST['robotstxt_telemetry_retention_period'] ) ) : '12hours';
$delete = ! empty( $_POST['robotstxt_telemetry_delete_on_uninstall'] );
// phpcs:enable
Robotstxt_Telemetry_Network::update_setting( 'robotstxt_telemetry_hash_useragent_url', $hash );
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 ) );
Robotstxt_Telemetry_Network::update_setting( 'robotstxt_telemetry_retention_period', $this->sanitize_retention( $retention ) );
Robotstxt_Telemetry_Network::update_setting( 'robotstxt_telemetry_delete_on_uninstall', $delete );
$this->redirect_network_settings( 'settings-updated' );
}
}
/**
* Redirect back to the Network Admin settings screen.
*
* @param string $flag Query flag to append.
*/
private function redirect_network_settings( $flag ) {
wp_safe_redirect(
add_query_arg(
array(
'page' => 'robotstxt-telemetry',
$flag => 'true',
),
network_admin_url( 'admin.php' )
)
);
exit;
@ -124,28 +299,95 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Admin' ) ) {
/**
* Render the settings saved notice.
*/
public function render_saved_notice(): void {
if ( ! current_user_can( 'manage_options' ) ) {
public function render_saved_notice() {
if ( ! current_user_can( Robotstxt_Telemetry_Network::manage_capability() ) ) {
return;
}
// 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'] ) ) : '';
// phpcs:enable
if ( 'true' !== $settings_updated || 'robotstxt-telemetry' !== $page ) {
if ( 'robotstxt-telemetry' !== $page ) {
return;
}
if ( 'true' === $settings_updated ) {
echo '<div class="notice notice-success is-dismissible"><p>' . esc_html__( 'Settings saved.', 'robotstxt-telemetry' ) . '</p></div>';
}
if ( 'true' === $mode_updated ) {
echo '<div class="notice notice-success is-dismissible"><p>' . esc_html__( 'Configuration mode saved.', 'robotstxt-telemetry' ) . '</p></div>';
}
}
/**
* Render the Network Admin settings page (Multisite only).
*/
public function render_network_settings_page() {
if ( ! current_user_can( 'manage_network_options' ) ) {
return;
}
$mode = get_site_option( Robotstxt_Telemetry_Network::MODE_OPTION, 'per-site' );
$is_global = Robotstxt_Telemetry_Network::is_global();
echo '<div class="wrap">';
echo '<h1>' . esc_html__( 'Telemetry Network Settings', 'robotstxt-telemetry' ) . '</h1>';
echo '<form method="post" action="' . esc_url( add_query_arg( 'page', 'robotstxt-telemetry', network_admin_url( 'admin.php' ) ) ) . '">';
wp_nonce_field( 'robotstxt_telemetry_network_mode' );
echo '<input type="hidden" name="action" value="save_network_mode" />';
echo '<input type="hidden" name="page" value="robotstxt-telemetry" />';
echo '<table class="form-table" role="presentation">';
echo '<tbody>';
echo '<tr>';
echo '<th scope="row">' . esc_html__( 'Configuration mode', 'robotstxt-telemetry' ) . '</th>';
echo '<td>';
echo '<fieldset>';
echo '<legend class="screen-reader-text">' . esc_html__( 'Configuration mode', 'robotstxt-telemetry' ) . '</legend>';
echo '<p style="margin: 0;">';
echo '<label><input type="radio" name="robotstxt_telemetry_config_mode" value="per-site" ' . checked( $mode, 'per-site', false ) . '/> ' . esc_html__( 'Per-site', 'robotstxt-telemetry' ) . '</label>';
echo '&nbsp;&nbsp;';
echo '<label><input type="radio" name="robotstxt_telemetry_config_mode" value="global" ' . checked( $mode, 'global', false ) . '/> ' . esc_html__( 'Global', 'robotstxt-telemetry' ) . '</label>';
echo '</p>';
echo '<p class="description">' . esc_html__( 'Per-site: every site keeps its own settings and its own log table, managed by each site administrator. Global: one shared configuration and one central log on the main site collect the outbound requests of the whole network; the Telemetry screens are then managed from here only.', 'robotstxt-telemetry' ) . '</p>';
echo '</fieldset>';
echo '</td>';
echo '</tr></tbody>';
echo '</table>';
submit_button( __( 'Save configuration mode', 'robotstxt-telemetry' ) );
echo '</form>';
if ( ! $is_global ) {
echo '<p>' . esc_html__( 'Switch to Global mode to manage the settings and the logs for the whole network from this screen.', 'robotstxt-telemetry' ) . '</p>';
echo '</div>';
return;
}
echo '<h2>' . esc_html__( 'Network settings', 'robotstxt-telemetry' ) . '</h2>';
echo '<form method="post" action="' . esc_url( add_query_arg( 'page', 'robotstxt-telemetry', network_admin_url( 'admin.php' ) ) ) . '">';
wp_nonce_field( 'robotstxt_telemetry_network_settings' );
echo '<input type="hidden" name="action" value="save_network_settings" />';
echo '<input type="hidden" name="page" value="robotstxt-telemetry" />';
$this->render_settings_fields();
submit_button();
echo '</form>';
echo '</div>';
}
/**
* Render settings page.
*/
public function render_settings_page(): void {
if ( ! current_user_can( 'manage_options' ) ) {
public function render_settings_page() {
if ( ! current_user_can( Robotstxt_Telemetry_Network::manage_capability() ) ) {
return;
}
@ -158,29 +400,115 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Admin' ) ) {
echo '<form method="post" action="options.php">';
settings_fields( 'robotstxt_telemetry_settings' );
echo '<table class="form-table" role="presentation">';
echo '<tbody><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) get_option( '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></tbody>';
echo '</table>';
$this->render_settings_fields();
submit_button();
echo '</form>';
echo '</div>';
}
/**
* Render the settings fields table.
*
* Values honor the configuration mode: per-site options or the
* shared network options in global mode.
*/
private function render_settings_fields() {
echo '<table class="form-table" role="presentation">';
echo '<tbody>';
echo '<tr>';
echo '<th scope="row">' . esc_html__( 'Outbound requests', 'robotstxt-telemetry' ) . '</th>';
echo '<td>';
echo '<label for="robotstxt-telemetry-hash-useragent">';
echo '<input type="checkbox" id="robotstxt-telemetry-hash-useragent" name="robotstxt_telemetry_hash_useragent_url" value="1" ' . checked( (bool) Robotstxt_Telemetry_Network::get_setting( 'robotstxt_telemetry_hash_useragent_url', true ), true, false ) . '/>';
echo '<span>' . esc_html__( 'Hash the site URL in the User-Agent of outbound requests', 'robotstxt-telemetry' ) . '</span>';
echo '</label>';
echo '<p class="description">' . esc_html__( 'Outbound requests normally identify this site with its URL (for example "WordPress/6.9; https://example.com/"). When enabled, the URL is replaced with a fixed hash so the site is no longer identifiable.', 'robotstxt-telemetry' ) . '</p>';
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 translation dates and 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 translation dates, 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 '&nbsp;&nbsp;';
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>';
}
$retention = Robotstxt_Telemetry_Network::get_setting( 'robotstxt_telemetry_retention_period', '12hours' );
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 )
);
}
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>';
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></tbody>';
echo '</table>';
}
/**
* Render logs page.
*/
public function render_logs_page(): void {
if ( ! current_user_can( 'manage_options' ) ) {
public function render_logs_page() {
$capability = Robotstxt_Telemetry_Network::is_global() ? 'manage_network_options' : Robotstxt_Telemetry_Network::manage_capability();
if ( ! current_user_can( $capability ) ) {
return;
}
@ -199,12 +527,36 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Admin' ) ) {
return;
}
$deleted_notice = isset( $_GET['deleted'] ) ? absint( wp_unslash( $_GET['deleted'] ) ) : 0;
if ( 'confirm_delete_all' === $view_action ) {
$this->render_delete_all_confirm();
echo '</div>';
return;
}
// Apply the retention policy before listing.
Robotstxt_Telemetry_DB::cleanup();
$deleted_notice = isset( $_GET['deleted'] ) ? sanitize_key( wp_unslash( $_GET['deleted'] ) ) : '';
// phpcs:enable
if ( $deleted_notice > 0 ) {
if ( 'all' === $deleted_notice ) {
echo '<div class="notice notice-success is-dismissible"><p>' . esc_html__( 'All log entries deleted.', 'robotstxt-telemetry' ) . '</p></div>';
} elseif ( ! empty( $deleted_notice ) ) {
echo '<div class="notice notice-success is-dismissible"><p>' . esc_html__( 'Log entry deleted.', 'robotstxt-telemetry' ) . '</p></div>';
}
$delete_all_url = wp_nonce_url(
add_query_arg(
array(
'page' => 'robotstxt-telemetry-logs',
'action' => 'confirm_delete_all',
),
Robotstxt_Telemetry_Network::base_url()
),
'robotstxt_telemetry_delete_all_confirm'
);
echo '<p><a href="' . esc_url( $delete_all_url ) . '" class="button">' . esc_html__( 'Delete all logs', 'robotstxt-telemetry' ) . '</a></p>';
$table = new Robotstxt_Telemetry_Logs_Table();
$table->prepare_items();
@ -215,12 +567,31 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Admin' ) ) {
echo '</div>';
}
/**
* Render the delete-all confirmation screen.
*/
private function render_delete_all_confirm() {
check_admin_referer( 'robotstxt_telemetry_delete_all_confirm' );
echo '<div class="notice notice-warning"><p>' . esc_html__( 'You are about to permanently delete all telemetry log entries. This action cannot be undone.', 'robotstxt-telemetry' ) . '</p></div>';
$logs_page_url = add_query_arg( 'page', 'robotstxt-telemetry-logs', Robotstxt_Telemetry_Network::base_url() );
echo '<form method="post" action="' . esc_url( $logs_page_url ) . '">';
wp_nonce_field( 'robotstxt_telemetry_delete_all_logs' );
echo '<input type="hidden" name="action" value="delete_all" />';
echo '<input type="hidden" name="page" value="robotstxt-telemetry-logs" />';
submit_button( __( 'Yes, delete all logs', 'robotstxt-telemetry' ), 'delete' );
echo '&nbsp;<a class="button" href="' . esc_url( $logs_page_url ) . '">' . esc_html__( 'Cancel', 'robotstxt-telemetry' ) . '</a>';
echo '</form>';
}
/**
* Render a single log entry.
*
* @param int $log_id Log ID.
*/
private function render_single_log( int $log_id ): void {
private function render_single_log( $log_id ) {
$log = Robotstxt_Telemetry_DB::get_log( $log_id );
if ( empty( $log ) ) {
@ -228,7 +599,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Admin' ) ) {
return;
}
echo '<p><a href="' . esc_url( admin_url( 'admin.php?page=robotstxt-telemetry-logs' ) ) . '">' . esc_html__( 'Back to logs', 'robotstxt-telemetry' ) . '</a></p>';
echo '<p><a href="' . esc_url( add_query_arg( 'page', 'robotstxt-telemetry-logs', Robotstxt_Telemetry_Network::base_url() ) ) . '">' . esc_html__( 'Back to logs', 'robotstxt-telemetry' ) . '</a></p>';
echo '<table class="widefat striped">';
echo '<tbody>';
@ -254,7 +625,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Admin' ) ) {
*
* @param array $log Log data.
*/
private function render_telemetry_analysis( array $log ): void {
private function render_telemetry_analysis( $log ) {
$sections = Robotstxt_Telemetry_Analysis::build_sections( $log );
if ( empty( $sections ) ) {
@ -279,7 +650,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Admin' ) ) {
* @param string $label Label.
* @param string $value Value.
*/
private function render_log_row( string $label, $value ): 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>';
@ -292,7 +663,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Admin' ) ) {
* @param string|null $value JSON string.
* @return string
*/
private function format_json_field( ?string $value ): string {
private function format_json_field( $value ) {
if ( empty( $value ) ) {
return '';
}
@ -312,7 +683,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Admin' ) ) {
* @param string $type Param source.
* @return string
*/
private function format_params_field( array $log, string $type ): string {
private function format_params_field( $log, $type ) {
$params = array();
if ( 'body' === $type ) {

View file

@ -21,7 +21,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Analysis_Api_WordPress_Org' ) ) {
* @param array $log Log data.
* @return array
*/
public static function build_sections( array $log ): array {
public static function build_sections( $log ) {
$sections = array();
$query_params = Robotstxt_Telemetry_Analysis::extract_query_params( $log );
@ -43,7 +43,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Analysis_Api_WordPress_Org' ) ) {
* @param array $params Query parameters.
* @return array
*/
private static function group_query_params( array $params ): array {
private static function group_query_params( $params ) {
$sections = array();
$core_keys = array(
@ -99,7 +99,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Analysis_Api_WordPress_Org' ) ) {
* @param array $params Body parameters.
* @return array
*/
private static function group_body_params( array $params ): array {
private static function group_body_params( $params ) {
$sections = array();
if ( isset( $params['translations'] ) ) {
@ -134,7 +134,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Analysis_Api_WordPress_Org' ) ) {
* @param string $prefix Prefix name.
* @return array
*/
private static function pluck_bracketed( array &$params, string $prefix ): array {
private static function pluck_bracketed( &$params, $prefix ) {
$result = array();
foreach ( $params as $key => $value ) {

View file

@ -21,7 +21,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Analysis' ) ) {
* @param array $log Log data.
* @return array
*/
public static function build_sections( array $log ): array {
public static function build_sections( $log ) {
$host = isset( $log['host'] ) ? strtolower( (string) $log['host'] ) : '';
if ( 'api.wordpress.org' === $host ) {
@ -37,7 +37,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Analysis' ) ) {
* @param array $log Log data.
* @return array
*/
private static function build_generic_sections( array $log ): array {
private static function build_generic_sections( $log ) {
$sections = array();
$query_params = self::extract_query_params( $log );
@ -61,7 +61,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Analysis' ) ) {
* @param array $log Log data.
* @return array
*/
public static function extract_query_params( array $log ): array {
public static function extract_query_params( $log ) {
if ( empty( $log['url'] ) && empty( $log['query_json'] ) ) {
return array();
}
@ -89,7 +89,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Analysis' ) ) {
* @param array $log Log data.
* @return array
*/
public static function extract_body_params( array $log ): array {
public static function extract_body_params( $log ) {
if ( ! empty( $log['body_json'] ) ) {
$decoded = json_decode( $log['body_json'], true );
if ( is_array( $decoded ) ) {
@ -114,7 +114,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Analysis' ) ) {
* @param string $query Query string.
* @return array
*/
public static function parse_query_string_flat( string $query ): array {
public static function parse_query_string_flat( $query ) {
$params = array();
$pairs = explode( '&', $query );
@ -152,7 +152,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Analysis' ) ) {
* @param array $params Parameters.
* @return string
*/
public static function format_params_lines( array $params ): string {
public static function format_params_lines( $params ) {
$lines = array();
$flatten = self::flatten_params( $params );
@ -174,7 +174,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Analysis' ) ) {
* @param string|null $prefix Current prefix.
* @return array
*/
public static function flatten_params( array $params, ?string $prefix = null ): array {
public static function flatten_params( $params, $prefix = null ) {
$flat = array();
foreach ( $params as $key => $value ) {

View file

@ -15,28 +15,41 @@ if ( ! class_exists( 'Robotstxt_Telemetry_DB' ) ) {
*/
class Robotstxt_Telemetry_DB {
/**
* Maximum number of log entries kept, regardless of retention period.
*
* @var int
*/
const MAX_LOG_ROWS = 1000;
/**
* Whether the schema was checked in this request.
*
* @var bool
*/
private static bool $did_check = false;
private static $did_check = false;
/**
* Get the table name.
*
* In global mode all sites share the main site table.
*
* @return string
*/
public static function get_table_name(): string {
public static function get_table_name() {
global $wpdb;
if ( Robotstxt_Telemetry_Network::is_global() ) {
return $wpdb->get_blog_prefix( Robotstxt_Telemetry_Network::main_site_id() ) . 'robotstxt_telemetry_logs';
}
return $wpdb->prefix . 'robotstxt_telemetry_logs';
}
/**
* Activation hook.
*/
public static function activate(): void {
public static function activate() {
self::create_table();
update_option( 'robotstxt_telemetry_db_version', ROBOTSTXT_TELEMETRY_DB_VERSION );
}
@ -44,13 +57,18 @@ if ( ! class_exists( 'Robotstxt_Telemetry_DB' ) ) {
/**
* Ensure the database schema is up to date.
*/
public static function maybe_upgrade(): void {
public static function maybe_upgrade() {
if ( self::$did_check ) {
return;
}
self::$did_check = true;
// In global mode the shared table belongs to the main site only.
if ( Robotstxt_Telemetry_Network::is_global() && ! is_main_site() ) {
return;
}
$installed_version = get_option( 'robotstxt_telemetry_db_version' );
if ( ROBOTSTXT_TELEMETRY_DB_VERSION !== $installed_version ) {
self::create_table();
@ -61,7 +79,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_DB' ) ) {
/**
* Create or update the logs table.
*/
public static function create_table(): void {
public static function create_table() {
global $wpdb;
require_once ABSPATH . 'wp-admin/includes/upgrade.php';
@ -99,7 +117,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_DB' ) ) {
*
* @param array $data Log data.
*/
public static function insert_log( array $data ): void {
public static function insert_log( array $data ) {
global $wpdb;
$wpdb->insert( // phpcs:ignore WordPress.DB.DirectDatabaseQuery -- Insert into the plugin's custom table via the wpdb API.
@ -128,15 +146,14 @@ if ( ! class_exists( 'Robotstxt_Telemetry_DB' ) ) {
* @param int $log_id Log ID.
* @return array|null
*/
public static function get_log( int $log_id ): ?array {
public static function get_log( $log_id ) {
global $wpdb;
$table_name = self::get_table_name();
$log = $wpdb->get_row( // phpcs:ignore WordPress.DB.DirectDatabaseQuery -- Custom table read via the wpdb API; single-row view is never cached.
$wpdb->prepare(
'SELECT * FROM %i WHERE id = %d',
$table_name,
"SELECT * FROM {$table_name} WHERE id = %d", // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- Table name is internal; the %i placeholder requires WordPress 6.2.
$log_id
),
ARRAY_A
@ -155,7 +172,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_DB' ) ) {
* @param int $log_id Log ID.
* @return bool
*/
public static function delete_log( int $log_id ): bool {
public static function delete_log( $log_id ) {
global $wpdb;
$deleted = $wpdb->delete( // phpcs:ignore WordPress.DB.DirectDatabaseQuery -- Delete from the plugin's custom table via the wpdb API.
@ -166,5 +183,65 @@ if ( ! class_exists( 'Robotstxt_Telemetry_DB' ) ) {
return false !== $deleted;
}
/**
* Delete all log rows.
*
* @return void
*/
public static function delete_all_logs() {
global $wpdb;
$table_name = self::get_table_name();
$wpdb->query( // phpcs:ignore WordPress.DB.DirectDatabaseQuery -- Delete from the plugin's custom table via the wpdb API.
"DELETE FROM {$table_name}" // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- Table name is internal; the %i placeholder requires WordPress 6.2.
);
}
/**
* Delete logs according to the retention settings.
*
* Removes entries older than the configured retention period and
* keeps at most MAX_LOG_ROWS entries (newest first). Runs when the
* logs list is visited and twice daily via cron.
*
* @return void
*/
public static function cleanup() {
global $wpdb;
$table_name = self::get_table_name();
$retention = Robotstxt_Telemetry_Network::get_setting( 'robotstxt_telemetry_retention_period', '12hours' );
$periods = array(
'12hours' => 12 * HOUR_IN_SECONDS,
'1day' => DAY_IN_SECONDS,
'3days' => 3 * DAY_IN_SECONDS,
);
if ( 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.
$wpdb->prepare( "DELETE FROM {$table_name} WHERE created_at < %s", $cutoff ) // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- Table name is internal; the %i placeholder requires WordPress 6.2.
);
}
// Keep only the newest MAX_LOG_ROWS entries.
$threshold_id = (int) $wpdb->get_var( // phpcs:ignore WordPress.DB.DirectDatabaseQuery -- Custom table read via the wpdb API; cleanup threshold lookup.
$wpdb->prepare(
"SELECT id FROM {$table_name} ORDER BY id DESC LIMIT 1 OFFSET %d", // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- Table name is internal; the %i placeholder requires WordPress 6.2.
self::MAX_LOG_ROWS - 1
)
);
if ( $threshold_id > 0 ) {
$wpdb->query( // phpcs:ignore WordPress.DB.DirectDatabaseQuery -- Delete from the plugin's custom table via the wpdb API.
$wpdb->prepare( "DELETE FROM {$table_name} WHERE id < %d", $threshold_id ) // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- Table name is internal; the %i placeholder requires WordPress 6.2.
);
}
}
}
}

View file

@ -20,26 +20,26 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Logger' ) ) {
*
* @var int
*/
private int $max_json_bytes = 65535;
private $max_json_bytes = 65535;
/**
* Maximum raw body size to store.
*
* @var int
*/
private int $max_raw_body_bytes = 65535;
private $max_raw_body_bytes = 65535;
/**
* Maximum caller summary size.
*
* @var int
*/
private int $max_caller_bytes = 16000;
private $max_caller_bytes = 16000;
/**
* Register hooks.
*/
public function register(): void {
public function register() {
add_filter( 'http_request_args', array( $this, 'capture_request' ), 10, 2 );
}
@ -50,7 +50,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Logger' ) ) {
* @param string $url Request URL.
* @return array
*/
public function capture_request( $args, $url ): array {
public function capture_request( $args, $url ) {
if ( empty( $url ) || ! is_array( $args ) ) {
return $args;
}
@ -61,7 +61,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Logger' ) ) {
if ( ! empty( $log_data ) ) {
Robotstxt_Telemetry_DB::insert_log( $log_data );
}
} catch ( Throwable $exception ) {
} catch ( Exception $exception ) {
// Never interrupt outbound requests if logging fails.
do_action( 'robotstxt_telemetry_logging_failed', $exception, $args, $url );
}
@ -76,7 +76,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Logger' ) ) {
* @param string $url Request URL.
* @return array
*/
private function prepare_log_data( array $args, string $url ): array {
private function prepare_log_data( $args, $url ) {
$method = isset( $args['method'] ) ? strtoupper( sanitize_text_field( (string) $args['method'] ) ) : 'GET';
$url = esc_url_raw( $url );
@ -139,7 +139,8 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Logger' ) ) {
}
}
$headers = $this->normalize_headers( $args['headers'] ?? array() );
$headers_args = isset( $args['headers'] ) && is_array( $args['headers'] ) ? $args['headers'] : array();
$headers = $this->normalize_headers( $headers_args );
$headers = $this->redact_array( $headers );
$headers_json = $this->encode_json_limited( $headers, $this->max_json_bytes );
$user_agent = $this->extract_user_agent( $args );
@ -175,7 +176,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Logger' ) ) {
* @param string $query Redacted query string.
* @return string
*/
private function build_redacted_url( array $parts, string $query ): string {
private function build_redacted_url( $parts, $query ) {
$url = '';
if ( ! empty( $parts['scheme'] ) && ! empty( $parts['host'] ) ) {
@ -188,7 +189,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Logger' ) ) {
$url .= ':' . (int) $parts['port'];
}
$url .= $parts['path'] ?? '';
$url .= isset( $parts['path'] ) ? $parts['path'] : '';
if ( '' !== $query ) {
$url .= '?' . $query;
@ -207,7 +208,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Logger' ) ) {
* @param mixed $headers Headers value.
* @return array
*/
private function normalize_headers( $headers ): array {
private function normalize_headers( $headers ) {
if ( is_object( $headers ) && method_exists( $headers, 'getAll' ) ) {
$headers = $headers->getAll();
}
@ -232,7 +233,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Logger' ) ) {
* @param array $args Request args.
* @return string|null
*/
private function extract_user_agent( array $args ): ?string {
private function extract_user_agent( $args ) {
$user_agent = '';
if ( isset( $args['user-agent'] ) ) {
@ -258,7 +259,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Logger' ) ) {
* @param string $body Raw body.
* @return array|null
*/
private function parse_body_string( string $body ): ?array {
private function parse_body_string( $body ) {
$decoded = json_decode( $body, true );
if ( is_array( $decoded ) ) {
return $decoded;
@ -278,7 +279,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Logger' ) ) {
* @param array $data Data to sanitize.
* @return array
*/
private function redact_array( array $data ): array {
private function redact_array( $data ) {
$redacted = array();
foreach ( $data as $key => $value ) {
@ -306,7 +307,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Logger' ) ) {
* @param string $key Key name.
* @return bool
*/
private function is_sensitive_key( string $key ): bool {
private function is_sensitive_key( $key ) {
$sensitive_keys = array(
'authorization',
'password',
@ -352,7 +353,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Logger' ) ) {
* @param int $limit Max size in bytes.
* @return string|null
*/
private function encode_json_limited( array $data, int $limit ): ?string {
private function encode_json_limited( $data, $limit ) {
$encoded = wp_json_encode( $this->truncate_array_values( $data, 2048 ) );
if ( false === $encoded ) {
@ -373,7 +374,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Logger' ) ) {
* @param int $max_len Max length per string value.
* @return array
*/
private function truncate_array_values( array $data, int $max_len ): array {
private function truncate_array_values( $data, $max_len ) {
$trimmed = array();
foreach ( $data as $key => $value ) {
@ -400,12 +401,17 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Logger' ) ) {
* @param int $limit Max length in bytes.
* @return string
*/
private function truncate_string( string $value, int $limit ): string {
private function truncate_string( $value, $limit ) {
if ( strlen( $value ) > $limit ) {
$value = substr( $value, 0, $limit );
}
// wp_check_invalid_utf8() requires WordPress 4.2.3.
if ( function_exists( 'wp_check_invalid_utf8' ) ) {
return wp_check_invalid_utf8( $value, true );
}
return $value;
}
}
}

View file

@ -24,7 +24,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Logs_Table' ) ) {
*
* @var int
*/
private int $per_page = 20;
private $per_page = 20;
/**
* Constructor.
@ -44,7 +44,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Logs_Table' ) ) {
*
* @return array
*/
public function get_columns(): array {
public function get_columns() {
return array(
'created_at' => __( 'Date', 'robotstxt-telemetry' ),
'method' => __( 'Method', 'robotstxt-telemetry' ),
@ -56,7 +56,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Logs_Table' ) ) {
/**
* Prepare items for display.
*/
public function prepare_items(): void {
public function prepare_items() {
global $wpdb;
$table_name = Robotstxt_Telemetry_DB::get_table_name();
@ -79,14 +79,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Logs_Table' ) ) {
$this->items = $wpdb->get_results( // phpcs:ignore WordPress.DB.DirectDatabaseQuery -- Custom table read via the wpdb API; list output is never cached.
$wpdb->prepare(
'SELECT * FROM %i
WHERE ( %s = \'\' OR method = %s )
AND ( %s = \'\' OR host = %s )
AND ( %s = \'\' OR created_at >= %s )
AND ( %s = \'\' OR created_at <= %s )
ORDER BY created_at DESC
LIMIT %d OFFSET %d',
$table_name,
"SELECT * FROM {$table_name} WHERE ( %s = '' OR method = %s ) AND ( %s = '' OR host = %s ) AND ( %s = '' OR created_at >= %s ) AND ( %s = '' OR created_at <= %s ) ORDER BY created_at DESC LIMIT %d OFFSET %d", // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- Table name is internal; the %i placeholder requires WordPress 6.2.
$method,
$method,
$host,
@ -103,12 +96,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Logs_Table' ) ) {
$total = (int) $wpdb->get_var( // phpcs:ignore WordPress.DB.DirectDatabaseQuery -- Custom table read via the wpdb API; pagination count is never cached.
$wpdb->prepare(
'SELECT COUNT(*) FROM %i
WHERE ( %s = \'\' OR method = %s )
AND ( %s = \'\' OR host = %s )
AND ( %s = \'\' OR created_at >= %s )
AND ( %s = \'\' OR created_at <= %s )',
$table_name,
"SELECT COUNT(*) FROM {$table_name} WHERE ( %s = '' OR method = %s ) AND ( %s = '' OR host = %s ) AND ( %s = '' OR created_at >= %s ) AND ( %s = '' OR created_at <= %s )", // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- Table name is internal; the %i placeholder requires WordPress 6.2.
$method,
$method,
$host,
@ -135,14 +123,14 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Logs_Table' ) ) {
* @param string $column_name Column name.
* @return string
*/
public function column_default( $item, $column_name ): string {
public function column_default( $item, $column_name ) {
switch ( $column_name ) {
case 'created_at':
return esc_html( $item[ $column_name ] ?? '' );
return esc_html( isset( $item[ $column_name ] ) ? $item[ $column_name ] : '' );
case 'method':
case 'host':
case 'path':
return esc_html( $item[ $column_name ] ?? '' );
return esc_html( isset( $item[ $column_name ] ) ? $item[ $column_name ] : '' );
default:
return '';
}
@ -154,7 +142,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Logs_Table' ) ) {
* @param array $item Item data.
* @return string
*/
public function column_created_at( $item ): string {
public function column_created_at( $item ) {
$log_id = (int) $item['id'];
$view_url = add_query_arg(
@ -163,7 +151,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Logs_Table' ) ) {
'action' => 'view',
'log' => $log_id,
),
admin_url( 'admin.php' )
Robotstxt_Telemetry_Network::base_url()
);
$delete_url = wp_nonce_url(
@ -173,7 +161,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Logs_Table' ) ) {
'action' => 'delete',
'log' => $log_id,
),
admin_url( 'admin.php' )
Robotstxt_Telemetry_Network::base_url()
),
'robotstxt_telemetry_delete_log_' . $log_id
);
@ -192,7 +180,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Logs_Table' ) ) {
* @param array $item Item data.
* @return string
*/
public function column_url( $item ): string {
public function column_url( $item ) {
if ( empty( $item['url'] ) ) {
return '';
}
@ -202,8 +190,8 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Logs_Table' ) ) {
return esc_html( $item['url'] );
}
$scheme = $parsed_url['scheme'] ?? 'https';
$path = $parsed_url['path'] ?? '';
$scheme = isset( $parsed_url['scheme'] ) ? $parsed_url['scheme'] : 'https';
$path = isset( $parsed_url['path'] ) ? $parsed_url['path'] : '';
$port = isset( $parsed_url['port'] ) ? ':' . (int) $parsed_url['port'] : '';
$base = sprintf( '%s://%s%s%s', $scheme, $parsed_url['host'], $port, $path );
@ -216,7 +204,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Logs_Table' ) ) {
* @param array $item Item data.
* @return string
*/
private function format_params_column( array $item ): string {
private function format_params_column( $item ) {
$params = array();
if ( ! empty( $item['url'] ) ) {
@ -227,12 +215,12 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Logs_Table' ) ) {
}
}
$query_params = $this->decode_json_params( $item['query_json'] ?? '' );
$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( $item['body_json'] ?? '' );
$body_params = $this->decode_json_params( isset( $item['body_json'] ) ? $item['body_json'] : '' );
if ( ! empty( $body_params ) ) {
$params = array_merge( $params, $body_params );
}
@ -266,7 +254,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Logs_Table' ) ) {
* @param string $value JSON string.
* @return array
*/
private function decode_json_params( string $value ): array {
private function decode_json_params( $value ) {
if ( empty( $value ) ) {
return array();
}
@ -296,7 +284,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Logs_Table' ) ) {
*
* @param string $which Top or bottom.
*/
public function extra_tablenav( $which ): void {
public function extra_tablenav( $which ) {
if ( 'top' !== $which ) {
return;
}
@ -354,7 +342,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Logs_Table' ) ) {
* @param string $key Filter key.
* @return string
*/
private function get_filter_value( string $key ): string {
private function get_filter_value( $key ) {
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Read-only list filters.
if ( ! isset( $_GET[ $key ] ) ) {
return '';
@ -369,7 +357,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Logs_Table' ) ) {
* @param string|null $value Date string.
* @return string|null
*/
private function sanitize_date_filter( ?string $value ): ?string {
private function sanitize_date_filter( $value ) {
if ( empty( $value ) ) {
return null;
}

View file

@ -35,7 +35,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Manager_Notice' ) ) {
/**
* Register hooks.
*/
public function register(): void {
public function register() {
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
add_action( 'admin_notices', array( $this, 'render_plugins_page_notice' ) );
add_action( 'network_admin_notices', array( $this, 'render_plugins_page_notice' ) );
@ -47,7 +47,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Manager_Notice' ) ) {
*
* @return bool
*/
public static function is_manager_active(): bool {
public static function is_manager_active() {
if ( ! function_exists( 'is_plugin_active' ) ) {
require_once ABSPATH . 'wp-admin/includes/plugin.php';
}
@ -59,16 +59,14 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Manager_Notice' ) ) {
/**
* Enqueue the inline dismissal script on the plugins list screen.
*/
public function enqueue_scripts(): void {
public function enqueue_scripts() {
if ( ! $this->should_show_notice() ) {
return;
}
wp_enqueue_script( 'common' );
wp_add_inline_script(
'common',
'(function () {
$script = '(function () {
document.addEventListener(
\'click\',
function ( event ) {
@ -82,15 +80,21 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Manager_Notice' ) ) {
fetch( window.ajaxurl, { method: \'POST\', credentials: \'same-origin\', body: data } );
}
);
})();',
'after'
);
})();';
if ( function_exists( 'wp_add_inline_script' ) ) {
wp_add_inline_script( 'common', $script, 'after' );
return;
}
// WordPress 4.0 - 4.4 fallback.
echo '<script>' . $script . '</script>'; // phpcs:ignore WordPress.Security.EscapeOutput -- Static script with an escaped nonce.
}
/**
* Render the dismissible notice on the plugins list screen.
*/
public function render_plugins_page_notice(): void {
public function render_plugins_page_notice() {
if ( ! $this->should_show_notice() ) {
return;
}
@ -101,7 +105,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Manager_Notice' ) ) {
/**
* Render a permanent notice for the settings screen.
*/
public function render_settings_notice(): void {
public function render_settings_notice() {
$this->render_notice( 'notice-info', '' );
}
@ -111,7 +115,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Manager_Notice' ) ) {
* @param string $classes Extra CSS classes.
* @param string $id Optional DOM id for the notice container.
*/
private function render_notice( string $classes, string $id ): void {
private function render_notice( $classes, $id ) {
if ( self::is_manager_active() ) {
return;
}
@ -123,7 +127,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Manager_Notice' ) ) {
wp_kses_post(
sprintf(
/* translators: 1: Manager plugin URL, 2: link text. */
__( 'To receive updates for Telemetry (by ROBOTSTXT), the <a href="%1$s">%2$s</a> plugin must be installed and active.', 'robotstxt-telemetry' ),
__( 'To receive updates for Telemetry disabler (by ROBOTSTXT), the <a href="%1$s">%2$s</a> plugin must be installed and active.', 'robotstxt-telemetry' ),
'https://www.robotstxt.software/plugins/robotstxt-manager/',
__( 'Manager (by ROBOTSTXT)', 'robotstxt-telemetry' )
)
@ -136,7 +140,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Manager_Notice' ) ) {
*
* @return bool
*/
private function should_show_notice(): bool {
private function should_show_notice() {
if ( ! current_user_can( 'manage_options' ) ) {
return false;
}
@ -156,7 +160,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Manager_Notice' ) ) {
/**
* Persist the notice dismissal for the current user.
*/
public function handle_dismiss(): void {
public function handle_dismiss() {
check_ajax_referer( 'robotstxt_telemetry_manager_notice' );
if ( ! current_user_can( 'manage_options' ) ) {

View file

@ -0,0 +1,198 @@
<?php
/**
* Configuration mode and settings helper.
*
* On Multisite the plugin can run in two modes, controlled from the
* Network Admin by a super administrator:
*
* - "per-site" (default): every site keeps its own settings and its own
* log table, managed by each site administrator.
* - "global": one shared configuration and one central log table (on the
* main site) collect the outbound requests of the whole network.
*
* @package RobotstxtTelemetry
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! class_exists( 'Robotstxt_Telemetry_Network' ) ) {
/**
* Class Robotstxt_Telemetry_Network
*/
class Robotstxt_Telemetry_Network {
/**
* Option name storing the configuration mode.
*
* @var string
*/
const MODE_OPTION = 'robotstxt_telemetry_config_mode';
/**
* Plugin settings and their defaults.
*
* @var array
*/
const SETTINGS = array(
'robotstxt_telemetry_hash_useragent_url' => true,
'robotstxt_telemetry_wp_core_check' => 'safe',
'robotstxt_telemetry_wp_themes_check' => 'safe',
'robotstxt_telemetry_wp_plugins_check' => 'safe',
'robotstxt_telemetry_retention_period' => '12hours',
'robotstxt_telemetry_delete_on_uninstall' => false,
);
/**
* Whether the network runs in global mode.
*
* @return bool
*/
public static function is_global() {
return is_multisite() && 'global' === get_site_option( self::MODE_OPTION, 'per-site' );
}
/**
* Whether the current request is a Network Admin screen.
*
* @return bool
*/
public static function is_network_admin() {
return is_network_admin();
}
/**
* Capability required to manage the plugin on the current screen.
*
* @return string
*/
public static function manage_capability() {
return self::is_network_admin() ? 'manage_network_options' : 'manage_options';
}
/**
* Base admin URL for the current screen context.
*
* @return string
*/
public static function base_url() {
return self::is_network_admin() ? network_admin_url( 'admin.php' ) : admin_url( 'admin.php' );
}
/**
* Read a plugin setting honoring the configuration mode.
*
* @param string $name Option name.
* @param mixed $default_value Default value.
* @return mixed
*/
public static function get_setting( $name, $default_value = null ) {
if ( self::is_global() ) {
return get_site_option( $name, $default_value );
}
return get_option( $name, $default_value );
}
/**
* Write a plugin setting honoring the configuration mode.
*
* @param string $name Option name.
* @param mixed $value Value.
* @return bool
*/
public static function update_setting( $name, $value ) {
if ( self::is_global() ) {
return update_site_option( $name, $value );
}
return update_option( $name, $value );
}
/**
* Delete a plugin setting honoring the configuration mode.
*
* @param string $name Option name.
* @return bool
*/
public static function delete_setting( $name ) {
if ( self::is_global() ) {
return delete_site_option( $name );
}
return delete_option( $name );
}
/**
* The main site ID of the current network.
*
* @return int
*/
public static function main_site_id() {
if ( function_exists( 'get_main_site_id' ) ) {
return (int) get_main_site_id();
}
$current_site = get_current_site();
return max( 1, (int) $current_site->blog_id );
}
/**
* All site IDs of the network.
*
* @return int[]
*/
public static function get_site_ids() {
if ( function_exists( 'get_sites' ) ) {
$sites = get_sites(
array(
'fields' => 'ids',
'number' => 0,
)
);
return array_map( 'intval', $sites );
}
// WordPress 3.7 - 4.5 fallback.
$site_ids = array();
// phpcs:ignore WordPress.WP.DeprecatedFunctions.wp_get_sitesFound -- Only called when get_sites() is unavailable (WordPress 3.7 - 4.5).
foreach ( (array) wp_get_sites( array( 'limit' => 100000 ) ) as $site ) {
if ( ! empty( $site['blog_id'] ) ) {
$site_ids[] = (int) $site['blog_id'];
}
}
return $site_ids;
}
/**
* Sanitize the configuration mode value.
*
* @param mixed $value Raw input value.
* @return string
*/
public static function sanitize_mode( $value ) {
return 'global' === $value ? 'global' : 'per-site';
}
/**
* Seed the network settings from the main site when switching to
* global mode, so the network keeps behaving like the main site.
*
* @return void
*/
public static function seed_network_settings() {
$main_site_id = self::main_site_id();
foreach ( self::SETTINGS as $name => $default ) {
if ( false === get_site_option( $name, false ) ) {
update_site_option( $name, get_blog_option( $main_site_id, $name, $default ) );
}
}
}
}
}

View file

@ -0,0 +1,331 @@
<?php
/**
* WordPress.org API privacy filters.
*
* Applies the "safe" modes for the WordPress.org core, themes, and plugins
* update check requests, limiting the transmitted data to the minimum
* required to keep receiving updates.
*
* @package RobotstxtTelemetry
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! class_exists( 'Robotstxt_Telemetry_WordPress_Api' ) ) {
/**
* Class Robotstxt_Telemetry_WordPress_Api
*/
class Robotstxt_Telemetry_WordPress_Api {
/**
* Option name for the core version check mode.
*
* @var string
*/
const OPT_CORE = 'robotstxt_telemetry_wp_core_check';
/**
* Option name for the themes update check mode.
*
* @var string
*/
const OPT_THEMES = 'robotstxt_telemetry_wp_themes_check';
/**
* Option name for the plugins update check mode.
*
* @var string
*/
const OPT_PLUGINS = 'robotstxt_telemetry_wp_plugins_check';
/**
* Register hooks.
*/
public function register() {
add_filter( 'core_version_check_query_args', array( $this, 'filter_core_query_args' ) );
add_filter( 'http_request_args', array( $this, 'filter_request_args' ), 10, 2 );
}
/**
* Limit the core version check query arguments in safe mode.
*
* @param array $query Query arguments.
* @return array
*/
public function filter_core_query_args( $query ) {
if ( ! $this->is_safe( self::OPT_CORE ) ) {
return $query;
}
$allowed = array( 'version', 'php', 'locale', 'mysql', 'channel' );
$query = array_intersect_key( $query, array_flip( $allowed ) );
if ( isset( $query['mysql'] ) && is_string( $query['mysql'] ) ) {
// Reduce the raw server version to "x.y.z-Variant", dropping
// distribution and logging suffixes (e.g. "11.8.8-MariaDB-ubu2404-log").
$query['mysql'] = preg_replace( '/^([^-]+-[^-]+).*$/', '$1', $query['mysql'] );
}
return $query;
}
/**
* Filter update check request arguments.
*
* @param array $args HTTP request arguments.
* @param string $url Request URL.
* @return array
*/
public function filter_request_args( $args, $url ) {
$parsed = wp_parse_url( $url );
if ( ! isset( $parsed['host'] ) || 'api.wordpress.org' !== strtolower( $parsed['host'] ) ) {
return $args;
}
$path = isset( $parsed['path'] ) ? $parsed['path'] : '';
if ( 0 === stripos( $path, '/core/version-check' ) ) {
return $this->filter_core_request( $args );
}
if ( 0 === stripos( $path, '/themes/update-check' ) ) {
return $this->filter_themes_request( $args );
}
if ( 0 === stripos( $path, '/plugins/update-check' ) ) {
return $this->filter_plugins_request( $args );
}
return $args;
}
/**
* Strip site-identifying data from the core version check in safe mode.
*
* Removes the wp_install/wp_blog headers and reduces the translations
* payload to its project dates.
*
* @param array $args HTTP request arguments.
* @return array
*/
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['body']['translations'] ) && is_string( $args['body']['translations'] ) ) {
$args['body']['translations'] = $this->filter_translations( $args['body']['translations'] );
}
return $args;
}
/**
* Limit the themes update check payload in safe mode.
*
* @param array $args HTTP request arguments.
* @return array
*/
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'] ) ) {
return $args;
}
$data = json_decode( $args['body']['themes'], true );
if ( ! is_array( $data ) || empty( $data['themes'] ) || ! is_array( $data['themes'] ) ) {
return $args;
}
$themes = array();
foreach ( $data['themes'] as $stylesheet => $fields ) {
if ( is_array( $fields ) ) {
$themes[ $stylesheet ] = $this->hash_update_uri(
$this->keep_fields(
$fields,
array( 'name', 'version', 'updateuri', 'template', 'stylesheet' )
)
);
}
}
if ( empty( $themes ) ) {
return $args;
}
$args['body'] = array(
'themes' => wp_json_encode( array( 'themes' => $themes ) ),
'translations' => $this->filter_translations( $this->body_field( $args, 'translations', '' ) ),
'locale' => $this->body_field( $args, 'locale', '[]' ),
);
return $args;
}
/**
* Limit the plugins update check payload in safe mode.
*
* @param array $args HTTP request arguments.
* @return array
*/
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'] ) ) {
return $args;
}
$data = json_decode( $args['body']['plugins'], true );
if ( ! is_array( $data ) || empty( $data['plugins'] ) || ! is_array( $data['plugins'] ) ) {
return $args;
}
$plugins = array();
foreach ( $data['plugins'] as $basename => $fields ) {
if ( is_array( $fields ) ) {
$plugins[ $basename ] = $this->hash_update_uri(
$this->keep_fields(
$fields,
array( 'updateuri', 'version', 'requireswp', 'requiresphp', 'requiresplugins' )
)
);
}
}
if ( empty( $plugins ) ) {
return $args;
}
$args['body'] = array(
'plugins' => wp_json_encode( array( 'plugins' => $plugins ) ),
'translations' => $this->filter_translations( $this->body_field( $args, 'translations', '' ) ),
'locale' => $this->body_field( $args, 'locale', '[]' ),
'all' => $this->body_field( $args, 'all', 'true' ),
);
return $args;
}
/**
* 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.
* @return string
*/
private function body_field( $args, $key, $fallback_value ) {
if ( isset( $args['body'][ $key ] ) && is_string( $args['body'][ $key ] ) ) {
return $args['body'][ $key ];
}
return $fallback_value;
}
/**
* Reduce translations payloads to the translation project dates.
*
* @param string $json Encoded translations payload.
* @return string
*/
private function filter_translations( $json ) {
$data = json_decode( $json, true );
if ( ! is_array( $data ) ) {
return $json;
}
$filtered = array();
foreach ( $data as $slug => $locales ) {
if ( ! is_array( $locales ) ) {
continue;
}
foreach ( $locales as $locale => $fields ) {
if ( is_array( $fields ) ) {
$kept = $this->keep_fields( $fields, array( 'pot-creation-date', 'po-revision-date' ) );
if ( ! empty( $kept ) ) {
$filtered[ $slug ][ $locale ] = $kept;
}
}
}
}
if ( empty( $filtered ) ) {
return $json;
}
return wp_json_encode( $filtered );
}
/**
* Keep only the allowed fields of a payload entry.
*
* Matching is case-insensitive; original keys are preserved.
*
* @param array $fields Fields of the entry.
* @param array $allowed Lowercase allowed field names.
* @return array
*/
private function keep_fields( $fields, $allowed ) {
$kept = array();
foreach ( $fields as $key => $value ) {
if ( in_array( strtolower( (string) $key ), $allowed, true ) ) {
$kept[ $key ] = $value;
}
}
return $kept;
}
/**
* Hash Update URI values hosted outside wordpress.org.
*
* Update URIs pointing at wordpress.org are kept as-is (they are
* public slugs). Any other host is replaced with a deterministic
* 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
*/
private function hash_update_uri( $fields ) {
foreach ( $fields as $key => $value ) {
if ( 'updateuri' !== strtolower( (string) $key ) || ! is_string( $value ) || '' === $value ) {
continue;
}
$host = wp_parse_url( $value, PHP_URL_HOST );
if ( ! is_string( $host ) || false === strpos( strtolower( $host ), 'wordpress.org' ) ) {
$fields[ $key ] = 'https://' . substr( hash( 'sha256', $value ), 0, 16 );
}
}
return $fields;
}
/**
* Whether a check is configured to run in safe mode.
*
* @param string $option Option name.
* @return bool
*/
private function is_safe( $option ) {
return 'original' !== Robotstxt_Telemetry_Network::get_setting( $option, 'safe' );
}
}
}

View file

@ -18,7 +18,7 @@ if ( ! class_exists( 'Robotstxt_Telemetry' ) ) {
/**
* Initialize the plugin.
*/
public static function init(): void {
public static function init() {
$instance = new self();
$instance->register_hooks();
}
@ -26,9 +26,15 @@ if ( ! class_exists( 'Robotstxt_Telemetry' ) ) {
/**
* Register hooks.
*/
private function register_hooks(): void {
private function register_hooks() {
add_action( 'plugins_loaded', array( $this, 'load_textdomain' ) );
add_action( 'init', array( 'Robotstxt_Telemetry_DB', 'maybe_upgrade' ) );
add_action( 'init', array( $this, 'schedule_cleanup' ) );
add_action( 'robotstxt_telemetry_cleanup', array( 'Robotstxt_Telemetry_DB', 'cleanup' ) );
add_filter( 'http_request_args', array( $this, 'hash_useragent_url' ), 9, 2 );
$wordpress_api = new Robotstxt_Telemetry_WordPress_Api();
$wordpress_api->register();
$logger = new Robotstxt_Telemetry_Logger();
$logger->register();
@ -42,10 +48,81 @@ if ( ! class_exists( 'Robotstxt_Telemetry' ) ) {
}
}
/**
* Replace the site URL in the outbound User-Agent with a fixed hash.
*
* The default outbound User-Agent is "WordPress/<version>; <site URL>",
* and the WordPress.org update checks send an explicit one with the
* same shape. When the setting is enabled, the URL part is replaced
* with a deterministic SHA-256 hash so the site is no longer
* identifiable while staying consistent across requests.
*
* 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
*/
public function hash_useragent_url( $args, $url ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter -- Second argument required by the http_request_args filter signature.
if ( ! (bool) Robotstxt_Telemetry_Network::get_setting( 'robotstxt_telemetry_hash_useragent_url', true ) ) {
return $args;
}
$site_url = get_bloginfo( 'url' );
if ( '' === $site_url ) {
return $args;
}
$hash = substr( hash( 'sha256', $site_url ), 0, 16 );
if ( isset( $args['user-agent'] ) && is_string( $args['user-agent'] ) && false !== strpos( $args['user-agent'], $site_url ) ) {
$args['user-agent'] = str_replace( $site_url, $hash, $args['user-agent'] );
}
if ( isset( $args['headers']['User-Agent'] ) && is_string( $args['headers']['User-Agent'] ) && false !== strpos( $args['headers']['User-Agent'], $site_url ) ) {
$args['headers']['User-Agent'] = str_replace( $site_url, $hash, $args['headers']['User-Agent'] );
}
return $args;
}
/**
* Schedule the log cleanup event if it is not scheduled yet.
*
* In global mode the shared table is cleaned from the main site
* only, so subsites do not schedule the event.
*/
public function schedule_cleanup() {
if ( Robotstxt_Telemetry_Network::is_global() && ! is_main_site() ) {
return;
}
if ( ! wp_next_scheduled( 'robotstxt_telemetry_cleanup' ) ) {
wp_schedule_event( time() + HOUR_IN_SECONDS, 'twicedaily', 'robotstxt_telemetry_cleanup' );
}
}
/**
* Deactivation handler: clear the scheduled cleanup event.
*/
public static function deactivate() {
wp_clear_scheduled_hook( 'robotstxt_telemetry_cleanup' );
if ( is_multisite() ) {
foreach ( Robotstxt_Telemetry_Network::get_site_ids() as $site_id ) {
switch_to_blog( $site_id );
wp_clear_scheduled_hook( 'robotstxt_telemetry_cleanup' );
restore_current_blog();
}
}
}
/**
* Load plugin translations.
*/
public function load_textdomain(): void {
public function load_textdomain() {
load_plugin_textdomain(
'robotstxt-telemetry',
false,

View file

@ -2,21 +2,21 @@
# This file is distributed under the GPL v3 or later.
msgid ""
msgstr ""
"Project-Id-Version: Telemetry (by ROBOTSTXT) 0.2.0\n"
"Report-Msgid-Bugs-To: https://www.robotstxt.software/plugins/robotstxt-telemetry/\n"
"Project-Id-Version: Telemetry disabler (by ROBOTSTXT) 0.6.1\n"
"Report-Msgid-Bugs-To: https://www.robotstxt.software/plugins/robotstxt-telemetry/"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"POT-Creation-Date: 2026-08-18T13:23:28+00:00\n"
"POT-Creation-Date: 2026-08-18T15:14:14+00:00\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"X-Generator: WP-CLI 2.12.0\n"
"X-Domain: robotstxt-telemetry\n"
#. Plugin Name of the plugin
#: robotstxt-telemetry.php
msgid "Telemetry (by ROBOTSTXT)"
msgid "Telemetry disabler (by ROBOTSTXT)"
msgstr ""
#. Plugin URI of the plugin
@ -26,7 +26,7 @@ msgstr ""
#. Description of the plugin
#: robotstxt-telemetry.php
msgid "Logs outbound HTTP requests made by WordPress for inspection."
msgid "Reduces the telemetry WordPress sends out and logs every outbound HTTP request, so your site shares less and you can see everything."
msgstr ""
#. Author of the plugin
@ -39,103 +39,231 @@ msgstr ""
msgid "https://www.robotstxt.software/"
msgstr ""
#: includes/class-robotstxt-telemetry-admin.php:33
#: includes/class-robotstxt-telemetry-admin.php:34
msgid "Telemetry"
msgstr ""
#: includes/class-robotstxt-telemetry-admin.php:42
#: includes/class-robotstxt-telemetry-admin.php:43
#: includes/class-robotstxt-telemetry-admin.php:44
msgid "Settings"
#: includes/class-robotstxt-telemetry-admin.php:82
#: includes/class-robotstxt-telemetry-admin.php:83
msgid "Telemetry"
msgstr ""
#: includes/class-robotstxt-telemetry-admin.php:52
#: includes/class-robotstxt-telemetry-admin.php:53
#: includes/class-robotstxt-telemetry-admin.php:92
#: includes/class-robotstxt-telemetry-admin.php:93
msgid "Settings"
msgstr ""
#: includes/class-robotstxt-telemetry-admin.php:61
#: includes/class-robotstxt-telemetry-admin.php:62
#: includes/class-robotstxt-telemetry-admin.php:102
#: includes/class-robotstxt-telemetry-admin.php:103
msgid "Logs"
msgstr ""
#: includes/class-robotstxt-telemetry-admin.php:141
#: includes/class-robotstxt-telemetry-admin.php:318
msgid "Settings saved."
msgstr ""
#: includes/class-robotstxt-telemetry-admin.php:153
#: includes/class-robotstxt-telemetry-admin.php:322
msgid "Configuration mode saved."
msgstr ""
#: includes/class-robotstxt-telemetry-admin.php:338
msgid "Telemetry Network Settings"
msgstr ""
#: includes/class-robotstxt-telemetry-admin.php:348
#: includes/class-robotstxt-telemetry-admin.php:351
msgid "Configuration mode"
msgstr ""
#: includes/class-robotstxt-telemetry-admin.php:353
msgid "Per-site"
msgstr ""
#: includes/class-robotstxt-telemetry-admin.php:355
msgid "Global"
msgstr ""
#: includes/class-robotstxt-telemetry-admin.php:357
msgid "Per-site: every site keeps its own settings and its own log table, managed by each site administrator. Global: one shared configuration and one central log on the main site collect the outbound requests of the whole network; the Telemetry screens are then managed from here only."
msgstr ""
#: includes/class-robotstxt-telemetry-admin.php:363
msgid "Save configuration mode"
msgstr ""
#: includes/class-robotstxt-telemetry-admin.php:367
msgid "Switch to Global mode to manage the settings and the logs for the whole network from this screen."
msgstr ""
#: includes/class-robotstxt-telemetry-admin.php:372
msgid "Network settings"
msgstr ""
#: includes/class-robotstxt-telemetry-admin.php:395
msgid "Telemetry Settings"
msgstr ""
#: includes/class-robotstxt-telemetry-admin.php:163
#: includes/class-robotstxt-telemetry-admin.php:421
msgid "Outbound requests"
msgstr ""
#: includes/class-robotstxt-telemetry-admin.php:425
msgid "Hash the site URL in the User-Agent of outbound requests"
msgstr ""
#: includes/class-robotstxt-telemetry-admin.php:427
msgid "Outbound requests normally identify this site with its URL (for example \"WordPress/6.9; https://example.com/\"). When enabled, the URL is replaced with a fixed hash so the site is no longer identifiable."
msgstr ""
#: includes/class-robotstxt-telemetry-admin.php:433
msgid "WordPress Core version check"
msgstr ""
#: includes/class-robotstxt-telemetry-admin.php:434
msgid "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."
msgstr ""
#: includes/class-robotstxt-telemetry-admin.php:437
msgid "WordPress Themes version check"
msgstr ""
#: includes/class-robotstxt-telemetry-admin.php:438
msgid "Safe sends only the theme name, version, update URI, template, and stylesheet, plus translation dates and locale. Original also sends author details and other theme metadata."
msgstr ""
#: includes/class-robotstxt-telemetry-admin.php:441
msgid "WordPress Plugins version check"
msgstr ""
#: includes/class-robotstxt-telemetry-admin.php:442
msgid "Safe sends only the plugin version, update URI, and requirements, plus translation dates, locale, and the \"all\" flag. Original also sends names, descriptions, authors, and other plugin metadata."
msgstr ""
#: includes/class-robotstxt-telemetry-admin.php:454
msgid "Original"
msgstr ""
#: includes/class-robotstxt-telemetry-admin.php:456
msgid "Safe"
msgstr ""
#: includes/class-robotstxt-telemetry-admin.php:467
#: includes/class-robotstxt-telemetry-admin.php:469
msgid "Log retention"
msgstr ""
#: includes/class-robotstxt-telemetry-admin.php:473
msgid "12 hours"
msgstr ""
#: includes/class-robotstxt-telemetry-admin.php:474
msgid "1 day"
msgstr ""
#: includes/class-robotstxt-telemetry-admin.php:475
msgid "3 days"
msgstr ""
#: includes/class-robotstxt-telemetry-admin.php:488
msgid "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."
msgstr ""
#: includes/class-robotstxt-telemetry-admin.php:493
msgid "Uninstall behavior"
msgstr ""
#: includes/class-robotstxt-telemetry-admin.php:167
#: includes/class-robotstxt-telemetry-admin.php:497
msgid "Delete all telemetry logs and plugin options on uninstall"
msgstr ""
#: includes/class-robotstxt-telemetry-admin.php:169
#: includes/class-robotstxt-telemetry-admin.php:499
msgid "By default, all telemetry logs are preserved when the plugin is uninstalled."
msgstr ""
#: includes/class-robotstxt-telemetry-admin.php:194
#: includes/class-robotstxt-telemetry-admin.php:522
msgid "Telemetry Logs"
msgstr ""
#: includes/class-robotstxt-telemetry-admin.php:205
#: includes/class-robotstxt-telemetry-admin.php:542
msgid "All log entries deleted."
msgstr ""
#: includes/class-robotstxt-telemetry-admin.php:544
msgid "Log entry deleted."
msgstr ""
#: includes/class-robotstxt-telemetry-admin.php:227
#: includes/class-robotstxt-telemetry-admin.php:558
msgid "Delete all logs"
msgstr ""
#: includes/class-robotstxt-telemetry-admin.php:576
msgid "You are about to permanently delete all telemetry log entries. This action cannot be undone."
msgstr ""
#: includes/class-robotstxt-telemetry-admin.php:584
msgid "Yes, delete all logs"
msgstr ""
#: includes/class-robotstxt-telemetry-admin.php:585
msgid "Cancel"
msgstr ""
#: includes/class-robotstxt-telemetry-admin.php:598
msgid "Log entry not found."
msgstr ""
#: includes/class-robotstxt-telemetry-admin.php:231
#: includes/class-robotstxt-telemetry-admin.php:602
msgid "Back to logs"
msgstr ""
#: includes/class-robotstxt-telemetry-admin.php:235
#: includes/class-robotstxt-telemetry-admin.php:606
#: includes/class-robotstxt-telemetry-logs-table.php:49
msgid "Date"
msgstr ""
#: includes/class-robotstxt-telemetry-admin.php:236
#: includes/class-robotstxt-telemetry-admin.php:607
#: includes/class-robotstxt-telemetry-logs-table.php:50
msgid "Method"
msgstr ""
#: includes/class-robotstxt-telemetry-admin.php:237
#: includes/class-robotstxt-telemetry-admin.php:608
msgid "URL"
msgstr ""
#: includes/class-robotstxt-telemetry-admin.php:238
#: includes/class-robotstxt-telemetry-admin.php:609
#: includes/class-robotstxt-telemetry-logs-table.php:51
#: includes/class-robotstxt-telemetry-logs-table.php:330
#: includes/class-robotstxt-telemetry-logs-table.php:318
msgid "Host"
msgstr ""
#: includes/class-robotstxt-telemetry-admin.php:239
#: includes/class-robotstxt-telemetry-admin.php:610
#: includes/class-robotstxt-telemetry-logs-table.php:52
msgid "Path"
msgstr ""
#: includes/class-robotstxt-telemetry-admin.php:240
#: includes/class-robotstxt-telemetry-admin.php:611
msgid "Body Params"
msgstr ""
#: includes/class-robotstxt-telemetry-admin.php:241
#: includes/class-robotstxt-telemetry-admin.php:612
msgid "Headers"
msgstr ""
#: includes/class-robotstxt-telemetry-admin.php:242
#: includes/class-robotstxt-telemetry-admin.php:613
msgid "User Agent"
msgstr ""
#: includes/class-robotstxt-telemetry-admin.php:243
#: includes/class-robotstxt-telemetry-admin.php:614
msgid "Raw Body"
msgstr ""
#: includes/class-robotstxt-telemetry-admin.php:244
#: includes/class-robotstxt-telemetry-admin.php:615
msgid "Caller"
msgstr ""
#: includes/class-robotstxt-telemetry-admin.php:264
#: includes/class-robotstxt-telemetry-admin.php:635
msgid "Telemetry Analysis"
msgstr ""
@ -176,48 +304,48 @@ msgstr ""
msgid "Body Parameters"
msgstr ""
#: includes/class-robotstxt-telemetry-logs-table.php:182
#: includes/class-robotstxt-telemetry-logs-table.php:170
msgid "View"
msgstr ""
#: includes/class-robotstxt-telemetry-logs-table.php:183
#: includes/class-robotstxt-telemetry-logs-table.php:171
msgid "Delete"
msgstr ""
#: includes/class-robotstxt-telemetry-logs-table.php:310
#: includes/class-robotstxt-telemetry-logs-table.php:298
msgid "Filter by method"
msgstr ""
#: includes/class-robotstxt-telemetry-logs-table.php:312
#: includes/class-robotstxt-telemetry-logs-table.php:300
msgid "All methods"
msgstr ""
#: includes/class-robotstxt-telemetry-logs-table.php:326
#: includes/class-robotstxt-telemetry-logs-table.php:314
msgid "Filter by host"
msgstr ""
#: includes/class-robotstxt-telemetry-logs-table.php:333
#: includes/class-robotstxt-telemetry-logs-table.php:321
msgid "From date"
msgstr ""
#: includes/class-robotstxt-telemetry-logs-table.php:339
#: includes/class-robotstxt-telemetry-logs-table.php:327
msgid "To date"
msgstr ""
#: includes/class-robotstxt-telemetry-logs-table.php:345
#: includes/class-robotstxt-telemetry-logs-table.php:333
msgid "Filter"
msgstr ""
#. translators: 1: Manager plugin URL, 2: link text.
#: includes/class-robotstxt-telemetry-manager-notice.php:126
#: includes/class-robotstxt-telemetry-manager-notice.php:130
#, php-format
msgid "To receive updates for Telemetry (by ROBOTSTXT), the <a href=\"%1$s\">%2$s</a> plugin must be installed and active."
msgid "To receive updates for Telemetry disabler (by ROBOTSTXT), the <a href=\"%1$s\">%2$s</a> plugin must be installed and active."
msgstr ""
#: includes/class-robotstxt-telemetry-manager-notice.php:128
#: includes/class-robotstxt-telemetry-manager-notice.php:132
msgid "Manager (by ROBOTSTXT)"
msgstr ""
#: includes/class-robotstxt-telemetry-manager-notice.php:163
#: includes/class-robotstxt-telemetry-manager-notice.php:167
msgid "You do not have sufficient permissions to perform this action."
msgstr ""

View file

@ -1,43 +1,67 @@
=== Telemetry (by ROBOTSTXT) ===
=== Telemetry disabler (by ROBOTSTXT) ===
Contributors: robotstxt, javiercasares
Tags: telemetry, http, logging, debug, requests
Requires at least: 6.2
Tags: telemetry, privacy, http, requests, logging
Requires at least: 4.0
Tested up to: 7.1
Stable tag: 0.2.0
Requires PHP: 7.4
Version: 0.2.0
Stable tag: 0.6.1
Requires PHP: 5.6
Version: 0.6.1
License: GPL-3.0-or-later
License URI: https://www.gnu.org/licenses/gpl-3.0.txt
Logs outbound HTTP requests made by WordPress for inspection.
Reduces the telemetry WordPress sends out and logs every outbound HTTP request, so your site shares less and you can see everything.
== Description ==
Telemetry (by ROBOTSTXT) records the external HTTP requests that WordPress (and its plugins and themes) performs through the WordPress HTTP API, so they can be inspected from the administration panel.
A WordPress site talks to the outside world all the time: update checks for core, plugins and themes, and every HTTP call made by the ecosystem around them. Each of those calls can expose details about your site: its URL, versions, active plugins and themes, database server, PHP extensions, and more.
For every outbound call, the plugin stores the request method, full URL, host and path, query parameters, body parameters or raw body, sanitized request headers, user agent, and the caller backtrace summary. Sensitive values (authorization headers, passwords, tokens, API keys, secrets, nonces) are automatically redacted before storing, and all payloads are size-limited to keep the database lean.
Telemetry disabler (by ROBOTSTXT) gives you control over that conversation in two ways: it sends less, and it shows you everything.
The Logs screen provides a paginated list with filters by method, host, and date range, a detailed single-entry view, and nonce-protected delete actions. Entries pointing to `api.wordpress.org` get a dedicated analysis view that groups environment, extensions, platform, and image support parameters.
= Send less =
Updates for this plugin are delivered through the [Manager (by ROBOTSTXT)](https://www.robotstxt.software/plugins/robotstxt-manager/) plugin. If the Manager is not active, the plugin shows a dismissible reminder in the plugins list and a permanent notice on its Settings screen.
The three WordPress.org update checks run in "Safe" mode by default, meaning they only send the minimum data required to keep receiving updates:
* **Core version check** (`api.wordpress.org/core/version-check/`): only the WordPress version, PHP version, locale, normalized MySQL/MariaDB version (for example "11.8.8-MariaDB", without distribution or logging suffixes), and update channel. Site counts, database history, PHP extensions and platform details are removed, the site-identifying `wp_install`/`wp_blog` headers are stripped, and translation payloads are reduced to their project dates (no `Project-Id-Version` or `X-Generator` metadata).
* **Themes version check** (`api.wordpress.org/themes/update-check/`): each theme is reported with only its name, version, update URI, template and stylesheet; translations are reduced to their project dates, plus the site locale.
* **Plugins version check** (`api.wordpress.org/plugins/update-check/`): each plugin is reported with only its version, update URI and requirements (WordPress, PHP, dependent plugins); translations are reduced to their project dates, plus the locale and the "all" flag.
* Update URIs pointing at wordpress.org are kept as-is (they are public slugs); update URIs hosted anywhere else are replaced with a deterministic hash, so external plugin and theme sources are not disclosed.
Each check can be switched back to "Original" in the Settings screen to send exactly what WordPress would send without this plugin.
Additionally, outbound requests normally identify the site in the User-Agent header (for example "WordPress/6.9; https://example.com/"). With the "Hash the site URL in the User-Agent" setting (enabled by default), the URL is replaced with a fixed hash so the site is no longer identifiable while remaining consistent across requests.
= See everything =
Every outbound HTTP request made through the WordPress HTTP API is recorded in the site's own database: request method, full URL, host and path, query parameters, body parameters or raw body, sanitized request headers, user agent, and a caller backtrace summary to know which component triggered the call.
The Logs screen provides a paginated list with filters by method, host and date range, a detailed single-entry view, and nonce-protected delete actions. Entries pointing to `api.wordpress.org` get a dedicated analysis view that groups environment, extensions, platform, and image support parameters.
= Privacy by default =
* Sensitive keys (`authorization`, `password`, `pass`, `token`, `secret`, `api_key`, `apikey`, `nonce`) are redacted before anything is written to the database.
* Credentials embedded in URLs are stripped, and query strings are stored redacted.
* Payloads are truncated (64 KB per JSON blob, 64 KB raw body, 16 KB caller trace).
* Log retention is configurable (12 hours by default, 1 day, or 3 days), a maximum of 1000 entries is always enforced, and the cleanup runs when browsing the logs and twice a day automatically.
* Logs are only accessible to administrators (`manage_options`).
* No data ever leaves the site; logs are stored in the site's own database.
On Multisite, the network administrator chooses between two modes in **Network Admin → Telemetry**: "Per-site" (default), where every site keeps its own settings and its own log table managed by each site administrator, or "Global", where one shared configuration and one central log table (on the main site) collect the outbound requests of the whole network, managed from the Network Admin only.
Updates for this plugin are delivered through the [Manager (by ROBOTSTXT)](https://www.robotstxt.software/plugins/robotstxt-manager/) plugin. If the Manager is not active, the plugin shows a dismissible reminder in the plugins list and a permanent notice on its Settings screen.
== Using the plugin ==
= Logs =
Navigate to **Telemetry → Logs**. Use the method, host, and date filters to narrow the list, then click **View** on any entry to see its full details, or **Delete** to remove it.
Navigate to **Telemetry → Logs**. Use the method, host and date filters to narrow the list, then click **View** on any entry to see its full details, or **Delete** to remove it. The **Delete all logs** button requires a second confirmation before permanently removing every entry.
= Settings =
Navigate to **Telemetry → Settings**. The "Delete all telemetry logs and plugin options on uninstall" checkbox controls the uninstall behavior: unchecked by default, so all telemetry data is preserved when the plugin is removed. When the Manager (by ROBOTSTXT) plugin is not active, a permanent notice about updates is shown on this screen.
Navigate to **Telemetry → Settings**. The three WordPress.org update checks (Core, Themes, Plugins) can run in "Safe" mode (default, limited data) or "Original" mode (unchanged WordPress behavior). "Hash the site URL in the User-Agent of outbound requests" (enabled by default) replaces the site URL in outbound User-Agent headers with a fixed hash. "Log retention" controls how long entries are kept (12 hours by default, 1 day, or 3 days). The "Delete all telemetry logs and plugin options on uninstall" checkbox controls the uninstall behavior: unchecked by default, so all telemetry data is preserved when the plugin is removed. When the Manager (by ROBOTSTXT) plugin is not active, a permanent notice about updates is shown on this screen.
= Multisite =
Navigate to **Network Admin → Telemetry**. The "Configuration mode" setting controls how the plugin runs: "Per-site" (default) lets every site manage its own Settings and Logs screens, while "Global" centralizes the configuration and the logs of the whole network on the main site, managed from the Network Admin only. When switching to Global, the network settings start from the main site values.
== Extra Configurations ==
@ -47,7 +71,7 @@ This plugin does not require any `define()` in `wp-config.php`.
= Automatic download =
Visit the plugin section in your WordPress, search for "Telemetry (by ROBOTSTXT)"; download and install the plugin.
Visit the plugin section in your WordPress, search for "Telemetry disabler (by ROBOTSTXT)"; download and install the plugin.
= Manual download =
@ -55,9 +79,21 @@ Extract the contents of the ZIP and upload the contents to the `/wp-content/plug
== Frequently Asked Questions ==
= Does the plugin stop WordPress updates from working? =
No. Safe mode keeps the minimum data the WordPress.org APIs need to deliver updates: what you have installed and at which version. Everything else (site counts, environment details, site-identifying headers, translation metadata) is removed.
= What is the difference between "Safe" and "Original" modes? =
"Safe" (default) sends only the minimum data required to keep receiving updates. "Original" sends exactly what WordPress would send without this plugin. You can switch each of the Core, Themes and Plugins checks independently.
= How does the plugin work on Multisite? =
By default every site manages its own settings and logs ("Per-site" mode). A super administrator can switch the network to "Global" mode in **Network Admin → Telemetry**: one shared configuration and one central log table on the main site then cover the whole network, and the per-site Telemetry screens are replaced by the Network Admin ones.
= Does the plugin send any data anywhere? =
No. The plugin only records outbound HTTP requests in the site's own database for local inspection. Nothing is transmitted to third parties.
No. The plugin only records outbound HTTP requests in the site's own database for local inspection, and reduces what WordPress sends to third parties. Nothing is transmitted by the plugin itself.
= Where is the data stored? =
@ -73,31 +109,31 @@ Install and activate the [Manager (by ROBOTSTXT)](https://www.robotstxt.software
== Compatibility ==
* WordPress: 6.2 - 7.1
* PHP: 7.4 - 8.5
* WordPress: 4.0 - 7.1
* PHP: 5.6 - 8.5
* MariaDB: 10.6+
* Multisite: compatible (`Network: true`)
* Multisite: compatible (Per-site and Global modes)
On WordPress versions older than 5.1, the Core update check Safe mode cannot reduce the query arguments (the needed hook does not exist in those versions); the site-identifying headers and the translations payload are still reduced.
== Changelog ==
Only the 3 last versions. The full changelog will be at changelog.txt
= 0.2.0 =
= 0.6.1 =
* Added: Settings screen with uninstall behavior option (data preserved by default)
* Added: Manager (by ROBOTSTXT) dependency notice, dismissible in the plugins list and permanent in Settings
* Added: `uninstall.php` routine honoring the delete-data option, Multisite aware
* Added: `bin/deploy.sh` distributable packaging script
* Changed: minimum requirements lowered to WordPress 6.2 and PHP 7.4
* Changed: Plugin, author, and update URLs moved to robotstxt.software
* Removed: bundled self-updater (`robotstxt-updater.php`, `update.json`) in favor of the Manager plugin
* Security: query strings and credentials in URLs are redacted before storing
* Fixed: query parameters were not stored due to a discarded `wp_parse_args()` return value
* Fixed: UTF-8 scrubbing no longer discards whole payloads
* Changed: minimum requirements lowered to WordPress 4.0 and PHP 5.6, with compatibility fallbacks for older WordPress APIs
* Fixed: duplicated "Save Changes" button on the Settings screen
* Changed: plugin renamed to "Telemetry disabler (by ROBOTSTXT)" with a new description
= 0.1.0 =
= 0.6.0 =
* Initial release: outbound HTTP logging with custom table, Logs admin screen with filters, pagination, view and delete actions, and secret redaction
* Added: Multisite configuration mode (Per-site by default, Global from the Network Admin) to run the settings and logs per site or centrally for the whole network
= 0.5.0 =
* Added: log retention setting (12 hours by default, 1 day, 3 days) with a 1000-entry cap, cleanup when browsing the logs and via a twice-daily cron
* Added: "Delete all logs" button with a double confirmation step
= Previous versions =

View file

@ -1,16 +1,16 @@
<?php
/**
* Plugin Name: Telemetry (by ROBOTSTXT)
* Plugin Name: Telemetry disabler (by ROBOTSTXT)
* Plugin URI: https://www.robotstxt.software/plugins/robotstxt-telemetry/
* Update URI: https://www.robotstxt.software/plugins/robotstxt-telemetry/
* Description: Logs outbound HTTP requests made by WordPress for inspection.
* Version: 0.2.0
* Description: Reduces the telemetry WordPress sends out and logs every outbound HTTP request, so your site shares less and you can see everything.
* Version: 0.6.1
* Author: ROBOTSTXT
* Author URI: https://www.robotstxt.software/
* Text Domain: robotstxt-telemetry
* Domain Path: /languages
* Requires at least: 6.2
* Requires PHP: 7.4
* Requires at least: 4.0
* Requires PHP: 5.6
* Tested up to: 7.1
* Network: true
* License: GPL v3 or later
@ -23,19 +23,48 @@ if ( ! defined( 'ABSPATH' ) ) {
exit;
}
define( 'ROBOTSTXT_TELEMETRY_VERSION', '0.2.0' );
define( 'ROBOTSTXT_TELEMETRY_VERSION', '0.6.1' );
define( 'ROBOTSTXT_TELEMETRY_DB_VERSION', '1.1.0' );
define( 'ROBOTSTXT_TELEMETRY_PLUGIN_FILE', __FILE__ );
define( 'ROBOTSTXT_TELEMETRY_PLUGIN_DIR', __DIR__ );
require_once ROBOTSTXT_TELEMETRY_PLUGIN_DIR . '/includes/class-robotstxt-telemetry-network.php';
require_once ROBOTSTXT_TELEMETRY_PLUGIN_DIR . '/includes/class-robotstxt-telemetry-db.php';
require_once ROBOTSTXT_TELEMETRY_PLUGIN_DIR . '/includes/class-robotstxt-telemetry-logger.php';
require_once ROBOTSTXT_TELEMETRY_PLUGIN_DIR . '/includes/class-robotstxt-telemetry-admin.php';
require_once ROBOTSTXT_TELEMETRY_PLUGIN_DIR . '/includes/class-robotstxt-telemetry-manager-notice.php';
require_once ROBOTSTXT_TELEMETRY_PLUGIN_DIR . '/includes/class-robotstxt-telemetry-wordpress-api.php';
require_once ROBOTSTXT_TELEMETRY_PLUGIN_DIR . '/includes/class-robotstxt-telemetry-analysis.php';
require_once ROBOTSTXT_TELEMETRY_PLUGIN_DIR . '/includes/class-robotstxt-telemetry-analysis-api-wordpress-org.php';
require_once ROBOTSTXT_TELEMETRY_PLUGIN_DIR . '/includes/class-robotstxt-telemetry.php';
register_activation_hook( __FILE__, array( 'Robotstxt_Telemetry_DB', 'activate' ) );
register_deactivation_hook( __FILE__, array( 'Robotstxt_Telemetry', 'deactivate' ) );
if ( ! function_exists( 'wp_json_encode' ) ) {
/**
* Encode a JSON string (compatibility shim for WordPress 4.0).
*
* @param mixed $data Data to encode.
* @param int $options JSON encode flags.
* @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.
}
}
if ( ! function_exists( 'wp_parse_url' ) ) {
/**
* Parse a URL (compatibility shim for WordPress 4.0 - 4.3).
*
* @param string $url The URL to parse.
* @param int $component The specific component to retrieve.
* @return mixed
*/
function wp_parse_url( $url, $component = -1 ) {
return parse_url( $url, $component ); // phpcs:ignore WordPress.WP.AlternativeFunctions.parse_url_parse_url -- Native call is the purpose of this compatibility shim for WordPress 4.0 - 4.3.
}
}
Robotstxt_Telemetry::init();

View file

@ -6,6 +6,9 @@
* "Delete all telemetry logs on uninstall" setting, the logs table and plugin
* options are removed.
*
* On Multisite in global mode the delete-data setting is a network option and
* the uninstall routine covers every site plus the shared network options.
*
* @package RobotstxtTelemetry
*/
@ -13,36 +16,17 @@ if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
exit;
}
$robotstxt_telemetry_delete_data = (bool) get_option( 'robotstxt_telemetry_delete_on_uninstall', false );
$robotstxt_telemetry_is_global = is_multisite() && 'global' === get_site_option( 'robotstxt_telemetry_config_mode', 'per-site' );
$robotstxt_telemetry_delete_data = $robotstxt_telemetry_is_global
? (bool) get_site_option( 'robotstxt_telemetry_delete_on_uninstall', false )
: (bool) get_option( 'robotstxt_telemetry_delete_on_uninstall', false );
// Remove per-user manager notice dismissals (user meta is global).
delete_metadata( 'user', 0, 'robotstxt_telemetry_manager_notice_dismissed', '', true );
if ( ! $robotstxt_telemetry_delete_data ) {
// Keep all log data. Only remove the plugin options.
delete_option( 'robotstxt_telemetry_delete_on_uninstall' );
delete_option( 'robotstxt_telemetry_db_version' );
return;
}
/**
* Delete telemetry data for the current site.
*
* @return void
*/
function robotstxt_telemetry_uninstall_site(): void {
global $wpdb;
$table_name = $wpdb->prefix . 'robotstxt_telemetry_logs';
$wpdb->query( $wpdb->prepare( 'DROP TABLE IF EXISTS %i', $table_name ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery, WordPress.DB.DirectDatabaseQuery.SchemaChange, WordPress.DB.DirectDatabaseQuery.NoCaching
delete_option( 'robotstxt_telemetry_delete_on_uninstall' );
delete_option( 'robotstxt_telemetry_db_version' );
}
// Clear the scheduled cleanup event on every site.
wp_clear_scheduled_hook( 'robotstxt_telemetry_cleanup' );
if ( is_multisite() ) {
$robotstxt_telemetry_site_ids = get_sites(
if ( function_exists( 'get_sites' ) ) {
$robotstxt_telemetry_uninstall_sites = get_sites(
array(
'fields' => 'ids',
'number' => 0,
@ -50,15 +34,80 @@ if ( is_multisite() ) {
'update_archived_cache' => false,
)
);
} else {
// WordPress 3.7 - 4.5 fallback.
$robotstxt_telemetry_uninstall_sites = array();
foreach ( $robotstxt_telemetry_site_ids as $robotstxt_telemetry_site_id ) {
switch_to_blog( $robotstxt_telemetry_site_id );
robotstxt_telemetry_uninstall_site();
// phpcs:ignore WordPress.WP.DeprecatedFunctions.wp_get_sitesFound -- Only called when get_sites() is unavailable (WordPress 3.7 - 4.5).
foreach ( (array) wp_get_sites( array( 'limit' => 100000 ) ) as $robotstxt_telemetry_uninstall_site ) {
if ( ! empty( $robotstxt_telemetry_uninstall_site['blog_id'] ) ) {
$robotstxt_telemetry_uninstall_sites[] = (int) $robotstxt_telemetry_uninstall_site['blog_id'];
}
}
}
foreach ( $robotstxt_telemetry_uninstall_sites as $robotstxt_telemetry_uninstall_id ) {
switch_to_blog( $robotstxt_telemetry_uninstall_id );
wp_clear_scheduled_hook( 'robotstxt_telemetry_cleanup' );
restore_current_blog();
}
} else {
robotstxt_telemetry_uninstall_site();
}
// Remove per-user manager notice dismissals (user meta is global).
delete_metadata( 'user', 0, 'robotstxt_telemetry_manager_notice_dismissed', '', true );
/**
* Delete the plugin options (and the logs table when requested) for a site.
*
* @param bool|null $force_drop Whether to drop the table, or null to use the
* site's own delete-data option.
* @return void
*/
function robotstxt_telemetry_uninstall_site( $force_drop = null ) {
global $wpdb;
$drop = null === $force_drop ? (bool) get_option( 'robotstxt_telemetry_delete_on_uninstall', false ) : $force_drop;
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
}
delete_option( 'robotstxt_telemetry_delete_on_uninstall' );
delete_option( 'robotstxt_telemetry_hash_useragent_url' );
delete_option( 'robotstxt_telemetry_wp_core_check' );
delete_option( 'robotstxt_telemetry_wp_themes_check' );
delete_option( 'robotstxt_telemetry_wp_plugins_check' );
delete_option( 'robotstxt_telemetry_retention_period' );
delete_option( 'robotstxt_telemetry_db_version' );
}
/**
* Delete the shared network options (Multisite in global mode).
*
* @return void
*/
function robotstxt_telemetry_uninstall_network() {
delete_site_option( 'robotstxt_telemetry_config_mode' );
delete_site_option( 'robotstxt_telemetry_delete_on_uninstall' );
delete_site_option( 'robotstxt_telemetry_hash_useragent_url' );
delete_site_option( 'robotstxt_telemetry_wp_core_check' );
delete_site_option( 'robotstxt_telemetry_wp_themes_check' );
delete_site_option( 'robotstxt_telemetry_wp_plugins_check' );
delete_site_option( 'robotstxt_telemetry_retention_period' );
}
if ( is_multisite() ) {
// In global mode the network-wide flag decides; per-site, each site's own option does.
$robotstxt_telemetry_drop_flag = $robotstxt_telemetry_is_global ? $robotstxt_telemetry_delete_data : null;
foreach ( $robotstxt_telemetry_uninstall_sites as $robotstxt_telemetry_uninstall_id ) {
switch_to_blog( $robotstxt_telemetry_uninstall_id );
robotstxt_telemetry_uninstall_site( $robotstxt_telemetry_drop_flag );
restore_current_blog();
}
robotstxt_telemetry_uninstall_network();
} else {
robotstxt_telemetry_uninstall_site();
}