Did you test your code while trashing a post or deleting permanently? “Trashing” a post is not really deleting it. Deleting permanently from the trash listing is deleting. For various reasons, none of your verification code may be 100% effective. Either the browser is not expecting output at the time or permissions prevent writing to logs.txt. For reliable verification, either use wp_die() or error_log().
The action fires on my site when deleting permanently from the trash listing. I used your code, but none of your methods were effective for me. I added in an error_log() call as well. That one did work.
Hi,
Thanks for your response.
I was deleting permanently.
However, I followed your advice of using wp_die() as my way of checking execution, and I actually started getting a response. Thanks very much for that suggestion. I used this to debug my issue. Issue turned out to be my side in the end. As I worked my way through it, it turned out to be stupidly simple: it wasn’t accessing the json file! It was supposed edit the one I’d set, but it was supposed to iterate over another one too, and it wasn’t doing that because… I didn’t tell it to!
Wouldn’t have been able to get there without your wp_die() suggestion. I was trying to debug it to find the failure point by writing to console, but yeah, as you suggested, the browser wasn’t expecting output. My echo’d console.log didn’t fire until wp_die() was invoked, at which point using the console was redundant.
I wasn’t aware of wp_die() before this. This is a far better way for me to test and debug, since it prevents the final execution, meaning I don’t have to reset the conditions (e.g. creating and deleting posts).
Cheers!
You’re welcome! It’s almost always something stupid simple 🙂 But finding it can be far from simple. I find debugging PHP very challenging, especially background tasks. Before PHP, I had gotten used to IDEs where we can easily set break points, add watches, step through code, etc. Nowadays there is Xdebug, but when I started with PHP, what was available was very crude and I learned to do without.