admin管理员组文章数量:1404927
I want to customize a plugin which uses a file called html-vendor-order-page.php to define the style of contents:
include_once( apply_filters( 'wcpv_vendor_order_page_template', dirname( __FILE__ ) . '/views/html-vendor-order-page.php' ) );
I want to create my own html-vendor-order-page.php by modifying this file and force the plugin to use this file instead by using add_filter.
I was thinking to filter __FILE__
which is a defined constant to point to my file.
Is that possible?
I want to customize a plugin which uses a file called html-vendor-order-page.php to define the style of contents:
include_once( apply_filters( 'wcpv_vendor_order_page_template', dirname( __FILE__ ) . '/views/html-vendor-order-page.php' ) );
I want to create my own html-vendor-order-page.php by modifying this file and force the plugin to use this file instead by using add_filter.
I was thinking to filter __FILE__
which is a defined constant to point to my file.
Is that possible?
Share Improve this question asked Jan 1, 2020 at 13:43 SaeidSaeid 1033 bronze badges1 Answer
Reset to default 1You can't just filter __FILE__
. Or any arbitrary function or variable. You can only filter values that are passed to apply_filters()
. In this case the wcpv_vendor_order_page_template
filterable value is:
dirname( __FILE__ ) . '/views/html-vendor-order-page.php'
In other words, it's a path to a PHP file. If you want to change the PHP file that's loaded, you can filter wcpv_vendor_order_page_template
to pass the path to a file in your theme.
So if you create a version of this file in wp-content/{yourtheme}/wcpv//views/html-vendor-order-page.php
, you can make the plugin load that version like this:
add_filter(
'wcpv_vendor_order_page_template',
function( $path ) {
return get_theme_file_path( 'wcpv//views/html-vendor-order-page.php' );
}
);
本文标签: filtersHow to override includeonce pointed file using addfilter
版权声明:本文标题:filters - How to override include_once pointed file using add_filter? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744867715a2629443.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论