From 9f63fc6cc41542716cfa9ef62c9e3cbb88cc4e69 Mon Sep 17 00:00:00 2001
From: Paul Biron <paul@sparrowhawkcomputing.com>
Date: Sun, 21 Dec 2025 16:04:52 -0700
Subject: [PATCH] Use the `menu_icon` set when the post type was registered as
the icon for the At a Glance item.
Outputting inline CSS to handle the case of SVG menu_icons is a bit of a kludge. If someone can find a cleaner implementation I'll be all ears.
---
src/wp-admin/css/dashboard.css | 11 ----------
src/wp-admin/includes/dashboard.php | 30 +++++++++++++++++++++++---
src/wp-includes/class-wp-post-type.php | 5 +++++
3 files changed, 32 insertions(+), 14 deletions(-)
diff --git a/src/wp-admin/css/dashboard.css b/src/wp-admin/css/dashboard.css
index 9901d1c2a2..e8ebe1cd7d 100644
|
a
|
b
|
|
| 409 | 409 | #dashboard_right_now .search-engines-info:before, |
| 410 | 410 | #dashboard_right_now li a:before, |
| 411 | 411 | #dashboard_right_now li > span:before { /* get only the first level span to exclude screen-reader-text in mu-storage */ |
| 412 | | content: "\f159" / ''; /* generic icon for items added by CPTs ? */ |
| 413 | 412 | padding: 0 5px 0 0; |
| 414 | 413 | } |
| 415 | 414 | |
| 416 | | #dashboard_right_now .page-count a:before, |
| 417 | | #dashboard_right_now .page-count span:before { |
| 418 | | content: "\f105" / ''; |
| 419 | | } |
| 420 | | |
| 421 | | #dashboard_right_now .post-count a:before, |
| 422 | | #dashboard_right_now .post-count span:before { |
| 423 | | content: "\f109" / ''; |
| 424 | | } |
| 425 | | |
| 426 | 415 | #dashboard_right_now .comment-count a:before { |
| 427 | 416 | content: "\f101" / ''; |
| 428 | 417 | } |
diff --git a/src/wp-admin/includes/dashboard.php b/src/wp-admin/includes/dashboard.php
index 2898e77c7f..a6c5fd47f0 100644
|
a
|
b
|
function wp_dashboard_right_now() { |
| 320 | 320 | } |
| 321 | 321 | $text = number_format_i18n( $num_post_published ) . ' ' . $post_label; |
| 322 | 322 | |
| 323 | | if ( $post_type_object && current_user_can( $post_type_object->cap->edit_posts ) ) { |
| 324 | | printf( '<li class="%1$s-count"><a href="edit.php?post_type=%1$s">%2$s</a></li>', $post_type, $text ); |
| | 323 | if ( str_starts_with( $post_type_object->menu_icon, 'dashicons' ) ) { |
| | 324 | if ( $post_type_object && current_user_can( $post_type_object->cap->edit_posts ) ) { |
| | 325 | printf( '<li class="%1$s-count"><a class="%3$s" href="edit.php?post_type=%1$s">%2$s</a></li>', $post_type, $text, $post_type_object->menu_icon ); |
| | 326 | } else { |
| | 327 | printf( '<li class="%1$s-count"><span class="%3$s">%2$s</span></li>', $post_type, $text, $post_type_object->menu_icon ); |
| | 328 | } |
| | 329 | } elseif ( str_starts_with( $post_type_object->menu_icon, 'data:image/svg+xml;base64,' ) ) { |
| | 330 | ?> |
| | 331 | <style> |
| | 332 | #dashboard_right_now li.<?php echo $post_type; ?>-count a:before, |
| | 333 | #dashboard_right_now li.<?php echo $post_type; ?>-count > span:before { |
| | 334 | content: url( <?php echo $post_type_object->menu_icon; ?> ); |
| | 335 | height: auto; |
| | 336 | width: 20px; |
| | 337 | } |
| | 338 | </style> |
| | 339 | <?php |
| | 340 | if ( $post_type_object && current_user_can( $post_type_object->cap->edit_posts ) ) { |
| | 341 | printf( '<li class="%1$s-count"><a href="edit.php?post_type=%1$s">%2$s</a></li>', $post_type, $text, $post_type_object->menu_icon ); |
| | 342 | } else { |
| | 343 | printf( '<li class="%1$s-count"><span>%2$s</span></li>', $post_type, $text, $post_type_object->menu_icon ); |
| | 344 | } |
| 325 | 345 | } else { |
| 326 | | printf( '<li class="%1$s-count"><span>%2$s</span></li>', $post_type, $text ); |
| | 346 | if ( $post_type_object && current_user_can( $post_type_object->cap->edit_posts ) ) { |
| | 347 | printf( '<li class="%1$s-count"><a href="edit.php?post_type=%1$s">%2$s</a></li>', $post_type, $text ); |
| | 348 | } else { |
| | 349 | printf( '<li class="%1$s-count"><span>%2$s</span></li>', $post_type, $text ); |
| | 350 | } |
| 327 | 351 | } |
| 328 | 352 | } |
| 329 | 353 | } |
diff --git a/src/wp-includes/class-wp-post-type.php b/src/wp-includes/class-wp-post-type.php
index f3585e8704..4135b79f3f 100644
|
a
|
b
|
final class WP_Post_Type { |
| 606 | 606 | $args['at_a_glance'] = (bool) $args['show_in_menu']; |
| 607 | 607 | } |
| 608 | 608 | |
| | 609 | // If not set, default to the post icon. |
| | 610 | if ( null === $args['menu_icon'] ) { |
| | 611 | $args['menu_icon'] = 'dashicons-admin-post'; |
| | 612 | } |
| | 613 | |
| 609 | 614 | // If not set, default to the setting for 'show_in_menu'. |
| 610 | 615 | if ( null === $args['show_in_admin_bar'] ) { |
| 611 | 616 | $args['show_in_admin_bar'] = (bool) $args['show_in_menu']; |