Make WordPress Core


Ignore:
File:
1 edited

Legend:

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

    r15470 r17354  
    1010 * Executing AJAX process.
    1111 *
    12  * @since unknown
     12 * @since 2.1.0
    1313 */
    1414define('DOING_AJAX', true);
    1515define('WP_ADMIN', true);
    1616
    17 require_once('../wp-load.php');
    18 
    1917if ( ! isset( $_REQUEST['action'] ) )
    2018    die('-1');
     19
     20require_once('../wp-load.php');
    2121
    2222require_once('./includes/admin.php');
     
    5151if ( isset( $_GET['action'] ) ) :
    5252switch ( $action = $_GET['action'] ) :
     53case 'fetch-list' :
     54
     55    $list_class = $_GET['list_args']['class'];
     56    check_ajax_referer( "fetch-list-$list_class", '_ajax_fetch_list_nonce' );
     57
     58    $current_screen = (object) $_GET['list_args']['screen'];
     59    //TODO fix this in a better way see #15336
     60    $current_screen->is_network = 'false' === $current_screen->is_network ? false : true;
     61    $current_screen->is_user = 'false' === $current_screen->is_user ? false : true;
     62
     63    define( 'WP_NETWORK_ADMIN', $current_screen->is_network );
     64    define( 'WP_USER_ADMIN', $current_screen->is_user );
     65
     66    $wp_list_table = _get_list_table( $list_class );
     67    if ( ! $wp_list_table )
     68        die( '0' );
     69
     70    if ( ! $wp_list_table->ajax_user_can() )
     71        die( '-1' );
     72
     73    $wp_list_table->ajax_response();
     74
     75    die( '0' );
     76    break;
    5377case 'ajax-tag-search' :
    54     if ( !current_user_can( 'edit_posts' ) )
    55         die('-1');
    56 
    57     $s = $_GET['q']; // is this slashed already?
    58 
    59     if ( isset($_GET['tax']) )
    60         $taxonomy = sanitize_title($_GET['tax']);
    61     else
     78    if ( isset( $_GET['tax'] ) ) {
     79        $taxonomy = sanitize_key( $_GET['tax'] );
     80        $tax = get_taxonomy( $taxonomy );
     81        if ( ! $tax )
     82            die( '0' );
     83        if ( ! current_user_can( $tax->cap->assign_terms ) )
     84            die( '-1' );
     85    } else {
    6286        die('0');
     87    }
     88
     89    $s = stripslashes( $_GET['q'] );
    6390
    6491    if ( false !== strpos( $s, ',' ) ) {
     
    7097        die; // require 2 chars for matching
    7198
    72     $results = $wpdb->get_col( "SELECT t.name FROM $wpdb->term_taxonomy AS tt INNER JOIN $wpdb->terms AS t ON tt.term_id = t.term_id WHERE tt.taxonomy = '$taxonomy' AND t.name LIKE ('%" . $s . "%')" );
     99    $results = $wpdb->get_col( $wpdb->prepare( "SELECT t.name FROM $wpdb->term_taxonomy AS tt INNER JOIN $wpdb->terms AS t ON tt.term_id = t.term_id WHERE tt.taxonomy = %s AND t.name LIKE (%s)", $taxonomy, '%' . like_escape( $s ) . '%' ) );
    73100
    74101    echo join( $results, "\n" );
     
    163190 * @return die
    164191 */
    165 function _wp_ajax_delete_comment_response( $comment_id ) {
     192function _wp_ajax_delete_comment_response( $comment_id, $delta = -1 ) {
    166193    $total = (int) @$_POST['_total'];
    167194    $per_page = (int) @$_POST['_per_page'];
     
    172199        die( (string) time() );
    173200
    174     if ( --$total < 0 ) // Take the total from POST and decrement it (since we just deleted one)
     201    $total += $delta;
     202    if ( $total < 0 )
    175203        $total = 0;
    176204
    177     if ( 0 != $total % $per_page && 1 != mt_rand( 1, $per_page ) ) // Only do the expensive stuff on a page-break, and about 1 other time per page
    178         die( (string) time() );
    179 
    180     $post_id = 0;
    181     $status = 'total_comments'; // What type of comment count are we looking for?
    182     $parsed = parse_url( $url );
    183     if ( isset( $parsed['query'] ) ) {
    184         parse_str( $parsed['query'], $query_vars );
    185         if ( !empty( $query_vars['comment_status'] ) )
    186             $status = $query_vars['comment_status'];
    187         if ( !empty( $query_vars['p'] ) )
    188             $post_id = (int) $query_vars['p'];
    189     }
    190 
    191     $comment_count = wp_count_comments($post_id);
     205    // Only do the expensive stuff on a page-break, and about 1 other time per page
     206    if ( 0 == $total % $per_page || 1 == mt_rand( 1, $per_page ) ) {
     207        $post_id = 0;
     208        $status = 'total_comments'; // What type of comment count are we looking for?
     209        $parsed = parse_url( $url );
     210        if ( isset( $parsed['query'] ) ) {
     211            parse_str( $parsed['query'], $query_vars );
     212            if ( !empty( $query_vars['comment_status'] ) )
     213                $status = $query_vars['comment_status'];
     214            if ( !empty( $query_vars['p'] ) )
     215                $post_id = (int) $query_vars['p'];
     216        }
     217
     218        $comment_count = wp_count_comments($post_id);
     219
     220        if ( isset( $comment_count->$status ) ) // We're looking for a known type of comment count
     221            $total = $comment_count->$status;
     222            // else use the decremented value from above
     223    }
     224
    192225    $time = time(); // The time since the last comment count
    193226
    194     if ( isset( $comment_count->$status ) ) // We're looking for a known type of comment count
    195         $total = $comment_count->$status;
    196     // else use the decremented value from above
    197 
    198     $page_links = paginate_links( array(
    199         'base' => add_query_arg( 'apage', '%#%', $url ),
    200         'format' => '',
    201         'prev_text' => __('&laquo;'),
    202         'next_text' => __('&raquo;'),
    203         'total' => ceil($total / $per_page),
    204         'current' => $page
    205     ) );
    206227    $x = new WP_Ajax_Response( array(
    207228        'what' => 'comment',
    208229        'id' => $comment_id, // here for completeness - not used
    209230        'supplemental' => array(
    210             'pageLinks' => $page_links,
     231            'total_items_i18n' => sprintf( _n( '1 item', '%s items', $total ), number_format_i18n( $total ) ),
     232            'total_pages' => ceil( $total / $per_page ),
     233            'total_pages_i18n' => number_format_i18n( ceil( $total / $per_page ) ),
    211234            'total' => $total,
    212235            'time' => $time
     
    305328    $status = wp_get_comment_status( $comment->comment_ID );
    306329
     330    $delta = -1;
    307331    if ( isset($_POST['trash']) && 1 == $_POST['trash'] ) {
    308332        if ( 'trash' == $status )
     
    313337            die( (string) time() );
    314338        $r = wp_untrash_comment( $comment->comment_ID );
     339        if ( ! isset( $_POST['comment_status'] ) || $_POST['comment_status'] != 'trash' ) // undo trash, not in trash
     340            $delta = 1;
    315341    } elseif ( isset($_POST['spam']) && 1 == $_POST['spam'] ) {
    316342        if ( 'spam' == $status )
     
    321347            die( (string) time() );
    322348        $r = wp_unspam_comment( $comment->comment_ID );
     349        if ( ! isset( $_POST['comment_status'] ) || $_POST['comment_status'] != 'spam' ) // undo spam, not in spam
     350            $delta = 1;
    323351    } elseif ( isset($_POST['delete']) && 1 == $_POST['delete'] ) {
    324352        $r = wp_delete_comment( $comment->comment_ID );
     
    328356
    329357    if ( $r ) // Decide if we need to send back '1' or a more complicated response including page links and comment counts
    330         _wp_ajax_delete_comment_response( $comment->comment_ID );
     358        _wp_ajax_delete_comment_response( $comment->comment_ID, $delta );
    331359    die( '0' );
    332360    break;
     
    349377    else
    350378        die('0');
    351     break;
    352 case 'delete-link-cat' :
    353     check_ajax_referer( "delete-link-category_$id" );
    354     if ( !current_user_can( 'manage_categories' ) )
    355         die('-1');
    356 
    357     $cat = get_term( $id, 'link_category' );
    358     if ( !$cat || is_wp_error( $cat ) )
    359         die('1');
    360 
    361     $cat_name = get_term_field('name', $id, 'link_category');
    362 
    363     $default = get_option('default_link_category');
    364 
    365     // Don't delete the default cats.
    366     if ( $id == $default ) {
    367         $x = new WP_AJAX_Response( array(
    368             'what' => 'link-cat',
    369             'id' => $id,
    370             'data' => new WP_Error( 'default-link-cat', sprintf(__("Can&#8217;t delete the <strong>%s</strong> category: this is the default one"), $cat_name) )
    371         ) );
    372         $x->send();
    373     }
    374 
    375     $r = wp_delete_term($id, 'link_category', array('default' => $default));
    376     if ( !$r )
    377         die('0');
    378     if ( is_wp_error($r) ) {
    379         $x = new WP_AJAX_Response( array(
    380             'what' => 'link-cat',
    381             'id' => $id,
    382             'data' => $r
    383         ) );
    384         $x->send();
    385     }
    386     die('1');
    387379    break;
    388380case 'delete-link' :
     
    516508    $x->send();
    517509    break;
    518 case 'add-link-cat' : // From Blogroll -> Categories
    519     check_ajax_referer( 'add-link-category' );
    520     if ( !current_user_can( 'manage_categories' ) )
    521         die('-1');
    522 
    523     if ( '' === trim($_POST['name']) ) {
    524         $x = new WP_Ajax_Response( array(
    525             'what' => 'link-cat',
    526             'id' => new WP_Error( 'name', __('You did not enter a category name.') )
    527         ) );
    528         $x->send();
    529     }
    530 
    531     $r = wp_insert_term($_POST['name'], 'link_category', $_POST );
    532     if ( is_wp_error( $r ) ) {
    533         $x = new WP_AJAX_Response( array(
    534             'what' => 'link-cat',
    535             'id' => $r
    536         ) );
    537         $x->send();
    538     }
    539 
    540     extract($r, EXTR_SKIP);
    541 
    542     if ( !$link_cat = link_cat_row( $term_id ) )
    543         die('0');
    544 
    545     $x = new WP_Ajax_Response( array(
    546         'what' => 'link-cat',
    547         'id' => $term_id,
    548         'position' => -1,
    549         'data' => $link_cat
    550     ) );
    551     $x->send();
    552     break;
    553 case 'add-tag' : // From Manage->Tags
     510case 'add-tag' :
    554511    check_ajax_referer( 'add-tag' );
    555512    $post_type = !empty($_POST['post_type']) ? $_POST['post_type'] : 'post';
     
    557514    $tax = get_taxonomy($taxonomy);
    558515
     516    if ( !current_user_can( $tax->cap->edit_terms ) )
     517        die('-1');
     518
    559519    $x = new WP_Ajax_Response();
    560520
    561     if ( !current_user_can( $tax->cap->edit_terms ) )
    562         die('-1');
    563 
    564521    $tag = wp_insert_term($_POST['tag-name'], $taxonomy, $_POST );
    565522
    566523    if ( !$tag || is_wp_error($tag) || (!$tag = get_term( $tag['term_id'], $taxonomy )) ) {
    567         $message = __('An error has occured. Please reload the page and try again.');
     524        $message = __('An error has occurred. Please reload the page and try again.');
    568525        if ( is_wp_error($tag) && $tag->get_error_message() )
    569526            $message = $tag->get_error_message();
     
    576533    }
    577534
    578     if ( isset($_POST['screen']) )
    579         set_current_screen($_POST['screen']);
     535    set_current_screen( $_POST['screen'] );
     536
     537    $wp_list_table = _get_list_table('WP_Terms_List_Table');
    580538
    581539    $level = 0;
    582     $tag_full_name = false;
    583     $tag_full_name = $tag->name;
    584540    if ( is_taxonomy_hierarchical($taxonomy) ) {
    585         $_tag = $tag;
    586         while ( $_tag->parent  ) {
    587             $_tag = get_term( $_tag->parent, $taxonomy );
    588             $tag_full_name = $_tag->name . ' &#8212; ' . $tag_full_name;
    589             $level++;
    590         }
    591         $noparents = _tag_row( $tag, $level, $taxonomy );
    592     }
    593     $tag->name = $tag_full_name;
    594     $parents = _tag_row( $tag, 0, $taxonomy);
     541        $level = count( get_ancestors( $tag->term_id, $taxonomy ) );
     542        ob_start();
     543        $wp_list_table->single_row( $tag, $level );
     544        $noparents = ob_get_clean();
     545    }
     546
     547    ob_start();
     548    $wp_list_table->single_row( $tag );
     549    $parents = ob_get_clean();
    595550
    596551    $x->add( array(
     
    601556        'what' => 'term',
    602557        'position' => $level,
    603         'supplemental' => get_term( $tag->term_id, $taxonomy, ARRAY_A ) //Refetch as $tag has been contaminated by the full name.
     558        'supplemental' => (array) $tag
    604559        ) );
    605560    $x->send();
    606561    break;
    607562case 'get-tagcloud' :
    608     if ( !current_user_can( 'edit_posts' ) )
    609         die('-1');
    610 
    611     if ( isset($_POST['tax']) )
    612         $taxonomy = sanitize_title($_POST['tax']);
    613     else
     563    if ( isset( $_POST['tax'] ) ) {
     564        $taxonomy = sanitize_key( $_POST['tax'] );
     565        $tax = get_taxonomy( $taxonomy );
     566        if ( ! $tax )
     567            die( '0' );
     568        if ( ! current_user_can( $tax->cap->assign_terms ) )
     569            die( '-1' );
     570    } else {
    614571        die('0');
     572    }
    615573
    616574    $tags = get_terms( $taxonomy, array( 'number' => 45, 'orderby' => 'count', 'order' => 'DESC' ) );
    617575
    618     if ( empty( $tags ) ) {
    619         $tax = get_taxonomy( $taxonomy );
     576    if ( empty( $tags ) )
    620577        die( isset( $tax->no_tagcloud ) ? $tax->no_tagcloud : __('No tags found!') );
    621     }
    622 
    623     if ( is_wp_error($tags) )
    624         die($tags->get_error_message());
     578
     579    if ( is_wp_error( $tags ) )
     580        die( $tags->get_error_message() );
    625581
    626582    foreach ( $tags as $key => $tag ) {
     
    639595    exit;
    640596    break;
    641 case 'add-comment' :
     597case 'get-comments' :
    642598    check_ajax_referer( $action );
    643     if ( !current_user_can( 'edit_posts' ) )
    644         die('-1');
    645     $search = isset($_POST['s']) ? $_POST['s'] : false;
    646     $status = isset($_POST['comment_status']) ? $_POST['comment_status'] : 'all';
    647     $per_page = isset($_POST['per_page']) ?  (int) $_POST['per_page'] + 8 : 28;
    648     $start = isset($_POST['page']) ? ( intval($_POST['page']) * $per_page ) -1 : $per_page - 1;
    649     if ( 1 > $start )
    650         $start = 27;
    651 
    652     $mode = isset($_POST['mode']) ? $_POST['mode'] : 'detail';
    653     $p = isset($_POST['p']) ? $_POST['p'] : 0;
    654     $comment_type = isset($_POST['comment_type']) ? $_POST['comment_type'] : '';
    655     list($comments, $total) = _wp_get_comment_list( $status, $search, $start, 1, $p, $comment_type );
    656 
    657     if ( get_option('show_avatars') )
    658         add_filter( 'comment_author', 'floated_admin_avatar' );
    659 
    660     if ( !$comments )
     599
     600    set_current_screen( 'edit-comments' );
     601
     602    $wp_list_table = _get_list_table('WP_Post_Comments_List_Table');
     603
     604    if ( !current_user_can( 'edit_post', $post_id ) )
     605        die('-1');
     606
     607    $wp_list_table->prepare_items();
     608
     609    if ( !$wp_list_table->has_items() )
    661610        die('1');
     611
     612    $comment_list_item = '';
    662613    $x = new WP_Ajax_Response();
    663     foreach ( (array) $comments as $comment ) {
     614    foreach ( $wp_list_table->items as $comment ) {
    664615        get_comment( $comment );
    665616        ob_start();
    666             _wp_comment_row( $comment->comment_ID, $mode, $status, true, true );
    667             $comment_list_item = ob_get_contents();
    668         ob_end_clean();
    669         $x->add( array(
    670             'what' => 'comment',
    671             'id' => $comment->comment_ID,
    672             'data' => $comment_list_item
    673         ) );
    674     }
    675     $x->send();
    676     break;
    677 case 'get-comments' :
    678     check_ajax_referer( $action );
    679 
    680     $post_ID = (int) $_POST['post_ID'];
    681     if ( !current_user_can( 'edit_post', $post_ID ) )
    682         die('-1');
    683 
    684     $start = isset($_POST['start']) ? intval($_POST['start']) : 0;
    685     $num = isset($_POST['num']) ? intval($_POST['num']) : 10;
    686 
    687     list($comments, $total) = _wp_get_comment_list( false, false, $start, $num, $post_ID );
    688 
    689     if ( !$comments )
    690         die('1');
    691 
    692     $comment_list_item = '';
    693     $x = new WP_Ajax_Response();
    694     foreach ( (array) $comments as $comment ) {
    695         get_comment( $comment );
    696         ob_start();
    697             _wp_comment_row( $comment->comment_ID, 'single', false, false );
     617            $wp_list_table->single_row( $comment );
    698618            $comment_list_item .= ob_get_contents();
    699619        ob_end_clean();
     
    707627case 'replyto-comment' :
    708628    check_ajax_referer( $action, '_ajax_nonce-replyto-comment' );
     629
     630    set_current_screen( 'edit-comments' );
    709631
    710632    $comment_post_ID = (int) $_POST['comment_post_ID'];
     
    745667    if ( ! $comment ) die('1');
    746668
    747     $modes = array( 'single', 'detail', 'dashboard' );
    748     $mode = isset($_POST['mode']) && in_array( $_POST['mode'], $modes ) ? $_POST['mode'] : 'detail';
    749669    $position = ( isset($_POST['position']) && (int) $_POST['position']) ? (int) $_POST['position'] : '-1';
    750     $checkbox = ( isset($_POST['checkbox']) && true == $_POST['checkbox'] ) ? 1 : 0;
    751 
    752     if ( get_option('show_avatars') && 'single' != $mode )
    753         add_filter( 'comment_author', 'floated_admin_avatar' );
    754670
    755671    $x = new WP_Ajax_Response();
    756672
    757673    ob_start();
    758         if ( 'dashboard' == $mode ) {
     674        if ( 'dashboard' == $_REQUEST['mode'] ) {
    759675            require_once( ABSPATH . 'wp-admin/includes/dashboard.php' );
    760             _wp_dashboard_recent_comments_row( $comment, false );
     676            _wp_dashboard_recent_comments_row( $comment );
    761677        } else {
    762             _wp_comment_row( $comment->comment_ID, $mode, false, $checkbox );
     678            if ( 'single' == $_REQUEST['mode'] ) {
     679                $wp_list_table = _get_list_table('WP_Post_Comments_List_Table');
     680            } else {
     681                $wp_list_table = _get_list_table('WP_Comments_List_Table');
     682            }
     683            $wp_list_table->single_row( $comment );
    763684        }
    764685        $comment_list_item = ob_get_contents();
     
    777698    check_ajax_referer( 'replyto-comment', '_ajax_nonce-replyto-comment' );
    778699
     700    set_current_screen( 'edit-comments' );
     701
    779702    $comment_post_ID = (int) $_POST['comment_post_ID'];
    780703    if ( ! current_user_can( 'edit_post', $comment_post_ID ) )
     
    788711    edit_comment();
    789712
    790     $mode = ( isset($_POST['mode']) && 'single' == $_POST['mode'] ) ? 'single' : 'detail';
    791713    $position = ( isset($_POST['position']) && (int) $_POST['position']) ? (int) $_POST['position'] : '-1';
     714    $comments_status = isset($_POST['comments_listing']) ? $_POST['comments_listing'] : '';
     715
    792716    $checkbox = ( isset($_POST['checkbox']) && true == $_POST['checkbox'] ) ? 1 : 0;
    793     $comments_listing = isset($_POST['comments_listing']) ? $_POST['comments_listing'] : '';
    794 
    795     if ( get_option('show_avatars') && 'single' != $mode )
    796         add_filter( 'comment_author', 'floated_admin_avatar' );
    797 
    798     $x = new WP_Ajax_Response();
     717    $wp_list_table = _get_list_table( $checkbox ? 'WP_Comments_List_Table' : 'WP_Post_Comments_List_Table' );
    799718
    800719    ob_start();
    801         _wp_comment_row( $comment_id, $mode, $comments_listing, $checkbox );
     720        $wp_list_table->single_row( get_comment( $comment_id ) );
    802721        $comment_list_item = ob_get_contents();
    803722    ob_end_clean();
     723
     724    $x = new WP_Ajax_Response();
    804725
    805726    $x->add( array(
     
    820741    require_once ABSPATH . 'wp-admin/includes/nav-menu.php';
    821742
    822     $item_ids = wp_save_nav_menu_items( 0, $_POST['menu-item'] );
     743    // For performance reasons, we omit some object properties from the checklist.
     744    // The following is a hacky way to restore them when adding non-custom items.
     745
     746    $menu_items_data = array();
     747    foreach ( (array) $_POST['menu-item'] as $menu_item_data ) {
     748        if (
     749            ! empty( $menu_item_data['menu-item-type'] ) &&
     750            'custom' != $menu_item_data['menu-item-type'] &&
     751            ! empty( $menu_item_data['menu-item-object-id'] )
     752        ) {
     753            switch( $menu_item_data['menu-item-type'] ) {
     754                case 'post_type' :
     755                    $_object = get_post( $menu_item_data['menu-item-object-id'] );
     756                break;
     757
     758                case 'taxonomy' :
     759                    $_object = get_term( $menu_item_data['menu-item-object-id'], $menu_item_data['menu-item-object'] );
     760                break;
     761            }
     762
     763            $_menu_items = array_map( 'wp_setup_nav_menu_item', array( $_object ) );
     764            $_menu_item = array_shift( $_menu_items );
     765
     766            // Restore the missing menu item properties
     767            $menu_item_data['menu-item-description'] = $_menu_item->description;
     768        }
     769
     770        $menu_items_data[] = $menu_item_data;
     771    }
     772
     773    $item_ids = wp_save_nav_menu_items( 0, $menu_items_data );
    823774    if ( is_wp_error( $item_ids ) )
    824775        die('-1');
     
    930881    if ( !current_user_can('create_users') )
    931882        die('-1');
    932     require_once(ABSPATH . WPINC . '/registration.php');
    933883    if ( !$user_id = add_user() )
    934884        die('0');
     
    942892    $user_object = new WP_User( $user_id );
    943893
     894    $wp_list_table = _get_list_table('WP_Users_List_Table');
     895
    944896    $x = new WP_Ajax_Response( array(
    945897        'what' => 'user',
    946898        'id' => $user_id,
    947         'data' => user_row( $user_object, '', $user_object->roles[0] ),
     899        'data' => $wp_list_table->single_row( $user_object, '', $user_object->roles[0] ),
    948900        'supplemental' => array(
    949901            'show-link' => sprintf(__( 'User <a href="#%s">%s</a> added' ), "user-$user_id", $user_object->user_login),
     
    11361088
    11371089    _wp_ajax_menu_quick_search( $_REQUEST );
     1090
     1091    exit;
     1092    break;
     1093case 'wp-link-ajax':
     1094    require_once ABSPATH . 'wp-admin/includes/internal-linking.php';
     1095
     1096    check_ajax_referer( 'internal-linking', '_ajax_linking_nonce' );
     1097
     1098    $args = array();
     1099
     1100    if ( isset( $_POST['search'] ) )
     1101        $args['s'] = stripslashes( $_POST['search'] );
     1102    $args['pagenum'] = ! empty( $_POST['page'] ) ? absint( $_POST['page'] ) : 1;
     1103
     1104    $results = wp_link_query( $args );
     1105
     1106    if ( ! isset( $results ) )
     1107        die( '0' );
     1108
     1109    echo json_encode( $results );
     1110    echo "\n";
    11381111
    11391112    exit;
     
    11941167    }
    11951168
    1196     if ( isset($_POST['screen']) )
    1197         set_current_screen($_POST['screen']);
     1169    set_current_screen( $_POST['screen'] );
    11981170
    11991171    if ( $last = wp_check_post_lock( $post_ID ) ) {
     
    12321204    edit_post();
    12331205
    1234     if ( in_array( $_POST['post_type'], get_post_types( array( 'show_ui' => true ) ) ) ) {
    1235         $post = array();
    1236         $post[] = get_post($_POST['post_ID']);
    1237         if ( is_post_type_hierarchical( $_POST['post_type'] ) ) {
    1238             page_rows( $post );
    1239         } else {
    1240             $mode = $_POST['post_view'];
    1241             post_rows( $post );
    1242         }
    1243     }
     1206    $wp_list_table = _get_list_table('WP_Posts_List_Table');
     1207
     1208    $mode = $_POST['post_view'];
     1209    $wp_list_table->display_rows( array( get_post( $_POST['post_ID'] ) ) );
    12441210
    12451211    exit;
     
    12481214    check_ajax_referer( 'taxinlineeditnonce', '_inline_edit' );
    12491215
    1250     $taxonomy = !empty($_POST['taxonomy']) ? $_POST['taxonomy'] : false;
    1251     if ( ! $taxonomy )
    1252         die( __('Cheatin&#8217; uh?') );
    1253     $tax = get_taxonomy($taxonomy);
     1216    $taxonomy = sanitize_key( $_POST['taxonomy'] );
     1217    $tax = get_taxonomy( $taxonomy );
     1218    if ( ! $tax )
     1219        die( '0' );
    12541220
    12551221    if ( ! current_user_can( $tax->cap->edit_terms ) )
    1256         die( __('Cheatin&#8217; uh?') );
     1222        die( '-1' );
     1223
     1224    set_current_screen( 'edit-' . $taxonomy );
     1225
     1226    $wp_list_table = _get_list_table('WP_Terms_List_Table');
    12571227
    12581228    if ( ! isset($_POST['tax_ID']) || ! ( $id = (int) $_POST['tax_ID'] ) )
    12591229        die(-1);
    12601230
    1261     switch ($_POST['tax_type']) {
    1262         case 'link-cat' :
    1263             $updated = wp_update_term($id, 'link_category', $_POST);
    1264 
    1265             if ( $updated && !is_wp_error($updated) )
    1266                 echo link_cat_row($updated['term_id']);
    1267             else
    1268                 die( __('Category not updated.') );
    1269 
    1270             break;
    1271         case 'tag' :
    1272             $taxonomy = !empty($_POST['taxonomy']) ? $_POST['taxonomy'] : 'post_tag';
    1273 
    1274             $tag = get_term( $id, $taxonomy );
    1275             $_POST['description'] = $tag->description;
    1276 
    1277             $updated = wp_update_term($id, $taxonomy, $_POST);
    1278             if ( $updated && !is_wp_error($updated) ) {
    1279                 $tag = get_term( $updated['term_id'], $taxonomy );
    1280                 if ( !$tag || is_wp_error( $tag ) ) {
    1281                     if ( is_wp_error($tag) && $tag->get_error_message() )
    1282                         die( $tag->get_error_message() );
    1283                     die( __('Item not updated.') );
    1284                 }
    1285 
    1286                 set_current_screen( 'edit-' . $taxonomy );
    1287 
    1288                 echo _tag_row($tag, 0, $taxonomy);
    1289             } else {
    1290                 if ( is_wp_error($updated) && $updated->get_error_message() )
    1291                     die( $updated->get_error_message() );
    1292                 die( __('Item not updated.') );
    1293             }
    1294 
    1295             break;
     1231    $tag = get_term( $id, $taxonomy );
     1232    $_POST['description'] = $tag->description;
     1233
     1234    $updated = wp_update_term($id, $taxonomy, $_POST);
     1235    if ( $updated && !is_wp_error($updated) ) {
     1236        $tag = get_term( $updated['term_id'], $taxonomy );
     1237        if ( !$tag || is_wp_error( $tag ) ) {
     1238            if ( is_wp_error($tag) && $tag->get_error_message() )
     1239                die( $tag->get_error_message() );
     1240            die( __('Item not updated.') );
     1241        }
     1242
     1243        echo $wp_list_table->single_row( $tag );
     1244    } else {
     1245        if ( is_wp_error($updated) && $updated->get_error_message() )
     1246            die( $updated->get_error_message() );
     1247        die( __('Item not updated.') );
    12961248    }
    12971249
     
    13151267    $searchand = $search = '';
    13161268    foreach ( (array) $search_terms as $term ) {
    1317         $term = addslashes_gpc($term);
     1269        $term = esc_sql( like_escape( $term ) );
    13181270        $search .= "{$searchand}(($wpdb->posts.post_title LIKE '%{$term}%') OR ($wpdb->posts.post_content LIKE '%{$term}%'))";
    13191271        $searchand = ' AND ';
    13201272    }
    1321     $term = $wpdb->escape($s);
     1273    $term = esc_sql( like_escape( $s ) );
    13221274    if ( count($search_terms) > 1 && $search_terms[0] != $s )
    13231275        $search .= " OR ($wpdb->posts.post_title LIKE '%{$term}%') OR ($wpdb->posts.post_content LIKE '%{$term}%')";
     
    13691321
    13701322    break;
    1371 case 'lj-importer' :
    1372     check_ajax_referer( 'lj-api-import' );
    1373     if ( !current_user_can( 'publish_posts' ) )
    1374         die('-1');
    1375     if ( empty( $_POST['step'] ) )
    1376         die( '-1' );
    1377     define('WP_IMPORTING', true);
    1378     include( ABSPATH . 'wp-admin/import/livejournal.php' );
    1379     $result = $lj_api_import->{ 'step' . ( (int) $_POST['step'] ) }();
    1380     if ( is_wp_error( $result ) )
    1381         echo $result->get_error_message();
    1382     die;
    1383     break;
    13841323case 'widgets-order' :
    13851324    check_ajax_referer( 'save-sidebar-widgets', 'savewidgets' );
     
    14291368    $multi_number = !empty($_POST['multi_number']) ? (int) $_POST['multi_number'] : 0;
    14301369    $settings = isset($_POST['widget-' . $id_base]) && is_array($_POST['widget-' . $id_base]) ? $_POST['widget-' . $id_base] : false;
    1431     $error = '<p>' . __('An error has occured. Please reload the page and try again.') . '</p>';
     1370    $error = '<p>' . __('An error has occurred. Please reload the page and try again.') . '</p>';
    14321371
    14331372    $sidebars = wp_get_sidebars_widgets();
     
    15191458    }
    15201459
    1521     if ( $thumbnail_id && get_post( $thumbnail_id ) ) {
    1522         $thumbnail_html = wp_get_attachment_image( $thumbnail_id, 'thumbnail' );
    1523         if ( !empty( $thumbnail_html ) ) {
    1524             update_post_meta( $post_ID, '_thumbnail_id', $thumbnail_id );
    1525             die( _wp_post_thumbnail_html( $thumbnail_id ) );
    1526         }
    1527     }
     1460    if ( set_post_thumbnail( $post_ID, $thumbnail_id ) )
     1461        die( _wp_post_thumbnail_html( $thumbnail_id ) );
    15281462    die( '0' );
     1463    break;
     1464case 'date_format' :
     1465    die( date_i18n( sanitize_option( 'date_format', $_POST['date'] ) ) );
     1466    break;
     1467case 'time_format' :
     1468    die( date_i18n( sanitize_option( 'time_format', $_POST['date'] ) ) );
    15291469    break;
    15301470default :
Note: See TracChangeset for help on using the changeset viewer.