| @@ -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', |
| @@ -17,9 +17,8 @@ | ||
| 17 | 17 | 'page_id', |
| 18 | 18 | 'category_name', |
| 19 | 19 | 'tag', |
| 20 | 20 | 'tag_id', |
| 21 | - 'cat', | |
| 22 | 21 | 'category__in', |
| 23 | 22 | 'category__and', |
| 24 | 23 | 'post__in', |
| 25 | 24 | 'post_name__in', |
| @@ -45,9 +44,8 @@ | ||
| 45 | 44 | |
| 46 | 45 | /** |
| 47 | 46 | * Check if translated taxonomy is queried |
| 48 | 47 | * Compatible with nested queries introduced in WP 4.1 |
| 49 | - * | |
| 50 | 48 | * @see https://wordpress.org/support/topic/tax_query-bug |
| 51 | 49 | * |
| 52 | 50 | * @since 1.7 |
| 53 | 51 | * |
| @@ -91,32 +89,14 @@ | ||
| 91 | 89 | * @param object $lang |
| 92 | 90 | */ |
| 93 | 91 | public function set_language( $lang ) { |
| 94 | 92 | // Defining directly the tax_query ( rather than setting 'lang' avoids transforming the query by WP ) |
| 95 | - $lang_query = array( | |
| 93 | + $this->query->query_vars['tax_query'][] = array( | |
| 96 | 94 | 'taxonomy' => 'language', |
| 97 | 95 | 'field' => 'term_taxonomy_id', // Since WP 3.5 |
| 98 | 96 | 'terms' => $lang->term_taxonomy_id, |
| 99 | 97 | 'operator' => 'IN', |
| 100 | 98 | ); |
| 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 | 99 | } |
| 120 | 100 | |
| 121 | 101 | /** |
| 122 | 102 | * Add the language in query after it has checked that it won't conflict with other query vars |
| @@ -128,30 +108,19 @@ | ||
| 128 | 108 | public function filter_query( $lang ) { |
| 129 | 109 | $qvars = &$this->query->query_vars; |
| 130 | 110 | |
| 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 | 112 | // Do not filter the query if the language is already specified in another way |
| 144 | - foreach ( $excludes as $k ) { | |
| 113 | + foreach ( self::$excludes as $k ) { | |
| 145 | 114 | 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 { | |
| 115 | + return; | |
| 116 | + } | |
| 117 | + } | |
| 118 | + | |
| 119 | + // Specific case for 'cat' as it can contain negative values | |
| 120 | + if ( ! empty( $qvars['cat'] ) ) { | |
| 121 | + foreach ( explode( ',', $qvars['cat'] ) as $cat ) { | |
| 122 | + if ( $cat > 0 ) { | |
| 154 | 123 | return; |
| 155 | 124 | } |
| 156 | 125 | } |
| 157 | 126 | } |