Make WordPress Core

Opened 10 months ago

Last modified 9 months ago

#61068 new defect (bug)

Wrong processing post_status for custom post_status

Reported by: unknownmark's profile uNknownMark Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 6.5
Component: Posts, Post Types Keywords: has-patch
Focuses: Cc:

Description

I have added a custom post status with the register_post_status function with such args.

<?php
            $args = array(
                'label'                     => _x( 'Processing', 'Status General Name', 'text_domain' ),
                'public'                    => true,
                'show_in_admin_all_list'    => true,
                'show_in_admin_status_list' => true,
                'exclude_from_search'       => false,
                '_builtin'                  => false,
                'internal'                  => false,
                'protected'                 => false,
                'private'                   => false,
                'publicly_queryable'        => true,
            );

            register_post_status( 'cm_processing', $args );


            $args = array(
                'label'                     => _x( 'Completed', 'Status General Name', 'text_domain' ),
                'public'                    => true,
                'show_in_admin_all_list'    => true,
                'show_in_admin_status_list' => true,
                'exclude_from_search'       => false,
                '_builtin'                  => false,
                'internal'                  => false,
                'protected'                 => false,
                'private'                   => false,
                'publicly_queryable'        => true,
            );

            register_post_status( 'cm_completed', $args );

But when I created a new post and set the status "processing" it saved as a draft. Same story if I edit already existing posts.
As far as I see main problem with post status processing happened in function

_wp_translate_postdata

in the file

wp-admin/includes/post.php

Looks like resetting custom post status happened in this piece of code

<?php
        // What to do based on which button they pressed.
        if ( isset( $post_data['saveasdraft'] ) && '' !== $post_data['saveasdraft'] ) {
                $post_data['post_status'] = 'draft';
        }
        if ( isset( $post_data['saveasprivate'] ) && '' !== $post_data['saveasprivate'] ) {
                $post_data['post_status'] = 'private';
        }
        if ( isset( $post_data['publish'] ) && ( '' !== $post_data['publish'] )
                && ( ! isset( $post_data['post_status'] ) || 'private' !== $post_data['post_status'] )
        ) {
                $post_data['post_status'] = 'publish';
        }
        if ( isset( $post_data['advanced'] ) && '' !== $post_data['advanced'] ) {
                $post_data['post_status'] = 'draft';
        }
        if ( isset( $post_data['pending'] ) && '' !== $post_data['pending'] ) {
                $post_data['post_status'] = 'pending';
        }

P.S. Any working workaround while waiting to fix it?

Change History (1)

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


9 months ago
#1

  • Keywords has-patch added

### Ticket: https://core.trac.wordpress.org/ticket/61068

## Description

This PR addresses an issue where custom post statuses registered using register_post_status are not being preserved correctly when saving or updating posts. Specifically, posts set to a custom status would be incorrectly saved as drafts or other default statuses.

### Changes Made

  • Updated the _wp_translate_postdata function to ensure custom post statuses are preserved during post save and update operations.
  • Added logic to check for custom post statuses and prevent them from being overwritten by default statuses based on button presses or other conditions.
  • Simplified and clarified condition checks to maintain readability and ensure correct status transitions.
Note: See TracTickets for help on using tickets.