Make WordPress Core

Opened 4 years ago

Last modified 5 months 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 (5)

#1 @angryjim
4 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
4 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.

This ticket was mentioned in PR #9723 on WordPress/wordpress-develop by @callumbw95.


6 months ago
#3

  • Keywords has-patch added; needs-patch removed

Update the get_post_statuses() team to return all of the previous post statuses, alongside any custom post statuses registered outside of core. I have also included filters on the output, as well as the on the $excluded_status to make working with post statuses easier.

Trac ticket: #55895

#4 @callumbw95
6 months ago

Hi @angryjim,

I've reviewed the get_post_statuses() function and submitted a PR with a proposed update building on your original work. My implementation ensures that all core post statuses are returned, along with any custom statuses, while still excluding those that were previously hidden.

The goal is to preserve existing behavior by default, so the function continues to operate as it always has—now with the added benefit of supporting custom post statuses. This approach should help avoid any breaking changes for external code, including plugins and themes.

Let me know your thoughts. 😃

#5 @mindctrl
5 months ago

  • Keywords needs-patch added; has-patch removed

@callumbw95 in the original description there was interest in custom statuses showing in the UI, to make it possible to select the status. Your PR doesn't address that part of the ticket.

Also, the proposed approach will not work for the use case described above, since get_post_statuses() is only used in one place in core, and that's in the wp_xmlrpc_server class.

Note: See TracTickets for help on using tickets.