How To Avoid Accidental Content Publishing In WordPress?

Sometimes it happen that you mistakenly click the ‘Publish’ button and your post goes live. This tutorial provides you a simple hack that you can put in your theme’s function.php file and then whenever you will be hitting your “Publish” button, a small dialog box will show up asking you if you’re sure about publishing your post or not. Now you can either click OK or CANCEL. Now no more acidentally published posts.

Open your theme’s function.php file and add the following code. That’s all.

$c_message = 'Are you SURE you want to publish this post?'; // This is the confirmation message that will appear.
function confirm_publish(){
    global $c_message;
    echo '
<script type="text/javascript"><!--
var publish = document.getElementById("publish");
if (publish !== null) publish.onclick = function(){
    return confirm("'.$c_message.'");
};
// --></script>';
}

add_action('admin_footer', 'confirm_publish');
?>

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.