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

references - Modify a Filters Second Parameter

programmeradmin3浏览0评论

I have this filter:

$post_arr = apply_filters('insert_product_post_data', $post_arr, $data);
add_filter('insert_product_post_data', 'my_filter', 10, 2);
function my_filter($post_arr, $data) {
    //change $data here
    return $post_arr;
}

I need to change the value of $data is any way to do this ?

I have this filter:

$post_arr = apply_filters('insert_product_post_data', $post_arr, $data);
add_filter('insert_product_post_data', 'my_filter', 10, 2);
function my_filter($post_arr, $data) {
    //change $data here
    return $post_arr;
}

I need to change the value of $data is any way to do this ?

Share Improve this question edited Jul 6, 2020 at 16:30 Tom J Nowell 61k7 gold badges79 silver badges148 bronze badges asked Jul 6, 2020 at 14:56 GogoGogo 1133 bronze badges 3
  • No. It’s not possible. And I’m having a hard time imagining why you’d need to do this in your example. Nothing is done with $data in these post data hooks, so modifying it wouldn’t achieve anything. – Jacob Peattie Commented Jul 6, 2020 at 15:05
  • i need to do this because the guy who created this plugin closed all the doors to change this data they have verry bad conception – Gogo Commented Jul 6, 2020 at 15:08
  • it's probably worth forking and fixing up the plugin itself if there are serious flaws – shea Commented Jul 9, 2020 at 13:58
Add a comment  | 

1 Answer 1

Reset to default 2

No this isn't possible without changing the original code. Filters work on the very first parameter, the other parameters are provided for context.

You will need too either get the author to add a filter for the data variable, fork the plugin, or use a competitor.

The only exception, is if $data is an object not an array and you want to modify it. However, it cannot be replaced, and it cannot be done with an array or any other data type.

发布评论

评论列表(0)

  1. 暂无评论