Make WordPress Core


Ignore:
Timestamp:
09/02/2025 04:48:32 PM (9 months ago)
Author:
SergeyBiryukov
Message:

Posts, Post Types: Check the result of creating a draft in get_default_post_to_edit().

As wp_insert_post() can return an error for various reasons, this commit ensures that this scenario is properly handled and an error message is displayed.

Follow-up to [12987].

Props rishabhwp, tfrommen, SirLouen, siliconforks, SergeyBiryukov.
Fixes #37441.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/post.php

    r60681 r60701  
    769769                'post_status' => 'auto-draft',
    770770            ),
    771             false,
     771            true,
    772772            false
    773773        );
    774         $post    = get_post( $post_id );
     774
     775        if ( is_wp_error( $post_id ) ) {
     776            wp_die( $post_id->get_error_message() );
     777        }
     778
     779        $post = get_post( $post_id );
     780
    775781        if ( current_theme_supports( 'post-formats' ) && post_type_supports( $post->post_type, 'post-formats' ) && get_option( 'default_post_format' ) ) {
    776782            set_post_format( $post, get_option( 'default_post_format' ) );
    777783        }
     784
    778785        wp_after_insert_post( $post, false, null );
    779786
Note: See TracChangeset for help on using the changeset viewer.