Skip to content

Commit 4928cc7

Browse files
committed
pbiron's update: dashboard widget icons with dashicons and svg
1 parent 08db4f0 commit 4928cc7

File tree

3 files changed

+29
-14
lines changed

3 files changed

+29
-14
lines changed

src/wp-admin/css/dashboard.css

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -409,20 +409,9 @@
409409
#dashboard_right_now .search-engines-info:before,
410410
#dashboard_right_now li a:before,
411411
#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 ? */
413412
padding: 0 5px 0 0;
414413
}
415414

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-
426415
#dashboard_right_now .comment-count a:before {
427416
content: "\f101" / '';
428417
}

src/wp-admin/includes/dashboard.php

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -320,10 +320,31 @@ function wp_dashboard_right_now() {
320320
}
321321
$text = number_format_i18n( $num_post_published ) . ' ' . $post_label;
322322

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+
$icon_class = '';
324+
325+
if ( str_starts_with( $post_type_object->menu_icon, 'dashicons' ) ) {
326+
$icon_class = $post_type_object->menu_icon;
327+
} elseif ( str_starts_with( $post_type_object->menu_icon, 'data:image/svg+xml;base64,' ) ) {
328+
printf(
329+
'<style>
330+
#dashboard_right_now li.%1$s-count a:before,
331+
#dashboard_right_now li.%1$s-count > span:before {
332+
content: url( %2$s );
333+
height: auto;
334+
width: 20px;
335+
}
336+
</style>',
337+
$post_type,
338+
$post_type_object->menu_icon
339+
);
340+
}
341+
342+
$class_attr = $icon_class ? sprintf( ' class="%s"', $icon_class ) : '';
343+
344+
if ( current_user_can( $post_type_object->cap->edit_posts ) ) {
345+
printf( '<li class="%1$s-count"><a%3$s href="edit.php?post_type=%1$s">%2$s</a></li>', $post_type, $text, $class_attr );
325346
} else {
326-
printf( '<li class="%1$s-count"><span>%2$s</span></li>', $post_type, $text );
347+
printf( '<li class="%1$s-count"><span%3$s>%2$s</span></li>', $post_type, $text, $class_attr );
327348
}
328349
}
329350
}

src/wp-includes/class-wp-post-type.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,11 @@ public function set_props( $args ) {
606606
$args['at_a_glance'] = (bool) $args['show_in_menu'];
607607
}
608608

609+
// If not set, default to the post icon.
610+
if ( null === $args['menu_icon'] ) {
611+
$args['menu_icon'] = 'dashicons-admin-post';
612+
}
613+
609614
// If not set, default to the setting for 'show_in_menu'.
610615
if ( null === $args['show_in_admin_bar'] ) {
611616
$args['show_in_admin_bar'] = (bool) $args['show_in_menu'];

0 commit comments

Comments
 (0)