-
-
Notifications
You must be signed in to change notification settings - Fork 54
Translation loading too early (WordPress 6.7.0 warning) #548
Description
Describe the bug
A warning is triggered due to translation functions being called too early in the plugin lifecycle.
The error message is:
Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the object-sync-for-salesforce domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. (This message was added in version 6.7.0.)
To Reproduce
Steps to reproduce the behavior:
- Activate the Object Sync for Salesforce plugin
- Load the admin panel or run a process that triggers plugin loading
- Check debug log or WP admin
- See the error/warning related to translation loading
Expected behavior
No warnings should be shown. Translations should be loaded only at or after the init hook, according to WordPress best practices from version 6.7.0 onward.
Screenshots
N/A
Environment (please complete the following information):
- WordPress Version: 6.7.0
- Other relevant plugins: N/A
- PHP Version: 8.x
Additional context
The issue appears to be caused by this line in the Object_Sync_Salesforce class:
add_action( 'plugins_loaded', array( $this, 'run' ), -10 );The run method causes instantiation of classes that call esc_html__() in their constructors, notably:
🔹 In Object_Sync_Sf_Mapping:
$this->fieldmap_statuses = array(
'active' => esc_html__( 'Active', 'object-sync-for-salesforce' ),
'inactive' => esc_html__( 'Inactive', 'object-sync-for-salesforce' ),
'any' => '',
);🔹 In Object_Sync_Sf_Admin:
$this->notices_data = $this->notices_data();These calls happen too early and trigger the warning.
Suggested fix
Update the hook that runs the plugin initialization logic.
Current code:
add_action( 'plugins_loaded', array( $this, 'run' ), -10 );
add_action( 'plugins_loaded', array( $this, 'textdomain' ) );Suggested replacement:
add_action( 'init', array( $this, 'run' ) );
add_action( 'init', array( $this, 'textdomain' ) );This change ensures that translation loading happens at the right time (init or later), following WordPress's internal expectations.
Note: While this fix removes the warning and aligns with WordPress best practices, it’s unclear if moving the run method to init may introduce unintended side effects in the plugin's behavior. Further regression testing is recommended.