WordPress:覆盖过滤器变量不起作用

时间:2019-01-07 21:05:23

标签: php wordpress function filter

我目前正在尝试覆盖插件中的过滤器。该过滤器有1个变量,用于定义一些模板所在文件夹的根路径。

此根路径通常在插件的资产文件夹中(真棒支持)。因为我想覆盖模板,所以我需要将模板文件夹的根路径更改为我自己的文件夹,以便使用我自己的模板而不是原始模板。


经过大量搜索,我在文档中找到了正确的过滤器:Filter

该过滤器在第722行应用于此文件:File

因此,我已将此过滤器添加到主题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/

您可以看到仍然设置了插件模板路径。我不知道我在做什么错..

1 个答案:

答案 0 :(得分:0)

插件作者说这是一个错误。这是修复程序的提交:

https://github.com/Awesome-Support/Awesome-Support/commit/4312c02a3e35bb369e943d807377610670e71f41