Merge Categories/Hierarchical taxonomies into edit-tags.php. See #11838

git-svn-id: https://develop.svn.wordpress.org/trunk@12818 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Dion Hulse 2010-01-24 11:00:27 +00:00
parent 46b0270ab7
commit bc3fbede7f
10 changed files with 155 additions and 54 deletions

View File

@ -610,7 +610,19 @@ case 'add-tag' : // From Manage->Tags
exit;
}
echo _tag_row( $tag, '', $taxonomy );
$level = 0;
$tag_full_name = false;
if ( is_taxonomy_hierarchical($taxonomy) ) {
$tag_full_name = $tag->name;
$_tag = $tag;
while ( $_tag->parent ) {
$_tag = get_term( $_tag->parent, $taxonomy );
$tag_full_name = $_tag->name . ' — ' . $tag_full_name;
$level++;
}
$tag_full_name = esc_attr($tag_full_name);
}
echo _tag_row( $tag, $level, $tag_full_name, $taxonomy );
exit;
break;
case 'get-tagcloud' :
@ -1210,7 +1222,7 @@ case 'inline-save-tax':
if ( !$tag || is_wp_error( $tag ) )
die( __('Tag not updated.') );
echo _tag_row($tag, '', $taxonomy);
echo _tag_row($tag, 0, '', $taxonomy);
} else {
die( __('Tag not updated.') );
}

View File

@ -226,5 +226,5 @@ if ( $page_links )
</div><!-- /col-container -->
</div><!-- /wrap -->
<?php inline_edit_term_row('edit-link-categories'); ?>
<?php inline_edit_term_row('edit-link-categories', 'link_category'); ?>
<?php include('admin-footer.php'); ?>

View File

@ -39,13 +39,22 @@ do_action('edit_tag_form_pre', $tag); ?>
<tr class="form-field">
<th scope="row" valign="top"><label for="slug"><?php _e('Tag slug') ?></label></th>
<td><input name="slug" id="slug" type="text" value="<?php if ( isset( $tag->slug ) ) echo esc_attr(apply_filters('editable_slug', $tag->slug)); ?>" size="40" />
<p class="description"><?php _e('The &#8220;slug&#8221; is the URL-friendly version of the name. It is usually all lowercase and contains only letters, numbers, and hyphens.'); ?></p></td>
<p class="description"><?php _e('The &#8220;slug&#8221; is the URL-friendly version of the name. It is usually all lowercase and contains only letters, numbers, and hyphens.'); ?></p></td>
</tr>
<?php } ?>
<?php if ( is_taxonomy_hierarchical($taxonomy) ) { ?>
<tr class="form-field">
<th scope="row" valign="top"><label for="parent"><?php _e('Category Parent') ?></label></th>
<td>
<?php wp_dropdown_categories(array('hide_empty' => 0, 'hide_if_empty' => false, 'name' => 'parent', 'orderby' => 'name', 'taxonomy' => $taxonomy, 'selected' => $tag->parent, 'exclude' => $tag->term_id, 'hierarchical' => true, 'show_option_none' => __('None'))); ?><br />
<span class="description"><?php _e('Categories, unlike tags, can have a hierarchy. You might have a Jazz category, and under that have children categories for Bebop and Big Band. Totally optional.'); ?></span>
</td>
</tr>
<?php } ?>
<tr class="form-field">
<th scope="row" valign="top"><label for="description"><?php _e('Description') ?></label></th>
<td><textarea name="description" id="description" rows="5" cols="50" style="width: 97%;"><?php echo esc_html($tag->description); ?></textarea><br />
<span class="description"><?php _e('The description is not prominent by default, however some themes may show it.'); ?></span></td>
<span class="description"><?php _e('The description is not prominent by default, however some themes may show it.'); ?></span></td>
</tr>
<?php do_action('edit_tag_form_fields', $tag); ?>
</table>

View File

