Make WordPress Core

Opened 9 years ago

Last modified 5 months ago

#37578 new enhancement

Dashboard Recent Activity widget - new filters to manipulate output

Reported by: jonnyauk's profile Jonnyauk Owned by:
Milestone: Future Release Priority: normal
Severity: normal Version: 4.6
Component: Administration Keywords: has-patch good-first-bug
Focuses: Cc:

Description

It is currently not possible to manipulate the recent post activity dashboard widget. Output is built using wp_dashboard_recent_posts(). 2 filters could be introduced for the parameters for future and recent posts.

This would allow easy interaction with the parameters array, for instance increasing the amount of posts shown, changing order, post status, CSS ID etc - would definitely make it more useful!

I realise that there is a filter dashboard_recent_posts_query_args inside thewp_dashboard_recent_posts() function (used to build the queries, useful for switching post type etc), but there is currently no way to interact with the calls to this function.

Attachments (4)

37578-01.diff (1.7 KB) - added by Jonnyauk 9 years ago.
New filters for Dashboard Recent Activity widget future and recent posts.
good first bug 1.txt (606 bytes) - added by vedantsonone1234 7 months ago.
37578.diff (1.7 KB) - added by pmbaldha 6 months ago.
Added a patch using the existing 'dashboard_recent_posts_query_args' filter with support for passing the $id to wp_dashboard_recent_posts() for better control.
37578-1.diff (1.8 KB) - added by pmbaldha 6 months ago.
PHPDoc Comment update.

Download all attachments as: .zip

Change History (13)

@Jonnyauk
9 years ago

New filters for Dashboard Recent Activity widget future and recent posts.

#1 @Jonnyauk
9 years ago

  • Keywords has-patch added

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


5 years ago

#3 @desrosj
12 months ago

  • Focuses ui administration removed
  • Keywords changes-requested good-first-bug added
  • Milestone set to Future Release

Hi @Jonnyauk,

My apologies that this took so long to receive a response!

Instead of adding new filters, what if the $id passed to wp_dashboard_recent_posts() were also passed to the filter as an additional parameter? Then the preexisting dashboard_recent_posts_query_args filter could be used for this in any context by providing a bit more control.

@pmbaldha
6 months ago

Added a patch using the existing 'dashboard_recent_posts_query_args' filter with support for passing the $id to wp_dashboard_recent_posts() for better control.

#4 @pmbaldha
6 months ago

  • Keywords needs-testing added

#5 @pmbaldha
6 months ago

  • Keywords changes-requested removed

@pmbaldha
6 months ago

PHPDoc Comment update.

#6 @SirLouen
6 months ago

  • Keywords needs-test-info added; needs-testing removed

@pmbaldha
For this filters, please provide an use-case for testing.

#7 follow-up: @pmbaldha
6 months ago

@SirLouen

Usecases:

  1. If you want to show 10 posts instead of the default 5:


add_filter( 'dashboard_recent_posts_query_args', 'increase_dashboard_post_count', 10, 2 );
function increase_dashboard_post_count( $args, $id ) {
    $args['max'] = 10;
    return $args;
}

2.⁠ ⁠Show Only Posts from a Specific Category in "Recently Published"
If your site has multiple categories and you want the widget to only show posts from the "Announcements" category:


add_filter( 'dashboard_recent_posts_query_args', 'dashboard_recent_posts_announcements_only', 10, 2 );
function dashboard_recent_posts_announcements_only( $args, $id ) {
    if ( 'published-posts' === $id ) {
        $args['cat'] = get_cat_ID( 'Announcements' );
    }

    return $args;
} ⁠

#8 in reply to: ↑ 7 @SirLouen
6 months ago

  • Keywords needs-refresh added; needs-test-info removed

Replying to pmbaldha:

Usecases:

Did you check JD comment on a possible alternative?

Adding new hooks is the worst thing possible when there is an alternative. They should always be the last resort.

This ticket was mentioned in PR #9026 on WordPress/wordpress-develop by @sukhendu2002.


5 months ago
#9

  • Keywords needs-refresh removed
Note: See TracTickets for help on using tickets.