WordPress.org

Make WordPress Core

Opened 3 years ago

Closed 3 years ago

Last modified 2 years ago

#21344 closed enhancement (fixed)

Add hook "restrict_manage_comments" to class-wp-comments-list-table.php for additional filtering by plugins

Reported by: hardy101 Owned by: nacin
Milestone: 3.5 Priority: normal
Severity: normal Version: 3.4.1
Component: Comments Keywords: has-patch needs-codex
Focuses: Cc:

Description

The comments list (class-wp-comments-list-table.php) in wp-admin needs a hook to allow plugins to do additional filtering of comments, just like class-wp-posts-list-table.php on line 220.

do_action( 'restrict_manage_posts' );

The new line of code would be in class-wp-comments-list-table.php:

do_action( 'restrict_manage_comments' );

A one-line patch (attached) does the trick.

Attachments (2)

comments-table-hook-patch.diff (528 bytes) - added by hardy101 3 years ago.
Allow plugins to do additional filtering of comment list in class-wp-comments-list-table.php
edit-comments.png (18.7 KB) - added by hardy101 3 years ago.
Form element before "Filter" button

Download all attachments as: .zip

Change History (9)

@hardy1013 years ago

Allow plugins to do additional filtering of comment list in class-wp-comments-list-table.php

comment:1 follow-up: @scribu3 years ago

  • Milestone changed from Awaiting Review to 3.5

Yes, I found myself needing such a hook several times in the past.

But I think the hook should be placed in the prepare_items() method, not between HTML tags.

comment:2 in reply to: ↑ 1 @hardy1013 years ago

Scribu,

Agreed - I just thought I'd parallel the current behavior and do the one-line patch for simplicity. I'll look into a patch for prepare_items()

Replying to scribu:

Yes, I found myself needing such a hook several times in the past.

But I think the hook should be placed in the prepare_items() method, not between HTML tags.

Version 0, edited 3 years ago by hardy101 (next)

comment:3 @hardy1013 years ago

The problem with adding the proposed hook to prepare_items() is that we actually need to be able to output a form element on edit-comments.php just prior to the "Filter" button. (e.g. add a select list that lets us filter by user_id).

class-wp-comments-list-table.php does it's own form element via extra_tablenav(), where our hook would also live.

The way it works now, to build edit-comments.php's page:

display()

calls

display_tablenav()

and class-wp-comments-list-table.php overrides

extra_tablenav()

to add a "comment_type" select list, then

display()

continues to build the rest of the rows in the edit-comments.php table.

Our simple hook (see attached "comments-table-hook-patch.diff") would allow us to place our own form element(s) prior to the filter button for a clean look. The "manage_comments_nav" filter is too late and would put our new form elements after the Filter button, which makes for an odd UX.

So after some additional thought, I still vote for putting the hook in class-wp-comments-list-table.php -> extra_tablenav() like the posts list currently does.

comment:4 follow-up: @scribu3 years ago

Right, I was actually thinking of a hook for altering the query arguments passed to get_comments(). Nevermind.

@hardy1013 years ago

Form element before "Filter" button

comment:5 in reply to: ↑ 4 @hardy1013 years ago

Cool. Attaching a screenshot for people that want visualize the scenario. Shout-out to WP royalty.

Replying to scribu:

Right, I was actually thinking of a hook for altering the query arguments passed to get_comments(). Nevermind.

comment:6 @nacin3 years ago

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

In [21985]:

Add restrict_manage_comments hook. props hardy101. fixes #21344.

comment:7 @DrewAPicture2 years ago

  • Keywords needs-codex added
Note: See TracTickets for help on using tickets.