GeneratorsContentPost Status

Post Status Generator

register_post_status() alone gets you a status nobody can select. This adds the editor dropdown, the list-table link and the label the display shows.

in-review-status.php
Saved just now
The status
%s is the count. Without it the number never shows in the list-table links.
Post types that can use it
Visibility
public
Posts in this status are viewable on the front end by anyone with the link.
internal
For core plumbing only — auto-draft and inherit use this. Leave it off.
exclude_from_search
Keeps these posts out of site search and feeds.
show_in_admin_all_list
Include them in the "All" view of the posts list.
show_in_admin_status_list
The filter link with a count at the top of the posts list.
date_floating
Leave the post date unset until it is published, the way drafts behave.
Make it usable
Label beside the post title
The display_post_states filter, so the list shows "— In review".
Editor status dropdown
Adds the option to the classic editor Status select. The block editor ignores PHP statuses.
Include in the All view
A pre_get_posts helper for when show_in_admin_all_list is off but you still want it in All.
<?php
// Generated with WP CodeKit — powered by GrowQuest (https://growquest.io).
/**
 * Plugin Name:       In review post status
 * Description:       Registers the in-review status for post.
 * Version:           1.0.0
 * Requires PHP:      7.4
 * Text Domain:       acme
 */

defined( 'ABSPATH' ) || exit;

/**
 * Register the In review status.
 */
function acme_register_status() {
	register_post_status(
		'in-review',
		array(
			'label'                     => _x( 'In review', 'post status', 'acme' ),
			'label_count'               => _n_noop(
				'In review <span class="count">(%s)</span>',
				'In review <span class="count">(%s)</span>',
				'acme'
			),
			'public'                    => false,
			'internal'                  => false,
			'exclude_from_search'       => true,
			'show_in_admin_all_list'    => true,
			'show_in_admin_status_list' => true,
			'date_floating'             => true,
			'post_type'                 => array( 'post' ),
		)
	);
}
add_action( 'init', 'acme_register_status' );

/**
 * Show the status beside the title in the posts list.
 *
 * @param string[] $states Existing state labels.
 * @param WP_Post  $post   The post.
 * @return string[]
 */
function acme_display_state( $states, $post ) {
	if ( 'in-review' === get_post_status( $post ) ) {
		$states['in-review'] = _x( 'In review', 'post status', 'acme' );
	}

	return $states;
}
add_filter( 'display_post_states', 'acme_display_state', 10, 2 );

/**
 * Add the status to the classic editor dropdown.
 *
 * The block editor ignores PHP-registered statuses, so this only
 * affects the classic editor and Quick Edit.
 *
 * @param WP_Post $post The post being edited.
 */
function acme_submitbox_status( $post ) {
	if ( ! in_array( $post->post_type, array( 'post' ), true ) ) {
		return;
	}

	$label  = _x( 'In review', 'post status', 'acme' );
	$option = sprintf(
		'<option value="%1$s"%2$s>%3$s</option>',
		esc_attr( 'in-review' ),
		selected( get_post_status( $post ), 'in-review', false ),
		esc_html( $label )
	);
	?>
	<script>
	jQuery( function ( $ ) {
		var option = <?php echo wp_json_encode( $option ); ?>;
		var label  = <?php echo wp_json_encode( $label ); ?>;

		$( 'select#post_status' ).append( option );

		<?php if ( get_post_status( $post ) === 'in-review' ) : ?>
			$( '#post-status-display' ).text( label );
		<?php endif; ?>
	} );
	</script>
	<?php
}
add_action( 'post_submitbox_misc_actions', 'acme_submitbox_status' );