Skip to content

Commit 7c35e24

Browse files
committed
Auto Draft title issue for custom post types
1 parent 0b50baa commit 7c35e24

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/wp-admin/includes/post.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -762,9 +762,10 @@ function get_default_post_to_edit( $post_type = 'post', $create_in_db = false )
762762
}
763763

764764
if ( $create_in_db ) {
765+
$default_title = post_type_supports( $post_type, 'title' ) ? __( 'Auto Draft' ) : __( '(no title supported)' );
765766
$post_id = wp_insert_post(
766767
array(
767-
'post_title' => __( 'Auto Draft' ),
768+
'post_title' => $default_title,
768769
'post_type' => $post_type,
769770
'post_status' => 'auto-draft',
770771
),

tests/phpunit/tests/admin/includesPost.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1339,4 +1339,24 @@ public function test_user_get_refreshed_metabox_nonce() {
13391339
$this->assertNotEmpty( $response['wp-refresh-metabox-loader-nonces']['replace']['_wpnonce'] );
13401340
$this->assertNotEmpty( $response['wp-refresh-metabox-loader-nonces']['replace']['metabox_loader_nonce'] );
13411341
}
1342+
1343+
/**
1344+
* Ensure default title is set to "(no title supported)" when CPT lacks title support.
1345+
*
1346+
* @ticket 45516
1347+
*/
1348+
public function test_no_title_supported_when_title_not_supported() {
1349+
wp_set_current_user( self::$editor_id );
1350+
1351+
register_post_type(
1352+
'no_title',
1353+
array(
1354+
'supports' => array( 'editor' ),
1355+
)
1356+
);
1357+
1358+
$default_post = get_default_post_to_edit( 'no_title', true );
1359+
$post = get_post( $default_post->ID );
1360+
$this->assertSame( '(no title supported)', $post->post_title );
1361+
}
13421362
}

0 commit comments

Comments
 (0)