最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - Disable plugin function to use my own

programmeradmin0浏览0评论

I have copied a function from a plugin because I intend to run the same function with some minor changes. So, to prevent the plugin function running and also mine, I am trying to disable the plugins function.

Plugin function code

/* new product */
function um_activity_new_woo_product( $post_id ) {
....
}
add_action('save_post', 'um_activity_new_woo_product', 99999, 1 );

I thought to try the below, but has not stopped the function from running:
add_filter( 'um_activity_new_woo_product', '__return_false' );

Any ideas or changes to try?

I have copied a function from a plugin because I intend to run the same function with some minor changes. So, to prevent the plugin function running and also mine, I am trying to disable the plugins function.

Plugin function code

/* new product */
function um_activity_new_woo_product( $post_id ) {
....
}
add_action('save_post', 'um_activity_new_woo_product', 99999, 1 );

I thought to try the below, but has not stopped the function from running:
add_filter( 'um_activity_new_woo_product', '__return_false' );

Any ideas or changes to try?

Share Improve this question asked May 3, 2019 at 17:06 wharfdalewharfdale 3484 silver badges17 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 2

You can use remove_action() to remove a function from a specified action hook. Documentation

remove_action( string $tag, callable $function_to_remove, int $priority = 10 )

This function removes a function attached to a specified action hook. This method can be used to remove default functions attached to a specific filter hook and possibly replace them with a substitute.

So in your case,

// Remove the function from 'save_post' action
remove_action('save_post', 'um_activity_new_woo_product', 99999 );

// Add your own function my_activity_new_woo_product(), to 'save_post' action
add_action('save_post', 'my_activity_new_woo_product', 99999, 1 );

I hope this may help.

发布评论

评论列表(0)

  1. 暂无评论