Make WordPress Core

Opened 12 years ago

Closed 12 years ago

#29374 closed enhancement (fixed)

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

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

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 12 years ago.
Add query args filter for dashboard recent posts

Download all attachments as: .zip

Change History (11)

#1 @DrewAPicture
12 years ago

  • Component GeneralWidgets
  • Summary wp_dashboard_recent_postsAdd hook(s) to include other post types in the Activity widget
  • Type defect (bug)enhancement

#2 @juliobox
12 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
12 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
12 years ago

  • Component WidgetsPosts, Post Types
  • Focuses administration added

#5 @knutsp
12 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
12 years ago

  • Keywords has-patch added
  • Milestone Awaiting Review4.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.


12 years ago

#8 @SergeyBiryukov
12 years ago

  • Keywords needs-docs added

The filter will need hook documentation.

@danielbachhuber
12 years ago

Add query args filter for dashboard recent posts

#9 @danielbachhuber
12 years ago

  • Keywords commit added; needs-docs removed

Added PHPdoc for the filter

#10 @SergeyBiryukov
12 years ago

  • Owner set to SergeyBiryukov
  • Resolutionfixed
  • Status newclosed

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.