WordPress Post Status
A library for better integration of custom post statuses with the UI in WordPress., (*1)
Getting Started
For the most part, use the same arguments as you would when directly calling register_post_status()
in WordPress:, (*2)
<?php
add_action( 'init', function () {
\wpscholar\WordPress\PostStatus::register( 'archive', [
'label' => esc_html_x( 'Archive', 'post status', 'text-domain' ),
'labels' => [
'post_state' => esc_html_x( 'Archived', 'post status state', 'text-domain' ),
],
'label_count' => _n_noop( 'Archived <span class="count">(%s)</span>', 'Archived <span class="count">(%s)</span>', 'text-domain' ),
'post_types' => [ 'post' ],
'public' => true,
'show_in_admin_all_list' => true,
'show_in_admin_status_list' => true,
] );
} );
Just be sure to replace text-domain
with your actual plugin (or theme) text domain., (*3)
Custom Arguments
The following are custom arguments:, (*4)
-
labels
- The post_state
label is used when displaying the status next to the title on the post listing page.
-
post_types
- Unless one or more post types are defined, the new status won't be assignable via the UI.
It is possible to assign any arguments you want when registering a custom post status. You can then filter by those arguments when calling get_post_stati()
., (*5)
Fetching Custom Labels
A custom label can be fetched as follows:, (*6)
<?php
// Label returned will be 'Archived' (given registration code from previous example)
$label = \wpscholar\WordPress\PostStatus::getLabel('archive', 'post_state');
If the requested label doesn't exist, the fallback is the main label
property from the post status object., (*7)