Dump contents of a variable inside a filter/hook callback that runs during save post

I just need to debug an array which comes into addfilter function like this:

add_filter('pll_copy_post_metas', 'copy_post_metas');
function copy_post_metas($metas) {
    var_dump($metas);
    return $metas;
}

How can I do that to just check what is the value of $metas?

This filter runs in admin when saving a post.

2 Answers
2

When you save a post, then you are basically submitting a big <form>. This form has an action pointing somewhere. Now there are two possibilities how the form is processed:

  1. AJAX (background reload)
  2. Default <form> handling (new request)

Basic form submitting is adding a new request (2), so the data gets processed and then the page reloads – that’s the reason why you can’t see the dump contents. Adding exit or die inside your callback (preferably after the var_dump/var_export/print_r), will stop the process and let you inspect the data.

If you are processing the data via AJAX (1), you will have to open your browsers developer tools (developer toolbar – Chrome, Firebug – FireFox, etc.) and look at the console/terminal. There you normally find a link when the AJAX request gets processed. This will lead you to the “network” (or similar) tab where you can inspect the request (headers, etc.) as well as a preview and/or the raw response. In there you will see the dumped data.

Leave a Comment