| @@ -9,24 +9,14 @@ | ||
| 9 | 9 | * @since 2.2 |
| 10 | 10 | */ |
| 11 | 11 | class PLL_Query { |
| 12 | 12 | /** |
| 13 | - * @var PLL_Model | |
| 14 | - */ | |
| 15 | - public $model; | |
| 16 | - | |
| 17 | - /** | |
| 18 | - * @var WP_Query | |
| 19 | - */ | |
| 20 | - public $query; | |
| 21 | - | |
| 22 | - /** | |
| 23 | 13 | * Constructor |
| 24 | 14 | * |
| 25 | 15 | * @since 2.2 |
| 26 | 16 | * |
| 27 | - * @param WP_Query $query Reference to the WP_Query object. | |
| 28 | - * @param PLL_Model $model Instance of PLL_Model. | |
| 17 | + * @param array $query Reference to the WP_Query object | |
| 18 | + * @param object $model | |
| 29 | 19 | */ |
| 30 | 20 | public function __construct( &$query, &$model ) { |
| 31 | 21 | $this->query = &$query; |
| 32 | 22 | $this->model = &$model; |
| @@ -32,32 +22,8 @@ | ||
| 32 | 22 | $this->model = &$model; |
| 33 | 23 | } |
| 34 | 24 | |
| 35 | 25 | /** |
| 36 | - * Checks if the query already includes a language taxonomy. | |
| 37 | - * | |
| 38 | - * @since 3.0 | |
| 39 | - * | |
| 40 | - * @param array $qvars WP_Query query vars. | |
| 41 | - * @return bool | |
| 42 | - */ | |
| 43 | - protected function is_already_filtered( $qvars ) { | |
| 44 | - if ( isset( $qvars['lang'] ) ) { | |
| 45 | - return true; | |
| 46 | - } | |
| 47 | - | |
| 48 | - if ( ! empty( $qvars['tax_query'] ) && is_array( $qvars['tax_query'] ) ) { | |
| 49 | - foreach ( $qvars['tax_query'] as $tax_query ) { | |
| 50 | - if ( isset( $tax_query['taxonomy'] ) && 'language' === $tax_query['taxonomy'] ) { | |
| 51 | - return true; | |
| 52 | - } | |
| 53 | - } | |
| 54 | - } | |
| 55 | - | |
| 56 | - return false; | |
| 57 | - } | |
| 58 | - | |
| 59 | - /** | |
| 60 | 26 | * Check if translated taxonomy is queried |
| 61 | 27 | * Compatible with nested queries introduced in WP 4.1 |
| 62 | 28 | * |
| 63 | 29 | * @see https://wordpress.org/support/topic/tax_query-bug |
| @@ -95,15 +61,14 @@ | ||
| 95 | 61 | return isset( $this->query->tax_query->queried_terms ) ? array_keys( wp_list_filter( $this->query->tax_query->queried_terms, array( 'operator' => 'NOT IN' ), 'NOT' ) ) : array(); |
| 96 | 62 | } |
| 97 | 63 | |
| 98 | 64 | /** |
| 99 | - * Sets the language in query. | |
| 100 | - * Optimized for (and requires) WP 3.5+. | |
| 65 | + * Sets the language in query | |
| 66 | + * Optimized for ( needs ) WP 3.5+ | |
| 101 | 67 | * |
| 102 | 68 | * @since 2.2 |
| 103 | 69 | * |
| 104 | - * @param PLL_Language $lang Language object. | |
| 105 | - * @return void | |
| 70 | + * @param object $lang | |
| 106 | 71 | */ |
| 107 | 72 | public function set_language( $lang ) { |
| 108 | 73 | // Defining directly the tax_query ( rather than setting 'lang' avoids transforming the query by WP ) |
| 109 | 74 | $lang_query = array( |
| @@ -132,24 +97,23 @@ | ||
| 132 | 97 | } |
| 133 | 98 | } |
| 134 | 99 | |
| 135 | 100 | /** |
| 136 | - * Adds the language in the query after it has checked that it won't conflict with other query vars. | |
| 101 | + * Add the language in query after it has checked that it won't conflict with other query vars | |
| 137 | 102 | * |
| 138 | 103 | * @since 2.2 |
| 139 | 104 | * |
| 140 | - * @param PLL_Language $lang Language. | |
| 141 | - * @return void | |
| 105 | + * @param object $lang Language | |
| 142 | 106 | */ |
| 143 | 107 | public function filter_query( $lang ) { |
| 144 | 108 | $qvars = &$this->query->query_vars; |
| 145 | 109 | |
| 146 | - if ( ! $this->is_already_filtered( $qvars ) ) { | |
| 110 | + if ( ! isset( $qvars['lang'] ) ) { | |
| 147 | 111 | $taxonomies = array_intersect( $this->model->get_translated_taxonomies(), get_taxonomies( array( '_builtin' => false ) ) ); |
| 148 | 112 | |
| 149 | 113 | foreach ( $taxonomies as $tax ) { |
| 150 | - $tax_object = get_taxonomy( $tax ); | |
| 151 | - if ( ! empty( $tax_object ) && ! empty( $qvars[ $tax_object->query_var ] ) ) { | |
| 114 | + $tax = get_taxonomy( $tax ); | |
| 115 | + if ( ! empty( $qvars[ $tax->query_var ] ) ) { | |
| 152 | 116 | return; |
| 153 | 117 | } |
| 154 | 118 | } |
| 155 | 119 | |
| @@ -163,9 +127,9 @@ | ||
| 163 | 127 | |
| 164 | 128 | if ( $taxonomies && ( empty( $qvars['post_type'] ) || 'any' === $qvars['post_type'] ) ) { |
| 165 | 129 | foreach ( $taxonomies as $taxonomy ) { |
| 166 | 130 | $tax_object = get_taxonomy( $taxonomy ); |
| 167 | - if ( ! empty( $tax_object ) && $this->model->is_translated_post_type( $tax_object->object_type ) ) { | |
| 131 | + if ( $this->model->is_translated_post_type( $tax_object->object_type ) ) { | |
| 168 | 132 | $this->set_language( $lang ); |
| 169 | 133 | break; |
| 170 | 134 | } |
| 171 | 135 | } |