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: http://svn.automattic.com/wordpress/trunk@15632 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
scribu 2010-09-18 19:30:53 +00:00
parent dea3a23691
commit a3bcc7c63c
2 changed files with 83 additions and 86 deletions

View File

@ -559,19 +559,16 @@ case 'add-tag' :
$wp_list_table = get_list_table('terms'); $wp_list_table = get_list_table('terms');
$level = 0; $level = 0;
$tag_full_name = false;
$tag_full_name = $tag->name;
if ( is_taxonomy_hierarchical($taxonomy) ) { if ( is_taxonomy_hierarchical($taxonomy) ) {
$_tag = $tag; $level = count( get_ancestors( $tag->term_id, $taxonomy ) );
while ( $_tag->parent ) { ob_start();
$_tag = get_term( $_tag->parent, $taxonomy ); $wp_list_table->single_row( $tag, $level );
$tag_full_name = $_tag->name . ' — ' . $tag_full_name; $noparents = ob_get_clean();
$level++;
}
$noparents = $wp_list_table->single_row( $tag, $level, $taxonomy );
} }
$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( $x->add( array(
'what' => 'taxonomy', 'what' => 'taxonomy',
@ -580,7 +577,7 @@ case 'add-tag' :
$x->add( array( $x->add( array(
'what' => 'term', 'what' => 'term',
'position' => $level, '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(); $x->send();
break; break;
@ -1227,7 +1224,7 @@ case 'inline-save-tax':
die( __('Item not updated.') ); die( __('Item not updated.') );
} }
echo $wp_list_table->single_row( $tag, 0, $taxonomy ); echo $wp_list_table->single_row( $tag );
} else { } else {
if ( is_wp_error($updated) && $updated->get_error_message() ) if ( is_wp_error($updated) && $updated->get_error_message() )
die( $updated->get_error_message() ); die( $updated->get_error_message() );

View File

@ -1597,13 +1597,72 @@ class WP_Terms_Table extends WP_List_Table {
return $output; return $output;
} }
function single_row( $tag, $level, $taxonomy = 'post_tag' ) { function single_row( $tag, $level = 0 ) {
global $post_type, $current_screen;
static $row_class = ''; static $row_class = '';
$row_class = ( $row_class == '' ? ' class="alternate"' : '' ); $row_class = ( $row_class == '' ? ' class="alternate"' : '' );
$this->level = $level;
echo '<tr id="tag-' . $tag->term_id . '"' . $row_class . '>';
echo $this->single_row_columns( $tag );
echo '</tr>';
}
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 '<input type="checkbox" name="delete_tags[]" value="' . $tag->term_id . '" />';
else
return '&nbsp;';
}
function column_name( $tag ) {
global $taxonomy, $tax, $post_type;
$default_term = get_option( 'default_' . $taxonomy );
$pad = str_repeat( '&#8212; ', 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&amp;taxonomy=$taxonomy&amp;post_type=$post_type&amp;tag_ID=$tag->term_id";
$out = '<strong><a class="row-title" href="' . $edit_link . '" title="' . esc_attr( sprintf( __( 'Edit &#8220;%s&#8221;' ), $name ) ) . '">' . $name . '</a></strong><br />';
$actions = array();
if ( current_user_can( $tax->cap->edit_terms ) ) {
$actions['edit'] = '<a href="' . $edit_link . '">' . __( 'Edit' ) . '</a>';
$actions['inline hide-if-no-js'] = '<a href="#" class="editinline">' . __( 'Quick&nbsp;Edit' ) . '</a>';
}
if ( current_user_can( $tax->cap->delete_terms ) && $tag->term_id != $default_term )
$actions['delete'] = "<a class='delete-tag' href='" . wp_nonce_url( "edit-tags.php?action=delete&amp;taxonomy=$taxonomy&amp;tag_ID=$tag->term_id", 'delete-tag_' . $tag->term_id ) . "'>" . __( 'Delete' ) . "</a>";
$actions = apply_filters( 'tag_row_actions', $actions, $tag );
$actions = apply_filters( "${taxonomy}_row_actions", $actions, $tag );
$out .= $this->row_actions( $actions );
$out .= '<div class="hidden" id="inline_' . $qe_data->term_id . '">';
$out .= '<div class="name">' . $qe_data->name . '</div>';
$out .= '<div class="slug">' . apply_filters( 'editable_slug', $qe_data->slug ) . '</div>';
$out .= '<div class="parent">' . $qe_data->parent . '</div></div></td>';
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 ); $count = number_format_i18n( $tag->count );
$tax = get_taxonomy( $taxonomy );
if ( 'post_tag' == $taxonomy ) { if ( 'post_tag' == $taxonomy ) {
$tagsel = 'tag'; $tagsel = 'tag';
@ -1615,78 +1674,19 @@ class WP_Terms_Table extends WP_List_Table {
$tagsel = $taxonomy; $tagsel = $taxonomy;
} }
$pad = str_repeat( '&#8212; ', max( 0, $level ) ); return "<a href='edit.php?$tagsel=$tag->slug&amp;post_type=$post_type'>$count</a>";
$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&amp;taxonomy=$taxonomy&amp;post_type=$post_type&amp;tag_ID=$tag->term_id";
$out = ''; function column_links( $tag ) {
$out .= '<tr id="tag-' . $tag->term_id . '"' . $row_class . '>'; $count = number_format_i18n( $tag->count );
return $count;
}
$default_term = get_option( 'default_' . $taxonomy ); function column_default( $tag, $column_name ) {
global $taxonomy;
list( $columns, $hidden ) = $this->get_column_headers();
return apply_filters( "manage_${taxonomy}_custom_column", '', $column_name, $tag->term_id );
foreach ( $columns as $column_name => $column_display_name ) { $out .= "</td>";
$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 .= '<th scope="row" class="check-column"> <input type="checkbox" name="delete_tags[]" value="' . $tag->term_id . '" /></th>';
else
$out .= '<th scope="row" class="check-column">&nbsp;</th>';
break;
case 'name':
$out .= '<td ' . $attributes . '><strong><a class="row-title" href="' . $edit_link . '" title="' . esc_attr( sprintf( __( 'Edit &#8220;%s&#8221;' ), $name ) ) . '">' . $name . '</a></strong><br />';
$actions = array();
if ( current_user_can( $tax->cap->edit_terms ) ) {
$actions['edit'] = '<a href="' . $edit_link . '">' . __( 'Edit' ) . '</a>';
$actions['inline hide-if-no-js'] = '<a href="#" class="editinline">' . __( 'Quick&nbsp;Edit' ) . '</a>';
}
if ( current_user_can( $tax->cap->delete_terms ) && $tag->term_id != $default_term )
$actions['delete'] = "<a class='delete-tag' href='" . wp_nonce_url( "edit-tags.php?action=delete&amp;taxonomy=$taxonomy&amp;tag_ID=$tag->term_id", 'delete-tag_' . $tag->term_id ) . "'>" . __( 'Delete' ) . "</a>";
$actions = apply_filters( 'tag_row_actions', $actions, $tag );
$actions = apply_filters( "${taxonomy}_row_actions", $actions, $tag );
$out .= $this->row_actions( $actions );
$out .= '<div class="hidden" id="inline_' . $qe_data->term_id . '">';
$out .= '<div class="name">' . $qe_data->name . '</div>';
$out .= '<div class="slug">' . apply_filters( 'editable_slug', $qe_data->slug ) . '</div>';
$out .= '<div class="parent">' . $qe_data->parent . '</div></div></td>';
break;
case 'description':
$out .= "<td $attributes>$tag->description</td>";
break;
case 'slug':
$out .= "<td $attributes>" . apply_filters( 'editable_slug', $tag->slug ) . "</td>";
break;
case 'posts':
$attributes = 'class="posts column-posts num"' . $style;
$out .= "<td $attributes><a href='edit.php?$tagsel=$tag->slug&amp;post_type=$post_type'>$count</a></td>";
break;
case 'links':
$attributes = 'class="links column-links num"' . $style;
$out .= "<td $attributes>$count</td>";
break;
default:
$out .= "<td $attributes>";
$out .= apply_filters( "manage_${taxonomy}_custom_column", '', $column_name, $tag->term_id );
$out .= "</td>";
}
}
$out .= "</tr>\n";
return $out;
} }
/** /**