I developed a custom plugin with the following structure in my folders:
wp-content
--- plugins
------ my-plugin
--------- languages
------------ po and mo files
--------- my-plugin.php
I internationalized it, and the translations all worked successfully. Now, I need that plugin to be a must-use plugin, by using the following structure:
wp-content
--- mu-plugins
------ my-plugin
--------- languages
------------ po and mo files
------ my-plugin.php
(The main plugin file has to be placed directly into the mu-plugins directory to be executed, from what I learned).
I now corrected all the paths in my main plugin file, due to the slight change of the location of the main plugin file (not inside the my-plugin
folder anymore, but inside the wp-content/mu-plugins
folder, as explained above), and all my functionalities are working, except from the programmed internationalization. I don't get what I'm still missing. Below's what I did:
Code in main plugin file when it was still a normal plugin, with localizations working:
// Callback loading the textdomain 'my-plugin', defined as such in header of main plugin file
public function my_plugin_load_plugin_textdomain() {
load_plugin_textdomain(
'my-plugin',
false,
basename( dirname( __FILE__ ) ).'//languages/'
);
}
// Hook of it
add_action(
'plugins_loaded',
array( $this, 'my_plugin_load_plugin_textdomain' )
);
Here everything worked without any problem (I coded my whole main plugin file inside a class, that's why you have array( $this, callback )
above). When switching to a mu-plugin, I tried:
// Callback loading the textdomain 'my-plugin', defined as such in header of main plugin file
public function my_plugin_load_muplugin_textdomain() {
load_muplugin_textdomain(
'my-plugin',
'my-plugin/languages'
);
}
// Hook of it
add_action(
'muplugins_loaded',
array( $this, 'my_plugin_load_muplugin_textdomain' )
);
I.E.:
changed the function called in the callback from
load_plugin_textdomain()
toload_muplugin_textdomain()
, and adapted parameters as above.Changed action hook from
plugins_loaded
tomuplugins_loaded
Changed Domain Path in main plugin file header from
/languages
to/my-muplugin/languages
Yet, the localization of my mu plugin is still not working. I rechecked the locales as well, and I'm using the correct ones (for example, when I change the users language in the wp admin from german to english(UK), my translation file named my-plugin-en_GB.mo
is not applied, and everything still appears in german).
Help??
plugins-mu
isn't really intended for full blown plugins, think of it more like single file dropinsobject-cache.php
etc that live in the root ofwp-content
, you can remove the deactivate link via wordpress.stackexchange.com/questions/253902/… you can also network activate it so that only super admins can deactivate. You can also keep the plugin in the plugins folder and load it via mu-plugins, then it won't matter if it's active or not. You can also override theactive_plugins
option