Make WordPress Core

Opened 3 years ago

Last modified 3 years ago

#55895 new defect (bug)

Register custom post statuses

Reported by: angryjim's profile angryjim Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Posts, Post Types Keywords: dev-feedback needs-patch
Focuses: Cc:

Description (last modified by SergeyBiryukov)

When a developer register a custom post status with register_post_status() The post status is not added to the visual parts of a post this means you can not set the post to this new status after register the new post status.

There have been several workarounds to this adding functions to get them visible but with recent WP versions this seems to have stopped working.

Another feature to add is regarding the get_post_statuses() and get_page_statuses() only returns a static array instead of checking the available post statues. There should also be a filter on this function to Add The correct label for your custom post status.

Things to improve:

  • Expand get_post_statuses() and get_page_statuses() to actually return the registered statuses. Add a filter to be able to label your custom post status correctly.
  • When custom post status is added it should also be available:
    • In the post list overview the post status if not published should be in the name like (draft etc)
    • When quick editing / bulk editing the options of all post status types should be available.
    • When editing a post the post status should be available in the right settings column this should also work with the classic- and Gutenberg- mode.

There is an old ticket with large thread about similar issues here: #12706.

Change History (2)

#1 @angryjim
3 years ago

Improvement suggestion on the get_post_status() so it can be used to fetch all the registered post statues with a description label. Also add a filter to let the dev change the description.

<?php
/**
 * ac_get_post_statuses()
 *
 * Return a list of registered post statuses core and custom with label
 * Provides the post status name and label description
 *
 * @param array $status Array of default status labels keyed by their status.
 * @return string[] Array of post status labels keyed by their status.
 */
public function ac_get_post_statuses() : array {
        $status = [
                'draft'   => __( 'Draft' ),
                'pending' => __( 'Pending Review' ),
                'private' => __( 'Private' ),
                'publish' => __( 'Published' ),
        ];

        foreach ( get_post_stati() as $post_status_name => $value ) {
                if ( ! array_key_exists( $post_status_name, $status ) ) {
                        $status[ $post_status_name ] = $value;
                }
        }

        return apply_filters( 'post_statuses_labels', $status );
}
?>


#2 @SergeyBiryukov
3 years ago

  • Description modified (diff)
  • Keywords needs-testing post-status custom-post-status removed

Hi there, welcome to WordPress Trac! Thanks for the ticket.

Adjusting the keywords per Trac Workflow Keywords.

Note: See TracTickets for help on using tickets.