Opened 6 years ago
Last modified 5 years ago
#45035 new enhancement
allow register_post_type() arg to control whether a CPT's counts are added to the "At a Glance" Dashboard widget
Reported by: | pbiron | Owned by: | |
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | normal | Version: | |
Component: | Posts, Post Types | Keywords: | has-patch has-unit-tests needs-testing |
Focuses: | administration | Cc: |
Description (last modified by )
It would be nice if there an arg to register_post_type()
that controlled whether the CPT's counts were added to the "At a Glance" Dashboard widget, e.g.
<?php register_post_type( 'mycpt', array( ..., 'at_a_glance' => true, ... ) );
Ideally, I think it should default to the value of show_in_menu
, but as current behavior is the equivalent of false
I'd be OK with that as the default as well.
Another "nice to have" would be to allow the param to take a string value that would be interpreted as a post_status
to show the count for, e.g., show counts for custom post_status = mycustompoststatus
instead of publish
.
I have code that does all of the above, but it would have to be refactored a little bit to submit as a patch (especially to account for the _builtin
post_types that already appear in AAG).
If folks think this would be a good enhancement I'd be glad to work on that refactoring and submit a patch.
Attachments (2)
Change History (9)
#3
in reply to:
↑ 2
@
6 years ago
Replying to swissspidy:
Another "nice to have" would be to allow the param to take a string value that would be interpreted as a post_status to show the count for, e.g., show counts for custom post_status = mycustompoststatus instead of publish.
What about two arguments:
at_a_glance
at_a_glance_count_cb
(likeupdate_count_callback
orregister_meta_box_cb
)This way one can provide a custom callback that returns a count. Otherwise it would fall back to
wp_count_posts
.
So at_a_glance
would be a boolean and at_a_glance_count_cb
would be ignored if at_a_glance
is false.
That certainly works for me.
#4
@
6 years ago
- Keywords needs-patch added; dev-feedback removed
My Extended CPTs library provides a dashboard_glance
argument that adds the post type to the At a Glance dashboard widget. I think a custom callback for the count is unnecessary - if you have a custom requirement such as that then the existing dashboard_glance_items
filter can be used.
#5
@
5 years ago
- Keywords has-patch needs-testing added; needs-patch removed
I've been thinking about the At a Glance functionality a bit after a recent project and liked the solution presented here. Here is my attempt at a patch (45035_patch.diff).
- Added
at_a_glance
arg toregister_post_type
defaulting toshow_in_menu
. - Added
'at_a_glance' => false
toattachment
post type registration. - Updated
wp_dashboard_right_now
to pull post types by the newat_a_glance
arg.
What about two arguments:
at_a_glance
at_a_glance_count_cb
(likeupdate_count_callback
orregister_meta_box_cb
)This way one can provide a custom callback that returns a count. Otherwise it would fall back to
wp_count_posts
.