inpsyde / modularity

A PSR-11 implementation for WordPress Plugins, Themes or Libraries.
https://inpsyde.github.io/modularity/
GNU General Public License v2.0
46 stars 4 forks source link

Avoid loading translations too early #56

Closed Biont closed 1 day ago

Biont commented 1 week ago

Please check if the PR fulfills these requirements

What kind of change does this PR introduce? (Bug fix, feature, docs update, ...) Bug fix

What is the current behavior? (You can also link to an open issue here) WordPress 6.7 removed the need to load_plugin_textdomain manually. In return, we receive a notice if translations are loaded/accessed too early.

What is the new behavior (if this is a feature change)?

Passing $translate = false in the call to get_plugin_data avoids the _doing_it_wrong and the resulting notice

Since ExecutableModule is responsible for hooking module logic into WordPress, it makes sense to bootstrap the package itself as early as feasible. Hence, deferring bootstrap to after_setup_thene or init as proposed by core severely limits our flexibility in terms of what modules can to in the "remaining time"

Does this PR introduce a breaking change? (What changes might users need to make in their application due to this PR?)

No.

Other information:

codecov[bot] commented 1 week ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 98.84%. Comparing base (2119d0e) to head (03af2d4). Report is 2 commits behind head on master.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #56 +/- ## ============================================ + Coverage 98.80% 98.84% +0.04% Complexity 251 251 ============================================ Files 10 10 Lines 586 607 +21 ============================================ + Hits 579 600 +21 Misses 7 7 ``` | [Flag](https://app.codecov.io/gh/inpsyde/modularity/pull/56/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=inpsyde) | Coverage Δ | | |---|---|---| | [unittests](https://app.codecov.io/gh/inpsyde/modularity/pull/56/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=inpsyde) | `98.84% <100.00%> (+0.04%)` | :arrow_up: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=inpsyde#carryforward-flags-in-the-pull-request-comment) to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

Chrico commented 1 week ago

We should also update the documentation and mention that the data in PluginProperties is not translated (and why). I guess it is also a good opportunity to add a note about the change done in https://github.com/inpsyde/modularity/pull/40 .

Biont commented 1 week ago

@Chrico Added!

Chrico commented 6 days ago

Sorry I need to jump in with another request...first of all: I think this is a breaking change for existing Packages, in case they are using something from the PluginProperties and relying on translated strings.

We should not break the default behavior, but at least fix the _doing_it_wrong()-calls.

In order to stay "backward compatible", we should add a check for the WP version to be < 6.7, to ensure that the current behavior stays as it is. If the current WP version is >= 6.7 and we're calling too early get_plugin_data(), than we should set this to false. I guess something like did_action('after_setup_theme') || current_action('after_setup_theme'); would work here, right?

There are probably some Plugins out there, which are booted late - so after after_setup_theme, like on init. This would not trigger the _doing_it_wrong() and allow to get translated get_plugin_data().

Biont commented 6 days ago

I guess something like did_action('after_setup_theme') || current_action('after_setup_theme'); would work here, right?

Your request makes sense and according to how I understand the situation, this should be a working approach, since it is essentially the same check that WP does before throwing the __doing_it_wrong. I'll make the edit after the weekend