You've already forked wp-prometheus
fix: Separate settings groups to prevent cross-tab overwrites (v0.4.5)
All checks were successful
Create Release Package / build-release (push) Successful in 1m2s
All checks were successful
Create Release Package / build-release (push) Successful in 1m2s
Split Metrics sub-tab settings into separate WordPress option groups: - wp_prometheus_endpoint_settings for auth token - wp_prometheus_selection_settings for enabled metrics - wp_prometheus_advanced_settings for isolated mode This fixes the bug where saving from one sub-tab would clear settings from other sub-tabs due to all settings sharing a single option group. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -107,18 +107,20 @@ class Settings {
|
||||
* @return void
|
||||
*/
|
||||
public function register_settings(): void {
|
||||
// Register settings for metrics tab.
|
||||
register_setting( 'wp_prometheus_metrics_settings', 'wp_prometheus_auth_token', array(
|
||||
// Register settings for endpoint sub-tab.
|
||||
register_setting( 'wp_prometheus_endpoint_settings', 'wp_prometheus_auth_token', array(
|
||||
'type' => 'string',
|
||||
'sanitize_callback' => 'sanitize_text_field',
|
||||
) );
|
||||
|
||||
register_setting( 'wp_prometheus_metrics_settings', 'wp_prometheus_enabled_metrics', array(
|
||||
// Register settings for selection sub-tab.
|
||||
register_setting( 'wp_prometheus_selection_settings', 'wp_prometheus_enabled_metrics', array(
|
||||
'type' => 'array',
|
||||
'sanitize_callback' => array( $this, 'sanitize_metrics' ),
|
||||
) );
|
||||
|
||||
register_setting( 'wp_prometheus_metrics_settings', 'wp_prometheus_disable_early_mode', array(
|
||||
// Register settings for advanced sub-tab.
|
||||
register_setting( 'wp_prometheus_advanced_settings', 'wp_prometheus_isolated_mode', array(
|
||||
'type' => 'boolean',
|
||||
'sanitize_callback' => 'rest_sanitize_boolean',
|
||||
'default' => false,
|
||||
@@ -484,7 +486,7 @@ class Settings {
|
||||
private function render_metrics_endpoint_subtab(): void {
|
||||
?>
|
||||
<form method="post" action="options.php">
|
||||
<?php settings_fields( 'wp_prometheus_metrics_settings' ); ?>
|
||||
<?php settings_fields( 'wp_prometheus_endpoint_settings' ); ?>
|
||||
|
||||
<h3><?php esc_html_e( 'Authentication', 'wp-prometheus' ); ?></h3>
|
||||
<p class="description"><?php esc_html_e( 'Configure authentication for the /metrics endpoint.', 'wp-prometheus' ); ?></p>
|
||||
@@ -513,7 +515,7 @@ class Settings {
|
||||
private function render_metrics_selection_subtab(): void {
|
||||
?>
|
||||
<form method="post" action="options.php">
|
||||
<?php settings_fields( 'wp_prometheus_metrics_settings' ); ?>
|
||||
<?php settings_fields( 'wp_prometheus_selection_settings' ); ?>
|
||||
|
||||
<h3><?php esc_html_e( 'Enabled Metrics', 'wp-prometheus' ); ?></h3>
|
||||
<p class="description"><?php esc_html_e( 'Select which metrics to expose on the /metrics endpoint.', 'wp-prometheus' ); ?></p>
|
||||
@@ -566,57 +568,93 @@ class Settings {
|
||||
* @return void
|
||||
*/
|
||||
private function render_metrics_advanced_subtab(): void {
|
||||
$disabled = get_option( 'wp_prometheus_disable_early_mode', false );
|
||||
$env_override = false !== getenv( 'WP_PROMETHEUS_DISABLE_EARLY_MODE' );
|
||||
$early_active = defined( 'WP_PROMETHEUS_EARLY_METRICS' ) && WP_PROMETHEUS_EARLY_METRICS;
|
||||
$isolated_mode = get_option( 'wp_prometheus_isolated_mode', false );
|
||||
$env_override = false !== getenv( 'WP_PROMETHEUS_ISOLATED_MODE' );
|
||||
$is_metrics_request = defined( 'WP_PROMETHEUS_METRICS_REQUEST' ) && WP_PROMETHEUS_METRICS_REQUEST;
|
||||
$is_isolated = defined( 'WP_PROMETHEUS_ISOLATED_MODE' ) && WP_PROMETHEUS_ISOLATED_MODE;
|
||||
?>
|
||||
<form method="post" action="options.php">
|
||||
<?php settings_fields( 'wp_prometheus_metrics_settings' ); ?>
|
||||
<?php settings_fields( 'wp_prometheus_advanced_settings' ); ?>
|
||||
|
||||
<h3><?php esc_html_e( 'Early Mode', 'wp-prometheus' ); ?></h3>
|
||||
<p class="description">
|
||||
<?php esc_html_e( 'Early mode intercepts /metrics requests before full WordPress initialization. This prevents memory exhaustion issues caused by some plugins (e.g., Twig-based themes/plugins) but disables the wp_prometheus_collect_metrics hook for custom metrics.', 'wp-prometheus' ); ?>
|
||||
</p>
|
||||
<h3><?php esc_html_e( 'Metrics Collection Mode', 'wp-prometheus' ); ?></h3>
|
||||
|
||||
<div class="notice notice-info inline" style="padding: 12px; margin: 15px 0;">
|
||||
<p><strong><?php esc_html_e( 'Safe Mode (Default)', 'wp-prometheus' ); ?></strong></p>
|
||||
<p><?php esc_html_e( 'Content filters are removed early to prevent memory issues with Twig-based plugins, but WordPress loads normally. Third-party plugins can add custom metrics via the wp_prometheus_collect_metrics hook.', 'wp-prometheus' ); ?></p>
|
||||
</div>
|
||||
|
||||
<?php if ( $env_override ) : ?>
|
||||
<div class="notice notice-info inline" style="padding: 12px; margin: 15px 0;">
|
||||
<div class="notice notice-warning inline" style="padding: 12px; margin: 15px 0;">
|
||||
<strong><?php esc_html_e( 'Environment Override Active', 'wp-prometheus' ); ?></strong>
|
||||
<p><?php esc_html_e( 'Early mode is configured via WP_PROMETHEUS_DISABLE_EARLY_MODE environment variable. Admin settings will be ignored.', 'wp-prometheus' ); ?></p>
|
||||
<p><?php esc_html_e( 'Mode is configured via WP_PROMETHEUS_ISOLATED_MODE environment variable. Admin settings will be ignored.', 'wp-prometheus' ); ?></p>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<table class="form-table" role="presentation">
|
||||
<tr>
|
||||
<th scope="row"><?php esc_html_e( 'Disable Early Mode', 'wp-prometheus' ); ?></th>
|
||||
<th scope="row"><?php esc_html_e( 'Isolated Mode', 'wp-prometheus' ); ?></th>
|
||||
<td>
|
||||
<label>
|
||||
<input type="checkbox" name="wp_prometheus_disable_early_mode" value="1"
|
||||
<?php checked( $disabled ); ?>
|
||||
<input type="checkbox" name="wp_prometheus_isolated_mode" value="1"
|
||||
<?php checked( $isolated_mode ); ?>
|
||||
<?php disabled( $env_override ); ?>>
|
||||
<?php esc_html_e( 'Disable early metrics interception', 'wp-prometheus' ); ?>
|
||||
<?php esc_html_e( 'Enable isolated mode', 'wp-prometheus' ); ?>
|
||||
</label>
|
||||
<p class="description">
|
||||
<?php esc_html_e( 'When disabled, metrics are collected through normal WordPress template loading. This enables the wp_prometheus_collect_metrics hook for custom metrics but may cause issues with some plugins.', 'wp-prometheus' ); ?>
|
||||
<?php esc_html_e( 'Isolated mode outputs metrics immediately before other plugins fully load. This provides maximum isolation but disables the wp_prometheus_collect_metrics hook. Use this only if you experience issues with Safe Mode.', 'wp-prometheus' ); ?>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row"><?php esc_html_e( 'Current Status', 'wp-prometheus' ); ?></th>
|
||||
<td>
|
||||
<?php if ( $early_active ) : ?>
|
||||
<?php if ( $is_isolated ) : ?>
|
||||
<span class="dashicons dashicons-lock" style="color: orange;"></span>
|
||||
<?php esc_html_e( 'Isolated mode active - custom hooks are disabled', 'wp-prometheus' ); ?>
|
||||
<?php elseif ( $is_metrics_request ) : ?>
|
||||
<span class="dashicons dashicons-yes-alt" style="color: green;"></span>
|
||||
<?php esc_html_e( 'Early mode is active (this request was served via early interception)', 'wp-prometheus' ); ?>
|
||||
<?php elseif ( $disabled || $env_override ) : ?>
|
||||
<span class="dashicons dashicons-dismiss" style="color: gray;"></span>
|
||||
<?php esc_html_e( 'Early mode is disabled', 'wp-prometheus' ); ?>
|
||||
<?php esc_html_e( 'Safe mode active - custom hooks enabled with filter protection', 'wp-prometheus' ); ?>
|
||||
<?php elseif ( $isolated_mode ) : ?>
|
||||
<span class="dashicons dashicons-lock" style="color: orange;"></span>
|
||||
<?php esc_html_e( 'Isolated mode enabled (active for /metrics requests)', 'wp-prometheus' ); ?>
|
||||
<?php else : ?>
|
||||
<span class="dashicons dashicons-yes-alt" style="color: green;"></span>
|
||||
<?php esc_html_e( 'Early mode is enabled (active for /metrics requests)', 'wp-prometheus' ); ?>
|
||||
<?php esc_html_e( 'Safe mode enabled (default) - custom hooks with filter protection', 'wp-prometheus' ); ?>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<hr style="margin: 20px 0;">
|
||||
|
||||
<h4><?php esc_html_e( 'Mode Comparison', 'wp-prometheus' ); ?></h4>
|
||||
<table class="widefat striped" style="max-width: 700px;">
|
||||
<thead>
|
||||
<tr>
|
||||
<th><?php esc_html_e( 'Feature', 'wp-prometheus' ); ?></th>
|
||||
<th><?php esc_html_e( 'Safe Mode', 'wp-prometheus' ); ?></th>
|
||||
<th><?php esc_html_e( 'Isolated Mode', 'wp-prometheus' ); ?></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td><?php esc_html_e( 'Custom metrics hook', 'wp-prometheus' ); ?></td>
|
||||
<td><span class="dashicons dashicons-yes" style="color: green;"></span></td>
|
||||
<td><span class="dashicons dashicons-no" style="color: red;"></span></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><?php esc_html_e( 'Plugin compatibility', 'wp-prometheus' ); ?></td>
|
||||
<td><?php esc_html_e( 'High', 'wp-prometheus' ); ?></td>
|
||||
<td><?php esc_html_e( 'Maximum', 'wp-prometheus' ); ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><?php esc_html_e( 'Memory usage', 'wp-prometheus' ); ?></td>
|
||||
<td><?php esc_html_e( 'Normal', 'wp-prometheus' ); ?></td>
|
||||
<td><?php esc_html_e( 'Minimal', 'wp-prometheus' ); ?></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<?php submit_button(); ?>
|
||||
</form>
|
||||
<?php
|
||||
|
||||
Reference in New Issue
Block a user