Fix early translation loading warning in Checkout controller#583
Fix early translation loading warning in Checkout controller#583proteusbr1 wants to merge 1 commit intopagarme:masterfrom
Conversation
This commit resolves the '_load_textdomain_just_in_time' warning caused by premature translation calls in the Checkout controller constructor. Changes: - Implemented lazy loading for the '' property. - Translations are now loaded on the 'init' hook (priority 20) instead of 'plugins_loaded'. - Added 'get_payment_methods()' method for safe access. - Marked the property as deprecated/unused based on static analysis, but preserved it for backward compatibility.
|
Por favor, catalogue-o seguindo as instruções nesta documentação. [Via VPN]. 💁 Qualquer problema ou dúvida, estamos no Slack, basta abrir um ticket no canal #help-foundation-platform. |
There was a problem hiding this comment.
Pull request overview
This PR addresses a _load_textdomain_just_in_time warning that occurred when translation functions were called too early in the Checkout controller's constructor, before WordPress's translation system was fully initialized.
Key Changes:
- Deferred translation loading by moving payment methods initialization from the constructor to an
inithook (priority 20) - Implemented lazy loading pattern with a new
get_payment_methods()getter method - Added a
$translations_loadedflag to prevent duplicate initialization
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| } | ||
|
|
||
| /** | ||
| * Loads payment methods translations after init |
There was a problem hiding this comment.
The method load_payment_methods_translations() is declared as public to be used as a WordPress action callback, but it's an internal initialization method. While this is a common pattern in WordPress, consider adding a documentation note explaining why it must be public (e.g., "Public visibility required for WordPress action hook callback").
| * Loads payment methods translations after init | |
| * Loads payment methods translations after init. | |
| * | |
| * Public visibility required for WordPress action hook callback. | |
| * |
| // If accessed before init hook fired but translations are needed | ||
| if (empty($this->payment_methods) && did_action('init')) { |
There was a problem hiding this comment.
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')) { |
|
|
||
| /** | ||
| * @var array | ||
| * @deprecated This property appears to be unused in the codebase but is kept for backward compatibility. |
There was a problem hiding this comment.
The deprecation notice format doesn't follow PHPDoc standards. Standard deprecation notices should use the @deprecated tag 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.
| * @deprecated This property appears to be unused in the codebase but is kept for backward compatibility. | |
| * @deprecated since 1.0.0 This property appears to be unused in the codebase and is kept for backward compatibility. |
Qual o tipo de PR é esse? (marque todos os aplicáveis)
Descrição
Este PR resolve o aviso
_load_textdomain_just_in_timeque ocorria porque o construtor do Checkout controller estava chamando funções de tradução (__()) muito cedo (durante o hookplugins_loaded), antes que o sistema de tradução do WordPress estivesse totalmente pronto.Alterações realizadas:
$payment_methods.Cenários testados