-
Notifications
You must be signed in to change notification settings - Fork 7
Fix early translation loading warning in Checkout controller #583
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
base: master
Are you sure you want to change the base?
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 | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -23,8 +23,18 @@ class Checkout | |||||||||||
| { | ||||||||||||
| protected $cards = array(); | ||||||||||||
|
|
||||||||||||
| /** | ||||||||||||
| * @var array | ||||||||||||
| * @deprecated This property appears to be unused in the codebase but is kept for backward compatibility. | ||||||||||||
| */ | ||||||||||||
| protected $payment_methods = []; | ||||||||||||
|
|
||||||||||||
| /** | ||||||||||||
| * Flag to indicate if translations have been loaded | ||||||||||||
| * @var bool | ||||||||||||
| */ | ||||||||||||
| private $translations_loaded = false; | ||||||||||||
|
|
||||||||||||
| /** @var CardInstallments */ | ||||||||||||
| protected $cardInstallments; | ||||||||||||
|
|
||||||||||||
|
|
@@ -45,6 +55,30 @@ public function __construct( | |||||||||||
| add_action('woocommerce_view_order', [$paymentDetails, 'render']); | ||||||||||||
| add_action('wp_ajax_xqRhBHJ5sW', array($this, 'build_installments')); | ||||||||||||
| add_action('wp_ajax_nopriv_xqRhBHJ5sW', array($this, 'build_installments')); | ||||||||||||
|
|
||||||||||||
| // Load translations later to avoid _load_textdomain_just_in_time warning | ||||||||||||
| add_action('init', array($this, 'load_payment_methods_translations'), 20); | ||||||||||||
|
|
||||||||||||
| $this->cardInstallments = $cardInstallments; | ||||||||||||
| if (!$this->cardInstallments) { | ||||||||||||
| $this->cardInstallments = new CardInstallments(); | ||||||||||||
| } | ||||||||||||
| $this->installments = $installments; | ||||||||||||
| if (!$this->installments) { | ||||||||||||
| $this->installments = new Installments(); | ||||||||||||
| } | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| /** | ||||||||||||
| * Loads payment methods translations after init | ||||||||||||
|
||||||||||||
| * Loads payment methods translations after init | |
| * Loads payment methods translations after init. | |
| * | |
| * Public visibility required for WordPress action hook callback. | |
| * |
Copilot
AI
Jan 2, 2026
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 condition logic is flawed. If get_payment_methods() is called before the init hook fires, the method will return an empty array even though translations are needed. The condition did_action('init') returns 0 (falsy) before the hook fires, so the check empty($this->payment_methods) && did_action('init') will be false, and translations won't be loaded.
Consider inverting the logic to: if (!$this->translations_loaded && did_action('init')) to ensure translations are loaded whenever the init hook has fired, or return a meaningful result when called too early.
| // If accessed before init hook fired but translations are needed | |
| if (empty($this->payment_methods) && did_action('init')) { | |
| // Load translations once init has fired and they haven't been loaded yet | |
| if (!$this->translations_loaded && did_action('init')) { |
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 deprecation notice format doesn't follow PHPDoc standards. Standard deprecation notices should use the
@deprecatedtag with a version number and optionally suggest an alternative. Consider formatting as:@deprecated since x.x.x Use get_payment_methods() instead. This property is kept for backward compatibility.