PluginProbe
Polylang / 2.5
Polylang v2.5
3.8.10 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 All 234 releases
← All changes | admin/admin-filters-columns.php +49 -114 2.8.2 → 2.5 View file →
@@ -1,8 +1,5 @@
1 1 <?php
2 -/**
3 - * @package Polylang
4 - */
5 2
6 3 /**
7 4 * Adds the language column in posts and terms list tables
8 5 * Manages quick edit and bulk edit as well
@@ -23,30 +20,27 @@
23 20 $this->links = &$polylang->links;
24 21 $this->model = &$polylang->model;
25 22 $this->filter_lang = &$polylang->filter_lang;
26 23
27 - // Hide the column of the filtered language.
28 - add_filter( 'hidden_columns', array( $this, 'hidden_columns' ) ); // Since WP 4.4.
29 -
30 - // Add the language and translations columns in 'All Posts', 'All Pages' and 'Media library' panels.
24 + // Add the language and translations columns in 'All Posts', 'All Pages' and 'Media library' panels
31 25 foreach ( $this->model->get_translated_post_types() as $type ) {
32 26 // Use the latest filter late as some plugins purely overwrite what's done by others :(
33 - // Specific case for media.
27 + // Specific case for media
34 28 add_filter( 'manage_' . ( 'attachment' == $type ? 'upload' : 'edit-' . $type ) . '_columns', array( $this, 'add_post_column' ), 100 );
35 29 add_action( 'manage_' . ( 'attachment' == $type ? 'media' : $type . '_posts' ) . '_custom_column', array( $this, 'post_column' ), 10, 2 );
36 30 }
37 31
38 - // Quick edit and bulk edit.
32 + // Quick edit and bulk edit
39 33 add_filter( 'quick_edit_custom_box', array( $this, 'quick_edit_custom_box' ), 10, 2 );
40 34 add_filter( 'bulk_edit_custom_box', array( $this, 'quick_edit_custom_box' ), 10, 2 );
41 35
42 - // Adds the language column in the 'Categories' and 'Post Tags' tables.
36 + // Adds the language column in the 'Categories' and 'Post Tags' tables
43 37 foreach ( $this->model->get_translated_taxonomies() as $tax ) {
44 38 add_filter( 'manage_edit-' . $tax . '_columns', array( $this, 'add_term_column' ) );
45 39 add_filter( 'manage_' . $tax . '_custom_column', array( $this, 'term_column' ), 10, 3 );
46 40 }
47 41
48 - // Ajax responses to update list table rows.
42 + // Ajax responses to update list table rows
49 43 add_action( 'wp_ajax_pll_update_post_rows', array( $this, 'ajax_update_post_rows' ) );
50 44 add_action( 'wp_ajax_pll_update_term_rows', array( $this, 'ajax_update_term_rows' ) );
51 45 }
52 46
@@ -65,9 +59,12 @@
65 59 $columns = array_slice( $columns, 0, $n );
66 60 }
67 61
68 62 foreach ( $this->model->get_languages_list() as $language ) {
69 - $columns[ 'language_' . $language->slug ] = $this->get_flag_html( $language ) . '<span class="screen-reader-text">' . esc_html( $language->name ) . '</span>';
63 + // Don't add the column for the filtered language
64 + if ( empty( $this->filter_lang ) || $language->slug != $this->filter_lang->slug ) {
65 + $columns[ 'language_' . $language->slug ] = $language->flag ? $language->flag . '<span class="screen-reader-text">' . esc_html( $language->name ) . '</span>' : esc_html( $language->slug );
66 + }
70 67 }
71 68
72 69 return isset( $end ) ? array_merge( $columns, $end ) : $columns;
73 70 }
@@ -79,12 +76,12 @@
79 76 *
80 77 * @return string first language column name
81 78 */
82 79 protected function get_first_language_column() {
83 - $columns = array();
84 -
85 80 foreach ( $this->model->get_languages_list() as $language ) {
86 - $columns[] = 'language_' . $language->slug;
81 + if ( empty( $this->filter_lang ) || $language->slug != $this->filter_lang->slug ) {
82 + $columns[] = 'language_' . $language->slug;
83 + }
87 84 }
88 85
89 86 return empty( $columns ) ? '' : reset( $columns );
90 87 }
@@ -89,23 +86,8 @@
89 86 return empty( $columns ) ? '' : reset( $columns );
90 87 }
91 88
92 89 /**
93 - * Hide the column for the filtered language
94 - *
95 - * @since 2.7
96 - *
97 - * @param array $hidden Array of hidden columns
98 - * @return array
99 - */
100 - public function hidden_columns( $hidden ) {
101 - if ( ! empty( $this->filter_lang ) ) {
102 - $hidden[] = 'language_' . $this->filter_lang->slug;
103 - }
104 - return $hidden;
105 - }
106 -
107 - /**
108 90 * Adds the language and translations columns ( before the comments column ) in the posts, pages and media library tables
109 91 *
110 92 * @since 0.1
111 93 *
@@ -125,10 +107,10 @@
125 107 * @param string $column Column name
126 108 * @param int $post_id
127 109 */
128 110 public function post_column( $column, $post_id ) {
129 - $inline = wp_doing_ajax() && isset( $_REQUEST['action'], $_POST['inline_lang_choice'] ) && 'inline-save' === $_REQUEST['action']; // phpcs:ignore WordPress.Security.NonceVerification
130 - $lang = $inline ? $this->model->get_language( sanitize_key( $_POST['inline_lang_choice'] ) ) : $this->model->post->get_language( $post_id ); // phpcs:ignore WordPress.Security.NonceVerification
111 + $inline = wp_doing_ajax() && isset( $_REQUEST['action'], $_POST['inline_lang_choice'] ) && 'inline-save' === $_REQUEST['action'];
112 + $lang = $inline ? $this->model->get_language( $_POST['inline_lang_choice'] ) : $this->model->post->get_language( $post_id );
131 113
132 114 if ( false === strpos( $column, 'language_' ) || ! $lang ) {
133 115 return;
134 116 }
@@ -139,17 +121,17 @@
139 121 if ( $column == $this->get_first_language_column() ) {
140 122 printf( '<div class="hidden" id="lang_%d">%s</div>', intval( $post_id ), esc_html( $lang->slug ) );
141 123 }
142 124
125 + $post_type_object = get_post_type_object( get_post_type( $post_id ) );
126 +
143 127 // Link to edit post ( or a translation )
144 128 if ( $id = $this->model->post->get( $post_id, $language ) ) {
145 129 // get_edit_post_link returns nothing if the user cannot edit the post
146 130 // Thanks to Solinx. See http://wordpress.org/support/topic/feature-request-incl-code-check-for-capabilities-in-admin-screens
147 131 if ( $link = get_edit_post_link( $id ) ) {
148 - $flag = '';
149 132 if ( $id === $post_id ) {
150 - $flag = $this->get_flag_html( $language );
151 - $class = 'pll_column_flag';
133 + $class = 'pll_icon_tick';
152 134 /* translators: accessibility text, %s is a native language name */
153 135 $s = sprintf( __( 'Edit this item in %s', 'polylang' ), $language->name );
154 136 } else {
155 137 $class = esc_attr( 'pll_icon_edit translation_' . $id );
@@ -156,27 +138,25 @@
156 138 /* translators: accessibility text, %s is a native language name */
157 139 $s = sprintf( __( 'Edit the translation in %s', 'polylang' ), $language->name );
158 140 }
159 141 printf(
160 - '<a class="%1$s" title="%2$s" href="%3$s"><span class="screen-reader-text">%4$s</span>%5$s</a>',
142 + '<a class="%1$s" title="%2$s" href="%3$s"><span class="screen-reader-text">%4$s</span></a>',
161 143 esc_attr( $class ),
162 144 esc_attr( get_post( $id )->post_title ),
163 145 esc_url( $link ),
164 - esc_html( $s ),
165 - $flag // phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped
146 + esc_html( $s )
166 147 );
167 148 } elseif ( $id === $post_id ) {
168 149 printf(
169 - '<span class="pll_column_flag" style=""><span class="screen-reader-text">%1$s</span>%2$s</span>',
150 + '<span class="pll_icon_tick"><span class="screen-reader-text">%s</span></span>',
170 151 /* translators: accessibility text, %s is a native language name */
171 - esc_html( sprintf( __( 'This item is in %s', 'polylang' ), $language->name ) ),
172 - $this->get_flag_html( $language ) // phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped
152 + esc_html( sprintf( __( 'This item is in %s', 'polylang' ), $language->name ) )
173 153 );
174 154 }
175 155 }
176 156 // Link to add a new translation
177 157 else {
178 - echo $this->links->new_post_translation_link( $post_id, $language ); // phpcs:ignore WordPress.Security.EscapeOutput
158 + echo $this->links->new_post_translation_link( $post_id, $language );
179 159 }
180 160 }
181 161
182 162 /**
@@ -192,9 +172,9 @@
192 172 if ( $column == $this->get_first_language_column() ) {
193 173
194 174 $elements = $this->model->get_languages_list();
195 175 if ( current_filter() == 'bulk_edit_custom_box' ) {
196 - array_unshift( $elements, (object) array( 'slug' => -1, 'name' => __( '&mdash; No Change &mdash;', 'polylang' ) ) );
176 + array_unshift( $elements, (object) array( 'slug' => -1, 'name' => __( '&mdash; No Change &mdash;' ) ) );
197 177 }
198 178
199 179 $dropdown = new PLL_Walker_Dropdown();
200 180 // The hidden field 'old_lang' allows to pass the old language to ajax request
@@ -207,9 +187,9 @@
207 187 </label>
208 188 </div>
209 189 </fieldset>',
210 190 esc_html__( 'Language', 'polylang' ),
211 - $dropdown->walk( $elements, -1, array( 'name' => 'inline_lang_choice', 'id' => '' ) ) // phpcs:ignore WordPress.Security.EscapeOutput
191 + $dropdown->walk( $elements, array( 'name' => 'inline_lang_choice', 'id' => '' ) )
212 192 );
213 193 }
214 194 return $column;
215 195 }
@@ -235,29 +215,16 @@
235 215 * @param string $column Column name
236 216 * @param int $term_id
237 217 */
238 218 public function term_column( $out, $column, $term_id ) {
239 - $inline = wp_doing_ajax() && isset( $_REQUEST['action'], $_POST['inline_lang_choice'] ) && 'inline-save-tax' === $_REQUEST['action']; // phpcs:ignore WordPress.Security.NonceVerification
240 - if ( false === strpos( $column, 'language_' ) || ! ( $lang = $inline ? $this->model->get_language( sanitize_key( $_POST['inline_lang_choice'] ) ) : $this->model->term->get_language( $term_id ) ) ) { // phpcs:ignore WordPress.Security.NonceVerification
219 + $inline = wp_doing_ajax() && isset( $_REQUEST['action'], $_POST['inline_lang_choice'] ) && 'inline-save-tax' === $_REQUEST['action'];
220 + if ( false === strpos( $column, 'language_' ) || ! ( $lang = $inline ? $this->model->get_language( $_POST['inline_lang_choice'] ) : $this->model->term->get_language( $term_id ) ) ) {
241 221 return $out;
242 222 }
243 223
244 - if ( isset( $_REQUEST['post_type'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
245 - $post_type = sanitize_key( $_REQUEST['post_type'] ); // phpcs:ignore WordPress.Security.NonceVerification
246 - }
224 + $post_type = isset( $GLOBALS['post_type'] ) ? $GLOBALS['post_type'] : $_REQUEST['post_type']; // 2nd case for quick edit
225 + $taxonomy = isset( $GLOBALS['taxonomy'] ) ? $GLOBALS['taxonomy'] : $_REQUEST['taxonomy'];
247 226
248 - if ( isset( $GLOBALS['post_type'] ) ) {
249 - $post_type = $GLOBALS['post_type'];
250 - }
251 -
252 - if ( isset( $_REQUEST['taxonomy'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
253 - $taxonomy = sanitize_key( $_REQUEST['taxonomy'] ); // phpcs:ignore WordPress.Security.NonceVerification
254 - }
255 -
256 - if ( isset( $GLOBALS['taxonomy'] ) ) {
257 - $taxonomy = $GLOBALS['taxonomy'];
258 - }
259 -
260 227 if ( ! post_type_exists( $post_type ) || ! taxonomy_exists( $taxonomy ) ) {
261 228 return $out;
262 229 }
263 230
@@ -275,12 +242,10 @@
275 242
276 243 // Link to edit term ( or a translation )
277 244 if ( ( $id = $this->model->term->get( $term_id, $language ) ) && $term = get_term( $id, $taxonomy ) ) {
278 245 if ( $link = get_edit_term_link( $id, $taxonomy, $post_type ) ) {
279 - $flag = '';
280 246 if ( $id === $term_id ) {
281 - $flag = $this->get_flag_html( $language );
282 - $class = 'pll_column_flag';
247 + $class = 'pll_icon_tick';
283 248 /* translators: accessibility text, %s is a native language name */
284 249 $s = sprintf( __( 'Edit this item in %s', 'polylang' ), $language->name );
285 250 } else {
286 251 $class = esc_attr( 'pll_icon_edit translation_' . $id );
@@ -287,21 +252,19 @@
287 252 /* translators: accessibility text, %s is a native language name */
288 253 $s = sprintf( __( 'Edit the translation in %s', 'polylang' ), $language->name );
289 254 }
290 255 $out .= sprintf(
291 - '<a class="%1$s" title="%2$s" href="%3$s"><span class="screen-reader-text">%4$s</span>%5$s</a>',
256 + '<a class="%1$s" title="%2$s" href="%3$s"><span class="screen-reader-text">%4$s</span></a>',
292 257 $class,
293 258 esc_attr( $term->name ),
294 259 esc_url( $link ),
295 - esc_html( $s ),
296 - $flag // phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped
260 + esc_html( $s )
297 261 );
298 262 } elseif ( $id === $term_id ) {
299 - $out .= sprintf(
300 - '<span class="pll_column_flag"><span class="screen-reader-text">%1$s</span>%2$s</span>',
263 + $out .= printf(
264 + '<span class="pll_icon_tick"><span class="screen-reader-text">%s</span></span>',
301 265 /* translators: accessibility text, %s is a native language name */
302 - esc_html( sprintf( __( 'This item is in %s', 'polylang' ), $language->name ) ),
303 - $this->get_flag_html( $language ) // phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped
266 + esc_html( sprintf( __( 'This item is in %s', 'polylang' ), $language->name ) )
304 267 );
305 268 }
306 269 }
307 270
@@ -318,31 +281,23 @@
318 281 *
319 282 * @since 1.7
320 283 */
321 284 public function ajax_update_post_rows() {
322 - check_ajax_referer( 'inlineeditnonce', '_pll_nonce' );
285 + global $wp_list_table;
323 286
324 - if ( ! isset( $_POST['post_type'], $_POST['post_id'], $_POST['screen'] ) ) {
325 - wp_die( 0 );
287 + if ( ! post_type_exists( $post_type = $_POST['post_type'] ) || ! $this->model->is_translated_post_type( $post_type ) ) {
288 + die( 0 );
326 289 }
327 290
328 - $post_type = sanitize_key( $_POST['post_type'] );
291 + check_ajax_referer( 'inlineeditnonce', '_pll_nonce' );
329 292
330 - if ( ! post_type_exists( $post_type ) || ! $this->model->is_translated_post_type( $post_type ) ) {
331 - wp_die( 0 );
332 - }
333 -
334 - global $wp_list_table;
335 - $wp_list_table = _get_list_table( 'WP_Posts_List_Table', array( 'screen' => sanitize_key( $_POST['screen'] ) ) );
336 -
337 293 $x = new WP_Ajax_Response();
294 + $wp_list_table = _get_list_table( 'WP_Posts_List_Table', array( 'screen' => $_POST['screen'] ) );
338 295
339 - // Collect old translations
340 - $translations = empty( $_POST['translations'] ) ? array() : explode( ',', $_POST['translations'] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput
296 + $translations = empty( $_POST['translations'] ) ? array() : explode( ',', $_POST['translations'] ); // collect old translations
297 + $translations = array_merge( $translations, array( $_POST['post_id'] ) ); // add current post
341 298 $translations = array_map( 'intval', $translations );
342 299
343 - $translations = array_merge( $translations, array( (int) $_POST['post_id'] ) ); // Add current post
344 -
345 300 foreach ( $translations as $post_id ) {
346 301 $level = is_post_type_hierarchical( $post_type ) ? count( get_ancestors( $post_id, $post_type ) ) : 0;
347 302 if ( $post = get_post( $post_id ) ) {
348 303 ob_start();
@@ -360,32 +315,24 @@
360 315 *
361 316 * @since 1.7
362 317 */
363 318 public function ajax_update_term_rows() {
364 - check_ajax_referer( 'pll_language', '_pll_nonce' );
319 + global $wp_list_table;
365 320
366 - if ( ! isset( $_POST['taxonomy'], $_POST['term_id'], $_POST['screen'] ) ) {
367 - wp_die( 0 );
321 + if ( ! taxonomy_exists( $taxonomy = $_POST['taxonomy'] ) || ! $this->model->is_translated_taxonomy( $taxonomy ) ) {
322 + die( 0 );
368 323 }
369 324
370 - $taxonomy = sanitize_key( $_POST['taxonomy'] );
325 + check_ajax_referer( 'pll_language', '_pll_nonce' );
371 326
372 - if ( ! taxonomy_exists( $taxonomy ) || ! $this->model->is_translated_taxonomy( $taxonomy ) ) {
373 - wp_die( 0 );
374 - }
375 -
376 - global $wp_list_table;
377 - $wp_list_table = _get_list_table( 'WP_Terms_List_Table', array( 'screen' => sanitize_key( $_POST['screen'] ) ) );
378 -
379 327 $x = new WP_Ajax_Response();
328 + $wp_list_table = _get_list_table( 'WP_Terms_List_Table', array( 'screen' => $_POST['screen'] ) );
380 329
381 - // Collect old translations
382 - $translations = empty( $_POST['translations'] ) ? array() : explode( ',', $_POST['translations'] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput
330 + $translations = empty( $_POST['translations'] ) ? array() : explode( ',', $_POST['translations'] ); // collect old translations
331 + $translations = array_merge( $translations, $this->model->term->get_translations( (int) $_POST['term_id'] ) ); // add current translations
332 + $translations = array_unique( $translations ); // remove duplicates
383 333 $translations = array_map( 'intval', $translations );
384 334
385 - $translations = array_merge( $translations, $this->model->term->get_translations( (int) $_POST['term_id'] ) ); // Add current translations
386 - $translations = array_unique( $translations ); // Remove duplicates
387 -
388 335 foreach ( $translations as $term_id ) {
389 336 $level = is_taxonomy_hierarchical( $taxonomy ) ? count( get_ancestors( $term_id, $taxonomy ) ) : 0;
390 337 if ( $tag = get_term( $term_id, $taxonomy ) ) {
391 338 ob_start();
@@ -395,18 +342,6 @@
395 342 }
396 343 }
397 344
398 345 $x->send();
399 - }
400 -
401 - /**
402 - * Returns the language flag or teh language slug if there is no flag.
403 - *
404 - * @since 2.8
405 - *
406 - * @param object $language PLL_Language object.
407 - * @return string
408 - */
409 - protected function get_flag_html( $language ) {
410 - return $language->flag ? $language->flag : sprintf( '<abbr>%s</abbr>', esc_html( $language->slug ) );
411 346 }
412 347 }