我目前正在尝试覆盖插件中的过滤器。此筛选器有 1 个变量,用于定义某些模板所在的文件夹的根路径。
此根路径通常位于插件的资产文件夹中(真棒支持)。因为我想覆盖模板,所以我需要将模板文件夹的根路径更改为我自己的文件夹,以便使用我自己的模板而不是原始模板。
经过大量搜索,我在文档中找到了正确的过滤器:过滤器
过滤器将应用于第 722 行的此文件中:文件
所以我已将此过滤器添加到我的主题function.php
文件中:
add_filter( 'wpas_email_template_root_path', 'set_wpas_email_template_root_path', 30, 1 );
function set_wpas_email_template_root_path( $template_root_path ) {
error_log( 'email-functions.php' );
return get_home_path() . 'wp-content/themes/' . get_option( 'stylesheet' ) . '/awesome-support/emails/';
}
为了测试它,我在我的函数中和需要覆盖根路径的地方添加了一些错误日志记录:
error_log( 'Before' );
// Allow other add-ons to set this path
apply_filters( 'wpas_email_template_root_path', $template_root_path );
error_log( 'functions-tools.php' . $template_root_path );
这是调试结果:
[08-Jan-2019 08:56:19 UTC] Before
[08-Jan-2019 08:56:19 UTC] email-functions.php
[08-Jan-2019 08:56:19 UTC] functions-tools.php/var/www/vhosts/localhost/httpdocs/wp-content/plugins/awesome-support/assets/admin/email-templates/blue-block/
如您所见,仍然设置了插件模板路径。我不知道我在这里做错了什么..
插件作者说这是一个错误。这是修复程序的提交:
https://github.com/Awesome-Support/Awesome-Support/commit/4312c02a3e35bb369e943d807377610670e71f41