Skip to content

Fixes #7523: defer license-notice translation to avoid _load_textdomain_just_in_time notice - #8655

Open
gunjanjaswal wants to merge 1 commit into
wp-media:developfrom
gunjanjaswal:fix/7523-defer-license-notice-translation
Open

Fixes #7523: defer license-notice translation to avoid _load_textdomain_just_in_time notice#8655
gunjanjaswal wants to merge 1 commit into
wp-media:developfrom
gunjanjaswal:fix/7523-defer-license-notice-translation

Conversation

@gunjanjaswal

Copy link
Copy Markdown

Description

Fixes #7523

On WordPress 6.7+ with an invalid WP Rocket license, debug.log fills with _load_textdomain_just_in_time was called incorrectly ... rocket domain ... triggered too early notices.

Type of change

  • Bug fix (non-breaking change which fixes an issue).

Detailed scenario

Enter invalid license data (or run with a license that no longer validates) on WP 6.7+. The notice is logged on every admin page load. With this PR it is gone.

Technical description

rocket_valid_key() runs on plugins_loaded (via rocket_init), before the rocket textdomain loads on init, yet it translated the "license data are not valid" message and stored it in the rocket_check_key_errors transient. That string is only rendered later, in rocket_need_api_key() on admin_notices.

This defers the translation to render time, following the pattern from #7103: rocket_valid_key() now stores a stable invalid_license_data sentinel, and rocket_need_api_key() expands it to the translated sentences when the notice is displayed. Server-returned error strings, written during the live license check in rocket_check_key() (which runs after init), are still echoed as-is.

Unit tests added for both sides: that the sentinel is stored without any eager translation, and that the renderer expands it while passing plain strings through unchanged.

rocket_valid_key() can run on plugins_loaded, before the rocket
textdomain is loaded on init. Translating the invalid-license notice
there triggers the _load_textdomain_just_in_time doing-it-wrong notice
on WordPress 6.7+.

Store a stable 'invalid_license_data' sentinel in the
rocket_check_key_errors transient instead, and expand it to the
translated messages in rocket_need_api_key() at render time on
admin_notices (after init). Server-returned error strings written during
the live license check are still echoed unchanged.
@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 complexity

Metric Results
Complexity 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

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.

PHP Notice: Function _load_textdomain_just_in_time

1 participant