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 ?

  • 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 Jul 6 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 – Morad Angel Jul 6 at 15:08
  • it's probably worth forking and fixing up the plugin itself if there are serious flaws – shea Jul 9 at 13:58

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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.