WordPress Publish Confirmation

I don’t typically like confirmation dialog boxes. In nearly all cases, an undo button is the better choice than a confirmation dialog.

However, because of our existing WordPress set up, publishing an entry sets off a whole chain of events involving RSS feed readers, caches and a CDN that make it difficult to undo. So I put together a simple WordPress function—a molly-guard, if you will—that will trigger an “Are you sure you want to publish this?” confirmation alert before firing the actual publish event.

Just drop this code into your functions.php:

/* = Add a "molly guard" to the publish button */

add_action( 'admin_print_footer_scripts', 'sr_publish_molly_guard' );
function sr_publish_molly_guard() {
echo <<<EOT 
    $('#publishing-action input[name="publish"]').click(function() {
        if(confirm('Are you sure you want to publish this?')) {
            return true;
        } else {
            $('#publishing-action .spinner').hide();
            $('#publishing-action img').hide();
            return false;

Note: This affects only the initial “Publish” event, not successive “Update” events. It’s easy enough to modify it to include both. Be sure to check out the gist—there are some revisions in there that might give you some ideas of how to tweak this to better suit your needs.