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: https://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.
Comments
9 responses to “WordPress Cancel Post Button”
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. π
That’s mostly why I bothered to write the code in the first place π
Interesting. Occasionally I’ll get a client I’d like to bake another feature in for: http://cl.ly/image/3n3a0A180L1W
Multisite? In theory you’d have to let users delete their sites and then just add that to the toolbar.
I should have doctored My Sites out after I doctored ‘Cancel Website’ in π
Ah, one stupid question: what does that snippet do?
See the picture? It adds a button called ‘Cancel’ which sends you back to the list of posts/pages/etc. That’s all.
Yeah, that’s exactly what it does in my case. Thought it would delete the draft or something …
You could add in a check for that, but I’m not up to snuff on my ajaxy actions yet. Really it’s just an example on how to add stuff in there π