@ -44,9 +44,9 @@ case 'add-tag':
$ret = wp_insert_term($_POST['tag-name'], $taxonomy, $_POST);
if ( $ret && !is_wp_error( $ret ) ) {
wp_redirect('edit-tags.php?message=1#addtag');
wp_redirect("edit-tags.php?taxonomy=$taxonomy&amp;message=1#addtag");
} else {
wp_redirect('edit-tags.php?message=4#addtag');
wp_redirect("edit-tags.php?taxonomy=$taxonomy&amp;message=4#addtag");
}
exit;
break;
@ -65,7 +65,7 @@ case 'delete':
wp_delete_term( $tag_ID, $taxonomy);
$location = 'edit-tags.php';
$location = 'edit-tags.php?taxonomy=' . $taxonomy;
if ( $referer = wp_get_referer() ) {
if ( false !== strpos($referer, 'edit-tags.php') )
$location = $referer;
@ -88,7 +88,7 @@ case 'bulk-delete':
wp_delete_term( $tag_ID, $taxonomy);
}
$location = 'edit-tags.php';
$location = 'edit-tags.php?taxonomy=' . $taxonomy;
if ( $referer = wp_get_referer() ) {
if ( false !== strpos($referer, 'edit-tags.php') )
$location = $referer;
@ -120,7 +120,7 @@ case 'editedtag':
$ret = wp_update_term($tag_ID, $taxonomy, $_POST);
$location = 'edit-tags.php';
$location = 'edit-tags.php?taxonomy=' . $taxonomy;
if ( $referer = wp_get_original_referer() ) {
if ( false !== strpos($referer, 'edit-tags.php') )
$location = $referer;
@ -200,10 +200,13 @@ if ( empty($tags_per_page) || $tags_per_page < 1 )
$tags_per_page = apply_filters( 'edit_tags_per_page', $tags_per_page );
$tags_per_page = apply_filters( 'tagsperpage', $tags_per_page ); // Old filter
if ( !empty($_GET['s']) )
$total_terms = count( get_terms( $taxonomy, array( 'search' => trim(stripslashes($_GET['s'])), 'number' => 0, 'hide_empty' => 0 ) ) );
else
if ( !empty($_GET['s']) ) {
$searchterms = trim(stripslashes($_GET['s']));
$total_terms = count( get_terms( $taxonomy, array( 'search' => $searchterms, 'number' => 0, 'hide_empty' => 0 ) ) );
} else {
$searchterms = '';
$total_terms = wp_count_terms($taxonomy);
}
$page_links = paginate_links( array(
'base' => add_query_arg( 'pagenum', '%#%' ),
@ -248,8 +251,6 @@ if ( $page_links )
<tbody id="the-list" class="list:tag">
<?php
$searchterms = isset( $_GET['s'] ) ? trim( $_GET['s'] ) : '';
$count = tag_rows( $pagenum, $tags_per_page, $searchterms, $taxonomy );
?>
</tbody>
@ -312,6 +313,13 @@ else
<p><?php _e('The &#8220;slug&#8221; is the URL-friendly version of the name. It is usually all lowercase and contains only letters, numbers, and hyphens.'); ?></p>
</div>
<?php } ?>
<?php if ( is_taxonomy_hierarchical($taxonomy) ) { ?>
<div class="form-field">
<label for="category_parent"><?php _e('Category Parent') ?></label>
<?php wp_dropdown_categories(array('hide_empty' => 0, 'hide_if_empty' => false, 'taxonomy' => $taxonomy, 'name' => 'parent', 'orderby' => 'name', 'hierarchical' => true, 'show_option_none' => __('None'))); ?>
<p><?php _e('Categories, unlike tags, can have a hierarchy. You might have a Jazz category, and under that have children categories for Bebop and Big Band. Totally optional.'); ?></p>
</div>
<?php } ?>
<div class="form-field">
<label for="description"><?php _e('Description') ?></label>
<textarea name="description" id="description" rows="5" cols="40"></textarea>
@ -329,7 +337,7 @@ else
</div><!-- /col-container -->
</div><!-- /wrap -->
<?php inline_edit_term_row('edit-tags'); ?>
<?php inline_edit_term_row('edit-tags', $taxonomy); ?>
<?php
break;

View File

@ -73,7 +73,7 @@ function wp_create_categories($categories, $post_id = '') {
$cat_ids[] = $id;
}
if ($post_id)
if ( $post_id )
wp_set_post_categories($post_id, $cat_ids);
return $cat_ids;

View File

@ -205,15 +205,15 @@ function _cat_row( $category, $level, $name_override = false ) {
*
* Outputs the HTML for the hidden table rows used in Categories, Link Caregories and Tags quick edit.
*
* @param string $type "tag", "category" or "link-category"
* @param string $type "edit-tags", "categoried" or "edit-link-categories"
* @param string $taxonomy The taxonomy of the row.
* @return
*/
function inline_edit_term_row($type) {
function inline_edit_term_row($type, $taxonomy) {
if ( ! current_user_can( 'manage_categories' ) )
return;
$is_tag = $type == 'edit-tags';
$columns = get_column_headers($type);
$hidden = array_intersect( array_keys( $columns ), array_filter( get_hidden_columns($type) ) );
$col_count = count($columns) - count($hidden);
@ -236,14 +236,13 @@ function inline_edit_term_row($type) {
</label>
<?php } ?>
<?php if ( 'category' == $type ) : ?>
<?php if ( is_taxonomy_hierarchical($taxonomy) ) : ?>
<label>
<span class="title"><?php _e( 'Parent' ); ?></span>
<?php wp_dropdown_categories(array('hide_empty' => 0, 'name' => 'parent', 'orderby' => 'name', 'hierarchical' => 1, 'show_option_none' => __('None'))); ?>
<?php wp_dropdown_categories(array('hide_empty' => 0, 'name' => 'parent', 'orderby' => 'name', 'hierarchical' => 1, 'taxonomy' => $taxonomy, 'show_option_none' => __('None'))); ?>
</label>
<?php endif; // $type ?>
<?php endif; // $hierarchical ?>
</div></fieldset>
@ -254,14 +253,14 @@ function inline_edit_term_row($type) {
foreach ( $columns as $column_name => $column_display_name ) {
if ( isset( $core_columns[$column_name] ) )
continue;
do_action( 'quick_edit_custom_box', $column_name, $type );
do_action( 'quick_edit_custom_box', $column_name, $type, $taxonomy );
}
?>
<p class="inline-edit-save submit">
<a accesskey="c" href="#inline-edit" title="<?php _e('Cancel'); ?>" class="cancel button-secondary alignleft"><?php _e('Cancel'); ?></a>
<?php $update_text = ( $is_tag ) ? __( 'Update Tag' ) : __( 'Update Category' ); ?>
<?php $update_text = ( 'post_tag' == $taxonomy ) ? __( 'Update Tag' ) : __( 'Update Category' ); ?>
<a accesskey="s" href="#inline-edit" title="<?php echo esc_attr( $update_text ); ?>" class="save button-primary alignright"><?php echo $update_text; ?></a>
<img class="waiting" style="display:none;" src="images/wpspin_light.gif" alt="" />
<span class="error" style="display:none;"></span>
@ -671,12 +670,18 @@ function wp_link_category_checklist( $link_id = 0 ) {
* @param unknown_type $class
* @return unknown
*/
function _tag_row( $tag, $class = '', $taxonomy = 'post_tag' ) {
function _tag_row( $tag, $level, $class = '', $taxonomy = 'post_tag' ) {
$count = number_format_i18n( $tag->count );
$tagsel = ($taxonomy == 'post_tag' ? 'tag' : $taxonomy);
if ( 'post_tag' == $taxonomy )
$tagsel = 'tag';
elseif ( 'category' == $taxonomy )
$tagsel = 'category_name';
else
$tagsel = $taxonomy;
$count = ( $count > 0 ) ? "<a href='edit.php?$tagsel=$tag->slug'>$count</a>" : $count;
$name = apply_filters( 'term_name', $tag->name );
$pad = str_repeat( '&#8212; ', max(0, $level) );
$name = apply_filters( 'term_name', $pad . ' ' . $tag->name );
$qe_data = get_term($tag->term_id, $taxonomy, object, 'edit');
$edit_link = "edit-tags.php?action=edit&amp;taxonomy=$taxonomy&amp;tag_ID=$tag->term_id";
$out = '';
@ -694,15 +699,22 @@ function _tag_row( $tag, $class = '', $taxonomy = 'post_tag' ) {
switch ($column_name) {
case 'cb':
$out .= '<th scope="row" class="check-column"> <input type="checkbox" name="delete_tags[]" value="' . $tag->term_id . '" /></th>';
if ( $tag->term_id != get_option('default_' . $taxonomy) )
$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();
$actions['edit'] = '<a href="' . $edit_link . '">' . __('Edit') . '</a>';
$actions['inline hide-if-no-js'] = '<a href="#" class="editinline">' . __('Quick&nbsp;Edit') . '</a>';
$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>";
if ( $tag->term_id != get_option('default_' . $taxonomy) )
$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);
$action_count = count($actions);
$i = 0;
$out .= '<div class="row-actions">';
@ -714,7 +726,8 @@ function _tag_row( $tag, $class = '', $taxonomy = 'post_tag' ) {
$out .= '</div>';
$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></div></td>';
$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>";
@ -758,23 +771,85 @@ function tag_rows( $page = 1, $pagesize = 20, $searchterms = '', $taxonomy = 'po
$args = array('offset' => $start, 'number' => $pagesize, 'hide_empty' => 0);
if ( !empty( $searchterms ) ) {
if ( !empty( $searchterms ) )
$args['search'] = $searchterms;
}
$tags = get_terms( $taxonomy, $args );
// convert it to table rows
$out = '';
$count = 0;
foreach( $tags as $tag )
$out .= _tag_row( $tag, ++$count % 2 ? ' class="alternate"' : '', $taxonomy );
if ( is_taxonomy_hierarchical($taxonomy) ) {
// We'll need the full set of terms then.
$args['number'] = $args['offset'] = 0;
$terms = get_terms( $taxonomy, $args );
if ( !empty( $searchterms ) ) // Ignore children on searches.
$children = array();
else
$children = _get_term_hierarchy($taxonomy);
// Some funky recursion to get the job done is contained within, Skip it for non-hierarchical taxonomies for performance sake
$out .= _term_rows($taxonomy, $terms, $children, $page, $pagesize, $count);
} else {
$terms = get_terms( $taxonomy, $args );
foreach( $terms as $term )
$out .= _tag_row( $term, 0, ++$count % 2 ? ' class="alternate"' : '', $taxonomy );
}
// filter and send to screen
echo $out;
return $count;
}
function _term_rows( $taxonomy, $terms, &$children, $page = 1, $per_page = 20, &$count, $parent = 0, $level = 0 ) {
$start = ($page - 1) * $per_page;
$end = $start + $per_page;
$output = '';
foreach ( $terms as $key => $term ) {
if ( $count >= $end )
break;
if ( $term->parent != $parent && empty($_GET['s']) )
continue;
// If the page starts in a subtree, print the parents.
if ( $count == $start && $term->parent > 0 && empty($_GET['s']) ) {
$my_parents = $parent_ids = array();
$p = $term->parent;
while ( $p ) {
$my_parent = get_term( $p, $taxonomy );
$my_parents[] = $my_parent;
$p = $my_parent->parent;
if ( in_array($p, $parent_ids) ) // Prevent parent loops.
break;
$parent_ids[] = $p;
}
unset($parent_ids);
$num_parents = count($my_parents);
$count -= $num_parents; // Do not include parents in the per-page count, This is due to paging issues with unknown numbers of rows.
while ( $my_parent = array_pop($my_parents) ) {
$output .= "\t" . _tag_row( $my_parent, $level - $num_parents, ++$count % 2 ? ' class="alternate"' : '', $taxonomy );
$num_parents--;
}
}
if ( $count >= $start )
$output .= "\t" . _tag_row( $term, $level, ++$count % 2 ? ' class="alternate"' : '', $taxonomy );
else
++$count;
unset($terms[$key]);
if ( isset($children[$term->term_id]) )
$output .= _term_rows( $taxonomy, $terms, $children, $page, $per_page, $count, $term->term_id, $level + 1 );
}
return $output;
}
// define the columns to display, the syntax is 'internal name' => 'display name'
/**
* {@internal Missing Short Description}}

View File

@ -34,7 +34,11 @@ jQuery(document).ready(function($) {
$('#ajax-response').append(r);
} else {
$('#ajax-response').empty();
$('#the-list').prepend(r);
var parent = form.find('select#parent').val();
if ( parent > 0 && $('#tag-' + parent ).length > 0 ) // If the parent exists on this page, insert it below. Else insert it at the top of the list.
$('#the-list #tag-' + parent).after(r);
else
$('#the-list').prepend(r);
$('input[type="text"]:visible, textarea:visible', form).val('');
}
});
@ -42,4 +46,4 @@ jQuery(document).ready(function($) {
return false;
});
});
});

View File

@ -1 +1 @@
jQuery(document).ready(function(a){a(".delete-tag").live("click",function(g){var b=a(this),f=b.parents("tr"),c=true,d;if("undefined"!=showNotice){c=showNotice.warn()}if(c){d=b.attr("href").replace(/[^?]*\?/,"").replace(/action=delete/,"action=delete-tag");a.post(ajaxurl,d,function(e){if("1"==e){a("#ajax-response").empty();f.fadeOut("normal",function(){f.remove()})}else{if("-1"==e){a("#ajax-response").empty().append('<div class="error"><p>'+tagsl10n.noPerm+"</p></div>");f.children().css("backgroundColor","")}else{a("#ajax-response").empty().append('<div class="error"><p>'+tagsl10n.broken+"</p></div>");f.children().css("backgroundColor","")}}});f.children().css("backgroundColor","#f33")}return false});a("#submit").click(function(){var b=a(this).parents("form");if(!validateForm(b)){return false}a.post(ajaxurl,a("#addtag").serialize(),function(c){if(c.indexOf('<div class="error"')===0){a("#ajax-response").append(c)}else{a("#ajax-response").empty();a("#the-list").prepend(c);a('input[type="text"]:visible, textarea:visible',b).val("")}});return false})});
jQuery(document).ready(function($){$(".delete-tag").live("click",function(e){var t=$(this),tr=t.parents("tr"),r=true,data;if("undefined"!=showNotice){r=showNotice.warn()}if(r){data=t.attr("href").replace(/[^?]*\?/,"").replace(/action=delete/,"action=delete-tag");$.post(ajaxurl,data,function(r){if("1"==r){$("#ajax-response").empty();tr.fadeOut("normal",function(){tr.remove()})}else{if("-1"==r){$("#ajax-response").empty().append('<div class="error"><p>'+tagsl10n.noPerm+"</p></div>");tr.children().css("backgroundColor","")}else{$("#ajax-response").empty().append('<div class="error"><p>'+tagsl10n.broken+"</p></div>");tr.children().css("backgroundColor","")}}});tr.children().css("backgroundColor","#f33")}return false});$("#submit").click(function(){var form=$(this).parents("form");if(!validateForm(form)){return false}$.post(ajaxurl,$("#addtag").serialize(),function(r){if(r.indexOf('<div class="error"')===0){$("#ajax-response").append(r)}else{$("#ajax-response").empty();var parent=form.find("select#parent").val();if(parent>0&&$("#tag-"+parent).length>0){$("#the-list #tag-"+parent).after(r)}else{$("#the-list").prepend(r)}$('input[type="text"]:visible, textarea:visible',form).val("")}});return false})});

View File

@ -50,11 +50,7 @@ $menu[5] = array( __('Posts'), 'edit_posts', 'edit.php', '', 'open-if-no-js menu
if ( ! in_array('post', (array) $tax->object_type, true) )
continue;
if ( $tax->hierarchical )
$submenu['edit.php'][$i] = array( esc_attr($tax->label), 'manage_categories', 'categories.php?taxonomy=' . $tax->name );
else
$submenu['edit.php'][$i] = array( esc_attr($tax->label), 'manage_categories', 'edit-tags.php?taxonomy=' . $tax->name );
++$i;
$submenu['edit.php'][$i++] = array( esc_attr($tax->label), 'manage_categories', 'edit-tags.php?taxonomy=' . $tax->name );
}
$menu[10] = array( __('Media'), 'upload_files', 'upload.php', '', 'menu-top', 'menu-media', 'div' );
@ -90,11 +86,7 @@ foreach ( (array) get_post_types( array('_show' => true) ) as $ptype ) {
if ( ! in_array($ptype, (array) $tax->object_type, true) )
continue;
if ( $tax->hierarchical )
$submenu["edit.php?post_type=$ptype"][$i] = array( esc_attr($tax->label), 'manage_categories', "categories.php?taxonomy=$tax->name&amp;post_type=$ptype" );
else
$submenu["edit.php?post_type=$ptype"][$i] = array( esc_attr($tax->label), 'manage_categories', "edit-tags.php?taxonomy=$tax->name&amp;post_type=$ptype" );
++$i;
$submenu["edit.php?post_type=$ptype"][$i++] = array( esc_attr($tax->label), 'manage_categories', "edit-tags.php?taxonomy=$tax->name&amp;post_type=$ptype" );
}
}
unset($ptype, $ptype_obj);

View File

@ -786,13 +786,13 @@ function &get_terms($taxonomies, $args = '') {
// don't limit the query results when we have to descend the family tree
if ( ! empty($number) && ! $hierarchical && empty( $child_of ) && '' === $parent ) {
if( $offset )
if ( $offset )
$limit = 'LIMIT ' . $offset . ',' . $number;
else
$limit = 'LIMIT ' . $number;
} else
} else {
$limit = '';
}
if ( !empty($search) ) {
$search = like_escape($search);
@ -2446,4 +2446,5 @@ function is_object_in_taxonomy($object_type, $taxonomy) {
return false;
}
?>