| 1 |
<?php |
| 2 |
/** |
| 3 |
* Top Ten Query wrapper. |
| 4 |
* |
| 5 |
* @package WebberZone\Top_Ten |
| 6 |
*/ |
| 7 |
|
| 8 |
use WebberZone\Top_Ten\Top_Ten_Core_Query; |
| 9 |
use WebberZone\Top_Ten\Util\Hook_Registry; |
| 10 |
|
| 11 |
// If this file is called directly, abort. |
| 12 |
if ( ! defined( 'WPINC' ) ) { |
| 13 |
die; |
| 14 |
} |
| 15 |
|
| 16 |
if ( ! class_exists( 'Top_Ten_Query' ) ) : |
| 17 |
/** |
| 18 |
* Query API: Top_Ten_Query class. |
| 19 |
* |
| 20 |
* @since 3.0.0 |
| 21 |
*/ |
| 22 |
class Top_Ten_Query extends WP_Query { |
| 23 |
|
| 24 |
/** |
| 25 |
* Main constructor. |
| 26 |
* |
| 27 |
* @since 3.0.0 |
| 28 |
* |
| 29 |
* @param array|string $args The Query variables. Accepts an array or a query string. |
| 30 |
*/ |
| 31 |
public function __construct( $args = array() ) { |
| 32 |
$args = wp_parse_args( $args, array( 'is_top_ten_query' => true ) ); |
| 33 |
$core_query = new Top_Ten_Core_Query( $args ); |
| 34 |
|
| 35 |
Hook_Registry::add_filter( 'pre_get_posts', array( $core_query, 'pre_get_posts' ), 10 ); |
| 36 |
Hook_Registry::add_filter( 'posts_fields', array( $core_query, 'posts_fields' ), 10, 2 ); |
| 37 |
Hook_Registry::add_filter( 'posts_join', array( $core_query, 'posts_join' ), 10, 2 ); |
| 38 |
Hook_Registry::add_filter( 'posts_where', array( $core_query, 'posts_where' ), 10, 2 ); |
| 39 |
Hook_Registry::add_filter( 'posts_orderby', array( $core_query, 'posts_orderby' ), 9999, 2 ); |
| 40 |
Hook_Registry::add_filter( 'posts_groupby', array( $core_query, 'posts_groupby' ), 10, 2 ); |
| 41 |
Hook_Registry::add_filter( 'posts_clauses', array( $core_query, 'posts_clauses' ), 20, 2 ); |
| 42 |
Hook_Registry::add_filter( 'posts_request', array( $core_query, 'posts_request' ), 20, 2 ); |
| 43 |
Hook_Registry::add_filter( 'posts_pre_query', array( $core_query, 'posts_pre_query' ), 10, 2 ); |
| 44 |
Hook_Registry::add_filter( 'the_posts', array( $core_query, 'the_posts' ), 10, 2 ); |
| 45 |
Hook_Registry::add_action( 'the_post', array( $core_query, 'switch_to_blog_in_loop' ) ); |
| 46 |
Hook_Registry::add_action( 'loop_end', array( $core_query, 'loop_end' ) ); |
| 47 |
|
| 48 |
parent::__construct( $core_query->query_args ); |
| 49 |
|
| 50 |
// Remove filters after use. |
| 51 |
Hook_Registry::remove_filter( 'pre_get_posts', array( $core_query, 'pre_get_posts' ) ); |
| 52 |
Hook_Registry::remove_filter( 'posts_fields', array( $core_query, 'posts_fields' ) ); |
| 53 |
Hook_Registry::remove_filter( 'posts_join', array( $core_query, 'posts_join' ) ); |
| 54 |
Hook_Registry::remove_filter( 'posts_where', array( $core_query, 'posts_where' ) ); |
| 55 |
Hook_Registry::remove_filter( 'posts_orderby', array( $core_query, 'posts_orderby' ), 9999 ); |
| 56 |
Hook_Registry::remove_filter( 'posts_groupby', array( $core_query, 'posts_groupby' ) ); |
| 57 |
Hook_Registry::remove_filter( 'posts_clauses', array( $core_query, 'posts_clauses' ) ); |
| 58 |
Hook_Registry::remove_filter( 'posts_request', array( $core_query, 'posts_request' ) ); |
| 59 |
Hook_Registry::remove_filter( 'posts_pre_query', array( $core_query, 'posts_pre_query' ) ); |
| 60 |
Hook_Registry::remove_filter( 'the_posts', array( $core_query, 'the_posts' ) ); |
| 61 |
Hook_Registry::remove_action( 'the_post', array( $core_query, 'switch_to_blog_in_loop' ) ); |
| 62 |
Hook_Registry::remove_action( 'loop_end', array( $core_query, 'loop_end' ) ); |
| 63 |
} |
| 64 |
} |
| 65 |
endif; |
| 66 |
|