Make WordPress Core

Opened 11 years ago

Closed 8 years ago

#26580 closed enhancement (fixed)

Add filters to WP_MS_Sites_List_Table::prepare_items()

Reported by: csixty4's profile csixty4 Owned by: flixos90's profile flixos90
Milestone: 4.6 Priority: normal
Severity: normal Version:
Component: Networks and Sites Keywords: good-first-bug has-patch
Focuses: multisite Cc:

Description

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 (2)

class-wp-ms-sites-list-table.php.diff (650 bytes) - added by lenasterg 10 years ago.
Suggestion new filter "wpmu_blogs_orderby" into prepare_items
26580.diff (709 bytes) - added by flixos90 8 years ago.

Download all attachments as: .zip

Change History (15)

#2 @jeremyfelt
11 years ago

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

#3 @danielbachhuber
11 years 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.)

#4 @lenasterg
10 years ago

Hi.
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?

@lenasterg
10 years ago

Suggestion new filter "wpmu_blogs_orderby" into prepare_items

#5 follow-up: @mbootsman
9 years 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.

#6 in reply to: ↑ 5 @danielpataki
9 years 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 :)

#7 @jeremyfelt
8 years ago

  • Milestone changed from Future Release to 4.6

With the addition of WP_Site_Query (#35791) and its use in WP_MS_Sites_List_Table (#36675), we should soon have a place to use a filter like ms_sites_list_table_query_args before the query for the list table is requested.

This ticket was mentioned in Slack in #core-multisite by jeremyfelt. View the logs.


8 years ago

#9 @jeremyfelt
8 years ago

  • Keywords good-first-bug added

After [37736], WP_MS_Sites_List_Table is now in a better position for a ms_sites_list_table_query_args filter. Marking this as a good first bug.

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


8 years ago

#11 @jeremyfelt
8 years ago

  • Owner set to flixos90
  • Status changed from new to assigned

@flixos90
8 years ago

#12 @flixos90
8 years ago

  • Keywords has-patch added; needs-patch removed

26580.diff adds the filter for the query arguments.

#13 @jeremyfelt
8 years ago

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

In 37899:

Multisite: Add a ms_sites_list_table_query_args filter to WP_MS_Sites_List_Table.

This allows a developer to filter the arguments used to query sites during the prepare_items() method.

Props flixos90.
Fixes #26580.

Note: See TracTickets for help on using tickets.