38 |
50 |
39 if ( empty( $taxonomy ) ) |
51 if ( empty( $taxonomy ) ) |
40 $taxonomy = 'post_tag'; |
52 $taxonomy = 'post_tag'; |
41 |
53 |
42 if ( ! taxonomy_exists( $taxonomy ) ) |
54 if ( ! taxonomy_exists( $taxonomy ) ) |
43 wp_die( __( 'Invalid taxonomy' ) ); |
55 wp_die( __( 'Invalid taxonomy.' ) ); |
44 |
56 |
45 $tax = get_taxonomy( $taxonomy ); |
57 $tax = get_taxonomy( $taxonomy ); |
46 |
58 |
47 // @todo Still needed? Maybe just the show_ui part. |
59 // @todo Still needed? Maybe just the show_ui part. |
48 if ( empty( $post_type ) || !in_array( $post_type, get_post_types( array( 'show_ui' => true ) ) ) ) |
60 if ( empty( $post_type ) || !in_array( $post_type, get_post_types( array( 'show_ui' => true ) ) ) ) |
49 $post_type = 'post'; |
61 $post_type = 'post'; |
50 |
62 |
51 } |
63 } |
52 |
64 |
|
65 /** |
|
66 * |
|
67 * @return bool |
|
68 */ |
53 public function ajax_user_can() { |
69 public function ajax_user_can() { |
54 return current_user_can( get_taxonomy( $this->screen->taxonomy )->cap->manage_terms ); |
70 return current_user_can( get_taxonomy( $this->screen->taxonomy )->cap->manage_terms ); |
55 } |
71 } |
56 |
72 |
|
73 /** |
|
74 */ |
57 public function prepare_items() { |
75 public function prepare_items() { |
58 $tags_per_page = $this->get_items_per_page( 'edit_' . $this->screen->taxonomy . '_per_page' ); |
76 $tags_per_page = $this->get_items_per_page( 'edit_' . $this->screen->taxonomy . '_per_page' ); |
59 |
77 |
60 if ( 'post_tag' == $this->screen->taxonomy ) { |
78 if ( 'post_tag' === $this->screen->taxonomy ) { |
61 /** |
79 /** |
62 * Filter the number of terms displayed per page for the Tags list table. |
80 * Filters the number of terms displayed per page for the Tags list table. |
63 * |
81 * |
64 * @since 2.8.0 |
82 * @since 2.8.0 |
65 * |
83 * |
66 * @param int $tags_per_page Number of tags to be displayed. Default 20. |
84 * @param int $tags_per_page Number of tags to be displayed. Default 20. |
67 */ |
85 */ |
68 $tags_per_page = apply_filters( 'edit_tags_per_page', $tags_per_page ); |
86 $tags_per_page = apply_filters( 'edit_tags_per_page', $tags_per_page ); |
69 |
87 |
70 /** |
88 /** |
71 * Filter the number of terms displayed per page for the Tags list table. |
89 * Filters the number of terms displayed per page for the Tags list table. |
72 * |
90 * |
73 * @since 2.7.0 |
91 * @since 2.7.0 |
74 * @deprecated 2.8.0 Use edit_tags_per_page instead. |
92 * @deprecated 2.8.0 Use edit_tags_per_page instead. |
75 * |
93 * |
76 * @param int $tags_per_page Number of tags to be displayed. Default 20. |
94 * @param int $tags_per_page Number of tags to be displayed. Default 20. |
77 */ |
95 */ |
78 $tags_per_page = apply_filters( 'tagsperpage', $tags_per_page ); |
96 $tags_per_page = apply_filters( 'tagsperpage', $tags_per_page ); |
79 } elseif ( 'category' == $this->screen->taxonomy ) { |
97 } elseif ( 'category' === $this->screen->taxonomy ) { |
80 /** |
98 /** |
81 * Filter the number of terms displayed per page for the Categories list table. |
99 * Filters the number of terms displayed per page for the Categories list table. |
82 * |
100 * |
83 * @since 2.8.0 |
101 * @since 2.8.0 |
84 * |
102 * |
85 * @param int $tags_per_page Number of categories to be displayed. Default 20. |
103 * @param int $tags_per_page Number of categories to be displayed. Default 20. |
86 */ |
104 */ |
107 'total_items' => wp_count_terms( $this->screen->taxonomy, compact( 'search' ) ), |
125 'total_items' => wp_count_terms( $this->screen->taxonomy, compact( 'search' ) ), |
108 'per_page' => $tags_per_page, |
126 'per_page' => $tags_per_page, |
109 ) ); |
127 ) ); |
110 } |
128 } |
111 |
129 |
|
130 /** |
|
131 * |
|
132 * @return bool |
|
133 */ |
112 public function has_items() { |
134 public function has_items() { |
113 // todo: populate $this->items in prepare_items() |
135 // todo: populate $this->items in prepare_items() |
114 return true; |
136 return true; |
115 } |
137 } |
116 |
138 |
|
139 /** |
|
140 */ |
117 public function no_items() { |
141 public function no_items() { |
118 echo get_taxonomy( $this->screen->taxonomy )->labels->not_found; |
142 echo get_taxonomy( $this->screen->taxonomy )->labels->not_found; |
119 } |
143 } |
120 |
144 |
|
145 /** |
|
146 * |
|
147 * @return array |
|
148 */ |
121 protected function get_bulk_actions() { |
149 protected function get_bulk_actions() { |
122 $actions = array(); |
150 $actions = array(); |
123 $actions['delete'] = __( 'Delete' ); |
151 |
|
152 if ( current_user_can( get_taxonomy( $this->screen->taxonomy )->cap->delete_terms ) ) { |
|
153 $actions['delete'] = __( 'Delete' ); |
|
154 } |
124 |
155 |
125 return $actions; |
156 return $actions; |
126 } |
157 } |
127 |
158 |
|
159 /** |
|
160 * |
|
161 * @return string |
|
162 */ |
128 public function current_action() { |
163 public function current_action() { |
129 if ( isset( $_REQUEST['action'] ) && isset( $_REQUEST['delete_tags'] ) && ( 'delete' == $_REQUEST['action'] || 'delete' == $_REQUEST['action2'] ) ) |
164 if ( isset( $_REQUEST['action'] ) && isset( $_REQUEST['delete_tags'] ) && ( 'delete' === $_REQUEST['action'] || 'delete' === $_REQUEST['action2'] ) ) |
130 return 'bulk-delete'; |
165 return 'bulk-delete'; |
131 |
166 |
132 return parent::current_action(); |
167 return parent::current_action(); |
133 } |
168 } |
134 |
169 |
|
170 /** |
|
171 * |
|
172 * @return array |
|
173 */ |
135 public function get_columns() { |
174 public function get_columns() { |
136 $columns = array( |
175 $columns = array( |
137 'cb' => '<input type="checkbox" />', |
176 'cb' => '<input type="checkbox" />', |
138 'name' => _x( 'Name', 'term name' ), |
177 'name' => _x( 'Name', 'term name' ), |
139 'description' => __( 'Description' ), |
178 'description' => __( 'Description' ), |
140 'slug' => __( 'Slug' ), |
179 'slug' => __( 'Slug' ), |
141 ); |
180 ); |
142 |
181 |
143 if ( 'link_category' == $this->screen->taxonomy ) { |
182 if ( 'link_category' === $this->screen->taxonomy ) { |
144 $columns['links'] = __( 'Links' ); |
183 $columns['links'] = __( 'Links' ); |
145 } else { |
184 } else { |
146 $columns['posts'] = _x( 'Count', 'Number/count of items' ); |
185 $columns['posts'] = _x( 'Count', 'Number/count of items' ); |
147 } |
186 } |
148 |
187 |
149 return $columns; |
188 return $columns; |
150 } |
189 } |
151 |
190 |
|
191 /** |
|
192 * |
|
193 * @return array |
|
194 */ |
152 protected function get_sortable_columns() { |
195 protected function get_sortable_columns() { |
153 return array( |
196 return array( |
154 'name' => 'name', |
197 'name' => 'name', |
155 'description' => 'description', |
198 'description' => 'description', |
156 'slug' => 'slug', |
199 'slug' => 'slug', |
157 'posts' => 'count', |
200 'posts' => 'count', |
158 'links' => 'count' |
201 'links' => 'count' |
159 ); |
202 ); |
160 } |
203 } |
161 |
204 |
|
205 /** |
|
206 */ |
162 public function display_rows_or_placeholder() { |
207 public function display_rows_or_placeholder() { |
163 $taxonomy = $this->screen->taxonomy; |
208 $taxonomy = $this->screen->taxonomy; |
164 |
209 |
165 $args = wp_parse_args( $this->callback_args, array( |
210 $args = wp_parse_args( $this->callback_args, array( |
166 'page' => 1, |
211 'page' => 1, |
281 $this->single_row_columns( $tag ); |
325 $this->single_row_columns( $tag ); |
282 echo '</tr>'; |
326 echo '</tr>'; |
283 } |
327 } |
284 |
328 |
285 /** |
329 /** |
286 * @param object $tag |
330 * @param WP_Term $tag Term object. |
287 * @return string |
331 * @return string |
288 */ |
332 */ |
289 public function column_cb( $tag ) { |
333 public function column_cb( $tag ) { |
290 $default_term = get_option( 'default_' . $this->screen->taxonomy ); |
334 if ( current_user_can( 'delete_term', $tag->term_id ) ) { |
291 |
|
292 if ( current_user_can( get_taxonomy( $this->screen->taxonomy )->cap->delete_terms ) && $tag->term_id != $default_term ) |
|
293 return '<label class="screen-reader-text" for="cb-select-' . $tag->term_id . '">' . sprintf( __( 'Select %s' ), $tag->name ) . '</label>' |
335 return '<label class="screen-reader-text" for="cb-select-' . $tag->term_id . '">' . sprintf( __( 'Select %s' ), $tag->name ) . '</label>' |
294 . '<input type="checkbox" name="delete_tags[]" value="' . $tag->term_id . '" id="cb-select-' . $tag->term_id . '" />'; |
336 . '<input type="checkbox" name="delete_tags[]" value="' . $tag->term_id . '" id="cb-select-' . $tag->term_id . '" />'; |
|
337 } |
295 |
338 |
296 return ' '; |
339 return ' '; |
297 } |
340 } |
298 |
341 |
299 /** |
342 /** |
300 * @param object $tag |
343 * @param WP_Term $tag Term object. |
301 * @return string |
344 * @return string |
302 */ |
345 */ |
303 public function column_name( $tag ) { |
346 public function column_name( $tag ) { |
304 $taxonomy = $this->screen->taxonomy; |
347 $taxonomy = $this->screen->taxonomy; |
305 $tax = get_taxonomy( $taxonomy ); |
|
306 |
|
307 $default_term = get_option( 'default_' . $taxonomy ); |
|
308 |
348 |
309 $pad = str_repeat( '— ', max( 0, $this->level ) ); |
349 $pad = str_repeat( '— ', max( 0, $this->level ) ); |
310 |
350 |
311 /** |
351 /** |
312 * Filter display of the term name in the terms list table. |
352 * Filters display of the term name in the terms list table. |
313 * |
353 * |
314 * The default output may include padding due to the term's |
354 * The default output may include padding due to the term's |
315 * current level in the term hierarchy. |
355 * current level in the term hierarchy. |
316 * |
356 * |
317 * @since 2.5.0 |
357 * @since 2.5.0 |
318 * |
358 * |
319 * @see WP_Terms_List_Table::column_name() |
359 * @see WP_Terms_List_Table::column_name() |
320 * |
360 * |
321 * @param string $pad_tag_name The term name, padded if not top-level. |
361 * @param string $pad_tag_name The term name, padded if not top-level. |
322 * @param object $tag Term object. |
362 * @param WP_Term $tag Term object. |
323 */ |
363 */ |
324 $name = apply_filters( 'term_name', $pad . ' ' . $tag->name, $tag ); |
364 $name = apply_filters( 'term_name', $pad . ' ' . $tag->name, $tag ); |
325 |
365 |
326 $qe_data = get_term( $tag->term_id, $taxonomy, OBJECT, 'edit' ); |
366 $qe_data = get_term( $tag->term_id, $taxonomy, OBJECT, 'edit' ); |
327 $edit_link = esc_url( get_edit_term_link( $tag->term_id, $taxonomy, $this->screen->post_type ) ); |
367 |
328 |
368 $uri = wp_doing_ajax() ? wp_get_referer() : $_SERVER['REQUEST_URI']; |
329 $out = '<strong><a class="row-title" href="' . $edit_link . '" title="' . esc_attr( sprintf( __( 'Edit “%s”' ), $name ) ) . '">' . $name . '</a></strong><br />'; |
369 |
|
370 $edit_link = add_query_arg( |
|
371 'wp_http_referer', |
|
372 urlencode( wp_unslash( $uri ) ), |
|
373 get_edit_term_link( $tag->term_id, $taxonomy, $this->screen->post_type ) |
|
374 ); |
|
375 |
|
376 $out = sprintf( |
|
377 '<strong><a class="row-title" href="%s" aria-label="%s">%s</a></strong><br />', |
|
378 esc_url( $edit_link ), |
|
379 /* translators: %s: taxonomy term name */ |
|
380 esc_attr( sprintf( __( '“%s” (Edit)' ), $tag->name ) ), |
|
381 $name |
|
382 ); |
|
383 |
|
384 $out .= '<div class="hidden" id="inline_' . $qe_data->term_id . '">'; |
|
385 $out .= '<div class="name">' . $qe_data->name . '</div>'; |
|
386 |
|
387 /** This filter is documented in wp-admin/edit-tag-form.php */ |
|
388 $out .= '<div class="slug">' . apply_filters( 'editable_slug', $qe_data->slug, $qe_data ) . '</div>'; |
|
389 $out .= '<div class="parent">' . $qe_data->parent . '</div></div>'; |
|
390 |
|
391 return $out; |
|
392 } |
|
393 |
|
394 /** |
|
395 * Gets the name of the default primary column. |
|
396 * |
|
397 * @since 4.3.0 |
|
398 * |
|
399 * @return string Name of the default primary column, in this case, 'name'. |
|
400 */ |
|
401 protected function get_default_primary_column_name() { |
|
402 return 'name'; |
|
403 } |
|
404 |
|
405 /** |
|
406 * Generates and displays row action links. |
|
407 * |
|
408 * @since 4.3.0 |
|
409 * |
|
410 * @param WP_Term $tag Tag being acted upon. |
|
411 * @param string $column_name Current column name. |
|
412 * @param string $primary Primary column name. |
|
413 * @return string Row actions output for terms. |
|
414 */ |
|
415 protected function handle_row_actions( $tag, $column_name, $primary ) { |
|
416 if ( $primary !== $column_name ) { |
|
417 return ''; |
|
418 } |
|
419 |
|
420 $taxonomy = $this->screen->taxonomy; |
|
421 $tax = get_taxonomy( $taxonomy ); |
|
422 $uri = wp_doing_ajax() ? wp_get_referer() : $_SERVER['REQUEST_URI']; |
|
423 |
|
424 $edit_link = add_query_arg( |
|
425 'wp_http_referer', |
|
426 urlencode( wp_unslash( $uri ) ), |
|
427 get_edit_term_link( $tag->term_id, $taxonomy, $this->screen->post_type ) |
|
428 ); |
330 |
429 |
331 $actions = array(); |
430 $actions = array(); |
332 if ( current_user_can( $tax->cap->edit_terms ) ) { |
431 if ( current_user_can( 'edit_term', $tag->term_id ) ) { |
333 $actions['edit'] = '<a href="' . $edit_link . '">' . __( 'Edit' ) . '</a>'; |
432 $actions['edit'] = sprintf( |
334 $actions['inline hide-if-no-js'] = '<a href="#" class="editinline">' . __( 'Quick Edit' ) . '</a>'; |
433 '<a href="%s" aria-label="%s">%s</a>', |
335 } |
434 esc_url( $edit_link ), |
336 if ( current_user_can( $tax->cap->delete_terms ) && $tag->term_id != $default_term ) |
435 /* translators: %s: taxonomy term name */ |
337 $actions['delete'] = "<a class='delete-tag' href='" . wp_nonce_url( "edit-tags.php?action=delete&taxonomy=$taxonomy&tag_ID=$tag->term_id", 'delete-tag_' . $tag->term_id ) . "'>" . __( 'Delete' ) . "</a>"; |
436 esc_attr( sprintf( __( 'Edit “%s”' ), $tag->name ) ), |
338 if ( $tax->public ) |
437 __( 'Edit' ) |
339 $actions['view'] = '<a href="' . get_term_link( $tag ) . '">' . __( 'View' ) . '</a>'; |
438 ); |
|
439 $actions['inline hide-if-no-js'] = sprintf( |
|
440 '<a href="#" class="editinline aria-button-if-js" aria-label="%s">%s</a>', |
|
441 /* translators: %s: taxonomy term name */ |
|
442 esc_attr( sprintf( __( 'Quick edit “%s” inline' ), $tag->name ) ), |
|
443 __( 'Quick Edit' ) |
|
444 ); |
|
445 } |
|
446 if ( current_user_can( 'delete_term', $tag->term_id ) ) { |
|
447 $actions['delete'] = sprintf( |
|
448 '<a href="%s" class="delete-tag aria-button-if-js" aria-label="%s">%s</a>', |
|
449 wp_nonce_url( "edit-tags.php?action=delete&taxonomy=$taxonomy&tag_ID=$tag->term_id", 'delete-tag_' . $tag->term_id ), |
|
450 /* translators: %s: taxonomy term name */ |
|
451 esc_attr( sprintf( __( 'Delete “%s”' ), $tag->name ) ), |
|
452 __( 'Delete' ) |
|
453 ); |
|
454 } |
|
455 if ( $tax->public ) { |
|
456 $actions['view'] = sprintf( |
|
457 '<a href="%s" aria-label="%s">%s</a>', |
|
458 get_term_link( $tag ), |
|
459 /* translators: %s: taxonomy term name */ |
|
460 esc_attr( sprintf( __( 'View “%s” archive' ), $tag->name ) ), |
|
461 __( 'View' ) |
|
462 ); |
|
463 } |
340 |
464 |
341 /** |
465 /** |
342 * Filter the action links displayed for each term in the Tags list table. |
466 * Filters the action links displayed for each term in the Tags list table. |
343 * |
467 * |
344 * @since 2.8.0 |
468 * @since 2.8.0 |
345 * @deprecated 3.0.0 Use {$taxonomy}_row_actions instead. |
469 * @deprecated 3.0.0 Use {$taxonomy}_row_actions instead. |
346 * |
470 * |
347 * @param array $actions An array of action links to be displayed. Default |
471 * @param array $actions An array of action links to be displayed. Default |
348 * 'Edit', 'Quick Edit', 'Delete', and 'View'. |
472 * 'Edit', 'Quick Edit', 'Delete', and 'View'. |
349 * @param object $tag Term object. |
473 * @param WP_Term $tag Term object. |
350 */ |
474 */ |
351 $actions = apply_filters( 'tag_row_actions', $actions, $tag ); |
475 $actions = apply_filters( 'tag_row_actions', $actions, $tag ); |
352 |
476 |
353 /** |
477 /** |
354 * Filter the action links displayed for each term in the terms list table. |
478 * Filters the action links displayed for each term in the terms list table. |
355 * |
479 * |
356 * The dynamic portion of the hook name, `$taxonomy`, refers to the taxonomy slug. |
480 * The dynamic portion of the hook name, `$taxonomy`, refers to the taxonomy slug. |
357 * |
481 * |
358 * @since 3.0.0 |
482 * @since 3.0.0 |
359 * |
483 * |
360 * @param array $actions An array of action links to be displayed. Default |
484 * @param array $actions An array of action links to be displayed. Default |
361 * 'Edit', 'Quick Edit', 'Delete', and 'View'. |
485 * 'Edit', 'Quick Edit', 'Delete', and 'View'. |
362 * @param object $tag Term object. |
486 * @param WP_Term $tag Term object. |
363 */ |
487 */ |
364 $actions = apply_filters( "{$taxonomy}_row_actions", $actions, $tag ); |
488 $actions = apply_filters( "{$taxonomy}_row_actions", $actions, $tag ); |
365 |
489 |
366 $out .= $this->row_actions( $actions ); |
490 return $this->row_actions( $actions ); |
367 $out .= '<div class="hidden" id="inline_' . $qe_data->term_id . '">'; |
491 } |
368 $out .= '<div class="name">' . $qe_data->name . '</div>'; |
492 |
369 |
493 /** |
370 /** This filter is documented in wp-admin/edit-tag-form.php */ |
494 * @param WP_Term $tag Term object. |
371 $out .= '<div class="slug">' . apply_filters( 'editable_slug', $qe_data->slug ) . '</div>'; |
|
372 $out .= '<div class="parent">' . $qe_data->parent . '</div></div>'; |
|
373 |
|
374 return $out; |
|
375 } |
|
376 |
|
377 /** |
|
378 * @param object $tag |
|
379 * @return string |
495 * @return string |
380 */ |
496 */ |
381 public function column_description( $tag ) { |
497 public function column_description( $tag ) { |
382 return $tag->description; |
498 if ( $tag->description ) { |
383 } |
499 return $tag->description; |
384 |
500 } else { |
385 /** |
501 return '<span aria-hidden="true">—</span><span class="screen-reader-text">' . __( 'No description' ) . '</span>'; |
386 * @param object $tag |
502 } |
|
503 } |
|
504 |
|
505 /** |
|
506 * @param WP_Term $tag Term object. |
387 * @return string |
507 * @return string |
388 */ |
508 */ |
389 public function column_slug( $tag ) { |
509 public function column_slug( $tag ) { |
390 /** This filter is documented in wp-admin/edit-tag-form.php */ |
510 /** This filter is documented in wp-admin/edit-tag-form.php */ |
391 return apply_filters( 'editable_slug', $tag->slug ); |
511 return apply_filters( 'editable_slug', $tag->slug, $tag ); |
392 } |
512 } |
393 |
513 |
394 /** |
514 /** |
395 * @param object $tag |
515 * @param WP_Term $tag Term object. |
396 * @return string |
516 * @return string |
397 */ |
517 */ |
398 public function column_posts( $tag ) { |
518 public function column_posts( $tag ) { |
399 $count = number_format_i18n( $tag->count ); |
519 $count = number_format_i18n( $tag->count ); |
400 |
520 |