PluginProbe
Polylang / 2.3.6
Polylang v2.3.6
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 +52 -11 2.92.3.6 View file →
@@ -1,8 +1,5 @@
1 1 <?php
2 -/**
3 - * @package Polylang
4 - */
5 2
6 3 /**
7 4 * A class to manipulate the language query var in WP_Query
8 5 *
@@ -8,8 +5,32 @@
8 5 *
9 6 * @since 2.2
10 7 */
11 8 class PLL_Query {
9 +
10 + static protected $excludes = array(
11 + 'p',
12 + 'post_parent',
13 + 'attachment',
14 + 'attachment_id',
15 + 'name',
16 + 'pagename',
17 + 'page_id',
18 + 'category_name',
19 + 'tag',
20 + 'tag_id',
21 + 'cat',
22 + 'category__in',
23 + 'category__and',
24 + 'post__in',
25 + 'post_name__in',
26 + 'tag__in',
27 + 'tag__and',
28 + 'tag_slug__in',
29 + 'tag_slug__and',
30 + 'post_parent__in',
31 + );
32 +
12 33 /**
13 34 * Constructor
14 35 *
15 36 * @since 2.2
@@ -24,9 +45,8 @@
24 45
25 46 /**
26 47 * Check if translated taxonomy is queried
27 48 * Compatible with nested queries introduced in WP 4.1
28 - *
29 49 * @see https://wordpress.org/support/topic/tax_query-bug
30 50 *
31 51 * @since 1.7
32 52 *
@@ -85,16 +105,10 @@
85 105 $lang_query,
86 106 array( $tax_query ),
87 107 'relation' => 'AND',
88 108 );
89 - } elseif ( is_array( $tax_query ) ) {
90 - // The tax query is expected to be *always* an array, but it seems that 3rd parties fill it with a string
91 - // Causing a fatal error if we don't check it.
92 - // See https://wordpress.org/support/topic/fatal-error-2947/
109 + } else {
93 110 $tax_query[] = $lang_query;
94 - } elseif ( empty( $tax_query ) ) {
95 - // Supposing the tax query has been wrongly filled with an empty string
96 - $tax_query = array( $lang_query );
97 111 }
98 112 }
99 113
100 114 /**
@@ -107,8 +121,35 @@
107 121 public function filter_query( $lang ) {
108 122 $qvars = &$this->query->query_vars;
109 123
110 124 if ( ! isset( $qvars['lang'] ) ) {
125 + /**
126 + * Filter the query vars which disable the language filter in a query
127 + *
128 + * @since 2.3.5
129 + *
130 + * @param array $excludes Query vars excluded from the language filter
131 + * @param object $query WP Query
132 + * @param object $lang Language
133 + */
134 + $excludes = apply_filters( 'pll_filter_query_excluded_query_vars', self::$excludes, $this->query, $lang );
135 +
136 + // Do not filter the query if the language is already specified in another way
137 + foreach ( $excludes as $k ) {
138 + if ( ! empty( $qvars[ $k ] ) ) {
139 + // Specific case for 'cat' as it can contain negative values
140 + if ( 'cat' === $k ) {
141 + foreach ( explode( ',', $qvars['cat'] ) as $cat ) {
142 + if ( $cat > 0 ) {
143 + return;
144 + }
145 + }
146 + } else {
147 + return;
148 + }
149 + }
150 + }
151 +
111 152 $taxonomies = array_intersect( $this->model->get_translated_taxonomies(), get_taxonomies( array( '_builtin' => false ) ) );
112 153
113 154 foreach ( $taxonomies as $tax ) {
114 155 $tax = get_taxonomy( $tax );