Make WordPress Core

Opened 3 years ago

Last modified 5 weeks ago

#23794 reopened enhancement

load_plugin_textdomain fails if plugin is loaded from mu-plugins

Reported by: ideag Owned by:
Milestone: Future Release Priority: normal
Severity: normal Version: 3.5.1
Component: I18N Keywords: needs-patch
Focuses: Cc:


load_plugin_textdomain is realative to WP_PLUGIN_DIR, so it fails to load localization files if plugin keeps them in its directory.

The function should check if is called from mu-plugins and use WP_MUPLUGIN_DIR in that case.

I can fix this in my own plugin by adding '../mu-lugins/' like this:

  load_plugin_textdomain( 'tiny_tribuna', false, '../mu-plugins/'.dirname( plugin_basename( __FILE__ ) ) . '/languages/');

but this is not a good option for other plugins.

Attachments (1)

23794.patch (1.6 KB) - added by johnbillion 2 years ago.

Download all attachments as: .zip

Change History (11)

comment:1 @ocean903 years ago

  • Keywords close added

You should use load_muplugin_textdomain() then.

comment:2 @ideag3 years ago

  • Resolution set to fixed
  • Status changed from new to closed

Problem is, a lot of plugins only use load_plugin_textdomain() :| That means I would have to modify them after every upgrade. Oh well, I guess I can contact the creators of those plugins,

comment:3 @ocean903 years ago

  • Keywords close removed
  • Milestone Awaiting Review deleted
  • Resolution changed from fixed to worksforme

comment:4 @SergeyBiryukov3 years ago

Here's a workaround I wrote for one of my plugins in case someone decided to put it in mu-plugins:

if ( false !== strpos( __FILE__, basename( WPMU_PLUGIN_DIR ) ) )
	load_muplugin_textdomain( '...' );
	load_plugin_textdomain( '...', false, dirname( plugin_basename( __FILE__ ) ) );

comment:5 follow-up: @nacin3 years ago

  • Milestone set to Future Release
  • Resolution worksforme deleted
  • Status changed from closed to reopened
  • Type changed from defect (bug) to enhancement

We should probably merge these functions to look in both directories — plugins then mu-plugins.

comment:6 in reply to: ↑ 5 @ideag3 years ago

Replying to nacin:

We should probably merge these functions to look in both directories — plugins then mu-plugins.

something like this?

function load_plugin_textdomain( $domain, $abs_rel_path = false, $plugin_rel_path = false ) {
          $locale = apply_filters( 'plugin_locale', get_locale(), $domain );
	        if ( false !== $plugin_rel_path ) {
	                $path = WP_PLUGIN_DIR . '/' . trim( $plugin_rel_path, '/' );
	        } else if ( false !== $abs_rel_path ) {
	                _deprecated_argument( __FUNCTION__, '2.7' );
	                $path = ABSPATH . trim( $abs_rel_path, '/' );
	        } else {
	                $path = WP_PLUGIN_DIR;

                if (!is_readable($path)) {
                        $path = WPMU_PLUGIN_DIR . '/' . trim( $plugin_rel_path, '/' );
	        $mofile = $path . '/'. $domain . '-' . $locale . '.mo';
	        return load_textdomain( $domain, $mofile );

@johnbillion2 years ago

comment:7 @johnbillion2 years ago

23794.patch adds the mu-plugin fallback from ideag and updates the inline docs and deprecated argument so it's in line with other deprecated arguments.

comment:8 @TroyDesign2 years ago

I solved using code below:

add_filter( 'load_textdomain_mofile', 'tdc_mu_load_textdomain_mofile', 10, 2 );
function tdc_mu_load_textdomain_mofile($mofile, $domain) {
	$mumofile = WPMU_PLUGIN_DIR.preg_replace('%^'.WP_PLUGIN_DIR.'%','',$mofile);
	if (file_exists($mumofile)) return $mumofile;
	else return $mofile;
Version 0, edited 2 years ago by TroyDesign (next)

comment:9 @janw.oostendorp2 years ago

  • Cc janw.oostendorp@… added

comment:10 @chriscct75 weeks ago

  • Keywords needs-patch added
  • Severity changed from minor to normal
Note: See TracTickets for help on using tickets.