From 501fa4bd4e2fd10429edada07d52d1b5d3f7272a Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Tue, 2 Sep 2025 16:50:32 +0000 Subject: [PATCH] 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 --- wp-admin/includes/post.php | 11 +++++++++-- wp-includes/version.php | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/wp-admin/includes/post.php b/wp-admin/includes/post.php index 0163008d17..97345331de 100644 --- a/wp-admin/includes/post.php +++ b/wp-admin/includes/post.php @@ -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. diff --git a/wp-includes/version.php b/wp-includes/version.php index c855bc32b9..ca44c1c024 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -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.