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
<script>
jQuery(document).ready(function($){
$('#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();
$(this).removeClass('button-primary-disabled');
return false;
}
});
});
</script>
EOT;
}
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.
Chapters
- 59 articles in the chapter Movable Type
- 17 articles in the chapter Design
- 11 articles in the chapter Social Networking
- 7 articles in the chapter Announcements
- 7 articles in the chapter CMS
- 7 articles in the chapter Journeys
- 6 articles in the chapter Code
- 5 articles in the chapter Writing
- 5 articles in the chapter Blogging
- 4 articles in the chapter Downloads
- 4 articles in the chapter CSS
- 3 articles in the chapter Reviews
- 3 articles in the chapter Projects
- 3 articles in the chapter App
- 2 articles in the chapter DIY
- 2 articles in the chapter Freebies
- 2 articles in the chapter WordPress
- 2 articles in the chapter Gadgets
- 2 articles in the chapter Plugins
- 2 articles in the chapter Apple
- 2 articles in the chapter SEO
- 2 articles in the chapter Accessibility
- 1 articles in the chapter Beginners
- 1 articles in the chapter Javascript
- 1 articles in the chapter Miscellany
- 1 articles in the chapter Users
- 1 articles in the chapter Standards
- 1 articles in the chapter Print
- 1 articles in the chapter Mobile
- 1 articles in the chapter Photography