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