Move remove_ordering_args calls from the_posts filter to query_filters method, this avoids conflicts with other plugins also hooking in and modify the args.

This commit is contained in:
Gerhard 2019-05-02 14:31:30 +02:00
parent d502827ee9
commit 48000e63a1
1 changed files with 3 additions and 5 deletions

View File

@ -40,7 +40,6 @@ class WC_Admin_List_Table_Products extends WC_Admin_List_Table {
add_filter( 'views_edit-product', array( $this, 'product_views' ) );
add_filter( 'get_search_query', array( $this, 'search_label' ) );
add_filter( 'posts_clauses', array( $this, 'posts_clauses' ), 10, 2 );
add_filter( 'the_posts', array( $this, 'remove_ordering_args' ) );
}
/**
@ -451,6 +450,7 @@ class WC_Admin_List_Table_Products extends WC_Admin_List_Table {
* @return array
*/
protected function query_filters( $query_vars ) {
$this->remove_ordering_args();
// Custom order by arguments.
if ( isset( $query_vars['orderby'] ) ) {
$orderby = strtolower( $query_vars['orderby'] );
@ -520,10 +520,9 @@ class WC_Admin_List_Table_Products extends WC_Admin_List_Table {
/**
* Remove ordering queries.
*
* @param array $posts Posts from WP Query.
* @return array
* @return void
*/
public function remove_ordering_args( $posts ) {
public function remove_ordering_args() {
remove_filter( 'posts_clauses', array( $this, 'order_by_price_asc_post_clauses' ) );
remove_filter( 'posts_clauses', array( $this, 'order_by_price_desc_post_clauses' ) );
remove_filter( 'posts_clauses', array( $this, 'order_by_sku_asc_post_clauses' ) );
@ -531,7 +530,6 @@ class WC_Admin_List_Table_Products extends WC_Admin_List_Table {
remove_filter( 'posts_clauses', array( $this, 'filter_downloadable_post_clauses' ) );
remove_filter( 'posts_clauses', array( $this, 'filter_virtual_post_clauses' ) );
remove_filter( 'posts_clauses', array( $this, 'filter_stock_status_post_clauses' ) );
return $posts;
}
/**