制作本地翻译Wordpress插件以识别MU插件
我在WordPress4.7安装中使用本地翻译插件 我已经正确注册了我的MU插件,并正确配置以加载其文本域 然而,本地翻译只能识别主题和常规插件,因此我不能使用本地翻译UI来翻译我的插件 我们将不胜感激。制作本地翻译Wordpress插件以识别MU插件,wordpress,localization,Wordpress,Localization,我在WordPress4.7安装中使用本地翻译插件 我已经正确注册了我的MU插件,并正确配置以加载其文本域 然而,本地翻译只能识别主题和常规插件,因此我不能使用本地翻译UI来翻译我的插件 我们将不胜感激。 谢谢欢迎来到stack overflow Jonathan Darchy 下面是一个将未注册的MU插件添加到本地翻译的示例 生的,取自 我想它回答了你的问题: <?php /** * MU plugins inside directories are not returned in `
谢谢欢迎来到stack overflow Jonathan Darchy 下面是一个将未注册的MU插件添加到本地翻译的示例 生的,取自 我想它回答了你的问题:
<?php
/**
* MU plugins inside directories are not returned in `get_mu_plugins`.
* This filter modifies the array obtained from Wordpress when Loco grabs it.
*
* Note that this filter only runs once per script execution, because the value is cached.
* Define the function *before* Loco Translate plugin is even included by WP.
*/
function add_unregistered_plugins_to_loco( array $plugins ){
// we know the plugin by this handle, even if WordPress doesn't
$handle = 'foo-bar/foo-bar.php';
// fetch the plugin's meta data from the would-be plugin file
$data = get_plugin_data( trailingslashit(WPMU_PLUGIN_DIR).$handle );
// extra requirement of Loco - $handle must be resolvable to full path
$data['basedir'] = WPMU_PLUGIN_DIR;
// add to array and return back to Loco Translate
$plugins[$handle] = $data;
return $plugins;
}
add_filter('loco_plugins_data', 'add_unregistered_plugins_to_loco', 10, 1 );