PluginProbe
Polylang / 3.1
Polylang v3.1
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/filters.php +31 -42 3.03.1 View file →
@@ -68,11 +68,8 @@
68 68
69 69 // Converts the locale to a valid W3C locale
70 70 add_filter( 'language_attributes', array( $this, 'language_attributes' ) );
71 71
72 - // Prevents deleting all the translations of the default category
73 - add_filter( 'map_meta_cap', array( $this, 'fix_delete_default_category' ), 10, 4 );
74 -
75 72 // Translate the site title in emails sent to users
76 73 add_filter( 'password_change_email', array( $this, 'translate_user_email' ) );
77 74 add_filter( 'email_change_email', array( $this, 'translate_user_email' ) );
78 75
@@ -98,26 +95,40 @@
98 95 /**
99 96 * Get the language to filter a comments query.
100 97 *
101 98 * @since 2.0
99 + * @since 3.1 Always returns an array. Renamed from get_comments_queried_language().
102 100 *
103 - * @param WP_Comment_Query $query WP_Comment_Query object.
104 - * @return PLL_Language|false The language to use in the filter, false otherwise.
101 + * @param WP_Comment_Query $query WP_Comment_Query object.
102 + * @return PLL_Language[] The languages to use in the filter.
105 103 */
106 - protected function get_comments_queried_language( $query ) {
104 + protected function get_comments_queried_languages( $query ) {
107 105 // Don't filter comments if comment ids or post ids are specified.
108 106 $plucked = wp_array_slice_assoc( $query->query_vars, array( 'comment__in', 'parent', 'post_id', 'post__in', 'post_parent' ) );
109 107 $fields = array_filter( $plucked );
110 108 if ( ! empty( $fields ) ) {
111 - return false;
109 + return array();
112 110 }
113 111
114 112 // Don't filter comments if a non translated post type is specified.
115 113 if ( ! empty( $query->query_vars['post_type'] ) && ! $this->model->is_translated_post_type( $query->query_vars['post_type'] ) ) {
116 - return false;
114 + return array();
117 115 }
118 116
119 - return empty( $query->query_vars['lang'] ) ? $this->curlang : $this->model->get_language( $query->query_vars['lang'] );
117 + // If comments are queried with a 'lang' parameter, keeps only language codes.
118 + if ( isset( $query->query_vars['lang'] ) ) {
119 + $languages = is_string( $query->query_vars['lang'] ) ? explode( ',', $query->query_vars['lang'] ) : $query->query_vars['lang'];
120 + if ( is_array( $languages ) ) {
121 + $languages = array_map( array( $this->model, 'get_language' ), $languages );
122 + return array_filter( $languages );
123 + }
124 + }
125 +
126 + if ( ! empty( $this->curlang ) ) {
127 + return array( $this->curlang );
128 + }
129 +
130 + return array();
120 131 }
121 132
122 133 /**
123 134 * Adds a language dependent cache domain when querying comments.
@@ -129,11 +140,12 @@
129 140 * @param WP_Comment_Query $query WP_Comment_Query object.
130 141 * @return void
131 142 */
132 143 public function parse_comment_query( $query ) {
133 - $lang = $this->get_comments_queried_language( $query );
134 - if ( $lang ) {
135 - $key = '_' . $lang->slug;
144 + $lang = $this->get_comments_queried_languages( $query );
145 + if ( ! empty( $lang ) ) {
146 + $lang = wp_list_pluck( $lang, 'slug' );
147 + $key = '_' . implode( ',', $lang );
136 148 $query->query_vars['cache_domain'] = empty( $query->query_vars['cache_domain'] ) ? 'pll' . $key : $query->query_vars['cache_domain'] . $key;
137 149 }
138 150 }
139 151
@@ -149,11 +161,13 @@
149 161 */
150 162 public function comments_clauses( $clauses, $query ) {
151 163 global $wpdb;
152 164
153 - $lang = $this->get_comments_queried_language( $query );
165 + $lang = $this->get_comments_queried_languages( $query );
154 166
155 167 if ( ! empty( $lang ) ) {
168 + $lang = wp_list_pluck( $lang, 'slug' );
169 +
156 170 // If this clause is not already added by WP.
157 171 if ( ! strpos( $clauses['join'], '.ID' ) ) {
158 172 $clauses['join'] .= " JOIN $wpdb->posts ON $wpdb->posts.ID = $wpdb->comments.comment_post_ID";
159 173 }
@@ -205,10 +219,10 @@
205 219 ),
206 220 ),
207 221 );
208 222
209 - // Take care that 'exclude' argument accepts integer or strings too
210 - $args['exclude'] = array_merge( wp_parse_id_list( $args['exclude'] ), get_posts( $r ) );
223 + // Take care that 'exclude' argument accepts integer or strings too.
224 + $args['exclude'] = array_merge( wp_parse_id_list( $args['exclude'] ), get_posts( $r ) ); // phpcs:ignore WordPressVIPMinimum.Performance.WPQueryParams.PostNotIn_exclude
211 225 $pages = get_pages( $args );
212 226 }
213 227
214 228 $ids = wp_list_pluck( $pages, 'ID' );
@@ -280,35 +294,10 @@
280 294 return $output;
281 295 }
282 296
283 297 /**
284 - * Prevents deleting all the translations of the default category
285 - *
286 - * @since 2.1
287 - *
288 - * @param array $caps The user's actual capabilities.
289 - * @param string $cap Capability name.
290 - * @param int $user_id The user ID.
291 - * @param array $args Adds the context to the cap. The category id.
292 - * @return array
293 - */
294 - public function fix_delete_default_category( $caps, $cap, $user_id, $args ) {
295 - if ( 'delete_term' === $cap ) {
296 - $term = get_term( reset( $args ) ); // Since WP 4.4, we can get the term to get the taxonomy
297 - if ( $term instanceof WP_Term ) {
298 - $default_cat = get_option( 'default_' . $term->taxonomy );
299 - if ( $default_cat && array_intersect( $args, $this->model->term->get_translations( $default_cat ) ) ) {
300 - $caps[] = 'do_not_allow';
301 - }
302 - }
303 - }
304 -
305 - return $caps;
306 - }
307 -
308 - /**
309 - * Translates the site title in emails sent to the user (change email, reset password).
310 - * It is necessary to filter the email because WP evaluates the site title before calling switch_to_locale().
298 + * Translates the site title in emails sent to the user (change email, reset password)
299 + * It is necessary to filter the email because WP evaluates the site title before calling switch_to_locale()
311 300 *
312 301 * @since 2.1.3
313 302 *
314 303 * @param string[] $email Email contents.