Hide the “Publish” button for certain custom statuses

We’ve all done it before — accidentally published a post before it was ready to go. With Edit Flow, you can minimize these accidents by hiding the “Publish” button for your in-progress custom statuses, and then only showing it when the post has reached the last stage of production.

First, read the introduction to extending Edit Flow. Once you’ve done so, you can modify the code snippet below to work for your needs. It will simply hide the “Publish” button until you’ve saved the post with one of the statuses in the array.

/**
 * Hide the "Publish" button until a post is ready to be published
 * In this example, we only show the "Publish button" until the post has the "Pending" status
 *
 * @see http://editflow.org/extend/hide-the-publish-button-for-certain-custom-statuses/
 */
function efx_hide_publish_button_until() {

	if ( ! function_exists( 'EditFlow' ) )
		return;

	if ( ! EditFlow()->custom_status->is_whitelisted_page() )
		return;

	// Show the publish button if the post has one of these statuses
	$show_publish_button_for_status = array(
			'pending',
			// The statuses below are WordPress' public statuses
			'future',
			'publish',
			'schedule',
			'private',
		);
	if ( ! in_array( get_post_status(), $show_publish_button_for_status ) ) {
		?>
		<style>
			#publishing-action { display: none; }
		</style>
		<?php
	}
}
add_action( 'admin_head', 'efx_hide_publish_button_until' );

Comments

  1. How do we enable this to only show the publish button when a custom edit-flow status is active? IE – instead of only when marked as pending, only when marked as “custom-edit-flow-status-name”? Thanks in advance

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: