PluginProbe
Polylang / 2.2
Polylang v2.2
3.8.9 3.8.8 3.8.7 3.8.6 3.8.5 3.8.4 3.8.3 2.7 2.7.0.1 2.7.1 2.7.2 2.7.3 2.7.4 2.8 2.8.1 2.8.2 2.8.3 2.8.4 2.9 2.9.1 2.9.2 3.0 3.0.1 3.0.2 3.0.3 All 233 releases
← All changes | include/query.php +15 -56 2.72.2 View file →
@@ -6,9 +6,9 @@
6 6 * @since 2.2
7 7 */
8 8 class PLL_Query {
9 9
10 - protected static $excludes = array(
10 + static protected $excludes = array(
11 11 'p',
12 12 'post_parent',
13 13 'attachment',
14 14 'attachment_id',
@@ -16,10 +16,10 @@
16 16 'pagename',
17 17 'page_id',
18 18 'category_name',
19 19 'tag',
20 + 'cat',
20 21 'tag_id',
21 - 'cat',
22 22 'category__in',
23 23 'category__and',
24 24 'post__in',
25 25 'post_name__in',
@@ -45,9 +45,8 @@
45 45
46 46 /**
47 47 * Check if translated taxonomy is queried
48 48 * Compatible with nested queries introduced in WP 4.1
49 - *
50 49 * @see https://wordpress.org/support/topic/tax_query-bug
51 50 *
52 51 * @since 1.7
53 52 *
@@ -54,18 +53,16 @@
54 53 * @param array $tax_queries
55 54 * @return bool
56 55 */
57 56 protected function have_translated_taxonomy( $tax_queries ) {
58 - if ( is_array( $tax_queries ) ) {
59 - foreach ( $tax_queries as $tax_query ) {
60 - if ( isset( $tax_query['taxonomy'] ) && $this->model->is_translated_taxonomy( $tax_query['taxonomy'] ) && ! ( isset( $tax_query['operator'] ) && 'NOT IN' === $tax_query['operator'] ) ) {
61 - return true;
62 - }
57 + foreach ( $tax_queries as $tax_query ) {
58 + if ( isset( $tax_query['taxonomy'] ) && $this->model->is_translated_taxonomy( $tax_query['taxonomy'] ) && ! ( isset( $tax_query['operator'] ) && 'NOT IN' === $tax_query['operator'] ) ) {
59 + return true;
60 + }
63 61
64 - // Nested queries
65 - elseif ( is_array( $tax_query ) && $this->have_translated_taxonomy( $tax_query ) ) {
66 - return true;
67 - }
62 + // Nested queries
63 + elseif ( is_array( $tax_query ) && $this->have_translated_taxonomy( $tax_query ) ) {
64 + return true;
68 65 }
69 66 }
70 67
71 68 return false;
@@ -91,32 +88,14 @@
91 88 * @param object $lang
92 89 */
93 90 public function set_language( $lang ) {
94 91 // Defining directly the tax_query ( rather than setting 'lang' avoids transforming the query by WP )
95 - $lang_query = array(
92 + $this->query->query_vars['tax_query'][] = array(
96 93 'taxonomy' => 'language',
97 94 'field' => 'term_taxonomy_id', // Since WP 3.5
98 95 'terms' => $lang->term_taxonomy_id,
99 96 'operator' => 'IN',
100 97 );
101 -
102 - $tax_query = &$this->query->query_vars['tax_query'];
103 -
104 - if ( isset( $tax_query['relation'] ) && 'OR' === $tax_query['relation'] ) {
105 - $tax_query = array(
106 - $lang_query,
107 - array( $tax_query ),
108 - 'relation' => 'AND',
109 - );
110 - } elseif ( is_array( $tax_query ) ) {
111 - // The tax query is expected to be *always* an array, but it seems that 3rd parties fill it with a string
112 - // Causing a fatal error if we don't check it.
113 - // See https://wordpress.org/support/topic/fatal-error-2947/
114 - $tax_query[] = $lang_query;
115 - } elseif ( empty( $tax_query ) ) {
116 - // Supposing the tax query has been wrongly filled with an empty string
117 - $tax_query = array( $lang_query );
118 - }
119 98 }
120 99
121 100 /**
122 101 * Add the language in query after it has checked that it won't conflict with other query vars
@@ -127,33 +106,13 @@
127 106 */
128 107 public function filter_query( $lang ) {
129 108 $qvars = &$this->query->query_vars;
130 109
110 + // Do not filter the query if the language is already specified in another way
131 111 if ( ! isset( $qvars['lang'] ) ) {
132 - /**
133 - * Filter the query vars which disable the language filter in a query
134 - *
135 - * @since 2.3.5
136 - *
137 - * @param array $excludes Query vars excluded from the language filter
138 - * @param object $query WP Query
139 - * @param object $lang Language
140 - */
141 - $excludes = apply_filters( 'pll_filter_query_excluded_query_vars', self::$excludes, $this->query, $lang );
142 -
143 - // Do not filter the query if the language is already specified in another way
144 - foreach ( $excludes as $k ) {
112 + foreach ( self::$excludes as $k ) {
145 113 if ( ! empty( $qvars[ $k ] ) ) {
146 - // Specific case for 'cat' as it can contain negative values
147 - if ( 'cat' === $k ) {
148 - foreach ( explode( ',', $qvars['cat'] ) as $cat ) {
149 - if ( $cat > 0 ) {
150 - return;
151 - }
152 - }
153 - } else {
154 - return;
155 - }
114 + return;
156 115 }
157 116 }
158 117
159 118 $taxonomies = array_intersect( $this->model->get_translated_taxonomies(), get_taxonomies( array( '_builtin' => false ) ) );
@@ -164,9 +123,9 @@
164 123 return;
165 124 }
166 125 }
167 126
168 - if ( ! empty( $qvars['tax_query'] ) && $this->have_translated_taxonomy( $qvars['tax_query'] ) ) {
127 + if ( ! empty( $qvars['tax_query'] ) && is_array( $qvars['tax_query'] ) && $this->have_translated_taxonomy( $qvars['tax_query'] ) ) {
169 128 return;
170 129 }
171 130
172 131 // Filter queries according to the requested language
@@ -186,9 +145,9 @@
186 145 }
187 146 }
188 147 } else {
189 148 // Do not filter untranslatable post types such as nav_menu_item
190 - if ( isset( $qvars['post_type'] ) && ! $this->model->is_translated_post_type( $qvars['post_type'] ) && ( empty( $qvars['tax_query'] ) || ! $this->have_translated_taxonomy( $qvars['tax_query'] ) ) ) {
149 + if ( isset( $qvars['post_type'] ) && ! $this->model->is_translated_post_type( $qvars['post_type'] ) ) {
191 150 unset( $qvars['lang'] );
192 151 }
193 152
194 153 // Unset 'all' query var (mainly for admin language filter).