diff --git a/src/wp-admin/includes/dashboard.php b/src/wp-admin/includes/dashboard.php
index d45f1e2477..ed10e49354 100644
a
|
b
|
function wp_dashboard_right_now() { |
264 | 264 | <div class="main"> |
265 | 265 | <ul> |
266 | 266 | <?php |
267 | | // Posts and Pages |
268 | | foreach ( array( 'post', 'page' ) as $post_type ) { |
| 267 | // At a Glance Post Types |
| 268 | foreach ( get_post_types( array( 'at_a_glance' => true ) ) as $post_type ) { |
269 | 269 | $num_posts = wp_count_posts( $post_type ); |
270 | 270 | if ( $num_posts && $num_posts->publish ) { |
271 | | if ( 'post' == $post_type ) { |
272 | | $text = _n( '%s Post', '%s Posts', $num_posts->publish ); |
273 | | } else { |
274 | | $text = _n( '%s Page', '%s Pages', $num_posts->publish ); |
275 | | } |
276 | | $text = sprintf( $text, number_format_i18n( $num_posts->publish ) ); |
277 | 271 | $post_type_object = get_post_type_object( $post_type ); |
| 272 | if ( ! $post_type_object ) { |
| 273 | continue; |
| 274 | } |
| 275 | $post_label = 1 === intval( $num_posts->publish ) ? $post_type_object->labels->singular_name : $post_type_object->labels->name; |
| 276 | $text = sprintf( '%s %s', number_format_i18n( $num_posts->publish ), $post_label ); |
278 | 277 | if ( $post_type_object && current_user_can( $post_type_object->cap->edit_posts ) ) { |
279 | 278 | printf( '<li class="%1$s-count"><a href="edit.php?post_type=%1$s">%2$s</a></li>', $post_type, $text ); |
280 | 279 | } else { |
diff --git a/src/wp-includes/class-wp-post-type.php b/src/wp-includes/class-wp-post-type.php
index f2e14a0a93..e5b4f535ed 100644
a
|
b
|
final class WP_Post_Type { |
127 | 127 | */ |
128 | 128 | public $show_in_menu = null; |
129 | 129 | |
| 130 | /** |
| 131 | * Makes this post type visible in the At a Glance dashboard widget. |
| 132 | * |
| 133 | * Default is the value of $show_in_menu. |
| 134 | * |
| 135 | * @var bool $at_a_glance |
| 136 | */ |
| 137 | public $at_a_glance = null; |
| 138 | |
130 | 139 | /** |
131 | 140 | * Makes this post type available for selection in navigation menus. |
132 | 141 | * |
… |
… |
final class WP_Post_Type { |
405 | 414 | 'show_in_rest' => false, |
406 | 415 | 'rest_base' => false, |
407 | 416 | 'rest_controller_class' => false, |
| 417 | 'at_a_glance' => null, |
408 | 418 | '_builtin' => false, |
409 | 419 | '_edit_link' => 'post.php?post=%d', |
410 | 420 | ); |
… |
… |
final class WP_Post_Type { |
428 | 438 | $args['show_in_menu'] = $args['show_ui']; |
429 | 439 | } |
430 | 440 | |
| 441 | // If not set, default to the setting for show_in_menu |
| 442 | if ( null === $args['at_a_glance'] ) { |
| 443 | $args['at_a_glance'] = (bool) $args['show_in_menu']; |
| 444 | } |
| 445 | |
431 | 446 | // If not set, default to the whether the full UI is shown. |
432 | 447 | if ( null === $args['show_in_admin_bar'] ) { |
433 | 448 | $args['show_in_admin_bar'] = (bool) $args['show_in_menu']; |
diff --git a/src/wp-includes/post.php b/src/wp-includes/post.php
index 7636c3d02b..b76f2757c5 100644
a
|
b
|
function create_initial_post_types() { |
78 | 78 | ), |
79 | 79 | 'public' => true, |
80 | 80 | 'show_ui' => true, |
| 81 | 'at_a_glance' => false, |
81 | 82 | '_builtin' => true, /* internal use only. don't use this when registering your own post type. */ |
82 | 83 | '_edit_link' => 'post.php?post=%d', /* internal use only. don't use this when registering your own post type. */ |
83 | 84 | 'capability_type' => 'post', |
diff --git a/tests/phpunit/tests/post/types.php b/tests/phpunit/tests/post/types.php
index cdab0337f3..56ef194498 100644
a
|
b
|
class Tests_Post_Types extends WP_UnitTestCase { |
156 | 156 | $this->assertSame( $public, $args->show_in_admin_bar ); |
157 | 157 | } |
158 | 158 | |
| 159 | /** |
| 160 | * @ticket 45035 |
| 161 | * @covers ::register_post_type() |
| 162 | */ |
| 163 | function test_register_post_type_at_a_glance_should_default_to_value_of_show_in_menu() { |
| 164 | /* |
| 165 | * 'public' Default is false |
| 166 | * 'show_ui' Default is null ('public') |
| 167 | * 'show_in_menu' Default is null ('show_ui' > 'public') |
| 168 | * 'at_a_glance' Default is null ('show_in_menu' > 'show_ui' > 'public') |
| 169 | */ |
| 170 | $args = $this->register_post_type( array( 'public' => $public = false ) ); |
| 171 | |
| 172 | // Should fall back to 'show_in_menu'. |
| 173 | $this->assertSame( $args->show_in_menu, $args->at_a_glance ); |
| 174 | |
| 175 | // Should fall back to 'show_ui'. |
| 176 | $this->assertSame( $args->show_ui, $args->at_a_glance ); |
| 177 | |
| 178 | // Should fall back to 'public'. |
| 179 | $this->assertSame( $public, $args->at_a_glance ); |
| 180 | } |
| 181 | |
159 | 182 | function test_register_taxonomy_for_object_type() { |
160 | 183 | global $wp_taxonomies; |
161 | 184 | |