-
-
Notifications
You must be signed in to change notification settings - Fork 1
Fix: Move textdomain loading to plugins_loaded hook for WordPress 6.7.0+ compatibility #66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -243,18 +243,30 @@ public static function find_field_by_id( $id ) { | |||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||
| public static function get_settings_tabs() { | ||||||||||||||||||||||||||||||||||||||
| $tabs = [ | ||||||||||||||||||||||||||||||||||||||
| 'general' => esc_html__( 'General', 'perform' ), | ||||||||||||||||||||||||||||||||||||||
| 'bloat' => esc_html__( 'Bloat', 'perform' ), | ||||||||||||||||||||||||||||||||||||||
| 'assets' => esc_html__( 'Assets', 'perform' ), | ||||||||||||||||||||||||||||||||||||||
| 'cdn' => esc_html__( 'CDN', 'perform' ), | ||||||||||||||||||||||||||||||||||||||
| 'advanced' => esc_html__( 'Advanced', 'perform' ), | ||||||||||||||||||||||||||||||||||||||
| 'general' => 'General', | ||||||||||||||||||||||||||||||||||||||
| 'bloat' => 'Bloat', | ||||||||||||||||||||||||||||||||||||||
| 'assets' => 'Assets', | ||||||||||||||||||||||||||||||||||||||
| 'cdn' => 'CDN', | ||||||||||||||||||||||||||||||||||||||
| 'advanced' => 'Advanced', | ||||||||||||||||||||||||||||||||||||||
| ]; | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| // Add WooCommerce tab if WooCommerce is active. | ||||||||||||||||||||||||||||||||||||||
| if ( self::is_woocommerce_active() ) { | ||||||||||||||||||||||||||||||||||||||
| $tabs['woocommerce'] = esc_html__( 'WooCommerce', 'perform' ); | ||||||||||||||||||||||||||||||||||||||
| $tabs['woocommerce'] = 'WooCommerce'; | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| return $tabs; | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||
| * ✅ Safe translation wrapper | ||||||||||||||||||||||||||||||||||||||
| * Translate only after init, otherwise return plain labels. | ||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||
| if ( did_action( 'init' ) ) { | ||||||||||||||||||||||||||||||||||||||
| foreach ( $tabs as $key => $label ) { | ||||||||||||||||||||||||||||||||||||||
| $tabs[ $key ] = esc_html__( $label, 'perform' ); | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+258
to
+266
|
||||||||||||||||||||||||||||||||||||||
| /** | |
| * ✅ Safe translation wrapper | |
| * Translate only after init, otherwise return plain labels. | |
| */ | |
| if ( did_action( 'init' ) ) { | |
| foreach ( $tabs as $key => $label ) { | |
| $tabs[ $key ] = esc_html__( $label, 'perform' ); | |
| } | |
| } | |
| /** | |
| * ✅ Safe translation wrapper | |
| * Translate only after init, otherwise return plain labels. | |
| */ | |
| if ( did_action( 'init' ) ) { | |
| foreach ( $tabs as $key => $label ) { | |
| $tabs[ $key ] = esc_html__( $label, 'perform' ); | |
| } | |
| } |
Copilot
AI
Dec 6, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic for conditional translation is flawed. Using did_action('init') means translations will NOT be applied when this function is called before the init hook fires (e.g., during plugins_loaded at priority 10). Since get_settings_tabs() is called from Menu::enqueue_admin_assets() which runs on admin_enqueue_scripts (which fires after init), this should work. However, the approach is fragile.
A more robust solution would be to ensure translations are always loaded before this function is called, rather than conditionally translating based on hook timing. The PR's stated goal of moving load_plugin_textdomain to plugins_loaded with priority 9 should ensure translations are available when register_services runs at priority 10 (default).
Copilot
AI
Dec 6, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This commented-out return statement should be removed. Commented code reduces maintainability and creates confusion.
| //return $tabs; |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -32,7 +32,7 @@ public function register() { | |||||
|
|
||||||
| // Register services used throughout the plugin. | ||||||
| add_action( 'plugins_loaded', [ $this, 'register_services' ] ); | ||||||
|
|
||||||
| // Load text domain. | ||||||
| add_action( 'init', [ $this, 'load_plugin_textdomain' ] ); | ||||||
|
||||||
| add_action( 'init', [ $this, 'load_plugin_textdomain' ] ); | |
| add_action( 'plugins_loaded', [ $this, 'load_plugin_textdomain' ], 9 ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using
esc_html__()with a variable$labelis incorrect. Theesc_html__()function expects a literal string as the first argument for translation extraction tools to work properly.Since the labels are now plain English strings defined earlier, they should be wrapped with
esc_html__()at definition time (lines 246-250, 255), not in a loop with variables. Revert to the original approach of translating strings inline where they are defined.