Make WordPress Core


Ignore:
Timestamp:
01/25/2008 07:29:01 PM (18 years ago)
Author:
ryan
Message:

First cut at Manage->Tags. Props jhodgdon. see #5684

File:
1 edited

Legend:

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

    r6633 r6660  
    6060
    6161    if ( wp_delete_category( $id ) )
     62        die('1');
     63    else    die('0');
     64    break;
     65case 'delete-tag' :
     66    check_ajax_referer( "delete-tag_$id" );
     67    if ( !current_user_can( 'manage_categories' ) )
     68        die('-1');
     69
     70    if ( wp_delete_term($id, 'post_tag'))
    6271        die('1');
    6372    else    die('0');
     
    300309        'id' => $term_id,
    301310        'data' => $link_cat
     311    ) );
     312    $x->send();
     313    break;
     314case 'add-tag' : // From Manage->Tags
     315    check_ajax_referer( 'add-tag' );
     316    if ( !current_user_can( 'manage_categories' ) )
     317        die('-1');
     318
     319    if ( '' === trim($_POST['name']) ) {
     320        $x = new WP_Ajax_Response( array(
     321            'what' => 'tag',
     322            'id' => new WP_Error( 'name', __('You did not enter a tag name.') )
     323        ) );
     324        $x->send();
     325    }
     326
     327    $tag = wp_insert_term($_POST['name'], 'post_tag', $_POST );
     328
     329    if ( is_wp_error($tag) ) {
     330        $x = new WP_Ajax_Response( array(
     331            'what' => 'tag',
     332            'id' => $tag
     333        ) );
     334        $x->send();
     335    }
     336
     337    if ( !$tag || (!$tag = get_term( $tag['term_id'], 'post_tag' )) )
     338        die('0');
     339
     340    $tag_full_name = $tag->name;
     341    $tag_full_name = attribute_escape($tag_full_name);
     342
     343    $x = new WP_Ajax_Response( array(
     344        'what' => 'tag',
     345        'id' => $tag->term_id,
     346        'data' => _tag_row( $tag ),
     347        'supplemental' => array('name' => $tag_full_name, 'show-link' => sprintf(__( 'Tag <a href="#%s">%s</a> added' ), "tag-$tag->term_id", $tag_full_name))
    302348    ) );
    303349    $x->send();
Note: See TracChangeset for help on using the changeset viewer.