75 } |
75 } |
76 |
76 |
77 /** |
77 /** |
78 */ |
78 */ |
79 public function prepare_items() { |
79 public function prepare_items() { |
80 $tags_per_page = $this->get_items_per_page( 'edit_' . $this->screen->taxonomy . '_per_page' ); |
80 $taxonomy = $this->screen->taxonomy; |
81 |
81 |
82 if ( 'post_tag' === $this->screen->taxonomy ) { |
82 $tags_per_page = $this->get_items_per_page( "edit_{$taxonomy}_per_page" ); |
|
83 |
|
84 if ( 'post_tag' === $taxonomy ) { |
83 /** |
85 /** |
84 * Filters the number of terms displayed per page for the Tags list table. |
86 * Filters the number of terms displayed per page for the Tags list table. |
85 * |
87 * |
86 * @since 2.8.0 |
88 * @since 2.8.0 |
87 * |
89 * |
96 * @deprecated 2.8.0 Use {@see 'edit_tags_per_page'} instead. |
98 * @deprecated 2.8.0 Use {@see 'edit_tags_per_page'} instead. |
97 * |
99 * |
98 * @param int $tags_per_page Number of tags to be displayed. Default 20. |
100 * @param int $tags_per_page Number of tags to be displayed. Default 20. |
99 */ |
101 */ |
100 $tags_per_page = apply_filters_deprecated( 'tagsperpage', array( $tags_per_page ), '2.8.0', 'edit_tags_per_page' ); |
102 $tags_per_page = apply_filters_deprecated( 'tagsperpage', array( $tags_per_page ), '2.8.0', 'edit_tags_per_page' ); |
101 } elseif ( 'category' === $this->screen->taxonomy ) { |
103 } elseif ( 'category' === $taxonomy ) { |
102 /** |
104 /** |
103 * Filters the number of terms displayed per page for the Categories list table. |
105 * Filters the number of terms displayed per page for the Categories list table. |
104 * |
106 * |
105 * @since 2.8.0 |
107 * @since 2.8.0 |
106 * |
108 * |
110 } |
112 } |
111 |
113 |
112 $search = ! empty( $_REQUEST['s'] ) ? trim( wp_unslash( $_REQUEST['s'] ) ) : ''; |
114 $search = ! empty( $_REQUEST['s'] ) ? trim( wp_unslash( $_REQUEST['s'] ) ) : ''; |
113 |
115 |
114 $args = array( |
116 $args = array( |
115 'search' => $search, |
117 'taxonomy' => $taxonomy, |
116 'page' => $this->get_pagenum(), |
118 'search' => $search, |
117 'number' => $tags_per_page, |
119 'page' => $this->get_pagenum(), |
|
120 'number' => $tags_per_page, |
|
121 'hide_empty' => 0, |
118 ); |
122 ); |
119 |
123 |
120 if ( ! empty( $_REQUEST['orderby'] ) ) { |
124 if ( ! empty( $_REQUEST['orderby'] ) ) { |
121 $args['orderby'] = trim( wp_unslash( $_REQUEST['orderby'] ) ); |
125 $args['orderby'] = trim( wp_unslash( $_REQUEST['orderby'] ) ); |
122 } |
126 } |
123 |
127 |
124 if ( ! empty( $_REQUEST['order'] ) ) { |
128 if ( ! empty( $_REQUEST['order'] ) ) { |
125 $args['order'] = trim( wp_unslash( $_REQUEST['order'] ) ); |
129 $args['order'] = trim( wp_unslash( $_REQUEST['order'] ) ); |
126 } |
130 } |
127 |
131 |
|
132 $args['offset'] = ( $args['page'] - 1 ) * $args['number']; |
|
133 |
|
134 // Save the values because 'number' and 'offset' can be subsequently overridden. |
128 $this->callback_args = $args; |
135 $this->callback_args = $args; |
|
136 |
|
137 if ( is_taxonomy_hierarchical( $taxonomy ) && ! isset( $args['orderby'] ) ) { |
|
138 // We'll need the full set of terms then. |
|
139 $args['number'] = 0; |
|
140 $args['offset'] = $args['number']; |
|
141 } |
|
142 |
|
143 $this->items = get_terms( $args ); |
129 |
144 |
130 $this->set_pagination_args( |
145 $this->set_pagination_args( |
131 array( |
146 array( |
132 'total_items' => wp_count_terms( |
147 'total_items' => wp_count_terms( |
133 array( |
148 array( |
134 'taxonomy' => $this->screen->taxonomy, |
149 'taxonomy' => $taxonomy, |
135 'search' => $search, |
150 'search' => $search, |
136 ) |
151 ) |
137 ), |
152 ), |
138 'per_page' => $tags_per_page, |
153 'per_page' => $tags_per_page, |
139 ) |
154 ) |
140 ); |
155 ); |
141 } |
|
142 |
|
143 /** |
|
144 * @return bool |
|
145 */ |
|
146 public function has_items() { |
|
147 // @todo Populate $this->items in prepare_items(). |
|
148 return true; |
|
149 } |
156 } |
150 |
157 |
151 /** |
158 /** |
152 */ |
159 */ |
153 public function no_items() { |
160 public function no_items() { |
214 /** |
221 /** |
215 */ |
222 */ |
216 public function display_rows_or_placeholder() { |
223 public function display_rows_or_placeholder() { |
217 $taxonomy = $this->screen->taxonomy; |
224 $taxonomy = $this->screen->taxonomy; |
218 |
225 |
219 $args = wp_parse_args( |
226 $number = $this->callback_args['number']; |
220 $this->callback_args, |
227 $offset = $this->callback_args['offset']; |
221 array( |
|
222 'taxonomy' => $taxonomy, |
|
223 'page' => 1, |
|
224 'number' => 20, |
|
225 'search' => '', |
|
226 'hide_empty' => 0, |
|
227 ) |
|
228 ); |
|
229 |
|
230 $page = $args['page']; |
|
231 |
|
232 // Set variable because $args['number'] can be subsequently overridden. |
|
233 $number = $args['number']; |
|
234 |
|
235 $offset = ( $page - 1 ) * $number; |
|
236 $args['offset'] = $offset; |
|
237 |
228 |
238 // Convert it to table rows. |
229 // Convert it to table rows. |
239 $count = 0; |
230 $count = 0; |
240 |
231 |
241 if ( is_taxonomy_hierarchical( $taxonomy ) && ! isset( $args['orderby'] ) ) { |
232 if ( empty( $this->items ) || ! is_array( $this->items ) ) { |
242 // We'll need the full set of terms then. |
|
243 $args['number'] = 0; |
|
244 $args['offset'] = $args['number']; |
|
245 } |
|
246 |
|
247 $terms = get_terms( $args ); |
|
248 |
|
249 if ( empty( $terms ) || ! is_array( $terms ) ) { |
|
250 echo '<tr class="no-items"><td class="colspanchange" colspan="' . $this->get_column_count() . '">'; |
233 echo '<tr class="no-items"><td class="colspanchange" colspan="' . $this->get_column_count() . '">'; |
251 $this->no_items(); |
234 $this->no_items(); |
252 echo '</td></tr>'; |
235 echo '</td></tr>'; |
253 return; |
236 return; |
254 } |
237 } |
255 |
238 |
256 if ( is_taxonomy_hierarchical( $taxonomy ) && ! isset( $args['orderby'] ) ) { |
239 if ( is_taxonomy_hierarchical( $taxonomy ) && ! isset( $this->callback_args['orderby'] ) ) { |
257 if ( ! empty( $args['search'] ) ) {// Ignore children on searches. |
240 if ( ! empty( $this->callback_args['search'] ) ) {// Ignore children on searches. |
258 $children = array(); |
241 $children = array(); |
259 } else { |
242 } else { |
260 $children = _get_term_hierarchy( $taxonomy ); |
243 $children = _get_term_hierarchy( $taxonomy ); |
261 } |
244 } |
262 |
245 |
263 /* |
246 /* |
264 * Some funky recursion to get the job done (paging & parents mainly) is contained within. |
247 * Some funky recursion to get the job done (paging & parents mainly) is contained within. |
265 * Skip it for non-hierarchical taxonomies for performance sake. |
248 * Skip it for non-hierarchical taxonomies for performance sake. |
266 */ |
249 */ |
267 $this->_rows( $taxonomy, $terms, $children, $offset, $number, $count ); |
250 $this->_rows( $taxonomy, $this->items, $children, $offset, $number, $count ); |
268 } else { |
251 } else { |
269 foreach ( $terms as $term ) { |
252 foreach ( $this->items as $term ) { |
270 $this->single_row( $term ); |
253 $this->single_row( $term ); |
271 } |
254 } |
272 } |
255 } |
273 } |
256 } |
274 |
257 |
277 * @param array $terms |
260 * @param array $terms |
278 * @param array $children |
261 * @param array $children |
279 * @param int $start |
262 * @param int $start |
280 * @param int $per_page |
263 * @param int $per_page |
281 * @param int $count |
264 * @param int $count |
282 * @param int $parent |
265 * @param int $parent_term |
283 * @param int $level |
266 * @param int $level |
284 */ |
267 */ |
285 private function _rows( $taxonomy, $terms, &$children, $start, $per_page, &$count, $parent = 0, $level = 0 ) { |
268 private function _rows( $taxonomy, $terms, &$children, $start, $per_page, &$count, $parent_term = 0, $level = 0 ) { |
286 |
269 |
287 $end = $start + $per_page; |
270 $end = $start + $per_page; |
288 |
271 |
289 foreach ( $terms as $key => $term ) { |
272 foreach ( $terms as $key => $term ) { |
290 |
273 |
291 if ( $count >= $end ) { |
274 if ( $count >= $end ) { |
292 break; |
275 break; |
293 } |
276 } |
294 |
277 |
295 if ( $term->parent !== $parent && empty( $_REQUEST['s'] ) ) { |
278 if ( $term->parent !== $parent_term && empty( $_REQUEST['s'] ) ) { |
296 continue; |
279 continue; |
297 } |
280 } |
298 |
281 |
299 // If the page starts in a subtree, print the parents. |
282 // If the page starts in a subtree, print the parents. |
300 if ( $count === $start && $term->parent > 0 && empty( $_REQUEST['s'] ) ) { |
283 if ( $count === $start && $term->parent > 0 && empty( $_REQUEST['s'] ) ) { |
362 $this->single_row_columns( $tag ); |
345 $this->single_row_columns( $tag ); |
363 echo '</tr>'; |
346 echo '</tr>'; |
364 } |
347 } |
365 |
348 |
366 /** |
349 /** |
367 * @param WP_Term $tag Term object. |
350 * @since 5.9.0 Renamed `$tag` to `$item` to match parent class for PHP 8 named parameter support. |
|
351 * |
|
352 * @param WP_Term $item Term object. |
368 * @return string |
353 * @return string |
369 */ |
354 */ |
370 public function column_cb( $tag ) { |
355 public function column_cb( $item ) { |
|
356 // Restores the more descriptive, specific name for use within this method. |
|
357 $tag = $item; |
|
358 |
371 if ( current_user_can( 'delete_term', $tag->term_id ) ) { |
359 if ( current_user_can( 'delete_term', $tag->term_id ) ) { |
372 return sprintf( |
360 return sprintf( |
373 '<label class="screen-reader-text" for="cb-select-%1$s">%2$s</label>' . |
361 '<label class="screen-reader-text" for="cb-select-%1$s">%2$s</label>' . |
374 '<input type="checkbox" name="delete_tags[]" value="%1$s" id="cb-select-%1$s" />', |
362 '<input type="checkbox" name="delete_tags[]" value="%1$s" id="cb-select-%1$s" />', |
375 $tag->term_id, |
363 $tag->term_id, |
407 |
395 |
408 $qe_data = get_term( $tag->term_id, $taxonomy, OBJECT, 'edit' ); |
396 $qe_data = get_term( $tag->term_id, $taxonomy, OBJECT, 'edit' ); |
409 |
397 |
410 $uri = wp_doing_ajax() ? wp_get_referer() : $_SERVER['REQUEST_URI']; |
398 $uri = wp_doing_ajax() ? wp_get_referer() : $_SERVER['REQUEST_URI']; |
411 |
399 |
412 $edit_link = get_edit_term_link( $tag->term_id, $taxonomy, $this->screen->post_type ); |
400 $edit_link = get_edit_term_link( $tag, $taxonomy, $this->screen->post_type ); |
413 |
401 |
414 if ( $edit_link ) { |
402 if ( $edit_link ) { |
415 $edit_link = add_query_arg( |
403 $edit_link = add_query_arg( |
416 'wp_http_referer', |
404 'wp_http_referer', |
417 urlencode( wp_unslash( $uri ) ), |
405 urlencode( wp_unslash( $uri ) ), |
454 |
442 |
455 /** |
443 /** |
456 * Generates and displays row action links. |
444 * Generates and displays row action links. |
457 * |
445 * |
458 * @since 4.3.0 |
446 * @since 4.3.0 |
459 * |
447 * @since 5.9.0 Renamed `$tag` to `$item` to match parent class for PHP 8 named parameter support. |
460 * @param WP_Term $tag Tag being acted upon. |
448 * |
|
449 * @param WP_Term $item Tag being acted upon. |
461 * @param string $column_name Current column name. |
450 * @param string $column_name Current column name. |
462 * @param string $primary Primary column name. |
451 * @param string $primary Primary column name. |
463 * @return string Row actions output for terms, or an empty string |
452 * @return string Row actions output for terms, or an empty string |
464 * if the current column is not the primary column. |
453 * if the current column is not the primary column. |
465 */ |
454 */ |
466 protected function handle_row_actions( $tag, $column_name, $primary ) { |
455 protected function handle_row_actions( $item, $column_name, $primary ) { |
467 if ( $primary !== $column_name ) { |
456 if ( $primary !== $column_name ) { |
468 return ''; |
457 return ''; |
469 } |
458 } |
470 |
459 |
|
460 // Restores the more descriptive, specific name for use within this method. |
|
461 $tag = $item; |
471 $taxonomy = $this->screen->taxonomy; |
462 $taxonomy = $this->screen->taxonomy; |
472 $tax = get_taxonomy( $taxonomy ); |
463 $tax = get_taxonomy( $taxonomy ); |
473 $uri = wp_doing_ajax() ? wp_get_referer() : $_SERVER['REQUEST_URI']; |
464 $uri = wp_doing_ajax() ? wp_get_referer() : $_SERVER['REQUEST_URI']; |
474 |
465 |
475 $edit_link = add_query_arg( |
466 $edit_link = add_query_arg( |
476 'wp_http_referer', |
467 'wp_http_referer', |
477 urlencode( wp_unslash( $uri ) ), |
468 urlencode( wp_unslash( $uri ) ), |
478 get_edit_term_link( $tag->term_id, $taxonomy, $this->screen->post_type ) |
469 get_edit_term_link( $tag, $taxonomy, $this->screen->post_type ) |
479 ); |
470 ); |
480 |
471 |
481 $actions = array(); |
472 $actions = array(); |
482 |
473 |
483 if ( current_user_can( 'edit_term', $tag->term_id ) ) { |
474 if ( current_user_can( 'edit_term', $tag->term_id ) ) { |
618 |
609 |
619 return $count; |
610 return $count; |
620 } |
611 } |
621 |
612 |
622 /** |
613 /** |
623 * @param WP_Term $tag Term object. |
614 * @since 5.9.0 Renamed `$tag` to `$item` to match parent class for PHP 8 named parameter support. |
|
615 * |
|
616 * @param WP_Term $item Term object. |
624 * @param string $column_name Name of the column. |
617 * @param string $column_name Name of the column. |
625 * @return string |
618 * @return string |
626 */ |
619 */ |
627 public function column_default( $tag, $column_name ) { |
620 public function column_default( $item, $column_name ) { |
628 /** |
621 /** |
629 * Filters the displayed columns in the terms list table. |
622 * Filters the displayed columns in the terms list table. |
630 * |
623 * |
631 * The dynamic portion of the hook name, `$this->screen->taxonomy`, |
624 * The dynamic portion of the hook name, `$this->screen->taxonomy`, |
632 * refers to the slug of the current taxonomy. |
625 * refers to the slug of the current taxonomy. |
636 * - `manage_category_custom_column` |
629 * - `manage_category_custom_column` |
637 * - `manage_post_tag_custom_column` |
630 * - `manage_post_tag_custom_column` |
638 * |
631 * |
639 * @since 2.8.0 |
632 * @since 2.8.0 |
640 * |
633 * |
641 * @param string $string Blank string. |
634 * @param string $string Custom column output. Default empty. |
642 * @param string $column_name Name of the column. |
635 * @param string $column_name Name of the column. |
643 * @param int $term_id Term ID. |
636 * @param int $term_id Term ID. |
644 */ |
637 */ |
645 return apply_filters( "manage_{$this->screen->taxonomy}_custom_column", '', $column_name, $tag->term_id ); |
638 return apply_filters( "manage_{$this->screen->taxonomy}_custom_column", '', $column_name, $item->term_id ); |
646 } |
639 } |
647 |
640 |
648 /** |
641 /** |
649 * Outputs the hidden row displayed when inline editing |
642 * Outputs the hidden row displayed when inline editing |
650 * |
643 * |
661 <form method="get"> |
654 <form method="get"> |
662 <table style="display: none"><tbody id="inlineedit"> |
655 <table style="display: none"><tbody id="inlineedit"> |
663 |
656 |
664 <tr id="inline-edit" class="inline-edit-row" style="display: none"> |
657 <tr id="inline-edit" class="inline-edit-row" style="display: none"> |
665 <td colspan="<?php echo $this->get_column_count(); ?>" class="colspanchange"> |
658 <td colspan="<?php echo $this->get_column_count(); ?>" class="colspanchange"> |
|
659 <div class="inline-edit-wrapper"> |
666 |
660 |
667 <fieldset> |
661 <fieldset> |
668 <legend class="inline-edit-legend"><?php _e( 'Quick Edit' ); ?></legend> |
662 <legend class="inline-edit-legend"><?php _e( 'Quick Edit' ); ?></legend> |
669 <div class="inline-edit-col"> |
663 <div class="inline-edit-col"> |
670 <label> |
664 <label> |
701 do_action( 'quick_edit_custom_box', $column_name, 'edit-tags', $this->screen->taxonomy ); |
695 do_action( 'quick_edit_custom_box', $column_name, 'edit-tags', $this->screen->taxonomy ); |
702 } |
696 } |
703 ?> |
697 ?> |
704 |
698 |
705 <div class="inline-edit-save submit"> |
699 <div class="inline-edit-save submit"> |
706 <button type="button" class="cancel button alignleft"><?php _e( 'Cancel' ); ?></button> |
700 <button type="button" class="save button button-primary"><?php echo $tax->labels->update_item; ?></button> |
707 <button type="button" class="save button button-primary alignright"><?php echo $tax->labels->update_item; ?></button> |
701 <button type="button" class="cancel button"><?php _e( 'Cancel' ); ?></button> |
708 <span class="spinner"></span> |
702 <span class="spinner"></span> |
709 |
703 |
710 <?php wp_nonce_field( 'taxinlineeditnonce', '_inline_edit', false ); ?> |
704 <?php wp_nonce_field( 'taxinlineeditnonce', '_inline_edit', false ); ?> |
711 <input type="hidden" name="taxonomy" value="<?php echo esc_attr( $this->screen->taxonomy ); ?>" /> |
705 <input type="hidden" name="taxonomy" value="<?php echo esc_attr( $this->screen->taxonomy ); ?>" /> |
712 <input type="hidden" name="post_type" value="<?php echo esc_attr( $this->screen->post_type ); ?>" /> |
706 <input type="hidden" name="post_type" value="<?php echo esc_attr( $this->screen->post_type ); ?>" /> |
713 <br class="clear" /> |
|
714 |
707 |
715 <div class="notice notice-error notice-alt inline hidden"> |
708 <div class="notice notice-error notice-alt inline hidden"> |
716 <p class="error"></p> |
709 <p class="error"></p> |
717 </div> |
710 </div> |
718 </div> |
711 </div> |
|
712 </div> |
719 |
713 |
720 </td></tr> |
714 </td></tr> |
721 |
715 |
722 </tbody></table> |
716 </tbody></table> |
723 </form> |
717 </form> |