Fix MoCache double-applying load_textdomain_mofile filter#27
Open
superdav42 wants to merge 1 commit intonawawi:masterfrom
Open
Fix MoCache double-applying load_textdomain_mofile filter#27superdav42 wants to merge 1 commit intonawawi:masterfrom
superdav42 wants to merge 1 commit intonawawi:masterfrom
Conversation
WordPress core already applies the `load_textdomain_mofile` filter in
`load_textdomain()` before calling `override_load_textdomain`. The
`$mofile` parameter passed to MoCache is already filtered.
Re-applying the filter in the MoCache constructor causes it to run
twice. This breaks plugins with stateful filter callbacks — notably
Polylang Pro's `PLL_Locale_Fallback::load_file`, which returns an
empty string on the second pass.
On PHP 8+, the empty path causes `fopen('')` to throw a ValueError
in `POMO_FileReader::__construct()`, resulting in a fatal error that
crashes the entire request (HTTP 500).
Changes:
- Use `$mofile` directly instead of re-filtering it
- Add empty-path guard before `import_from_file()` for robustness
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
load_textdomain_mofilefilter inMoCache::__construct()— WordPress core already applied it before callingoverride_load_textdomainimport_from_file()to prevent PHP 8+ValueErrorFixes #26
Problem
MoCache::__construct()callsapply_filters('load_textdomain_mofile', $mofile, $domain), but$mofilewas already filtered by WordPress core inload_textdomain()before reaching theoverride_load_textdomainhook. This double-filtering breaks plugins with stateful filter callbacks.Specifically, Polylang Pro's
PLL_Locale_Fallback::load_filereturns an empty string on the second pass, causing$this->mofileto be''. Later,import_from_file('')throwsValueError: Path cannot be emptyon PHP 8+.Reproduction
Drop this mu-plugin into any WordPress site with Docket Cache (MOCACHE enabled), PHP 8+, and any plugin that has a
.motranslation file:Any page load that triggers a translation will crash with:
Testing
Tested on a production WordPress 6.9 multisite with PHP 8.2, Polylang Pro, and the affiliate-links plugin:
Test plan