9 */ |
9 */ |
10 class WP_Terms_List_Table extends WP_List_Table { |
10 class WP_Terms_List_Table extends WP_List_Table { |
11 |
11 |
12 var $callback_args; |
12 var $callback_args; |
13 |
13 |
14 function __construct() { |
14 function __construct( $args = array() ) { |
15 global $post_type, $taxonomy, $tax; |
15 global $post_type, $taxonomy, $action, $tax; |
16 |
|
17 wp_reset_vars( array( 'action', 'taxonomy', 'post_type' ) ); |
|
18 |
|
19 if ( empty( $taxonomy ) ) |
|
20 $taxonomy = 'post_tag'; |
|
21 |
|
22 if ( !taxonomy_exists( $taxonomy ) ) |
|
23 wp_die( __( 'Invalid taxonomy' ) ); |
|
24 |
|
25 $tax = get_taxonomy( $taxonomy ); |
|
26 |
|
27 if ( empty( $post_type ) || !in_array( $post_type, get_post_types( array( 'show_ui' => true ) ) ) ) |
|
28 $post_type = 'post'; |
|
29 |
16 |
30 parent::__construct( array( |
17 parent::__construct( array( |
31 'plural' => 'tags', |
18 'plural' => 'tags', |
32 'singular' => 'tag', |
19 'singular' => 'tag', |
|
20 'screen' => isset( $args['screen'] ) ? $args['screen'] : null, |
33 ) ); |
21 ) ); |
|
22 |
|
23 $action = $this->screen->action; |
|
24 $post_type = $this->screen->post_type; |
|
25 $taxonomy = $this->screen->taxonomy; |
|
26 |
|
27 if ( empty( $taxonomy ) ) |
|
28 $taxonomy = 'post_tag'; |
|
29 |
|
30 if ( ! taxonomy_exists( $taxonomy ) ) |
|
31 wp_die( __( 'Invalid taxonomy' ) ); |
|
32 |
|
33 $tax = get_taxonomy( $taxonomy ); |
|
34 |
|
35 // @todo Still needed? Maybe just the show_ui part. |
|
36 if ( empty( $post_type ) || !in_array( $post_type, get_post_types( array( 'show_ui' => true ) ) ) ) |
|
37 $post_type = 'post'; |
|
38 |
34 } |
39 } |
35 |
40 |
36 function ajax_user_can() { |
41 function ajax_user_can() { |
37 global $tax; |
42 return current_user_can( get_taxonomy( $this->screen->taxonomy )->cap->manage_terms ); |
38 |
|
39 return current_user_can( $tax->cap->manage_terms ); |
|
40 } |
43 } |
41 |
44 |
42 function prepare_items() { |
45 function prepare_items() { |
43 global $taxonomy; |
46 $tags_per_page = $this->get_items_per_page( 'edit_' . $this->screen->taxonomy . '_per_page' ); |
44 |
47 |
45 $tags_per_page = $this->get_items_per_page( 'edit_' . $taxonomy . '_per_page' ); |
48 if ( 'post_tag' == $this->screen->taxonomy ) { |
46 |
|
47 if ( 'post_tag' == $taxonomy ) { |
|
48 $tags_per_page = apply_filters( 'edit_tags_per_page', $tags_per_page ); |
49 $tags_per_page = apply_filters( 'edit_tags_per_page', $tags_per_page ); |
49 $tags_per_page = apply_filters( 'tagsperpage', $tags_per_page ); // Old filter |
50 $tags_per_page = apply_filters( 'tagsperpage', $tags_per_page ); // Old filter |
50 } elseif ( 'category' == $taxonomy ) { |
51 } elseif ( 'category' == $this->screen->taxonomy ) { |
51 $tags_per_page = apply_filters( 'edit_categories_per_page', $tags_per_page ); // Old filter |
52 $tags_per_page = apply_filters( 'edit_categories_per_page', $tags_per_page ); // Old filter |
52 } |
53 } |
53 |
54 |
54 $search = !empty( $_REQUEST['s'] ) ? trim( stripslashes( $_REQUEST['s'] ) ) : ''; |
55 $search = !empty( $_REQUEST['s'] ) ? trim( stripslashes( $_REQUEST['s'] ) ) : ''; |
55 |
56 |
66 $args['order'] = trim( stripslashes( $_REQUEST['order'] ) ); |
67 $args['order'] = trim( stripslashes( $_REQUEST['order'] ) ); |
67 |
68 |
68 $this->callback_args = $args; |
69 $this->callback_args = $args; |
69 |
70 |
70 $this->set_pagination_args( array( |
71 $this->set_pagination_args( array( |
71 'total_items' => wp_count_terms( $taxonomy, compact( 'search' ) ), |
72 'total_items' => wp_count_terms( $this->screen->taxonomy, compact( 'search' ) ), |
72 'per_page' => $tags_per_page, |
73 'per_page' => $tags_per_page, |
73 ) ); |
74 ) ); |
74 } |
75 } |
75 |
76 |
76 function has_items() { |
77 function has_items() { |
91 |
92 |
92 return parent::current_action(); |
93 return parent::current_action(); |
93 } |
94 } |
94 |
95 |
95 function get_columns() { |
96 function get_columns() { |
96 global $taxonomy, $post_type; |
|
97 |
|
98 $columns = array( |
97 $columns = array( |
99 'cb' => '<input type="checkbox" />', |
98 'cb' => '<input type="checkbox" />', |
100 'name' => _x( 'Name', 'term name' ), |
99 'name' => _x( 'Name', 'term name' ), |
101 'description' => __( 'Description' ), |
100 'description' => __( 'Description' ), |
102 'slug' => __( 'Slug' ), |
101 'slug' => __( 'Slug' ), |
103 ); |
102 ); |
104 |
103 |
105 if ( 'link_category' == $taxonomy ) { |
104 if ( 'link_category' == $this->screen->taxonomy ) { |
106 $columns['links'] = __( 'Links' ); |
105 $columns['links'] = __( 'Links' ); |
107 } else { |
106 } else { |
108 $post_type_object = get_post_type_object( $post_type ); |
107 $post_type_object = get_post_type_object( $this->screen->post_type ); |
109 $columns['posts'] = $post_type_object ? $post_type_object->labels->name : __( 'Posts' ); |
108 $columns['posts'] = $post_type_object ? $post_type_object->labels->name : __( 'Posts' ); |
110 } |
109 } |
111 |
110 |
112 return $columns; |
111 return $columns; |
113 } |
112 } |
229 echo $this->single_row_columns( $tag ); |
228 echo $this->single_row_columns( $tag ); |
230 echo '</tr>'; |
229 echo '</tr>'; |
231 } |
230 } |
232 |
231 |
233 function column_cb( $tag ) { |
232 function column_cb( $tag ) { |
234 global $taxonomy, $tax; |
233 $default_term = get_option( 'default_' . $this->screen->taxonomy ); |
235 |
234 |
236 $default_term = get_option( 'default_' . $taxonomy ); |
235 if ( current_user_can( get_taxonomy( $this->screen->taxonomy )->cap->delete_terms ) && $tag->term_id != $default_term ) |
237 |
236 return '<label class="screen-reader-text" for="cb-select-' . $tag->term_id . '">' . sprintf( __( 'Select %s' ), $tag->name ) . '</label>' |
238 if ( current_user_can( $tax->cap->delete_terms ) && $tag->term_id != $default_term ) |
237 . '<input type="checkbox" name="delete_tags[]" value="' . $tag->term_id . '" id="cb-select-' . $tag->term_id . '" />'; |
239 return '<input type="checkbox" name="delete_tags[]" value="' . $tag->term_id . '" />'; |
238 |
240 else |
239 return ' '; |
241 return ' '; |
|
242 } |
240 } |
243 |
241 |
244 function column_name( $tag ) { |
242 function column_name( $tag ) { |
245 global $taxonomy, $tax, $post_type; |
243 $taxonomy = $this->screen->taxonomy; |
|
244 $tax = get_taxonomy( $taxonomy ); |
246 |
245 |
247 $default_term = get_option( 'default_' . $taxonomy ); |
246 $default_term = get_option( 'default_' . $taxonomy ); |
248 |
247 |
249 $pad = str_repeat( '— ', max( 0, $this->level ) ); |
248 $pad = str_repeat( '— ', max( 0, $this->level ) ); |
250 $name = apply_filters( 'term_name', $pad . ' ' . $tag->name, $tag ); |
249 $name = apply_filters( 'term_name', $pad . ' ' . $tag->name, $tag ); |
251 $qe_data = get_term( $tag->term_id, $taxonomy, OBJECT, 'edit' ); |
250 $qe_data = get_term( $tag->term_id, $taxonomy, OBJECT, 'edit' ); |
252 $edit_link = esc_url( get_edit_term_link( $tag->term_id, $taxonomy, $post_type ) ); |
251 $edit_link = esc_url( get_edit_term_link( $tag->term_id, $taxonomy, $this->screen->post_type ) ); |
253 |
252 |
254 $out = '<strong><a class="row-title" href="' . $edit_link . '" title="' . esc_attr( sprintf( __( 'Edit “%s”' ), $name ) ) . '">' . $name . '</a></strong><br />'; |
253 $out = '<strong><a class="row-title" href="' . $edit_link . '" title="' . esc_attr( sprintf( __( 'Edit “%s”' ), $name ) ) . '">' . $name . '</a></strong><br />'; |
255 |
254 |
256 $actions = array(); |
255 $actions = array(); |
257 if ( current_user_can( $tax->cap->edit_terms ) ) { |
256 if ( current_user_can( $tax->cap->edit_terms ) ) { |
281 function column_slug( $tag ) { |
280 function column_slug( $tag ) { |
282 return apply_filters( 'editable_slug', $tag->slug ); |
281 return apply_filters( 'editable_slug', $tag->slug ); |
283 } |
282 } |
284 |
283 |
285 function column_posts( $tag ) { |
284 function column_posts( $tag ) { |
286 global $taxonomy, $post_type; |
|
287 |
|
288 $count = number_format_i18n( $tag->count ); |
285 $count = number_format_i18n( $tag->count ); |
289 |
286 |
290 $tax = get_taxonomy( $taxonomy ); |
287 $tax = get_taxonomy( $this->screen->taxonomy ); |
291 |
288 |
292 $ptype_object = get_post_type_object( $post_type ); |
289 $ptype_object = get_post_type_object( $this->screen->post_type ); |
293 if ( ! $ptype_object->show_ui ) |
290 if ( ! $ptype_object->show_ui ) |
294 return $count; |
291 return $count; |
295 |
292 |
296 if ( $tax->query_var ) { |
293 if ( $tax->query_var ) { |
297 $args = array( $tax->query_var => $tag->slug ); |
294 $args = array( $tax->query_var => $tag->slug ); |
298 } else { |
295 } else { |
299 $args = array( 'taxonomy' => $tax->name, 'term' => $tag->slug ); |
296 $args = array( 'taxonomy' => $tax->name, 'term' => $tag->slug ); |
300 } |
297 } |
301 |
298 |
302 if ( 'post' != $post_type ) |
299 if ( 'post' != $this->screen->post_type ) |
303 $args['post_type'] = $post_type; |
300 $args['post_type'] = $this->screen->post_type; |
|
301 |
|
302 if ( 'attachment' == $this->screen->post_type ) |
|
303 return "<a href='" . esc_url ( add_query_arg( $args, 'upload.php' ) ) . "'>$count</a>"; |
304 |
304 |
305 return "<a href='" . esc_url ( add_query_arg( $args, 'edit.php' ) ) . "'>$count</a>"; |
305 return "<a href='" . esc_url ( add_query_arg( $args, 'edit.php' ) ) . "'>$count</a>"; |
306 } |
306 } |
307 |
307 |
308 function column_links( $tag ) { |
308 function column_links( $tag ) { |
311 $count = "<a href='link-manager.php?cat_id=$tag->term_id'>$count</a>"; |
311 $count = "<a href='link-manager.php?cat_id=$tag->term_id'>$count</a>"; |
312 return $count; |
312 return $count; |
313 } |
313 } |
314 |
314 |
315 function column_default( $tag, $column_name ) { |
315 function column_default( $tag, $column_name ) { |
316 $screen = get_current_screen(); |
316 return apply_filters( "manage_{$this->screen->taxonomy}_custom_column", '', $column_name, $tag->term_id ); |
317 |
|
318 return apply_filters( "manage_{$screen->taxonomy}_custom_column", '', $column_name, $tag->term_id ); |
|
319 } |
317 } |
320 |
318 |
321 /** |
319 /** |
322 * Outputs the hidden row displayed when inline editing |
320 * Outputs the hidden row displayed when inline editing |
323 * |
321 * |
324 * @since 3.1.0 |
322 * @since 3.1.0 |
325 */ |
323 */ |
326 function inline_edit() { |
324 function inline_edit() { |
327 global $post_type, $tax; |
325 $tax = get_taxonomy( $this->screen->taxonomy ); |
328 |
326 |
329 if ( ! current_user_can( $tax->cap->edit_terms ) ) |
327 if ( ! current_user_can( $tax->cap->edit_terms ) ) |
330 return; |
328 return; |
331 ?> |
329 ?> |
332 |
330 |
355 |
353 |
356 foreach ( $columns as $column_name => $column_display_name ) { |
354 foreach ( $columns as $column_name => $column_display_name ) { |
357 if ( isset( $core_columns[$column_name] ) ) |
355 if ( isset( $core_columns[$column_name] ) ) |
358 continue; |
356 continue; |
359 |
357 |
360 do_action( 'quick_edit_custom_box', $column_name, 'edit-tags', $tax->name ); |
358 do_action( 'quick_edit_custom_box', $column_name, 'edit-tags', $this->screen->taxonomy ); |
361 } |
359 } |
362 |
360 |
363 ?> |
361 ?> |
364 |
362 |
365 <p class="inline-edit-save submit"> |
363 <p class="inline-edit-save submit"> |
366 <a accesskey="c" href="#inline-edit" title="<?php esc_attr_e( 'Cancel' ); ?>" class="cancel button-secondary alignleft"><?php _e( 'Cancel' ); ?></a> |
364 <a accesskey="c" href="#inline-edit" title="<?php esc_attr_e( 'Cancel' ); ?>" class="cancel button-secondary alignleft"><?php _e( 'Cancel' ); ?></a> |
367 <?php $update_text = $tax->labels->update_item; ?> |
365 <?php $update_text = $tax->labels->update_item; ?> |
368 <a accesskey="s" href="#inline-edit" title="<?php echo esc_attr( $update_text ); ?>" class="save button-primary alignright"><?php echo $update_text; ?></a> |
366 <a accesskey="s" href="#inline-edit" title="<?php echo esc_attr( $update_text ); ?>" class="save button-primary alignright"><?php echo $update_text; ?></a> |
369 <img class="waiting" style="display:none;" src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" alt="" /> |
367 <span class="spinner"></span> |
370 <span class="error" style="display:none;"></span> |
368 <span class="error" style="display:none;"></span> |
371 <?php wp_nonce_field( 'taxinlineeditnonce', '_inline_edit', false ); ?> |
369 <?php wp_nonce_field( 'taxinlineeditnonce', '_inline_edit', false ); ?> |
372 <input type="hidden" name="taxonomy" value="<?php echo esc_attr( $tax->name ); ?>" /> |
370 <input type="hidden" name="taxonomy" value="<?php echo esc_attr( $this->screen->taxonomy ); ?>" /> |
373 <input type="hidden" name="post_type" value="<?php echo esc_attr( $post_type ); ?>" /> |
371 <input type="hidden" name="post_type" value="<?php echo esc_attr( $this->screen->post_type ); ?>" /> |
374 <br class="clear" /> |
372 <br class="clear" /> |
375 </p> |
373 </p> |
376 </td></tr> |
374 </td></tr> |
377 </tbody></table></form> |
375 </tbody></table></form> |
378 <?php |
376 <?php |