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' );
}
);
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744867716a4598075.html
评论列表(0条)