This commit is contained in:
Javier Casares 2026-08-18 19:06:22 +00:00
commit 7ae471e27f

View file

@ -47,24 +47,33 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Admin' ) ) {
'dashicons-admin-generic'
);
add_submenu_page(
'robotstxt-telemetry',
__( 'Settings', 'robotstxt-telemetry' ),
__( 'Settings', 'robotstxt-telemetry' ),
'manage_options',
'robotstxt-telemetry',
array( $this, 'render_settings_page' )
);
add_submenu_page(
'robotstxt-telemetry',
__( 'Settings', 'robotstxt-telemetry' ),
__( 'Settings', 'robotstxt-telemetry' ),
'manage_options',
'robotstxt-telemetry',
array( $this, 'render_settings_page' )
);
add_submenu_page(
'robotstxt-telemetry',
__( 'Logs', 'robotstxt-telemetry' ),
__( 'Logs', 'robotstxt-telemetry' ),
'manage_options',
'robotstxt-telemetry-logs',
array( $this, 'render_logs_page' )
);
}
add_submenu_page(
'robotstxt-telemetry',
__( 'Plugins', 'robotstxt-telemetry' ),
__( 'Plugins', 'robotstxt-telemetry' ),
'manage_options',
'robotstxt-telemetry-plugins',
array( $this, 'render_plugins_page' )
);
add_submenu_page(
'robotstxt-telemetry',
__( 'Logs', 'robotstxt-telemetry' ),
__( 'Logs', 'robotstxt-telemetry' ),
'manage_options',
'robotstxt-telemetry-logs',
array( $this, 'render_logs_page' )
);
}
/**
* Register the Network Admin menus (Multisite only).
@ -87,16 +96,25 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Admin' ) ) {
'dashicons-admin-generic'
);
add_submenu_page(
'robotstxt-telemetry',
__( 'Settings', 'robotstxt-telemetry' ),
__( 'Settings', 'robotstxt-telemetry' ),
'manage_network_options',
'robotstxt-telemetry',
array( $this, 'render_network_settings_page' )
);
add_submenu_page(
'robotstxt-telemetry',
__( 'Settings', 'robotstxt-telemetry' ),
__( 'Settings', 'robotstxt-telemetry' ),
'manage_network_options',
'robotstxt-telemetry',
array( $this, 'render_network_settings_page' )
);
if ( Robotstxt_Telemetry_Network::is_global() ) {
add_submenu_page(
'robotstxt-telemetry',
__( 'Plugins', 'robotstxt-telemetry' ),
__( 'Plugins', 'robotstxt-telemetry' ),
'manage_network_options',
'robotstxt-telemetry-plugins',
array( $this, 'render_plugins_page' )
);
if ( Robotstxt_Telemetry_Network::is_global() ) {
add_submenu_page(
'robotstxt-telemetry',
__( 'Logs', 'robotstxt-telemetry' ),
@ -245,6 +263,13 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Admin' ) ) {
return;
}
if ( 'save_plugin_modes' === $action ) {
if ( 'robotstxt-telemetry-plugins' === $page ) {
$this->handle_plugin_modes_save();
}
return;
}
if ( 'robotstxt-telemetry-logs' !== $page ) {
return;
}
@ -733,6 +758,136 @@ if ( ! class_exists( 'Robotstxt_Telemetry_Admin' ) ) {
echo '</table>';
}
/**
* Render the Plugins page.
*/
public function render_plugins_page() {
$capability = Robotstxt_Telemetry_Network::is_global() ? 'manage_network_options' : Robotstxt_Telemetry_Network::manage_capability();
if ( ! current_user_can( $capability ) ) {
return;
}
if ( ! function_exists( 'get_plugins' ) ) {
require_once ABSPATH . 'wp-admin/includes/plugin.php';
}
$installed = get_plugins();
$profiles = Robotstxt_Telemetry_Plugin_Profiles::get_profiles();
$tested = Robotstxt_Telemetry_Plugin_Profiles::tested_versions();
$modes = Robotstxt_Telemetry_Network::get_plugin_modes();
$supported = array();
foreach ( $installed as $basename => $data ) {
$slug = dirname( $basename );
if ( isset( $profiles[ $slug ] ) && '.' !== $slug ) {
$supported[ $basename ] = $data;
}
}
?>
<div class="wrap">
<h1><?php esc_html_e( 'Telemetry - Plugins', 'robotstxt-telemetry' ); ?></h1>
<?php if ( isset( $_GET['updated'] ) ) : // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Read-only success flag. ?>
<div class="notice notice-success is-dismissible"><p><?php esc_html_e( 'Plugin modes saved.', 'robotstxt-telemetry' ); ?></p></div>
<?php endif; ?>
<p><?php esc_html_e( 'Every installed plugin with a known telemetry behavior is listed below. In Safe mode the known telemetry endpoints are blocked or reduced to the minimum data each service needs to work; in Original mode the plugin behaves exactly as it would without Telemetry disabler. The tested version is the plugin version the Safe profile was verified against.', 'robotstxt-telemetry' ); ?></p>
<form method="post" action="">
<input type="hidden" name="action" value="save_plugin_modes" />
<?php wp_nonce_field( 'robotstxt_telemetry_plugin_modes' ); ?>
<table class="widefat striped robotstxt-telemetry-plugin-modes" style="border: 1px solid #c3c4c7;">
<thead>
<tr>
<th scope="col"><?php esc_html_e( 'Safe Mode', 'robotstxt-telemetry' ); ?></th>
<th scope="col"><?php esc_html_e( 'Plugin', 'robotstxt-telemetry' ); ?></th>
<th scope="col"><?php esc_html_e( 'Actual version', 'robotstxt-telemetry' ); ?></th>
<th scope="col"><?php esc_html_e( 'Tested version', 'robotstxt-telemetry' ); ?></th>
<th scope="col"><?php esc_html_e( 'Description', 'robotstxt-telemetry' ); ?></th>
</tr>
</thead>
<tbody>
<?php foreach ( $supported as $basename => $data ) : ?>
<?php
$slug = dirname( $basename );
$mode = isset( $modes[ $slug ] ) && 'original' === $modes[ $slug ] ? 'original' : 'safe';
$name = isset( $data['Name'] ) && '' !== $data['Name'] ? $data['Name'] : $basename;
$actual = isset( $data['Version'] ) ? $data['Version'] : '';
$version = isset( $tested[ $slug ] ) ? $tested[ $slug ] : '';
$note = $profiles[ $slug ]['note'];
?>
<tr>
<td>
<input type="checkbox" name="robotstxt_telemetry_plugin_modes[<?php echo esc_attr( $slug ); ?>]" value="safe" aria-label="<?php echo esc_attr( sprintf( /* translators: %s: Plugin name. */ __( 'Safe Mode for %s', 'robotstxt-telemetry' ), $name ) ); ?>"<?php checked( $mode, 'safe' ); ?> />
<span class="screen-reader-text"><?php echo esc_html( sprintf( /* translators: %s: Plugin name. */ __( 'Safe Mode for %s', 'robotstxt-telemetry' ), $name ) ); ?></span>
</td>
<td><strong><?php echo esc_html( $name ); ?></strong></td>
<td><?php echo esc_html( $actual ); ?></td>
<td><?php echo esc_html( $version ); ?></td>
<td><?php echo esc_html( $note ); ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php submit_button( __( 'Save plugin modes', 'robotstxt-telemetry' ) ); ?>
</form>
</div>
<?php
}
/**
* Save the per-plugin safe-mode settings.
*/
private function handle_plugin_modes_save() {
check_admin_referer( 'robotstxt_telemetry_plugin_modes' );
if ( ! function_exists( 'get_plugins' ) ) {
require_once ABSPATH . 'wp-admin/includes/plugin.php';
}
$posted = isset( $_POST['robotstxt_telemetry_plugin_modes'] ) && is_array( $_POST['robotstxt_telemetry_plugin_modes'] ) ? wp_unslash( $_POST['robotstxt_telemetry_plugin_modes'] ) : array(); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- Each value is whitelisted below.
$profiles = Robotstxt_Telemetry_Plugin_Profiles::get_profiles();
$modes = array();
$installed = get_plugins();
foreach ( $posted as $slug => $mode ) {
$slug = sanitize_key( (string) $slug );
if ( ! isset( $profiles[ $slug ] ) ) {
continue;
}
$found = false;
foreach ( array_keys( $installed ) as $basename ) {
if ( dirname( $basename ) === $slug ) {
$found = true;
break;
}
}
if ( ! $found ) {
continue;
}
// Unchecked boxes mean Original mode; store Safe only for checked ones.
if ( 'safe' === $mode ) {
$modes[ $slug ] = 'safe';
} else {
$modes[ $slug ] = 'original';
}
}
Robotstxt_Telemetry_Network::update_setting( 'robotstxt_telemetry_plugin_modes', $modes );
wp_safe_redirect(
add_query_arg(
array(
'page' => 'robotstxt-telemetry-plugins',
'updated' => 'true',
),
Robotstxt_Telemetry_Network::base_url()
)
);
exit;
}
/**
* Render the Plugins tab contents.
*