Make WordPress Core


Ignore:
Timestamp:
07/01/2009 08:12:39 AM (17 years ago)
Author:
azaozz
Message:

Use new jQuery methods when adding, editing and deleting tags with AJAX, fix warning when deleting tags, see #10239

File:
1 edited

Legend:

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

    r11660 r11676  
    214214        break;
    215215case 'delete-tag' :
    216         check_ajax_referer( "delete-tag_$id" );
     216        $tag_id = (int) $_POST['tag_ID'];
     217        check_ajax_referer( "delete-tag_$tag_id" );
    217218        if ( !current_user_can( 'manage_categories' ) )
    218219                die('-1');
    219220
    220         if ( !empty($_POST['taxonomy']) )
    221                 $taxonomy = $_POST['taxonomy'];
    222         else
    223                 $taxonomy = 'post_tag';
    224 
    225         $tag = get_term( $id, $taxonomy );
     221        $taxonomy = !empty($_POST['taxonomy']) ? $_POST['taxonomy'] : 'post_tag';
     222
     223        $tag = get_term( $tag_id, $taxonomy );
    226224        if ( !$tag || is_wp_error( $tag ) )
    227225                die('1');
    228226
    229         if ( wp_delete_term($id, $taxonomy))
     227        if ( wp_delete_term($tag_id, $taxonomy))
    230228                die('1');
    231229        else
    … …  
    528526                die('-1');
    529527
    530         if ( '' === trim($_POST['name']) ) {
    531                 $x = new WP_Ajax_Response( array(
    532                         'what' => 'tag',
    533                         'id' => new WP_Error( 'name', __('You did not enter a tag name.') )
    534                 ) );
    535                 $x->send();
    536         }
    537 
    538         if ( !empty($_POST['taxonomy']) )
    539                 $taxonomy = $_POST['taxonomy'];
    540         else
    541                 $taxonomy = 'post_tag';
    542 
    543         $tag = wp_insert_term($_POST['name'], $taxonomy, $_POST );
    544 
    545         if ( is_wp_error($tag) ) {
    546                 $x = new WP_Ajax_Response( array(
    547                         'what' => 'tag',
    548                         'id' => $tag
    549                 ) );
    550                 $x->send();
    551         }
    552 
    553         if ( !$tag || (!$tag = get_term( $tag['term_id'], $taxonomy )) )
    554                 die('0');
    555 
    556         $tag_full_name = $tag->name;
    557         $tag_full_name = esc_attr($tag_full_name);
    558 
    559         $x = new WP_Ajax_Response( array(
    560                 'what' => 'tag',
    561                 'id' => $tag->term_id,
    562                 'position' => '-1',
    563                 'data' => _tag_row( $tag, '', $taxonomy ),
    564                 'supplemental' => array('name' => $tag_full_name, 'show-link' => sprintf(__( 'Tag <a href="#%s">%s</a> added' ), "tag-$tag->term_id", $tag_full_name))
    565         ) );
    566         $x->send();
     528        $taxonomy = !empty($_POST['taxonomy']) ? $_POST['taxonomy'] : 'post_tag';
     529        $tag = wp_insert_term($_POST['tag-name'], $taxonomy, $_POST );
     530
     531        if ( !$tag || is_wp_error($tag) || (!$tag = get_term( $tag['term_id'], $taxonomy )) ) {
     532                echo '<div class="error"><p>' . __('An error has occured. Please reload the page and try again.') . '</p></div>';
     533                exit;
     534        }
     535
     536        echo _tag_row( $tag, '', $taxonomy );
     537        exit;
    567538        break;
    568539case 'get-tagcloud' :
    … …  
    11491120                        break;
    11501121                case 'tag' :
    1151                         if ( !empty($_POST['taxonomy']) )
    1152                                 $taxonomy = $_POST['taxonomy'];
    1153                         else
    1154                                 $taxonomy = 'post_tag';
     1122                        $taxonomy = !empty($_POST['taxonomy']) ? $_POST['taxonomy'] : 'post_tag';
    11551123
    11561124                        $tag = get_term( $id, $taxonomy );
    … …  
    11631131                                        die( __('Tag not updated.') );
    11641132
    1165                                 echo _tag_row($tag);
     1133                                echo _tag_row($tag, '', $taxonomy);
    11661134                        } else {
    11671135                                die( __('Tag not updated.') );
Note: See TracChangeset for help on using the changeset viewer.