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

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.

tech