Hooks: Change several action priorities to ensure translation loading is not triggered too early.
Continuation of https://github.com/Automattic/jetpack/pull/39696
Proposed changes:
- This PR ensures that both the Tiled Gallery and Contact Info blocks are loaded later to ensure translation loading is not triggered too early, resulting in loading issues and error log warnings.
- It also ensures
Automattic\Jetpack\Sync\Actionsis hooked intoinit, instead ofplugins_loaded, for the same reason. - Also, Jetpack's
load_modulesis hooked intoafter_setup_theme'to ensure it also runs after translations have been loaded. - Lastly, a function has been created to load VideoPress' page suffix as that calls a translation function and runs too early otherwise, so the function itself is now hooked into
init.
Notice that is being prevented with these changes:
PHP Notice: Function _load_textdomain_just_in_time was called <strong>incorrectly</strong>. Translation loading for the <code>jetpack</code> domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the <code>init</code> action or later. Please see <a href="https://developer.wordpress.org/advanced-administration/debug/debug-wordpress/">Debugging in WordPress</a> for more information. (This message was added in version 6.7.0.) in /var/www/html/wp-includes/functions.php on line 6099
Other information:
- [ ] Have you written new tests for your changes, if applicable?
- [x] Have you checked the E2E test CI results, and verified that your changes do not break them?
- [ ] Have you tested your changes on WordPress.com, if applicable (if so, you'll see a generated comment below with a script to run)?
Jetpack product discussion
See links in https://github.com/Automattic/jetpack/pull/39696
Does this pull request change what data or activity we track or use?
No.
Testing instructions:
Note - you may need to set a non-English (United States) language for your site (and install the corresponding translations, which is done via /wp-admin/update-core.php).
You should also tail your sites error logs to check for the above notice, which in testing with trunk and WP 6.7 should be visible.
Self-hosted testing steps:
- On a free site, connected to WordPress.com, install the WordPress Beta Tester plugin
- Go to Tools > Beta Testing, and set the plugin to use Bleeding edge
- Go to Dashboard > Updates, and update to the most recent version of WP.
- Go to Posts > Add New
- Ensure the Tiled Gallery and Contact Info blocks work as expected.
- Ensure sync actions still work. Try schedule a sync checksum via the Jetpack debugger, for example, or add a new post and ensure the change is reflected on WPcom (
https://wordpress.com/posts/mysite.com). - Also, test some modules to ensure they are loading correctly, particularly comments.
- Lastly, test adding and activating the VideoPress standalone plugin (if testing locally, ensure the PR is applied using the Beta tester plugin for the VideoPress plugin), and make sure no errors show up. The VideoPress 'Jetpack VideoPress' menu item name should display without issue.
- None of the testing should trigger the notice shared under 'Proposed changes' above.
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
-
To test on WoA, go to the Plugins menu on a WordPress.com Simple site. Click on the "Upload" button and follow the upgrade flow to be able to upload, install, and activate the Jetpack Beta plugin. Once the plugin is active, go to Jetpack > Jetpack Beta, select your plugin, and enable the
update/hooks-prevent-doing-it-wrong-noticebranch.- For
jetpack-mu-wpcomchanges, also adddefine( 'JETPACK_MU_WPCOM_LOAD_VIA_BETA_PLUGIN', true );to yourwp-config.phpfile.
- For
-
To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack update/hooks-prevent-doing-it-wrong-noticebin/jetpack-downloader test jetpack-mu-wpcom-plugin update/hooks-prevent-doing-it-wrong-notice
Interested in more tips and information?
- In your local development environment, use the
jetpack rsynccommand to sync your changes to a WoA dev blog. - Read more about our development workflow here: PCYsg-eg0-p2
- Figure out when your changes will be shipped to customers here: PCYsg-eg5-p2
Thank you for your PR!
When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
- :white_check_mark: Include a description of your PR changes.
- :white_check_mark: Add a "[Status]" label (In Progress, Needs Team Review, ...).
- :white_check_mark: Add testing instructions.
- :white_check_mark: Specify whether this PR includes any changes to data or privacy.
- :white_check_mark: Add changelog entries to affected projects
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation :robot:
The e2e test report can be found here. Please note that it can take a few minutes after the e2e tests checks are complete for the report to be available.
Follow this PR Review Process:
- Ensure all required checks appearing at the bottom of this PR are passing.
- Choose a review path based on your changes:
-
A. Team Review: add the "[Status] Needs Team Review" label
- For most changes, including minor cross-team impacts.
- Example: Updating a team-specific component or a small change to a shared library.
-
B. Crew Review: add the "[Status] Needs Review" label
- For significant changes to core functionality.
- Example: Major updates to a shared library or complex features.
-
C. Both: Start with Team, then request Crew
- For complex changes or when you need extra confidence.
- Example: Refactor affecting multiple systems.
-
A. Team Review: add the "[Status] Needs Team Review" label
- Get at least one approval before merging.
Still unsure? Reach out in #jetpack-developers for guidance!
Jetpack plugin:
The Jetpack plugin has different release cadences depending on the platform:
- WordPress.com Simple releases happen semi-continuously (PCYsg-Jjm-p2).
- WoA releases happen weekly.
- Releases to self-hosted sites happen monthly. The next release is scheduled for November 5, 2024 (scheduled code freeze on November 4, 2024).
If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.
I believe from Sync's perspective, instead of updating Actions::init to run very early on init vs late on plugins_loaded we could instead fix the code that introduces the notice and comes from running jetpack_cron_schedule (has translations) early via init_sync_cron_jobs on Actions::init here
I believe we can fix this by updating self::init_sync_cron_jobs(); above to add_action( 'init', array( __CLASS__, 'init_sync_cron_jobs' ), 1 );
Adding a comment here whilst this is in review as I spotted an issue when testing with some standalones active - the only one with an issue was VideoPress, so a commit has been added for that (and updated testing instructions).
I believe we can fix this by updating self::init_sync_cron_jobs(); above to add_action( 'init', array( CLASS, 'init_sync_cron_jobs' ), 1 );
That's a great idea. Added in 19acfc539b08950effa32e84bcebd08ea6f6212f
Also, Jetpack's load_modules is hooked into after_setup_theme' to ensure it also runs after translations have been loaded.
I guess this broke any modules that hook the function to the plugins_loaded. One is google-fonts module and I proposed https://github.com/Automattic/jetpack/pull/39977 to resolve it. Another one might be the upcoming-event shortcode but I'm not familiar with it.
Only ones like the google-fonts that specifically need to run after Jetpack's load_modules and use plugin_loaded to do so. Something like the event shortcode you linked should be fine.