Make WordPress Core

Opened 9 years ago

Closed 9 years ago

#29374 closed enhancement (fixed)

Add hook(s) to include other post types in the Activity widget

Reported by: samueljmello's profile samueljmello Owned by: sergeybiryukov's profile SergeyBiryukov
Milestone: 4.2 Priority: normal
Severity: normal Version: 3.8
Component: Posts, Post Types Keywords: has-patch commit
Focuses: administration Cc:

Description

wp_dashboard_recent_posts does not include custom post types (or pages) and gives no filter for adding them in manually.

Ideally wp_dashboard_recent_posts should get all registered post types (as well as post and pages) when showing recent activity in the dashboard.

At the very least, make it modifiable with an action or filter. Right now the only way is to remove the activity widget and re-add your own modding the current function in a plugin.

Attachments (1)

29374.1.diff (700 bytes) - added by danielbachhuber 9 years ago.
Add query args filter for dashboard recent posts

Download all attachments as: .zip

Change History (11)

#1 @DrewAPicture
9 years ago

  • Component changed from General to Widgets
  • Summary changed from wp_dashboard_recent_posts to Add hook(s) to include other post types in the Activity widget
  • Type changed from defect (bug) to enhancement

#2 @juliobox
9 years ago

"Ideally wp_dashboard_recent_posts should get all registered post types"
I do not agree, i prefer to say "only public ones" or why not add a support like "dashboard_stat".

#3 @SergeyBiryukov
9 years ago

wp_dashboard_recent_posts does not include custom post types (or pages) and gives no filter for adding them in manually.

You can use pre_get_posts action as a workaround:

function add_custom_post_types_to_activity_widget( $query ) {
	if ( ! is_admin() || 'dashboard' !== get_current_screen()->id ) {
		return;
	}

	// Ignore Drafts section in Quick Draft widget
	if ( 'draft' === $query->get( 'post_status' ) ) {
		return;
	}

	$query->set( 'post_type', get_post_types( array( 'public' => true ) ) );
}
add_action( 'pre_get_posts', 'add_custom_post_types_to_activity_widget' );

#4 @SergeyBiryukov
9 years ago

  • Component changed from Widgets to Posts, Post Types
  • Focuses administration added

#5 @knutsp
9 years ago

Thanks, Sergey. Elegant. pre_get_posts is extremely powerful and can do almost anything. It's no problem making it work, but to tame it not to do it when it shouldn't.

But I hope, some day, using this method is not necessary for such a simple task. It should show all public post types by default, and perhaps have a filter to exclude some.

#6 @danielbachhuber
9 years ago

  • Keywords has-patch added
  • Milestone changed from Awaiting Review to 4.2

29374.1.diff adds a filter to wp_dashboard_recent_posts() to make the query args filterable.

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


9 years ago

#8 @SergeyBiryukov
9 years ago

  • Keywords needs-docs added

The filter will need hook documentation.

@danielbachhuber
9 years ago

Add query args filter for dashboard recent posts

#9 @danielbachhuber
9 years ago

  • Keywords commit added; needs-docs removed

Added PHPdoc for the filter

#10 @SergeyBiryukov
9 years ago

  • Owner set to SergeyBiryukov
  • Resolution set to fixed
  • Status changed from new to closed

In 31508:

Dashboard: Add a filter for the query arguments used for the Recent Posts widget.

props danielbachhuber.
fixes #29374.

Note: See TracTickets for help on using tickets.