Skip to content

Instantly share code, notes, and snippets.

@mjangda
Created October 22, 2010 18:29
Show Gist options
  • Save mjangda/641110 to your computer and use it in GitHub Desktop.
Save mjangda/641110 to your computer and use it in GitHub Desktop.
WordPress confirm on publish
<?php
/*
Plugin Name: Confirm On Publish
Description: Prompts you to confirm if you want to publish or update a post
*/
add_action( 'load-post.php', 'x_confirm_before_publish' );
function x_confirm_before_publish() {
?>
<script>
;(function($) {
// Not quite perfect because it triggers the auto-save and the loady spinny doesn't go away after if you cancel
jQuery(document).ready(function() {
jQuery('#publish').click(function(e) {
if(!confirm('Are you sure you want to publish this?')) return false;
});
});
})(jQuery);
</script>
<?php
}
@sbressler
Copy link

My version (just the JS) that I wrote a few months back, which also hides the throbber:

jQuery(document).ready(function($) {
    if ( $("input#publish").attr("value") == "Publish" ) {
        $("input#publish").click(function() {
            if (!confirm('Are you sure you want to publish this?')) {
                // Apparently just calling removeClass doesn't work, so as a hack, set a timeout of 0 so it happens a second later
                setTimeout("jQuery('input#publish').removeClass('button-primary-disabled')", 0);
                setTimeout("jQuery('input#save-post').removeClass('button-disabled')", 0);
                $("div#publishing-action img#ajax-loading").hide();
                return false;
            } else {
                $("div#publishing-action img#ajax-loading").show();
            }
        });
    }
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment