Using wp_die for error messages

While developing a plugin, we might have to display error messages if something went terrible wrong and the user just can go on, like if their version of PHP is too old.

One way to do it is with die('error'), which kills the page and displays the error message. However, this doesn’t look very pretty and no HTML is printed. Just an empty document with the text ‘error’.

Instead, we could use WordPress build-in function wp_die(), which creates a better looking error message, in which we can provide helpful links etc.

Code Snippet:

<?php wp_die( __("Your PHP version isn't up-to-date, please <a href='http://php.net'>update</a>.") ); ?>

Posted in Pure hacks