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:
@@ -121,14 +121,62 @@ class Collector {
|
||||
/**
|
||||
* Fires after default metrics are collected.
|
||||
*
|
||||
* Skip in early metrics mode to avoid triggering third-party hooks
|
||||
* that may cause recursion issues (e.g., Twig-based plugins).
|
||||
* In isolated mode, skip custom hooks to avoid any potential issues.
|
||||
* In safe mode (default), fire hooks with protection against recursion.
|
||||
*
|
||||
* @param Collector $collector The metrics collector instance.
|
||||
*/
|
||||
if ( ! defined( 'WP_PROMETHEUS_EARLY_METRICS' ) || ! WP_PROMETHEUS_EARLY_METRICS ) {
|
||||
do_action( 'wp_prometheus_collect_metrics', $this );
|
||||
if ( defined( 'WP_PROMETHEUS_ISOLATED_MODE' ) && WP_PROMETHEUS_ISOLATED_MODE ) {
|
||||
// Isolated mode: skip all third-party hooks for maximum safety.
|
||||
return;
|
||||
}
|
||||
|
||||
// Safe mode: fire custom hooks with protection.
|
||||
$this->fire_custom_metrics_hook();
|
||||
}
|
||||
|
||||
/**
|
||||
* Fire custom metrics hook with protection against recursion.
|
||||
*
|
||||
* Removes potentially problematic filters, uses output buffering,
|
||||
* and catches any errors from third-party plugins.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function fire_custom_metrics_hook(): void {
|
||||
// Remove content filters again (in case any plugin re-added them).
|
||||
if ( function_exists( 'wp_prometheus_remove_content_filters' ) ) {
|
||||
wp_prometheus_remove_content_filters();
|
||||
} else {
|
||||
// Fallback if function doesn't exist.
|
||||
remove_all_filters( 'the_content' );
|
||||
remove_all_filters( 'the_excerpt' );
|
||||
remove_all_filters( 'get_the_excerpt' );
|
||||
remove_all_filters( 'the_title' );
|
||||
}
|
||||
|
||||
// Use output buffering to prevent any accidental output from plugins.
|
||||
ob_start();
|
||||
|
||||
try {
|
||||
/**
|
||||
* Fires after default metrics are collected.
|
||||
*
|
||||
* Third-party plugins can use this hook to add custom metrics.
|
||||
*
|
||||
* @param Collector $collector The metrics collector instance.
|
||||
*/
|
||||
do_action( 'wp_prometheus_collect_metrics', $this );
|
||||
} catch ( \Throwable $e ) {
|
||||
// Log the error but don't let it break metrics output.
|
||||
if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
|
||||
// phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log
|
||||
error_log( 'WP Prometheus: Error in custom metrics hook: ' . $e->getMessage() );
|
||||
}
|
||||
}
|
||||
|
||||
// Discard any output from plugins.
|
||||
ob_end_clean();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user