Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions src/Admin/Settings/Menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,6 @@
}

class Menu extends Api {
/**
* Tabs for the settings page.
*
* @since 2.0.0
* @access public
*
* @var array
*/
public $tabs = [];

/**
* Constructor
*
Expand All @@ -34,7 +24,6 @@ class Menu extends Api {
*/
public function __construct() {
$this->prefix = 'perform_';
$this->tabs = Helpers::get_settings_tabs();

add_action( 'admin_menu', [ $this, 'register_admin_menu' ], 9 );
add_action( 'wp_ajax_perform_save_settings', [ $this, 'save_settings' ] );
Expand Down
26 changes: 19 additions & 7 deletions src/Includes/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' );
Copy link

Copilot AI Dec 6, 2025

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 $label is incorrect. The esc_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.

Copilot uses AI. Check for mistakes.
}
}
Comment on lines +258 to +266
Copy link

Copilot AI Dec 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent indentation: this block uses spaces instead of tabs. The rest of the codebase uses tabs for indentation. Lines 258-266 should be indented with tabs to match the project's coding style.

Suggested change
/**
* ✅ 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 uses AI. Check for mistakes.
Comment on lines +262 to +266
Copy link

Copilot AI Dec 6, 2025

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 uses AI. Check for mistakes.

//return $tabs;
Copy link

Copilot AI Dec 6, 2025

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.

Suggested change
//return $tabs;

Copilot uses AI. Check for mistakes.
return apply_filters( 'perform_settings_tabs', $tabs );
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' ] );
Copy link

Copilot AI Dec 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The textdomain loading hook hasn't been changed from init to plugins_loaded as described in the PR description. According to the PR, this line should be:

add_action( 'plugins_loaded', [ $this, 'load_plugin_textdomain' ], 9 );

This change is necessary to fix the WordPress 6.7.0+ deprecation warning about translations being loaded too early.

Suggested change
add_action( 'init', [ $this, 'load_plugin_textdomain' ] );
add_action( 'plugins_loaded', [ $this, 'load_plugin_textdomain' ], 9 );

Copilot uses AI. Check for mistakes.
}
Expand Down
Loading