From 2e97d456936933f95c9df2ccba989beb42544ddf Mon Sep 17 00:00:00 2001 From: scribu Date: Sat, 18 Sep 2010 19:30:53 +0000 Subject: [PATCH] WP_Terms_Table cleanup: * use column_*() methods * remove $taxonomy argument from single_row() * don't calculate tag full name in admin-ajax.php See #14579 git-svn-id: https://develop.svn.wordpress.org/trunk@15632 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-admin/admin-ajax.php | 23 ++-- wp-admin/includes/default-list-tables.php | 146 +++++++++++----------- 2 files changed, 83 insertions(+), 86 deletions(-) diff --git a/wp-admin/admin-ajax.php b/wp-admin/admin-ajax.php index 1c472e45ca..11c11cedf1 100644 --- a/wp-admin/admin-ajax.php +++ b/wp-admin/admin-ajax.php @@ -559,19 +559,16 @@ case 'add-tag' : $wp_list_table = get_list_table('terms'); $level = 0; - $tag_full_name = false; - $tag_full_name = $tag->name; if ( is_taxonomy_hierarchical($taxonomy) ) { - $_tag = $tag; - while ( $_tag->parent ) { - $_tag = get_term( $_tag->parent, $taxonomy ); - $tag_full_name = $_tag->name . ' — ' . $tag_full_name; - $level++; - } - $noparents = $wp_list_table->single_row( $tag, $level, $taxonomy ); + $level = count( get_ancestors( $tag->term_id, $taxonomy ) ); + ob_start(); + $wp_list_table->single_row( $tag, $level ); + $noparents = ob_get_clean(); } - $tag->name = $tag_full_name; - $parents = $wp_list_table->single_row( $tag, 0, $taxonomy); + + ob_start(); + $wp_list_table->single_row( $tag ); + $parents = ob_get_clean(); $x->add( array( 'what' => 'taxonomy', @@ -580,7 +577,7 @@ case 'add-tag' : $x->add( array( 'what' => 'term', 'position' => $level, - 'supplemental' => get_term( $tag->term_id, $taxonomy, ARRAY_A ) // Refetch as $tag has been contaminated by the full name. + 'supplemental' => $tag ) ); $x->send(); break; @@ -1227,7 +1224,7 @@ case 'inline-save-tax': die( __('Item not updated.') ); } - echo $wp_list_table->single_row( $tag, 0, $taxonomy ); + echo $wp_list_table->single_row( $tag ); } else { if ( is_wp_error($updated) && $updated->get_error_message() ) die( $updated->get_error_message() ); diff --git a/wp-admin/includes/default-list-tables.php b/wp-admin/includes/default-list-tables.php index adf983f47b..fc546541d8 100644 --- a/wp-admin/includes/default-list-tables.php +++ b/wp-admin/includes/default-list-tables.php @@ -1597,13 +1597,72 @@ class WP_Terms_Table extends WP_List_Table { return $output; } - function single_row( $tag, $level, $taxonomy = 'post_tag' ) { - global $post_type, $current_screen; + function single_row( $tag, $level = 0 ) { static $row_class = ''; $row_class = ( $row_class == '' ? ' class="alternate"' : '' ); + $this->level = $level; + + echo ''; + echo $this->single_row_columns( $tag ); + echo ''; + } + + function column_cb( $tag ) { + global $taxonomy, $tax; + + $default_term = get_option( 'default_' . $taxonomy ); + + if ( current_user_can( $tax->cap->delete_terms ) && $tag->term_id != $default_term ) + return ''; + else + return ' '; + } + + function column_name( $tag ) { + global $taxonomy, $tax, $post_type; + + $default_term = get_option( 'default_' . $taxonomy ); + + $pad = str_repeat( '— ', max( 0, $this->level ) ); + $name = apply_filters( 'term_name', $pad . ' ' . $tag->name, $tag ); + $qe_data = get_term( $tag->term_id, $taxonomy, OBJECT, 'edit' ); + $edit_link = "edit-tags.php?action=edit&taxonomy=$taxonomy&post_type=$post_type&tag_ID=$tag->term_id"; + + $out = '' . $name . '
'; + + $actions = array(); + if ( current_user_can( $tax->cap->edit_terms ) ) { + $actions['edit'] = '' . __( 'Edit' ) . ''; + $actions['inline hide-if-no-js'] = '' . __( 'Quick Edit' ) . ''; + } + if ( current_user_can( $tax->cap->delete_terms ) && $tag->term_id != $default_term ) + $actions['delete'] = "term_id ) . "'>" . __( 'Delete' ) . ""; + + $actions = apply_filters( 'tag_row_actions', $actions, $tag ); + $actions = apply_filters( "${taxonomy}_row_actions", $actions, $tag ); + + $out .= $this->row_actions( $actions ); + $out .= ''; + + return $out; + } + + function column_description( $tag ) { + return $tag->description; + } + + function column_slug( $tag ) { + return apply_filters( 'editable_slug', $tag->slug ); + } + + function column_posts( $tag ) { + global $taxonomy, $post_type; + $count = number_format_i18n( $tag->count ); - $tax = get_taxonomy( $taxonomy ); if ( 'post_tag' == $taxonomy ) { $tagsel = 'tag'; @@ -1615,78 +1674,19 @@ class WP_Terms_Table extends WP_List_Table { $tagsel = $taxonomy; } - $pad = str_repeat( '— ', max( 0, $level ) ); - $name = apply_filters( 'term_name', $pad . ' ' . $tag->name, $tag ); - $qe_data = get_term( $tag->term_id, $taxonomy, object, 'edit' ); - $edit_link = "edit-tags.php?action=edit&taxonomy=$taxonomy&post_type=$post_type&tag_ID=$tag->term_id"; + return "$count"; + } - $out = ''; - $out .= ''; + function column_links( $tag ) { + $count = number_format_i18n( $tag->count ); + return $count; + } - $default_term = get_option( 'default_' . $taxonomy ); - - list( $columns, $hidden ) = $this->get_column_headers(); - - foreach ( $columns as $column_name => $column_display_name ) { - $class = "class=\"$column_name column-$column_name\""; - - $style = ''; - if ( in_array( $column_name, $hidden ) ) - $style = ' style="display:none;"'; - - $attributes = "$class$style"; - - switch ( $column_name ) { - case 'cb': - if ( current_user_can( $tax->cap->delete_terms ) && $tag->term_id != $default_term ) - $out .= ' '; - else - $out .= ' '; - break; - case 'name': - $out .= '' . $name . '
'; - - $actions = array(); - if ( current_user_can( $tax->cap->edit_terms ) ) { - $actions['edit'] = '' . __( 'Edit' ) . ''; - $actions['inline hide-if-no-js'] = '' . __( 'Quick Edit' ) . ''; - } - if ( current_user_can( $tax->cap->delete_terms ) && $tag->term_id != $default_term ) - $actions['delete'] = "term_id ) . "'>" . __( 'Delete' ) . ""; - - $actions = apply_filters( 'tag_row_actions', $actions, $tag ); - $actions = apply_filters( "${taxonomy}_row_actions", $actions, $tag ); - - $out .= $this->row_actions( $actions ); - $out .= ''; - break; - case 'description': - $out .= "$tag->description"; - break; - case 'slug': - $out .= "" . apply_filters( 'editable_slug', $tag->slug ) . ""; - break; - case 'posts': - $attributes = 'class="posts column-posts num"' . $style; - $out .= "$count"; - break; - case 'links': - $attributes = 'class="links column-links num"' . $style; - $out .= "$count"; - break; - default: - $out .= ""; - $out .= apply_filters( "manage_${taxonomy}_custom_column", '', $column_name, $tag->term_id ); - $out .= ""; - } - } - - $out .= "\n"; - - return $out; + function column_default( $tag, $column_name ) { + global $taxonomy; + + return apply_filters( "manage_${taxonomy}_custom_column", '', $column_name, $tag->term_id ); + $out .= ""; } /**