Convert Terms page to use WP_Ajax_Response(), hierarchical terms will now appear under their parent OR have the parents prefixed, Terms will be removed from tag cloud/parent list upon deletion, Terms will be added to Parent list in correct order upon ajax creation, Errors on term creation flow back to UI, clean up _tag_row() alternate class handling, Show None text in Category dropdown if empty and show_if_empty = true. See #11838
git-svn-id: http://svn.automattic.com/wordpress/trunk@13086 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
87556345bf
commit
c9ea3a7686
|
@ -538,30 +538,51 @@ case 'add-tag' : // From Manage->Tags
|
|||
$taxonomy = !empty($_POST['taxonomy']) ? $_POST['taxonomy'] : 'post_tag';
|
||||
$tax = get_taxonomy($taxonomy);
|
||||
|
||||
$x = new WP_Ajax_Response();
|
||||
|
||||
if ( !current_user_can( $tax->edit_cap ) )
|
||||
die('-1');
|
||||
|
||||
$tag = wp_insert_term($_POST['tag-name'], $taxonomy, $_POST );
|
||||
|
||||
if ( !$tag || is_wp_error($tag) || (!$tag = get_term( $tag['term_id'], $taxonomy )) ) {
|
||||
echo '<div class="error"><p>' . __('An error has occured. Please reload the page and try again.') . '</p></div>';
|
||||
exit;
|
||||
$message = __('An error has occured. Please reload the page and try again.');
|
||||
if ( is_wp_error($tag) && $tag->get_error_message() )
|
||||
$message = $tag->get_error_message();
|
||||
|
||||
$x->add( array(
|
||||
'what' => 'taxonomy',
|
||||
'data' => new WP_Error('error', $message )
|
||||
) );
|
||||
$x->send();
|
||||
}
|
||||
|
||||
$level = 0;
|
||||
$tag_full_name = false;
|
||||
if ( is_taxonomy_hierarchical($taxonomy) ) {
|
||||
$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++;
|
||||
}
|
||||
$tag_full_name = esc_attr($tag_full_name);
|
||||
}
|
||||
echo _tag_row( $tag, $level, $tag_full_name, $taxonomy );
|
||||
exit;
|
||||
if ( is_taxonomy_hierarchical($taxonomy) )
|
||||
$noparents = _tag_row( $tag, $level, $taxonomy );
|
||||
$tag->name = $tag_full_name;
|
||||
$parents = _tag_row( $tag, 0, $taxonomy);
|
||||
|
||||
$x->add( array(
|
||||
'what' => 'taxonomy',
|
||||
'supplemental' => compact('parents', 'noparents')
|
||||
) );
|
||||
$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.
|
||||
) );
|
||||
$x->send();
|
||||
break;
|
||||
case 'get-tagcloud' :
|
||||
if ( !current_user_can( 'edit_posts' ) )
|
||||
|
|
|
@ -482,7 +482,10 @@ function wp_link_category_checklist( $link_id = 0 ) {
|
|||
* @param unknown_type $class
|
||||
* @return unknown
|
||||
*/
|
||||
function _tag_row( $tag, $level, $class = '', $taxonomy = 'post_tag' ) {
|
||||
function _tag_row( $tag, $level, $taxonomy = 'post_tag' ) {
|
||||
static $row_class = '';
|
||||
$row_class = ($row_class == '' ? ' class="alternate"' : '');
|
||||
|
||||
$count = number_format_i18n( $tag->count );
|
||||
if ( 'post_tag' == $taxonomy )
|
||||
$tagsel = 'tag';
|
||||
|
@ -496,12 +499,13 @@ function _tag_row( $tag, $level, $class = '', $taxonomy = 'post_tag' ) {
|
|||
$count = ( $count > 0 ) ? "<a href='edit.php?$tagsel=$tag->slug'>$count</a>" : $count;
|
||||
|
||||
$pad = str_repeat( '— ', max(0, $level) );
|
||||
$name = apply_filters( 'term_name', $pad . ' ' . $tag->name );
|
||||
$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&tag_ID=$tag->term_id";
|
||||
|
||||
$out = '';
|
||||
$out .= '<tr id="tag-' . $tag->term_id . '"' . $class . '>';
|
||||
$out .= '<tr id="tag-' . $tag->term_id . '"' . $row_class . '>';
|
||||
|
||||
|
||||
$columns = get_column_headers('edit-tags');
|
||||
$hidden = get_hidden_columns('edit-tags');
|
||||
|
@ -607,12 +611,12 @@ function tag_rows( $page = 1, $pagesize = 20, $searchterms = '', $taxonomy = 'po
|
|||
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
|
||||
// Some funky recursion to get the job done(Paging & parents mainly) 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 );
|
||||
$out .= _tag_row( $term, 0, $taxonomy );
|
||||
}
|
||||
|
||||
echo $out;
|
||||
|
@ -648,21 +652,20 @@ function _term_rows( $taxonomy, $terms, &$children, $page = 1, $per_page = 20, &
|
|||
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 );
|
||||
$output .= "\t" . _tag_row( $my_parent, $level - $num_parents, $taxonomy );
|
||||
$num_parents--;
|
||||
}
|
||||
}
|
||||
|
||||
if ( $count >= $start )
|
||||
$output .= "\t" . _tag_row( $term, $level, ++$count % 2 ? ' class="alternate"' : '', $taxonomy );
|
||||
else
|
||||
$output .= "\t" . _tag_row( $term, $level, $taxonomy );
|
||||
|
||||
++$count;
|
||||
|
||||
unset($terms[$key]);
|
||||
|
||||
if ( isset($children[$term->term_id]) )
|
||||
if ( isset($children[$term->term_id]) && empty($_GET['s']) )
|
||||
$output .= _term_rows( $taxonomy, $terms, $children, $page, $per_page, $count, $term->term_id, $level + 1 );
|
||||
}
|
||||
|
||||
|
|
|
@ -10,6 +10,9 @@ jQuery(document).ready(function($) {
|
|||
if ( '1' == r ) {
|
||||
$('#ajax-response').empty();
|
||||
tr.fadeOut('normal', function(){ tr.remove(); });
|
||||
// Remove the term from the parent box and tag cloud
|
||||
$('select#parent option[value=' + data.match(/tag_ID=(\d+)/)[1] + ']').remove();
|
||||
$('a.tag-link-' + data.match(/tag_ID=(\d+)/)[1]).remove();
|
||||
} else if ( '-1' == r ) {
|
||||
$('#ajax-response').empty().append('<div class="error"><p>' + tagsl10n.noPerm + '</p></div>');
|
||||
tr.children().css('backgroundColor', '');
|
||||
|
@ -30,17 +33,31 @@ jQuery(document).ready(function($) {
|
|||
return false;
|
||||
|
||||
$.post(ajaxurl, $('#addtag').serialize(), function(r){
|
||||
if ( r.indexOf('<div class="error"') === 0 ) {
|
||||
$('#ajax-response').append(r);
|
||||
} else {
|
||||
$('#ajax-response').empty();
|
||||
var res = wpAjax.parseAjaxResponse(r, 'ajax-response');
|
||||
if ( ! res )
|
||||
return;
|
||||
|
||||
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);
|
||||
$('#the-list #tag-' + parent).after( res.responses[0].supplemental['noparents'] ); // As the parent exists, Insert the version with - - - prefixed
|
||||
else
|
||||
$('#the-list').prepend(r);
|
||||
$('input[type="text"]:visible, textarea:visible', form).val('');
|
||||
$('#the-list').prepend( res.responses[0].supplemental['parents'] ); // As the parent is not visible, Insert the version with Parent - Child - ThisTerm
|
||||
|
||||
if ( form.find('select#parent') ) {
|
||||
// Parents field exists, Add new term to the list.
|
||||
var term = res.responses[1].supplemental;
|
||||
|
||||
// Create an indent for the Parent field
|
||||
var indent = '';
|
||||
for ( var i = 0; i < res.responses[1].position; i++ )
|
||||
indent += ' ';
|
||||
|
||||
form.find('select#parent option:selected').after('<option value="' + term['term_id'] + '">' + indent + term['name'] + '</option>');
|
||||
}
|
||||
|
||||
$('input[type="text"]:visible, textarea:visible', form).val('');
|
||||
});
|
||||
|
||||
return false;
|
||||
|
|
|
@ -1 +1 @@
|
|||
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})});
|
||||
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()});$("select#parent option[value="+data.match(/tag_ID=(\d+)/)[1]+"]").remove();$("a.tag-link-"+data.match(/tag_ID=(\d+)/)[1]).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){$("#ajax-response").empty();var res=wpAjax.parseAjaxResponse(r,"ajax-response");if(!res){return}var parent=form.find("select#parent").val();if(parent>0&&$("#tag-"+parent).length>0){$("#the-list #tag-"+parent).after(res.responses[0].supplemental.noparents)}else{$("#the-list").prepend(res.responses[0].supplemental.parents)}if(form.find("select#parent")){var term=res.responses[1].supplemental;var indent="";for(var i=0;i<res.responses[1].position;i++){indent+=" "}form.find("select#parent option:selected").after('<option value="'+term.term_id+'">'+indent+term.name+"</option>")}$('input[type="text"]:visible, textarea:visible',form).val("")});return false})});
|
|
@ -364,6 +364,12 @@ function wp_dropdown_categories( $args = '' ) {
|
|||
$output = "<select name='$name' id='$name' class='$class' $tab_index_attribute>\n";
|
||||
else
|
||||
$output = '';
|
||||
|
||||
if ( empty($categories) && ! $r['hide_if_empty'] && !empty($show_option_none) ) {
|
||||
$show_option_none = apply_filters( 'list_cats', $show_option_none );
|
||||
$output .= "\t<option value='-1' selected='selected'>$show_option_none</option>\n";
|
||||
}
|
||||
|
||||
if ( ! empty( $categories ) ) {
|
||||
|
||||
if ( $show_option_all ) {
|
||||
|
|
Loading…
Reference in New Issue