Changes from branches/3.0/wp-admin/admin-ajax.php at r15470 to trunk/wp-admin/admin-ajax.php at r17354
- File:
-
- 1 edited
-
trunk/wp-admin/admin-ajax.php (modified) (30 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/admin-ajax.php
r15470 r17354 10 10 * Executing AJAX process. 11 11 * 12 * @since unknown12 * @since 2.1.0 13 13 */ 14 14 define('DOING_AJAX', true); 15 15 define('WP_ADMIN', true); 16 16 17 require_once('../wp-load.php');18 19 17 if ( ! isset( $_REQUEST['action'] ) ) 20 18 die('-1'); 19 20 require_once('../wp-load.php'); 21 21 22 22 require_once('./includes/admin.php'); … … 51 51 if ( isset( $_GET['action'] ) ) : 52 52 switch ( $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; 53 77 case '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 else78 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 { 62 86 die('0'); 87 } 88 89 $s = stripslashes( $_GET['q'] ); 63 90 64 91 if ( false !== strpos( $s, ',' ) ) { … … 70 97 die; // require 2 chars for matching 71 98 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 ) . '%' ) ); 73 100 74 101 echo join( $results, "\n" ); … … 163 190 * @return die 164 191 */ 165 function _wp_ajax_delete_comment_response( $comment_id ) {192 function _wp_ajax_delete_comment_response( $comment_id, $delta = -1 ) { 166 193 $total = (int) @$_POST['_total']; 167 194 $per_page = (int) @$_POST['_per_page']; … … 172 199 die( (string) time() ); 173 200 174 if ( --$total < 0 ) // Take the total from POST and decrement it (since we just deleted one) 201 $total += $delta; 202 if ( $total < 0 ) 175 203 $total = 0; 176 204 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 192 225 $time = time(); // The time since the last comment count 193 226 194 if ( isset( $comment_count->$status ) ) // We're looking for a known type of comment count195 $total = $comment_count->$status;196 // else use the decremented value from above197 198 $page_links = paginate_links( array(199 'base' => add_query_arg( 'apage', '%#%', $url ),200 'format' => '',201 'prev_text' => __('«'),202 'next_text' => __('»'),203 'total' => ceil($total / $per_page),204 'current' => $page205 ) );206 227 $x = new WP_Ajax_Response( array( 207 228 'what' => 'comment', 208 229 'id' => $comment_id, // here for completeness - not used 209 230 '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 ) ), 211 234 'total' => $total, 212 235 'time' => $time … … 305 328 $status = wp_get_comment_status( $comment->comment_ID ); 306 329 330 $delta = -1; 307 331 if ( isset($_POST['trash']) && 1 == $_POST['trash'] ) { 308 332 if ( 'trash' == $status ) … … 313 337 die( (string) time() ); 314 338 $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; 315 341 } elseif ( isset($_POST['spam']) && 1 == $_POST['spam'] ) { 316 342 if ( 'spam' == $status ) … … 321 347 die( (string) time() ); 322 348 $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; 323 351 } elseif ( isset($_POST['delete']) && 1 == $_POST['delete'] ) { 324 352 $r = wp_delete_comment( $comment->comment_ID ); … … 328 356 329 357 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 ); 331 359 die( '0' ); 332 360 break; … … 349 377 else 350 378 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’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' => $r383 ) );384 $x->send();385 }386 die('1');387 379 break; 388 380 case 'delete-link' : … … 516 508 $x->send(); 517 509 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 510 case 'add-tag' : 554 511 check_ajax_referer( 'add-tag' ); 555 512 $post_type = !empty($_POST['post_type']) ? $_POST['post_type'] : 'post'; … … 557 514 $tax = get_taxonomy($taxonomy); 558 515 516 if ( !current_user_can( $tax->cap->edit_terms ) ) 517 die('-1'); 518 559 519 $x = new WP_Ajax_Response(); 560 520 561 if ( !current_user_can( $tax->cap->edit_terms ) )562 die('-1');563 564 521 $tag = wp_insert_term($_POST['tag-name'], $taxonomy, $_POST ); 565 522 566 523 if ( !$tag || is_wp_error($tag) || (!$tag = get_term( $tag['term_id'], $taxonomy )) ) { 567 $message = __('An error has occur ed. Please reload the page and try again.');524 $message = __('An error has occurred. Please reload the page and try again.'); 568 525 if ( is_wp_error($tag) && $tag->get_error_message() ) 569 526 $message = $tag->get_error_message(); … … 576 533 } 577 534 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'); 580 538 581 539 $level = 0; 582 $tag_full_name = false;583 $tag_full_name = $tag->name;584 540 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 . ' — ' . $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(); 595 550 596 551 $x->add( array( … … 601 556 'what' => 'term', 602 557 '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 604 559 ) ); 605 560 $x->send(); 606 561 break; 607 562 case '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 { 614 571 die('0'); 572 } 615 573 616 574 $tags = get_terms( $taxonomy, array( 'number' => 45, 'orderby' => 'count', 'order' => 'DESC' ) ); 617 575 618 if ( empty( $tags ) ) { 619 $tax = get_taxonomy( $taxonomy ); 576 if ( empty( $tags ) ) 620 577 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() ); 625 581 626 582 foreach ( $tags as $key => $tag ) { … … 639 595 exit; 640 596 break; 641 case ' add-comment' :597 case 'get-comments' : 642 598 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() ) 661 610 die('1'); 611 612 $comment_list_item = ''; 662 613 $x = new WP_Ajax_Response(); 663 foreach ( (array) $comments as $comment ) {614 foreach ( $wp_list_table->items as $comment ) { 664 615 get_comment( $comment ); 665 616 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 ); 698 618 $comment_list_item .= ob_get_contents(); 699 619 ob_end_clean(); … … 707 627 case 'replyto-comment' : 708 628 check_ajax_referer( $action, '_ajax_nonce-replyto-comment' ); 629 630 set_current_screen( 'edit-comments' ); 709 631 710 632 $comment_post_ID = (int) $_POST['comment_post_ID']; … … 745 667 if ( ! $comment ) die('1'); 746 668 747 $modes = array( 'single', 'detail', 'dashboard' );748 $mode = isset($_POST['mode']) && in_array( $_POST['mode'], $modes ) ? $_POST['mode'] : 'detail';749 669 $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' );754 670 755 671 $x = new WP_Ajax_Response(); 756 672 757 673 ob_start(); 758 if ( 'dashboard' == $ mode) {674 if ( 'dashboard' == $_REQUEST['mode'] ) { 759 675 require_once( ABSPATH . 'wp-admin/includes/dashboard.php' ); 760 _wp_dashboard_recent_comments_row( $comment , false);676 _wp_dashboard_recent_comments_row( $comment ); 761 677 } 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 ); 763 684 } 764 685 $comment_list_item = ob_get_contents(); … … 777 698 check_ajax_referer( 'replyto-comment', '_ajax_nonce-replyto-comment' ); 778 699 700 set_current_screen( 'edit-comments' ); 701 779 702 $comment_post_ID = (int) $_POST['comment_post_ID']; 780 703 if ( ! current_user_can( 'edit_post', $comment_post_ID ) ) … … 788 711 edit_comment(); 789 712 790 $mode = ( isset($_POST['mode']) && 'single' == $_POST['mode'] ) ? 'single' : 'detail';791 713 $position = ( isset($_POST['position']) && (int) $_POST['position']) ? (int) $_POST['position'] : '-1'; 714 $comments_status = isset($_POST['comments_listing']) ? $_POST['comments_listing'] : ''; 715 792 716 $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' ); 799 718 800 719 ob_start(); 801 _wp_comment_row( $comment_id, $mode, $comments_listing, $checkbox);720 $wp_list_table->single_row( get_comment( $comment_id ) ); 802 721 $comment_list_item = ob_get_contents(); 803 722 ob_end_clean(); 723 724 $x = new WP_Ajax_Response(); 804 725 805 726 $x->add( array( … … 820 741 require_once ABSPATH . 'wp-admin/includes/nav-menu.php'; 821 742 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 ); 823 774 if ( is_wp_error( $item_ids ) ) 824 775 die('-1'); … … 930 881 if ( !current_user_can('create_users') ) 931 882 die('-1'); 932 require_once(ABSPATH . WPINC . '/registration.php');933 883 if ( !$user_id = add_user() ) 934 884 die('0'); … … 942 892 $user_object = new WP_User( $user_id ); 943 893 894 $wp_list_table = _get_list_table('WP_Users_List_Table'); 895 944 896 $x = new WP_Ajax_Response( array( 945 897 'what' => 'user', 946 898 '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] ), 948 900 'supplemental' => array( 949 901 'show-link' => sprintf(__( 'User <a href="#%s">%s</a> added' ), "user-$user_id", $user_object->user_login), … … 1136 1088 1137 1089 _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"; 1138 1111 1139 1112 exit; … … 1194 1167 } 1195 1168 1196 if ( isset($_POST['screen']) ) 1197 set_current_screen($_POST['screen']); 1169 set_current_screen( $_POST['screen'] ); 1198 1170 1199 1171 if ( $last = wp_check_post_lock( $post_ID ) ) { … … 1232 1204 edit_post(); 1233 1205 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'] ) ) ); 1244 1210 1245 1211 exit; … … 1248 1214 check_ajax_referer( 'taxinlineeditnonce', '_inline_edit' ); 1249 1215 1250 $taxonomy = !empty($_POST['taxonomy']) ? $_POST['taxonomy'] : false;1251 if ( ! $taxonomy )1252 die( __('Cheatin’ uh?') );1253 $tax = get_taxonomy($taxonomy);1216 $taxonomy = sanitize_key( $_POST['taxonomy'] ); 1217 $tax = get_taxonomy( $taxonomy ); 1218 if ( ! $tax ) 1219 die( '0' ); 1254 1220 1255 1221 if ( ! current_user_can( $tax->cap->edit_terms ) ) 1256 die( __('Cheatin’ uh?') ); 1222 die( '-1' ); 1223 1224 set_current_screen( 'edit-' . $taxonomy ); 1225 1226 $wp_list_table = _get_list_table('WP_Terms_List_Table'); 1257 1227 1258 1228 if ( ! isset($_POST['tax_ID']) || ! ( $id = (int) $_POST['tax_ID'] ) ) 1259 1229 die(-1); 1260 1230 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.') ); 1296 1248 } 1297 1249 … … 1315 1267 $searchand = $search = ''; 1316 1268 foreach ( (array) $search_terms as $term ) { 1317 $term = addslashes_gpc($term);1269 $term = esc_sql( like_escape( $term ) ); 1318 1270 $search .= "{$searchand}(($wpdb->posts.post_title LIKE '%{$term}%') OR ($wpdb->posts.post_content LIKE '%{$term}%'))"; 1319 1271 $searchand = ' AND '; 1320 1272 } 1321 $term = $wpdb->escape($s);1273 $term = esc_sql( like_escape( $s ) ); 1322 1274 if ( count($search_terms) > 1 && $search_terms[0] != $s ) 1323 1275 $search .= " OR ($wpdb->posts.post_title LIKE '%{$term}%') OR ($wpdb->posts.post_content LIKE '%{$term}%')"; … … 1369 1321 1370 1322 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;1384 1323 case 'widgets-order' : 1385 1324 check_ajax_referer( 'save-sidebar-widgets', 'savewidgets' ); … … 1429 1368 $multi_number = !empty($_POST['multi_number']) ? (int) $_POST['multi_number'] : 0; 1430 1369 $settings = isset($_POST['widget-' . $id_base]) && is_array($_POST['widget-' . $id_base]) ? $_POST['widget-' . $id_base] : false; 1431 $error = '<p>' . __('An error has occur ed. Please reload the page and try again.') . '</p>';1370 $error = '<p>' . __('An error has occurred. Please reload the page and try again.') . '</p>'; 1432 1371 1433 1372 $sidebars = wp_get_sidebars_widgets(); … … 1519 1458 } 1520 1459 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 ) ); 1528 1462 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'] ) ) ); 1529 1469 break; 1530 1470 default :
Note: See TracChangeset
for help on using the changeset viewer.