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/src/wp-admin/css/dashboard.css
+++ b/src/wp-admin/css/dashboard.css
@@ -409,20 +409,9 @@
 #dashboard_right_now .search-engines-info:before,
 #dashboard_right_now li a:before,
 #dashboard_right_now li > span:before { /* get only the first level span to exclude screen-reader-text in mu-storage */
-	content: "\f159" / ''; /* generic icon for items added by CPTs ? */
 	padding: 0 5px 0 0;
 }
 
-#dashboard_right_now .page-count a:before,
-#dashboard_right_now .page-count span:before {
-	content: "\f105" / '';
-}
-
-#dashboard_right_now .post-count a:before,
-#dashboard_right_now .post-count span:before {
-	content: "\f109" / '';
-}
-
 #dashboard_right_now .comment-count a:before {
 	content: "\f101" / '';
 }
diff --git a/src/wp-admin/includes/dashboard.php b/src/wp-admin/includes/dashboard.php
index 2898e77c7f..a6c5fd47f0 100644
--- a/src/wp-admin/includes/dashboard.php
+++ b/src/wp-admin/includes/dashboard.php
@@ -320,10 +320,34 @@ function wp_dashboard_right_now() {
 			}
 			$text = number_format_i18n( $num_post_published ) . ' ' . $post_label;
 
-			if ( $post_type_object && current_user_can( $post_type_object->cap->edit_posts ) ) {
-				printf( '<li class="%1$s-count"><a href="edit.php?post_type=%1$s">%2$s</a></li>', $post_type, $text );
+			if ( str_starts_with( $post_type_object->menu_icon, 'dashicons' ) ) {
+				if ( $post_type_object && current_user_can( $post_type_object->cap->edit_posts ) ) {
+					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 );
+				} else {
+					printf( '<li class="%1$s-count"><span class="%3$s">%2$s</span></li>', $post_type, $text, $post_type_object->menu_icon );
+				}
+			} elseif ( str_starts_with( $post_type_object->menu_icon, 'data:image/svg+xml;base64,' ) ) {
+				?>
+<style>
+#dashboard_right_now li.<?php echo $post_type; ?>-count a:before,
+#dashboard_right_now li.<?php echo $post_type; ?>-count > span:before {
+	content: url( <?php echo $post_type_object->menu_icon; ?> );
+	height: auto;
+	width: 20px;
+}
+</style>
+			<?php
+				if ( $post_type_object && current_user_can( $post_type_object->cap->edit_posts ) ) {
+					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 );
+				} else {
+					printf( '<li class="%1$s-count"><span>%2$s</span></li>', $post_type, $text, $post_type_object->menu_icon );
+				}
 			} else {
-				printf( '<li class="%1$s-count"><span>%2$s</span></li>', $post_type, $text );
+				if ( $post_type_object && current_user_can( $post_type_object->cap->edit_posts ) ) {
+					printf( '<li class="%1$s-count"><a href="edit.php?post_type=%1$s">%2$s</a></li>', $post_type, $text );
+				} else {
+					printf( '<li class="%1$s-count"><span>%2$s</span></li>', $post_type, $text );
+				}
 			}
 		}
 	}
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/src/wp-includes/class-wp-post-type.php
+++ b/src/wp-includes/class-wp-post-type.php
@@ -606,6 +606,11 @@ final class WP_Post_Type {
 			$args['at_a_glance'] = (bool) $args['show_in_menu'];
 		}
 
+		// If not set, default to the post icon.
+		if ( null === $args['menu_icon'] ) {
+			$args['menu_icon'] = 'dashicons-admin-post';
+		}
+
 		// If not set, default to the setting for 'show_in_menu'.
 		if ( null === $args['show_in_admin_bar'] ) {
 			$args['show_in_admin_bar'] = (bool) $args['show_in_menu'];
-- 
2.37.0.windows.1

