diff --git a/src/wp-admin/includes/post.php b/src/wp-admin/includes/post.php index ebdd61df345dc..3ee280ca33184 100644 --- a/src/wp-admin/includes/post.php +++ b/src/wp-admin/includes/post.php @@ -762,9 +762,10 @@ function get_default_post_to_edit( $post_type = 'post', $create_in_db = false ) } if ( $create_in_db ) { + $default_title = post_type_supports( $post_type, 'title' ) ? __( 'Auto Draft' ) : __( '(no title supported)' ); $post_id = wp_insert_post( array( - 'post_title' => __( 'Auto Draft' ), + 'post_title' => $default_title, 'post_type' => $post_type, 'post_status' => 'auto-draft', ), diff --git a/tests/phpunit/tests/admin/includesPost.php b/tests/phpunit/tests/admin/includesPost.php index de7b42f5eb15a..86a11c9bee504 100644 --- a/tests/phpunit/tests/admin/includesPost.php +++ b/tests/phpunit/tests/admin/includesPost.php @@ -1325,4 +1325,22 @@ public function test_user_get_refreshed_metabox_nonce() { $this->assertNotEmpty( $response['wp-refresh-metabox-loader-nonces']['replace']['_wpnonce'] ); $this->assertNotEmpty( $response['wp-refresh-metabox-loader-nonces']['replace']['metabox_loader_nonce'] ); } + + /** + * Ensure default title is set to "(no title supported)" when CPT lacks title support. + * + * @ticket 45516 + */ + public function test_no_title_supported_when_title_not_supported() { + register_post_type( + 'no_title', + array( + 'supports' => array( 'editor' ), + ) + ); + + $default_post = get_default_post_to_edit( 'no_title', true ); + $post = get_post( $default_post->ID ); + $this->assertSame( '(no title supported)', $post->post_title ); + } }