Make WordPress Core

Opened 9 years ago

Last modified 4 months ago

#33714 new enhancement

Add custom post types to the 'At a Glance' widget

Reported by: paulwilde's profile paulwilde Owned by:
Milestone: Priority: low
Severity: normal Version: 3.8
Component: Posts, Post Types Keywords: has-patch needs-refresh needs-docs
Focuses: ui, administration Cc:

Description

This patch introduces a new argument to the register_post_type() function which will list a custom post type in the 'At a Glance' widget.

A few notes:

  • For backwards compatibility reasons the new argument is set to false by default.
  • If no menu_icon argument is set, then it will default to dashicons-marker. This is the same behaviour as previous.
  • I've added menu_icon arguments to the core post/page post_types. I'm not sure if this has any negative implications.
  • Removed a small chunk of unnecessary CSS where the dashicons were hardcoded into the styling rather than using the existing .dashicons classes. (Related #27414)
  • wp_dashboard_quota() was slightly refactored due to the removal of some of the CSS.

Attachments (3)

33714.diff (9.2 KB) - added by paulwilde 9 years ago.
33714.2.diff (617 bytes) - added by wonderboymusic 9 years ago.
glance-icons.diff (3.7 KB) - added by GaryJ 9 years ago.

Download all attachments as: .zip

Change History (17)

@paulwilde
9 years ago

#1 @paulwilde
9 years ago

  • Keywords has-patch dev-feedback added

#2 @johnbillion
9 years ago

  • Focuses ui administration added
  • Keywords dev-feedback removed
  • Priority changed from normal to low
  • Type changed from feature request to enhancement
  • Version changed from trunk to 3.8

+1.

It would be nice if the dashboard_glance argument defaulted to whatever show_ui was set to, but that would have the same back compat problem.

#3 @johnbillion
9 years ago

  • Keywords reporter-feedback added

A few issues:

  1. The menu_icon argument can be not only a dashicon name, but also a URL, a data URI, or none.
  2. $text = number_format_i18n( $num_posts->publish ) . ' ' . $label; is, unfortunately, not localisable. We're really missing a post type label here (hence the existing $text = _n( '%s Post', '%s Posts', $num_posts->publish );).
  3. The post types should appear in the same order they appear in the main admin menu (according to the menu_position argument).

Can you upload a patch which doesn't include the unrelated changes to the storage quota section?

#4 @wonderboymusic
9 years ago

Why would we add more UI hints to register_post_type()? Can't this be filtered in the Dashboard widget code?

#5 @wonderboymusic
9 years ago

  • Keywords needs-refresh needs-docs added; reporter-feedback removed
  • Milestone changed from Awaiting Review to 4.4
  • Summary changed from Introduce argument to register_post_type which adds a custom post type to the 'At a Glance' widget to Add custom post types to the 'At a Glance' widget

This should not be in register_post_type() - see what I have done in 33714.2.diff

#6 @paulwilde
9 years ago

The problem with that patch is that you have to then enqueue some custom styling in order to set each icon for each CPT.

It's a cleaner approach, I agree. It would also be nice if it also handled serving the correct icon based on what is set within register_post_type as well.

Last edited 9 years ago by paulwilde (previous) (diff)

#7 @wonderboymusic
9 years ago

Then we should propose more changes in wp_dashboard_right_now() to ensure that the icon can show up. register_post_type() should know as little as possible about UI and how post types are actually used.

@GaryJ
9 years ago

#8 @GaryJ
9 years ago

I wrote glance-icons.diff with the intent on solving basically the same problem (further identified here) then found this ticket already exists.

My approach re-uses the dashicon rulesets that already exist, and eliminates most uses of the heavy ID selector for targeting the icons. This allows CPT icons to be added via filter customisations that include the necessary HTML classes. There doesn't have on be a reliance on the post type object or the menu_icon value.

For existing filter callbacks that won't have those classes, it falls back to using the dashicons-marker via CSS :not(). The existing generic ruleset is kept, so that fixes like this will also still work.

#9 follow-up: @netweb
9 years ago

bbPress has been adding it's post types and taxonomy for quite a while now filtering dashboard_glance_items

A quick test using glance-icons.diff​ sees no noticeable issues for back compat for bbPress, both the before and after screenshots testing the patch look the same :)

https://cldup.com/OIaNmEVFei.png

#10 in reply to: ↑ 9 @GaryJ
9 years ago

Replying to netweb:

bbPress has been adding it's post types and taxonomy for quite a while now filtering dashboard_glance_items

A quick test using glance-icons.diff​ sees no noticeable issues for back compat for bbPress, both the before and after screenshots testing the patch look the same :)

Thanks for testing. Yes, at this stage, my patch should make everything behave the same. What changes though, is that it simplifies how plugins can add their own icons.

For instance, in bbPress, they'd be able to drop:

#dashboard_right_now a.bbp-glance-topic-tags:before {
	content: '\f323';
}

(and other #dashboard_right_now selectors) and change this line to include the dashicons-before dashicons-tags classes that already exist in WP.

With simpler plugins that have no other admin styles, this may mean avoiding adding a <style> element or enqueuing a .css just to override the default marker.

This ticket was mentioned in Slack in #core by sergey. View the logs.


9 years ago

#12 @SergeyBiryukov
9 years ago

Custom post types were pulled from this widget in [26704] due to i18n issues, and we have hardcoded labels there for now. Looks like 33714.2.diff doesn't account for that.

They should probably be moved to post type labels. At the time of 3.8, adding new post type labels just for this widget didn't seem like a good idea, but we've added a few since then, so we might as well add these ones too.

#13 @wonderboymusic
9 years ago

  • Milestone changed from 4.4 to Future Release

#14 @SergeyBiryukov
4 months ago

#61486 was marked as a duplicate.

Note: See TracTickets for help on using tickets.