WordPress uses PHP as the core language. So die() would be just fine to use. In fact, I have used it several times and did not notice any major bugs. Never wonder what is the real different between them before I tried the wp_die() yesterday.
This is how it is different on the look:
So, rather than design of output, what are the differences between these?
- die() = exit() = Output a message and terminate the current script.
- wp_die() – Kills WordPress execution and displays HTML page with an error message.
When to use wp_die() and die()
This completely based on my experience so please feel free to share yours.
- die() output is ugly. Not good for user experience. If you want to display the error to front-end users in a better way, should use wp_die() instead.
- When handling AJAX requests in WordPress, die() should be use to let the ajax knows when the action finish. Use case maybe a live searchbar.
- If you want to pass arguments to control behavior, use wp_die(). It has more options than die().
Anyway, I like die() because it is just purely simple PHP and just does what it supposed to do.