WordPress.org

Make WordPress Core


Ignore:
Timestamp:
02/13/2010 05:40:47 AM (10 years ago)
Author:
dd32
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/admin-ajax.php

    r13046 r13086  
    539539    $tax = get_taxonomy($taxonomy);
    540540
     541    $x = new WP_Ajax_Response();
     542
    541543    if ( !current_user_can( $tax->edit_cap ) )
    542544        die('-1');
     
    545547
    546548    if ( !$tag || is_wp_error($tag) || (!$tag = get_term( $tag['term_id'], $taxonomy )) ) {
    547         echo '<div class="error"><p>' . __('An error has occured. Please reload the page and try again.') . '</p></div>';
    548         exit;
     549        $message = __('An error has occured. Please reload the page and try again.');
     550        if ( is_wp_error($tag) && $tag->get_error_message() )
     551            $message = $tag->get_error_message();
     552
     553        $x->add( array(
     554            'what' => 'taxonomy',
     555            'data' => new WP_Error('error', $message )
     556        ) );
     557        $x->send();
    549558    }
    550559
    551560    $level = 0;
    552561    $tag_full_name = false;
     562    $tag_full_name = $tag->name;
    553563    if ( is_taxonomy_hierarchical($taxonomy) ) {
    554         $tag_full_name = $tag->name;
    555564        $_tag = $tag;
    556         while ( $_tag->parent ) {
     565        while ( $_tag->parent  ) {
    557566            $_tag = get_term( $_tag->parent, $taxonomy );
    558567            $tag_full_name = $_tag->name . ' &#8212; ' . $tag_full_name;
    559568            $level++;
    560569        }
    561         $tag_full_name = esc_attr($tag_full_name);
    562     }
    563     echo _tag_row( $tag, $level, $tag_full_name, $taxonomy );
    564     exit;
     570    }
     571    if ( is_taxonomy_hierarchical($taxonomy) )
     572        $noparents = _tag_row( $tag, $level, $taxonomy );
     573    $tag->name = $tag_full_name;
     574    $parents = _tag_row( $tag, 0, $taxonomy);
     575
     576    $x->add( array(
     577        'what' => 'taxonomy',
     578        'supplemental' => compact('parents', 'noparents')
     579        ) );
     580    $x->add( array(
     581        'what' => 'term',
     582        'position' => $level,
     583        'supplemental' => get_term( $tag->term_id, $taxonomy, ARRAY_A ) //Refetch as $tag has been contaminated by the full name.
     584        ) );
     585    $x->send();
    565586    break;
    566587case 'get-tagcloud' :
Note: See TracChangeset for help on using the changeset viewer.