Make WordPress Core

Opened 11 years ago

Closed 9 years ago

#25360 closed enhancement (fixed)

Add a filter in WP_Users_List_Table

Reported by: juliobox's profile juliobox Owned by: drewapicture's profile DrewAPicture
Milestone: 4.4 Priority: normal
Severity: normal Version: 3.6
Component: Users Keywords: has-patch
Focuses: Cc:



Can we (i) request a filter in the WP_Users_List_Table class, in the prepare_items() function :


// Query the user IDs for this page
$wp_user_search = new WP_User_Query( $args );


// Query the user IDs for this page
$args = apply_filters( 'users_list_table_args', $args );
$wp_user_search = new WP_User_Query( $args );

The goal is to hack the query of course.

Thank you

Attachments (1)

25360.patch (980 bytes) - added by juliobox 9 years ago.

Download all attachments as: .zip

Change History (15)

#1 @jeremyfelt
11 years ago

  • Milestone changed from Awaiting Review to Future Release
  • Severity changed from trivial to normal
  • Type changed from feature request to enhancement

A similar filter would be useful in WP_MS_Users_List_Table as well. I opened #25285 to address any user query, but I'd be happy with a filter at the list table level as well.

#2 @SergeyBiryukov
10 years ago

  • Version changed from trunk to 3.6

9 years ago

#4 @juliobox
9 years ago

  • Keywords has-patch added


Maybe a patch can help to close the ticket ;)

#5 @SergeyBiryukov
9 years ago

  • Keywords needs-docs added

New filters should be documented per the documentation standards.

#6 @wonderboymusic
9 years ago

  • Keywords good-first-bug added
  • Milestone changed from Future Release to 4.4

#7 @roccotripaldi
9 years ago

Tested and works well as a filter. The documentation should be addressed as @SergeyBiryukov mentions.

I'm wondering if the filter's should be different, for example, users_list_table_args and ms_users_list_table_args

Can you create future patches from the root?

#8 @wonderboymusic
9 years ago

  • Keywords needs-refresh added

#9 @DrewAPicture
9 years ago

  • Owner set to DrewAPicture
  • Status changed from new to accepted

#10 @DrewAPicture
9 years ago

  • Resolution set to fixed
  • Status changed from accepted to closed

In 34796:

Users: Introduce the users_list_table_query_args filter, for modifying the WP_User_Query arguments used within the prepare_items() methods in the users list tables.

The current list table is passed as a second parameter, $this, and can take the form of either a WP_Users_List_Table or WP_MS_Users_List_Table instance depending on the context in which the filter was evaluated.

Props juliobox for the initial patch.
Fixes #25360.

#11 @DrewAPicture
9 years ago

  • Keywords needs-docs good-first-bug needs-refresh removed

@jeremyfelt @roccotripaldi: In [34796], I passed the current list table instance as a second parameter, which should provide the necessary context to properly target the single vs multisite users list tables.

#12 @jeremyfelt
9 years ago

  • Resolution fixed deleted
  • Status changed from closed to reopened

@DrewAPicture - I think we can remove the $this parameter. Both is_network_admin() and get_current_screen() can be used to determine context in a more straight forward way.

Also, blog_id is available in the original $args when MS where role is in the args when single site. That would be a little tougher to rely on, but is there.

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

9 years ago

#14 @DrewAPicture
9 years ago

  • Resolution set to fixed
  • Status changed from reopened to closed

In 34813:

Users: Don't pass the current WP_Users_List_Table or WP_MS_Users_List_Table instance to the users_list_table_query_args filter after all.

After some discussion, it was decided that Multisite vs single site context can just as easily be derived using available functions like is_network_admin(), get_current_screen(), etc., rendering the second parameter moot. The hook was introduced in [34796].

Fixes #25360.

Note: See TracTickets for help on using tickets.