WordPress Cancel Post Button

Someone asked about this in the forums. I can see why folks would find it useful, so here’s a simple addition to add a ‘Cancel Post’ button to your publishing metabox.

This plugin checks what post-type you’re on and redirects you correctly for pages and CPTs.

To Install

Make a file called cancel-button.php and put it in your mu-plugins folder (if you don’t have one, just make it in /wp-content/). In that file, paste the following (yes there’s no ending PHP tag, it’s okay, you don’t need it):

<?php

/* 
Plugin Name: Cancel
Plugin URI: http://halfelf.org/
Description: Adds a 'cancel' button to posts, next to Publish.
Version: 1.0
Author: Ipstenu
License: GPL2

*/

add_action( 'post_submitbox_misc_actions', 'author_in_publish' );

function author_in_publish() {
    $screen = get_current_screen();
    $cancel = get_admin_url();
    if ( $screen->id == 'post') {$cancel = "edit.php"; }
    else { $cancel = "edit.php?post_type=$screen->id";}
    
    echo "<div class=\"misc-pub-section\"><a class=\"button\" href=\"".$cancel."\" id=\"post-preview\">".__('Cancel Post')."</a><input type=\"hidden\" name=\"wp-cancelpost\" id=\"wp-cancelpost\" value=\"\"></div>";
}

This will add the button for all your sites on a network, if you happen to use Multisite.

StudioPress Theme of the Month

Comments

  1. This is fantastic. While I don’t have a use for this button per se, you’ve just shown me how to hook into the submitbox via example. Thanks! Been wondering about that, but haven’t had a reason to actually do it, so I hadn’t had call to learn before today. :-)

  2. Interesting. Occasionally I’ll get a client I’d like to bake another feature in for: http://cl.ly/image/3n3a0A180L1W

  3. Jack Beauregard says:

    Ah, one stupid question: what does that snippet do?

  4. Jack Beauregard says:

    Yeah, that’s exactly what it does in my case. Thought it would delete the draft or something …

Half-Elf? Try Half OFF WordPress ebooks!