$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>plugins - Override filter variable not working|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

plugins - Override filter variable not working

matteradmin10PV0评论

I'm currently trying to override a filter in a plugin. This filter has 1 variable which defines a root path to a folder where some templates are located.

This root path is normally in the assets folder of the plugin (Awesome Support). Because I want to override the templates I need to change the root path of the templates folder to my own folder so that my own templates are used and not the original ones.


After a lot of searching I found the right filter in the documentation: Filter

The filter gets applied in this file on line 722: File

So I've added this filter to my themes function.php file:

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/';
}

To test it I've added some error logging in my function and at the place where I need to override the root path:

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

This is the debugging result:

[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/

As you can see there is still the plugins template path set. I don't know what I'm doing wrong here..

I'm currently trying to override a filter in a plugin. This filter has 1 variable which defines a root path to a folder where some templates are located.

This root path is normally in the assets folder of the plugin (Awesome Support). Because I want to override the templates I need to change the root path of the templates folder to my own folder so that my own templates are used and not the original ones.


After a lot of searching I found the right filter in the documentation: Filter

The filter gets applied in this file on line 722: File

So I've added this filter to my themes function.php file:

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/';
}

To test it I've added some error logging in my function and at the place where I need to override the root path:

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

This is the debugging result:

[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/

As you can see there is still the plugins template path set. I don't know what I'm doing wrong here..

Share Improve this question asked Jan 8, 2019 at 9:29 Johnny97Johnny97 2147 silver badges18 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

The plugin author said that this is a bug. The fix will be included into the next release in some days. Therefore you can see the changes in the link below:

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

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far