Skip to content

Add warnings if loading translations too early#6462

Closed
swissspidy wants to merge 13 commits into
WordPress:trunkfrom
swissspidy:fix/44937-warn
Closed

Add warnings if loading translations too early#6462
swissspidy wants to merge 13 commits into
WordPress:trunkfrom
swissspidy:fix/44937-warn

Conversation

@swissspidy

@swissspidy swissspidy commented Apr 30, 2024

Copy link
Copy Markdown
Member

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.

@github-actions

github-actions Bot commented Apr 30, 2024

Copy link
Copy Markdown

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.

@github-actions

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
Copy Markdown
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.

Comment thread src/wp-includes/l10n.php Outdated
Comment thread src/wp-includes/l10n.php Outdated
Comment thread src/wp-includes/l10n.php Outdated
Comment thread src/wp-includes/l10n.php Outdated
Comment thread src/wp-includes/l10n.php Outdated
Comment thread src/wp-includes/l10n.php Outdated
Comment thread src/wp-includes/l10n.php Outdated
Comment thread src/wp-includes/l10n.php Outdated
Comment thread src/wp-includes/l10n.php Outdated
Comment thread src/wp-includes/l10n.php Outdated
Comment thread src/wp-includes/l10n.php Outdated
Comment thread src/wp-includes/l10n.php Outdated
Comment thread src/wp-includes/l10n.php Outdated
Comment thread src/wp-includes/l10n.php Outdated
Comment thread src/wp-includes/l10n.php Outdated
Comment thread src/wp-includes/l10n.php Outdated
Comment thread src/wp-includes/l10n.php Outdated
@swissspidy

Copy link
Copy Markdown
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
Copy Markdown
Member

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

@swissspidy

Copy link
Copy Markdown
Member Author

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