Opened 7 years ago
Last modified 3 weeks 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: |
|
Owned by: | |
|---|---|---|---|
| Milestone: | 7.0 | Priority: | normal |
| Severity: | normal | Version: | |
| Component: | Posts, Post Types | Keywords: | tested |
| 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 (4)
Change History (18)
#3
in reply to:
↑ 2
@
7 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_glanceat_a_glance_count_cb(likeupdate_count_callbackorregister_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
@
7 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
@
6 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_glancearg toregister_post_typedefaulting toshow_in_menu. - Added
'at_a_glance' => falsetoattachmentpost type registration. - Updated
wp_dashboard_right_nowto pull post types by the newat_a_glancearg.
This ticket was mentioned in Slack in #core-test by sirlouen. View the logs.
4 weeks ago
This ticket was mentioned in PR #10647 on WordPress/wordpress-develop by @SirLouen.
4 weeks ago
#9
Following the patch in 45035.diff by @gwelser, I have refreshed and updated to work.
### Testing Instructions
- Add a new CPT
- Set the
at_a_glanceargument totruein that CPT - Create a couple posts in that CPT, some published some not published
- Go to the admin dashboard, and check if "At a Glance" show the right number of published posts
#10
@
4 weeks ago
- Milestone changed from Awaiting Review to Future Release
Test Report
Description
✅ This report validates that the indicated patch works as expected.
Patch tested: https://github.com/WordPress/wordpress-develop/pull/10647.diff
Environment
- WordPress: 7.0-alpha-61215-src
- PHP: 8.2.29
- Server: nginx/1.29.3
- Database: mysqli (Server: 8.4.7 / Client: mysqlnd 8.2.29)
- Browser: Chrome 143.0.0.0
- OS: Windows 10/11
- Theme: Twenty Twenty-Five 1.4
- MU Plugins: None activated
- Plugins:
- BBB Testing Dolly
- Gutenberg 22.3.0
- Test Reports 1.2.1
Testing Instructions
Actual Results
- ✅ Issue resolved with patch.
Additional Notes
- I have refreshed
45035.diffto test the idea. - @johnbillion what do you say of the idea that @gwelser provided?
Supplemental Artifacts
@pbiron commented on PR #10647:
3 weeks ago
#12
The other thing this PR should do is output relevant CSS that uses the menu_icon param to register_post_type() for the icon in the At a Glance item. Have to think a bit about the best way to do that, especially to for menu_icon being an inline SVG.
#13
@
3 weeks ago
https://core.trac.wordpress.org/attachment/ticket/45035/at-a-glance-icon.diff uses the menu_icon arg for the icon of the "At a Glance" item.
It has to be applied to what is already in https://github.com/WordPress/wordpress-develop/pull/10647
#14
@
3 weeks ago
- Keywords tested added; has-patch has-unit-tests needs-testing removed
Test Report
Description
This report validates whether the indicated patch works as expected by allowing
developers to explicitly control whether a custom post type appears in the
“At a Glance” dashboard widget using the at_a_glance argument.
Patch tested:
https://patch-diff.githubusercontent.com/raw/WordPress/wordpress-develop/pull/10647.diff
Environment
- WordPress: 7.0-alpha-20251226.164314
- PHP: 8.5.0
- Server: PHP/8.5.0 (Development Server)
- Database: mysqli (Server: 9.1.0 / Client: mysqlnd 8.5.0)
- Browser: Chrome 143.0.0.0
- OS: Windows 10/11
- Theme: Twenty Twenty-Five 1.4
- MU Plugins: None activated
- Plugins:
- Test Reports 1.2.1
Steps to Reproduce / Verify
- Set up a local WordPress core development environment using the
wordpress-developrepository and run WordPress from thebuild/directory. - Download and apply the patch:
https://patch-diff.githubusercontent.com/raw/WordPress/wordpress-develop/pull/10647.diff
using
git apply. - Rebuild WordPress assets using
npm run build. - Register a custom post type with the
at_a_glanceargument set totrue, for example:
register_post_type(
'mycpt',
array(
'label' => 'My CPT',
'public' => true,
'show_ui' => true,
'at_a_glance' => true,
)
);
- Create and publish at least one post of the custom post type.
- Navigate to Dashboard → At a Glance.
- Verify that the custom post type appears in the widget with the correct count.
- Update the custom post type registration by setting
at_a_glancetofalse(or removing the argument), refresh the dashboard, and verify that the custom post type no longer appears.
Actual Results
- ✅ With the patch applied, a custom post type registered with
at_a_glance => trueappears correctly in the “At a Glance” dashboard widget after publishing at least one post of that type. - ✅ Setting
at_a_glance => false(or omitting the argument) prevents the custom post type from appearing in the widget. - ⚠️ Admin button icons (Dashicons) were not visible in the local environment, likely due to a Node.js / npm version mismatch during the build process. This did not affect the functionality or validation of the patch itself.
Additional Notes
- This functionality is introduced via a patch and is not available in core by default. To test the change locally, the patch must be applied manually.
- Steps to apply the patch in a local WordPress core development environment:
- Download the patch: https://patch-diff.githubusercontent.com/raw/WordPress/wordpress-develop/pull/10647.diff
- Place the file in the root of the
wordpress-developrepository. - Apply the patch using:
git apply 10647.diff - Rebuild WordPress assets (recommended):
npm run build - Run WordPress from the
build/directory and verify the behavior via Dashboard → At a Glance.


What about two arguments:
at_a_glanceat_a_glance_count_cb(likeupdate_count_callbackorregister_meta_box_cb)This way one can provide a custom callback that returns a count. Otherwise it would fall back to
wp_count_posts.