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.
Built from https://develop.svn.wordpress.org/trunk@60701


git-svn-id: http://core.svn.wordpress.org/trunk@60037 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov
2025-09-02 16:50:32 +00:00
parent cc73b8b920
commit 501fa4bd4e
2 changed files with 10 additions and 3 deletions

View File

@@ -768,13 +768,20 @@ function get_default_post_to_edit( $post_type = 'post', $create_in_db = false )
'post_type' => $post_type,
'post_status' => 'auto-draft',
),
false,
true,
false
);
$post = get_post( $post_id );
if ( is_wp_error( $post_id ) ) {
wp_die( $post_id->get_error_message() );
}
$post = get_post( $post_id );
if ( current_theme_supports( 'post-formats' ) && post_type_supports( $post->post_type, 'post-formats' ) && get_option( 'default_post_format' ) ) {
set_post_format( $post, get_option( 'default_post_format' ) );
}
wp_after_insert_post( $post, false, null );
// Schedule auto-draft cleanup.

View File

@@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '6.9-alpha-60700';
$wp_version = '6.9-alpha-60701';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.