gpt4 book ai didi

wordpress - 制作 Loco Translate Wordpress 插件以识别 MU-PLUGINS

转载 作者:行者123 更新时间:2023-12-04 02:07:54 26 4
gpt4 key购买 nike

我在安装 Wordpress 4.7 时使用 Loco Translate 翻译插件。

我的 MU-Plugin 已正确注册并正确配置以加载其文本域。

但 Loco Translate 只能识别主题和常规插件,因此我无法使用 Loco Translate UI 来翻译我的插件。

帮助将不胜感激。谢谢

最佳答案

欢迎来到 stack overflow Jonathan Darchy!

这里是一个将未注册的 MU 插件添加到 Loco Translate 的例子原始,取自 this gist

我认为它回答了您的问题:

<?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 );

关于wordpress - 制作 Loco Translate Wordpress 插件以识别 MU-PLUGINS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41719521/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com