diff --git a/src/wp-includes/view-config.php b/src/wp-includes/view-config.php index f0448d976433c..fa7b4f852877a 100644 --- a/src/wp-includes/view-config.php +++ b/src/wp-includes/view-config.php @@ -45,7 +45,8 @@ function wp_get_entity_view_config_hook_name( $kind, $name ) { * returns `false`. * * @since 7.1.0 - * @since 7.2.0 Shows a placeholder for an empty excerpt and a missing author. + * @since 7.2.0 Shows a placeholder for an empty excerpt and a missing author, + * and summarizes the `date` panel with the `publish_date` field. * * @return array The default form configuration. */ @@ -95,7 +96,13 @@ function _wp_get_default_posttype_form() { 'sticky', ), ), - 'date', + array( + 'id' => 'date', + 'layout' => array( + 'type' => 'panel', + 'summary' => 'publish_date', + ), + ), 'slug', array( 'id' => 'author', diff --git a/tests/phpunit/tests/view-config.php b/tests/phpunit/tests/view-config.php index 745fbbaab6821..84e6fb113de2c 100644 --- a/tests/phpunit/tests/view-config.php +++ b/tests/phpunit/tests/view-config.php @@ -139,6 +139,59 @@ public static function data_default_form_post_types() { ); } + /** + * The `date` panel of the default form is summarized by the + * `publish_date` field, which reads "Immediately" while the post has no + * date of its own. + * + * @ticket 65981 + * + * @covers ::_wp_get_default_posttype_form + * + * @dataProvider data_default_form_post_types + * + * @param string $post_type The post type. + */ + public function test_date_panel_is_summarized_by_publish_date( $post_type ) { + if ( ! post_type_exists( $post_type ) ) { + register_post_type( $post_type ); + } + + $config = wp_get_entity_view_config( 'postType', $post_type ); + + $this->assertSame( + array( + 'type' => 'panel', + 'summary' => 'publish_date', + ), + $this->get_form_field( $config, 'date' )['layout'] + ); + + if ( 'page' !== $post_type && 'post' !== $post_type ) { + unregister_post_type( $post_type ); + } + } + + /** + * Post types with their own form keep their `date` member, if any, as it + * is. + * + * @ticket 65981 + * + * @dataProvider data_post_types_with_own_form + * + * @param string $post_type The post type. + */ + public function test_own_form_post_types_do_not_get_date_summary( $post_type ) { + $config = wp_get_entity_view_config( 'postType', $post_type ); + $date = $this->get_form_field( $config, 'date' ); + + $this->assertFalse( + isset( $date['layout']['summary'] ), + "The `date` member of the $post_type form should not have a summary." + ); + } + /** * Post types with their own form do not receive the default form groups. *