Make WordPress Core


Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/3.0/wp-admin/admin-ajax.php

    r17354 r15470  
    1010 * Executing AJAX process.
    1111 *
    12  * @since 2.1.0
     12 * @since unknown
    1313 */
    1414define('DOING_AJAX', true);
    1515define('WP_ADMIN', true);
    1616
     17require_once('../wp-load.php');
     18
    1719if ( ! isset( $_REQUEST['action'] ) )
    1820    die('-1');
    19 
    20 require_once('../wp-load.php');
    2121
    2222require_once('./includes/admin.php');
     
    5151if ( isset( $_GET['action'] ) ) :
    5252switch ( $action = $_GET['action'] ) :
    53 case '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;
    7753case 'ajax-tag-search' :
    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 {
     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
    8662        die('0');
    87     }
    88 
    89     $s = stripslashes( $_GET['q'] );
    9063
    9164    if ( false !== strpos( $s, ',' ) ) {
     
    9770        die; // require 2 chars for matching
    9871
    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 ) . '%' ) );
     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 . "%')" );
    10073
    10174    echo join( $results, "\n" );
     
    190163 * @return die
    191164 */
    192 function _wp_ajax_delete_comment_response( $comment_id, $delta = -1 ) {
     165function _wp_ajax_delete_comment_response( $comment_id ) {
    193166    $total = (int) @$_POST['_total'];
    194167    $per_page = (int) @$_POST['_per_page'];
     
    199172        die( (string) time() );
    200173
    201     $total += $delta;
    202     if ( $total < 0 )
     174    if ( --$total < 0 ) // Take the total from POST and decrement it (since we just deleted one)
    203175        $total = 0;
    204176
    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 
     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);
    225192    $time = time(); // The time since the last comment count
    226193
     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    ) );
    227206    $x = new WP_Ajax_Response( array(
    228207        'what' => 'comment',
    229208        'id' => $comment_id, // here for completeness - not used
    230209        'supplemental' => array(
    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 ) ),
     210            'pageLinks' => $page_links,
    234211            'total' => $total,
    235212            'time' => $time
     
    328305    $status = wp_get_comment_status( $comment->comment_ID );
    329306
    330     $delta = -1;
    331307    if ( isset($_POST['trash']) && 1 == $_POST['trash'] ) {
    332308        if ( 'trash' == $status )
     
    337313            die( (string) time() );
    338314        $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;
    341315    } elseif ( isset($_POST['spam']) && 1 == $_POST['spam'] ) {
    342316        if ( 'spam' == $status )
     
    347321            die( (string) time() );
    348322        $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;
    351323    } elseif ( isset($_POST['delete']) && 1 == $_POST['delete'] ) {
    352324        $r = wp_delete_comment( $comment->comment_ID );
     
    356328
    357329    if ( $r ) // Decide if we need to send back '1' or a more complicated response including page links and comment counts
    358         _wp_ajax_delete_comment_response( $comment->comment_ID, $delta );
     330        _wp_ajax_delete_comment_response( $comment->comment_ID );
    359331    die( '0' );
    360332    break;
     
    377349    else
    378350        die('0');
     351    break;
     352case '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');
    379387    break;
    380388case 'delete-link' :
     
    508516    $x->send();
    509517    break;
    510 case 'add-tag' :
     518case '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;
     553case 'add-tag' : // From Manage->Tags
    511554    check_ajax_referer( 'add-tag' );
    512555    $post_type = !empty($_POST['post_type']) ? $_POST['post_type'] : 'post';
     
    514557    $tax = get_taxonomy($taxonomy);
    515558
     559    $x = new WP_Ajax_Response();
     560
    516561    if ( !current_user_can( $tax->cap->edit_terms ) )
    517562        die('-1');
    518563
    519     $x = new WP_Ajax_Response();
    520 
    521564    $tag = wp_insert_term($_POST['tag-name'], $taxonomy, $_POST );
    522565
    523566    if ( !$tag || is_wp_error($tag) || (!$tag = get_term( $tag['term_id'], $taxonomy )) ) {
    524         $message = __('An error has occurred. Please reload the page and try again.');
     567        $message = __('An error has occured. Please reload the page and try again.');
    525568        if ( is_wp_error($tag) && $tag->get_error_message() )
    526569            $message = $tag->get_error_message();
     
    533576    }
    534577
    535     set_current_screen( $_POST['screen'] );
    536 
    537     $wp_list_table = _get_list_table('WP_Terms_List_Table');
     578    if ( isset($_POST['screen']) )
     579        set_current_screen($_POST['screen']);
    538580
    539581    $level = 0;
     582    $tag_full_name = false;
     583    $tag_full_name = $tag->name;
    540584    if ( is_taxonomy_hierarchical($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();
     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);
    550595
    551596    $x->add( array(
     
    556601        'what' => 'term',
    557602        'position' => $level,
    558         'supplemental' => (array) $tag
     603        'supplemental' => get_term( $tag->term_id, $taxonomy, ARRAY_A ) //Refetch as $tag has been contaminated by the full name.
    559604        ) );
    560605    $x->send();
    561606    break;
    562607case 'get-tagcloud' :
    563     if ( isset( $_POST['tax'] ) ) {
    564         $taxonomy = sanitize_key( $_POST['tax'] );
     608    if ( !current_user_can( 'edit_posts' ) )
     609        die('-1');
     610
     611    if ( isset($_POST['tax']) )
     612        $taxonomy = sanitize_title($_POST['tax']);
     613    else
     614        die('0');
     615
     616    $tags = get_terms( $taxonomy, array( 'number' => 45, 'orderby' => 'count', 'order' => 'DESC' ) );
     617
     618    if ( empty( $tags ) ) {
    565619        $tax = get_taxonomy( $taxonomy );
    566         if ( ! $tax )
    567             die( '0' );
    568         if ( ! current_user_can( $tax->cap->assign_terms ) )
    569             die( '-1' );
    570     } else {
    571         die('0');
    572     }
    573 
    574     $tags = get_terms( $taxonomy, array( 'number' => 45, 'orderby' => 'count', 'order' => 'DESC' ) );
    575 
    576     if ( empty( $tags ) )
    577620        die( isset( $tax->no_tagcloud ) ? $tax->no_tagcloud : __('No tags found!') );
    578 
    579     if ( is_wp_error( $tags ) )
    580         die( $tags->get_error_message() );
     621    }
     622
     623    if ( is_wp_error($tags) )
     624        die($tags->get_error_message());
    581625
    582626    foreach ( $tags as $key => $tag ) {
     
    595639    exit;
    596640    break;
     641case 'add-comment' :
     642    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 )
     661        die('1');
     662    $x = new WP_Ajax_Response();
     663    foreach ( (array) $comments as $comment ) {
     664        get_comment( $comment );
     665        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;
    597677case 'get-comments' :
    598678    check_ajax_referer( $action );
    599679
    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() )
     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 )
    610690        die('1');
    611691
    612692    $comment_list_item = '';
    613693    $x = new WP_Ajax_Response();
    614     foreach ( $wp_list_table->items as $comment ) {
     694    foreach ( (array) $comments as $comment ) {
    615695        get_comment( $comment );
    616696        ob_start();
    617             $wp_list_table->single_row( $comment );
     697            _wp_comment_row( $comment->comment_ID, 'single', false, false );
    618698            $comment_list_item .= ob_get_contents();
    619699        ob_end_clean();
     
    627707case 'replyto-comment' :
    628708    check_ajax_referer( $action, '_ajax_nonce-replyto-comment' );
    629 
    630     set_current_screen( 'edit-comments' );
    631709
    632710    $comment_post_ID = (int) $_POST['comment_post_ID'];
     
    667745    if ( ! $comment ) die('1');
    668746
     747    $modes = array( 'single', 'detail', 'dashboard' );
     748    $mode = isset($_POST['mode']) && in_array( $_POST['mode'], $modes ) ? $_POST['mode'] : 'detail';
    669749    $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' );
    670754
    671755    $x = new WP_Ajax_Response();
    672756
    673757    ob_start();
    674         if ( 'dashboard' == $_REQUEST['mode'] ) {
     758        if ( 'dashboard' == $mode ) {
    675759            require_once( ABSPATH . 'wp-admin/includes/dashboard.php' );
    676             _wp_dashboard_recent_comments_row( $comment );
     760            _wp_dashboard_recent_comments_row( $comment, false );
    677761        } else {
    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 );
     762            _wp_comment_row( $comment->comment_ID, $mode, false, $checkbox );
    684763        }
    685764        $comment_list_item = ob_get_contents();
     
    698777    check_ajax_referer( 'replyto-comment', '_ajax_nonce-replyto-comment' );
    699778
    700     set_current_screen( 'edit-comments' );
    701 
    702779    $comment_post_ID = (int) $_POST['comment_post_ID'];
    703780    if ( ! current_user_can( 'edit_post', $comment_post_ID ) )
     
    711788    edit_comment();
    712789
     790    $mode = ( isset($_POST['mode']) && 'single' == $_POST['mode'] ) ? 'single' : 'detail';
    713791    $position = ( isset($_POST['position']) && (int) $_POST['position']) ? (int) $_POST['position'] : '-1';
    714     $comments_status = isset($_POST['comments_listing']) ? $_POST['comments_listing'] : '';
    715 
    716792    $checkbox = ( isset($_POST['checkbox']) && true == $_POST['checkbox'] ) ? 1 : 0;
    717     $wp_list_table = _get_list_table( $checkbox ? 'WP_Comments_List_Table' : 'WP_Post_Comments_List_Table' );
     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();
    718799
    719800    ob_start();
    720         $wp_list_table->single_row( get_comment( $comment_id ) );
     801        _wp_comment_row( $comment_id, $mode, $comments_listing, $checkbox );
    721802        $comment_list_item = ob_get_contents();
    722803    ob_end_clean();
    723 
    724     $x = new WP_Ajax_Response();
    725804
    726805    $x->add( array(
     
    741820    require_once ABSPATH . 'wp-admin/includes/nav-menu.php';
    742821
    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 );
     822    $item_ids = wp_save_nav_menu_items( 0, $_POST['menu-item'] );
    774823    if ( is_wp_error( $item_ids ) )
    775824        die('-1');
     
    881930    if ( !current_user_can('create_users') )
    882931        die('-1');
     932    require_once(ABSPATH . WPINC . '/registration.php');
    883933    if ( !$user_id = add_user() )
    884934        die('0');
     
    892942    $user_object = new WP_User( $user_id );
    893943
    894     $wp_list_table = _get_list_table('WP_Users_List_Table');
    895 
    896944    $x = new WP_Ajax_Response( array(
    897945        'what' => 'user',
    898946        'id' => $user_id,
    899         'data' => $wp_list_table->single_row( $user_object, '', $user_object->roles[0] ),
     947        'data' => user_row( $user_object, '', $user_object->roles[0] ),
    900948        'supplemental' => array(
    901949            'show-link' => sprintf(__( 'User <a href="#%s">%s</a> added' ), "user-$user_id", $user_object->user_login),
     
    10881136
    10891137    _wp_ajax_menu_quick_search( $_REQUEST );
    1090 
    1091     exit;
    1092     break;
    1093 case '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";
    11111138
    11121139    exit;
     
    11671194    }
    11681195
    1169     set_current_screen( $_POST['screen'] );
     1196    if ( isset($_POST['screen']) )
     1197        set_current_screen($_POST['screen']);
    11701198
    11711199    if ( $last = wp_check_post_lock( $post_ID ) ) {
     
    12041232    edit_post();
    12051233
    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'] ) ) );
     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    }
    12101244
    12111245    exit;
     
    12141248    check_ajax_referer( 'taxinlineeditnonce', '_inline_edit' );
    12151249
    1216     $taxonomy = sanitize_key( $_POST['taxonomy'] );
    1217     $tax = get_taxonomy( $taxonomy );
    1218     if ( ! $tax )
    1219         die( '0' );
     1250    $taxonomy = !empty($_POST['taxonomy']) ? $_POST['taxonomy'] : false;
     1251    if ( ! $taxonomy )
     1252        die( __('Cheatin&#8217; uh?') );
     1253    $tax = get_taxonomy($taxonomy);
    12201254
    12211255    if ( ! current_user_can( $tax->cap->edit_terms ) )
    1222         die( '-1' );
    1223 
    1224     set_current_screen( 'edit-' . $taxonomy );
    1225 
    1226     $wp_list_table = _get_list_table('WP_Terms_List_Table');
     1256        die( __('Cheatin&#8217; uh?') );
    12271257
    12281258    if ( ! isset($_POST['tax_ID']) || ! ( $id = (int) $_POST['tax_ID'] ) )
    12291259        die(-1);
    12301260
    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.') );
     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;
    12481296    }
    12491297
     
    12671315    $searchand = $search = '';
    12681316    foreach ( (array) $search_terms as $term ) {
    1269         $term = esc_sql( like_escape( $term ) );
     1317        $term = addslashes_gpc($term);
    12701318        $search .= "{$searchand}(($wpdb->posts.post_title LIKE '%{$term}%') OR ($wpdb->posts.post_content LIKE '%{$term}%'))";
    12711319        $searchand = ' AND ';
    12721320    }
    1273     $term = esc_sql( like_escape( $s ) );
     1321    $term = $wpdb->escape($s);
    12741322    if ( count($search_terms) > 1 && $search_terms[0] != $s )
    12751323        $search .= " OR ($wpdb->posts.post_title LIKE '%{$term}%') OR ($wpdb->posts.post_content LIKE '%{$term}%')";
     
    13211369
    13221370    break;
     1371case '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;
    13231384case 'widgets-order' :
    13241385    check_ajax_referer( 'save-sidebar-widgets', 'savewidgets' );
     
    13681429    $multi_number = !empty($_POST['multi_number']) ? (int) $_POST['multi_number'] : 0;
    13691430    $settings = isset($_POST['widget-' . $id_base]) && is_array($_POST['widget-' . $id_base]) ? $_POST['widget-' . $id_base] : false;
    1370     $error = '<p>' . __('An error has occurred. Please reload the page and try again.') . '</p>';
     1431    $error = '<p>' . __('An error has occured. Please reload the page and try again.') . '</p>';
    13711432
    13721433    $sidebars = wp_get_sidebars_widgets();
     
    14581519    }
    14591520
    1460     if ( set_post_thumbnail( $post_ID, $thumbnail_id ) )
    1461         die( _wp_post_thumbnail_html( $thumbnail_id ) );
     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    }
    14621528    die( '0' );
    1463     break;
    1464 case 'date_format' :
    1465     die( date_i18n( sanitize_option( 'date_format', $_POST['date'] ) ) );
    1466     break;
    1467 case 'time_format' :
    1468     die( date_i18n( sanitize_option( 'time_format', $_POST['date'] ) ) );
    14691529    break;
    14701530default :
Note: See TracChangeset for help on using the changeset viewer.