You've already forked wp-prometheus
fix: Defer textdomain loading to init action for WordPress 6.7+ compatibility (v0.4.8)
All checks were successful
Create Release Package / build-release (push) Successful in 1m1s
All checks were successful
Create Release Package / build-release (push) Successful in 1m1s
Fixes _load_textdomain_just_in_time notice and headers already sent warnings on admin pages by deferring load_plugin_textdomain() and Settings tab label initialization to the init action instead of plugins_loaded. Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -49,15 +49,6 @@ class Settings {
|
||||
* Constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->tabs = array(
|
||||
'license' => __( 'License', 'wp-prometheus' ),
|
||||
'metrics' => __( 'Metrics', 'wp-prometheus' ),
|
||||
'storage' => __( 'Storage', 'wp-prometheus' ),
|
||||
'custom' => __( 'Custom Metrics', 'wp-prometheus' ),
|
||||
'dashboards' => __( 'Dashboards', 'wp-prometheus' ),
|
||||
'help' => __( 'Help', 'wp-prometheus' ),
|
||||
);
|
||||
|
||||
$this->metric_builder = new CustomMetricBuilder();
|
||||
$this->dashboard_provider = new DashboardProvider();
|
||||
|
||||
@@ -76,14 +67,37 @@ class Settings {
|
||||
add_action( 'wp_ajax_wp_prometheus_test_storage', array( $this, 'ajax_test_storage' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get available tabs.
|
||||
*
|
||||
* Lazily initializes tab labels to avoid triggering textdomain loading
|
||||
* before the 'init' action (required since WordPress 6.7).
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function get_tabs(): array {
|
||||
if ( empty( $this->tabs ) ) {
|
||||
$this->tabs = array(
|
||||
'license' => __( 'License', 'wp-prometheus' ),
|
||||
'metrics' => __( 'Metrics', 'wp-prometheus' ),
|
||||
'storage' => __( 'Storage', 'wp-prometheus' ),
|
||||
'custom' => __( 'Custom Metrics', 'wp-prometheus' ),
|
||||
'dashboards' => __( 'Dashboards', 'wp-prometheus' ),
|
||||
'help' => __( 'Help', 'wp-prometheus' ),
|
||||
);
|
||||
}
|
||||
return $this->tabs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current tab.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function get_current_tab(): string {
|
||||
$tab = isset( $_GET['tab'] ) ? sanitize_key( $_GET['tab'] ) : 'license';
|
||||
return array_key_exists( $tab, $this->tabs ) ? $tab : 'license';
|
||||
$tabs = $this->get_tabs();
|
||||
$tab = isset( $_GET['tab'] ) ? sanitize_key( $_GET['tab'] ) : 'license';
|
||||
return array_key_exists( $tab, $tabs ) ? $tab : 'license';
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -268,7 +282,7 @@ class Settings {
|
||||
?>
|
||||
<nav class="nav-tab-wrapper wp-clearfix">
|
||||
<?php
|
||||
foreach ( $this->tabs as $tab_id => $tab_name ) {
|
||||
foreach ( $this->get_tabs() as $tab_id => $tab_name ) {
|
||||
$tab_url = add_query_arg(
|
||||
array(
|
||||
'page' => 'wp-prometheus',
|
||||
|
||||
@@ -57,7 +57,9 @@ final class Plugin {
|
||||
private function __construct() {
|
||||
$this->init_components();
|
||||
$this->init_hooks();
|
||||
$this->load_textdomain();
|
||||
|
||||
// Defer textdomain loading to 'init' action (required since WordPress 6.7).
|
||||
add_action( 'init', array( $this, 'load_textdomain' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -144,9 +146,11 @@ final class Plugin {
|
||||
/**
|
||||
* Load plugin textdomain.
|
||||
*
|
||||
* Hooked to 'init' action to comply with WordPress 6.7+ requirements.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function load_textdomain(): void {
|
||||
public function load_textdomain(): void {
|
||||
load_plugin_textdomain(
|
||||
'wp-prometheus',
|
||||
false,
|
||||
|
||||
Reference in New Issue
Block a user