Custom post statuses for an editorial workflow in WordPress
WordPress has one step between draft and published: “Pending Review”. A newsroom often needs more: an editor sends a text back for revision or marks it as approved, and somebody else schedules it. register_post_status() adds such statuses, but the function has a known gap: the block editor does not show custom statuses in its interface. This article covers what works out of the box, what has to be added, and the rules that keep the workflow safe.
Problem: A news site with one editor and three contributors tracks the state of each article in a spreadsheet: submitted, needs revision, approved. The posts themselves are all “Pending” or “Draft”, and nobody sees in the admin which text waits for whom.
Solution: Keep the core status pending for “submitted”, register two statuses ha-needs-revision and ha-approved on init, show them in the post list, add a status select to the block editor with the PluginPostStatusInfo slot, allow ha-approved only for users who can publish with the wp_insert_post_data filter, and notify the author on transition_post_status.
Register the statuses
add_action( 'init', 'ha_register_editorial_statuses' );
function ha_register_editorial_statuses(): void {
register_post_status( 'ha-needs-revision', array(
'label' => _x( 'Needs revision', 'post status', 'textdomain' ),
'public' => false,
'protected' => true,
'show_in_admin_all_list' => true,
'show_in_admin_status_list' => true,
/* translators: %s: number of posts */
'label_count' => _n_noop( 'Needs revision <span class="count">(%s)</span>', 'Needs revision <span class="count">(%s)</span>', 'textdomain' ),
) );
register_post_status( 'ha-approved', array(
'label' => _x( 'Approved', 'post status', 'textdomain' ),
'public' => false,
'protected' => true,
'show_in_admin_all_list' => true,
'show_in_admin_status_list' => true,
/* translators: %s: number of posts */
'label_count' => _n_noop( 'Approved <span class="count">(%s)</span>', 'Approved <span class="count">(%s)</span>', 'textdomain' ),
) );
}
add_filter( 'display_post_states', 'ha_show_editorial_state', 10, 2 );
function ha_show_editorial_state( array $states, WP_Post $post ): array {
$status = get_post_status_object( $post->post_status );
if ( in_array( $post->post_status, array( 'ha-needs-revision', 'ha-approved' ), true ) && $status ) {
$states[ $post->post_status ] = $status->label;
}
return $states;
}
The slug is at most 20 characters (the post_status column is varchar(20)). protected makes the posts visible in the admin to users who can edit them, like drafts, and keeps them away from the front end. show_in_admin_status_list adds the links “Needs revision (2)” above the post list, and display_post_states prints the status next to the title in the list, as WordPress does for drafts.
A status select in the block editor
The block editor saves through the REST API, which accepts any registered, non-internal status. It only lacks a control for it. This script adds one to the Summary panel; it uses wp.element.createElement, so it needs no build step.
// js/editorial-status.js
( function ( wp ) {
const { createElement: el } = wp.element;
const { SelectControl } = wp.components;
const { useSelect, useDispatch } = wp.data;
// WordPress 6.6 moved the slot to wp.editor; wp.editPost still has it for older versions.
const PluginPostStatusInfo = wp.editor?.PluginPostStatusInfo ?? wp.editPost.PluginPostStatusInfo;
function HaStatusControl() {
const status = useSelect( ( select ) => select( 'core/editor' ).getEditedPostAttribute( 'status' ), [] );
const { editPost } = useDispatch( 'core/editor' );
const options = window.haEditorial.options;
if ( status === 'publish' || status === 'future' ) {
return null;
}
return el( PluginPostStatusInfo, {},
el( SelectControl, {
label: window.haEditorial.label,
value: status,
options,
onChange: ( value ) => editPost( { status: value } ),
__nextHasNoMarginBottom: true,
} )
);
}
wp.plugins.registerPlugin( 'ha-editorial-status', { render: HaStatusControl } );
} )( window.wp );
add_action( 'enqueue_block_editor_assets', 'ha_editorial_status_script' );
function ha_editorial_status_script(): void {
if ( 'post' !== get_current_screen()->post_type ) {
return;
}
wp_enqueue_script( 'ha-editorial-status', plugins_url( 'js/editorial-status.js', __FILE__ ),
array( 'wp-components', 'wp-data', 'wp-edit-post', 'wp-editor', 'wp-element', 'wp-plugins' ), '1.0.0', true );
$options = array(
array( 'value' => 'draft', 'label' => __( 'Draft', 'textdomain' ) ),
array( 'value' => 'pending', 'label' => __( 'Submitted', 'textdomain' ) ),
array( 'value' => 'ha-needs-revision', 'label' => __( 'Needs revision', 'textdomain' ) ),
);
if ( current_user_can( 'publish_posts' ) ) {
$options[] = array( 'value' => 'ha-approved', 'label' => __( 'Approved', 'textdomain' ) );
}
wp_localize_script( 'ha-editorial-status', 'haEditorial', array(
'label' => __( 'Editorial status', 'textdomain' ),
'options' => $options,
) );
}
The new status is saved with the next click on “Save”. The block editor’s own buttons do not know the custom statuses: for a post in ha-approved, the main button still says “Publish” (for editors) or “Submit for Review” (for contributors), which is what the workflow needs next anyway.
Only editors approve
Hiding the option in the select is not a permission check, a REST request can set any registered status. The server decides:
add_filter( 'wp_insert_post_data', 'ha_guard_approved_status', 10, 2 );
function ha_guard_approved_status( array $data, array $postarr ): array {
if ( 'ha-approved' === $data['post_status'] && ! current_user_can( 'publish_posts' ) ) {
$previous = empty( $postarr['ID'] ) ? '' : get_post_status( $postarr['ID'] );
$data['post_status'] = ( $previous && 'ha-approved' !== $previous ) ? $previous : 'pending';
}
return $data;
}
The filter runs before the database write, also for REST requests, Quick Edit and wp_insert_post() from code. A contributor’s attempt keeps the old status instead of ending the request with an error halfway through the save. This is also why the check is not in transition_post_status: that hook fires after the post is already stored.
Notify the author
add_action( 'transition_post_status', 'ha_editorial_notify', 10, 3 );
function ha_editorial_notify( string $new, string $old, WP_Post $post ): void {
if ( $new === $old || 'post' !== $post->post_type || ! in_array( $new, array( 'ha-needs-revision', 'ha-approved' ), true ) ) {
return;
}
$author = get_userdata( $post->post_author );
if ( ! $author || get_current_user_id() === (int) $post->post_author ) {
return;
}
$label = get_post_status_object( $new )->label;
wp_mail(
$author->user_email,
/* translators: 1: status, 2: post title */
sprintf( __( '[%1$s] %2$s', 'textdomain' ), $label, wp_strip_all_tags( get_the_title( $post ) ) ),
/* translators: %s: edit link */
sprintf( __( "The status of your article changed. Edit it here:\n%s", 'textdomain' ), get_edit_post_link( $post->ID, 'raw' ) )
);
}
get_edit_post_link() with 'raw' returns the URL without &, which matters in a plain text email. Similar transitions for WooCommerce orders work the same way: custom order statuses in WooCommerce.
NOTE: Deactivating the plugin leaves posts with a status WordPress no longer knows: they disappear from all post lists in the admin. Before removing the plugin, move them back, for example with wp post list --post_status=ha-approved --format=ids and wp post update ... --post_status=pending. Custom statuses in the block editor are a long-standing open topic in the Gutenberg project; editorial plugins like PublishPress solve it with their own interface.