Opened 6 months ago
Last modified 4 months ago
#63725 assigned defect (bug)
Theme textdomain not loaded, if plugin used the textdomain before
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Milestone: | Awaiting Review | Priority: | normal |
| Severity: | minor | Version: | 6.8 |
| Component: | I18N | Keywords: | has-patch |
| Focuses: | Cc: |
Description
If a plugin uses the same textdomain as a theme, the theme's textdomain path is not loaded and still requires manually calling load_theme_textdomain()
This is because of:
https://github.com/WordPress/wordpress-develop/blob/trunk/src/wp-includes/class-wp-theme.php#L1522
This means that themes' still must call load_theme_textdomain() themselves to avoid plugins accidentally hijacking their textdomain and their translations not getting loaded correctly.
While generally this isn't an issue (since it not something that should be done/happen) that plugins use the same textdomain as a theme, the real world use cases where this happens all the time:
1) miss-spellings. e.g. plugin has textdomain foo-bar, theme uses foobar. If the plugin has a single string with the wrong textdomain, the problem happens
2) copied code (e.g. plugin authors copied or reused part of a theme without changing the textdomain)
3) customizations: end-users (and developers) might copy strings from themes to plugins as a first step of customization. This will cause the theme's textdomain to not load correctly.
Why this is marked as "blocker":
by removing "load_theme_textdomain" in a theme since WP 6.8 for a theme, theme authors get loads of support requests due to translations not loading due to no fault of their own - but bc plugins are using the wrong textdomain (accidentally).
This means for now, the recommended solution for themes is to keep their "load_theme_textdomain" until that issue is resolved.
Change History (3)
This ticket was mentioned in PR #9760 on WordPress/wordpress-develop by @gautam23.
4 months ago
#2
- Keywords has-patch added
#3
@
4 months ago
- Severity changed from blocker to minor
When you say "this happens all the time" and "theme authors get loads of support", is there any data to back this up?
Note that textdomain conflicts are a known limitation ever since we introduced just-in-time loading back in WP 4.6. There's really no good solution except to avoid reusing the same slugs/domains.
As for this particular code in question, it should probably be fine to simply remove that is_textdomain_loaded() check because nowadays we can load multiple translation files anyway.
## 🐞 Problem
When a plugin loads the same textdomain as a theme before the theme does, the theme’s translations may not load at all. This is because WordPress considers the textdomain already loaded and silently skips it — even if the .mo file is different. This leads to missing translations in themes.
Tracked in Trac #63725
## ✅ Solution
This PR introduces a $force parameter to the WP_Theme::load_textdomain() method, allowing themes to explicitly reload their own textdomain — even if it was previously loaded by a plugin.
## 🔧 Changes
Enhancement: Added optional
$forceparameter to WP_Theme::load_textdomain() to enable reloading of already-loaded textdomains.Behavioral Update: When
$forceis true, the method bypasses the is_textdomain_loaded() check and reloads the .mo file.## 📌 Notes
This change provides theme authors a way to recover from textdomain conflicts caused by plugins loading the same domain early.