Skip to content
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

Add warnings if loading translations too early #6462

Closed
wants to merge 13 commits into from

Conversation

swissspidy
Copy link
Member

@swissspidy swissspidy commented Apr 30, 2024

In my quick local testing I already identified a few plugins doing load_plugin_textdomain() wrong:

Plugins doing just-in-time loading wrong:


To-do:

  • Improve wording for the _load_textdomain_just_in_time case, mentioning that it's typically caused by unintended side effects in a plugin or theme.
  • What about themes? They usually do stuff in after_setup_theme, which runs right before init and current user setup. Probably all classic themes will be affected by this.

Strangely, when one of these plugins and Query Monitor is active, there is some sort of infinite loop happening and the site crashes with a 500. @johnbillion Any thoughts why QM might run in circles here?


Trac ticket: https://core.trac.wordpress.org/ticket/44937


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

Copy link

github-actions bot commented Apr 30, 2024

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props swissspidy, johnbillion.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

This comment was marked as resolved.

@johnbillion

This comment was marked as resolved.

@johnbillion

This comment was marked as resolved.

@swissspidy

This comment was marked as resolved.

@swissspidy

This comment was marked as resolved.

@johnbillion

This comment was marked as resolved.

@swissspidy
Copy link
Member Author

Looking into warnings emitted by themes, such as twentytwentyone.

Some observations:

  • Themes usually trigger just-in-time loading on after_setup_theme
  • In the admin, the current user is set up right after setup_theme because of the load_default_textdomain() call in wp-settings.php
  • Checking for after_setup_theme to emit a warning might be a better solution

I am concerned about calling __() from within the load textdomain functions though.

At this point determine_locale() will already have been called, and the current user thus setup. So I don't see any other side effect happening because of this.

src/wp-includes/l10n.php Outdated Show resolved Hide resolved
src/wp-includes/l10n.php Outdated Show resolved Hide resolved
src/wp-includes/l10n.php Outdated Show resolved Hide resolved
src/wp-includes/l10n.php Outdated Show resolved Hide resolved
src/wp-includes/l10n.php Outdated Show resolved Hide resolved
src/wp-includes/l10n.php Outdated Show resolved Hide resolved
src/wp-includes/l10n.php Outdated Show resolved Hide resolved
src/wp-includes/l10n.php Outdated Show resolved Hide resolved
src/wp-includes/l10n.php Outdated Show resolved Hide resolved
src/wp-includes/l10n.php Outdated Show resolved Hide resolved
src/wp-includes/l10n.php Outdated Show resolved Hide resolved
src/wp-includes/l10n.php Outdated Show resolved Hide resolved
src/wp-includes/l10n.php Outdated Show resolved Hide resolved
src/wp-includes/l10n.php Outdated Show resolved Hide resolved
src/wp-includes/l10n.php Outdated Show resolved Hide resolved
src/wp-includes/l10n.php Outdated Show resolved Hide resolved
src/wp-includes/l10n.php Outdated Show resolved Hide resolved
@swissspidy
Copy link
Member Author

@ocean90 @SergeyBiryukov @johnbillion Is this something one of you could provide feedback on? I think it's a nice safeguard that could still land before the beta, but it also might be a bit noisy.

@johnbillion
Copy link
Member

This could be noisy but it might be interesting to see if any feedback about that is raised during beta.

@swissspidy
Copy link
Member Author

@swissspidy swissspidy closed this Sep 30, 2024
@swissspidy swissspidy deleted the fix/44937-warn branch September 30, 2024 15:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants