Make WordPress Core

Opened 22 months ago

Last modified 3 months ago

#26580 new enhancement

Add filters to WP_MS_Sites_List_Table::prepare_items()

Reported by: csixty4 Owned by:
Milestone: Future Release Priority: normal
Severity: normal Version:
Component: Networks and Sites Keywords: needs-patch
Focuses: multisite Cc:


In WP_MS_Sites_List_Table::prepare_items(), it would be helpful to be able to filter $like_s before it gets integrated into the query (we needed to force a like %keyword% query).

It might also be handy to filter the WHERE and ORDER BY clauses.

The query filter can be used to alter the SQL after it's generated, but that's just asking for trouble.

Attachments (1)

class-wp-ms-sites-list-table.php.diff (650 bytes) - added by lenasterg 15 months ago.
Suggestion new filter "wpmu_blogs_orderby" into prepare_items

Download all attachments as: .zip

Change History (7)

comment:2 @jeremyfelt21 months ago

  • Component changed from Multisite to Networks and Sites
  • Focuses multisite added

comment:3 @danielbachhuber20 months ago

  • Keywords needs-patch added
  • Milestone changed from Awaiting Review to Future Release

#25338 is related in the sense that there's this general trend of wanting to be able to easily filter prepare_items(). I think it would be interesting to see a patch (that would also solve pagination, total items, etc.)

comment:4 @lenasterg15 months ago

In the attached file I imported a simple filter "wpmu_blogs_orderby' in prepare_items() function. This way at least a custom column made be a plugin can be sortable.
Example usage:
Sort a custom column created from a plugin which shows the "deleted" field of wp_blogs

add_filter( 'wpmu_blogs_orderby' , 'mycustom_column_orderby' ) ;

function mycustom_column_orderby( $order_by ) {
    if ( $order_by == 'deleted' ) {
        $query = 'ORDER BY deleted ' ;
        return $query ;
    } else {
        return null ;

What do you think about this solution?

@lenasterg15 months ago

Suggestion new filter "wpmu_blogs_orderby" into prepare_items

comment:5 follow-up: @mbootsman3 months ago

This would also be useful to have plugins give the ability to add filters to the sites list. Like, only show deleted/active sites.

comment:6 in reply to: ↑ 5 @danielpataki3 months ago

I think that's slightly different than the title of this ticket, although it is definitely related. I created #32956 to add the frontend requirements for what you need :)

Note: See TracTickets for help on using tickets.