filters - How to override include_once pointed file using add_filter?

I want to customize a plugin which uses a file called html-vendor-order-page.php to define the style of contents:include

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 badges
Add a comment  | 

1 Answer 1

Reset to default 1

You 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

相关推荐

  • filters - How to override include_once pointed file using add_filter?

    I want to customize a plugin which uses a file called html-vendor-order-page.php to define the style of contents:include

    3天前
    50

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信