Changeset 45934 for trunk/src/wp-admin/includes/ajax-actions.php
- Timestamp:
- 09/04/2019 01:10:57 AM (7 years ago)
- File:
-
- 1 edited
-
trunk/src/wp-admin/includes/ajax-actions.php (modified) (99 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/includes/ajax-actions.php
r45932 r45934 112 112 $taxonomy = sanitize_key( $_GET['tax'] ); 113 113 $tax = get_taxonomy( $taxonomy ); 114 114 115 if ( ! $tax ) { 115 116 wp_die( 0 ); … … 126 127 $s = str_replace( $comma, ',', $s ); 127 128 } 129 128 130 if ( false !== strpos( $s, ',' ) ) { 129 131 $s = explode( ',', $s ); 130 132 $s = $s[ count( $s ) - 1 ]; 131 133 } 134 132 135 $s = trim( $s ); 133 136 … … 194 197 wp_die( -1 ); 195 198 } 199 196 200 if ( false !== stripos( $_SERVER['HTTP_ACCEPT_ENCODING'], 'deflate' ) && function_exists( 'gzdeflate' ) && ! $force_gzip ) { 197 201 header( 'Content-Encoding: deflate' ); … … 203 207 wp_die( -1 ); 204 208 } 209 205 210 echo $out; 206 211 wp_die(); … … 231 236 232 237 include_once( ABSPATH . 'wp-admin/includes/image-edit.php' ); 238 233 239 if ( ! stream_preview_image( $post_id ) ) { 234 240 wp_die( -1 ); … … 296 302 ) 297 303 ) : array() ); 304 298 305 $exclude_blog_users = ( $type == 'add' ? get_users( 299 306 array( … … 482 489 $status = 'all'; 483 490 $parsed = parse_url( $url ); 491 484 492 if ( isset( $parsed['query'] ) ) { 485 493 parse_str( $parsed['query'], $query_vars ); 494 486 495 if ( ! empty( $query_vars['comment_status'] ) ) { 487 496 $status = $query_vars['comment_status']; 488 497 } 498 489 499 if ( ! empty( $query_vars['p'] ) ) { 490 500 $post_id = (int) $query_vars['p']; 491 501 } 502 492 503 if ( ! empty( $query_vars['comment_type'] ) ) { 493 504 $type = $query_vars['comment_type']; … … 551 562 $taxonomy = get_taxonomy( substr( $action, 4 ) ); 552 563 check_ajax_referer( $action, '_ajax_nonce-add-' . $taxonomy->name ); 564 553 565 if ( ! current_user_can( $taxonomy->cap->edit_terms ) ) { 554 566 wp_die( -1 ); 555 567 } 568 556 569 $names = explode( ',', $_POST[ 'new' . $taxonomy->name ] ); 557 570 $parent = isset( $_POST[ 'new' . $taxonomy->name . '_parent' ] ) ? (int) $_POST[ 'new' . $taxonomy->name . '_parent' ] : 0; 571 558 572 if ( 0 > $parent ) { 559 573 $parent = 0; 560 574 } 575 561 576 if ( $taxonomy->name == 'category' ) { 562 577 $post_category = isset( $_POST['post_category'] ) ? (array) $_POST['post_category'] : array(); … … 564 579 $post_category = ( isset( $_POST['tax_input'] ) && isset( $_POST['tax_input'][ $taxonomy->name ] ) ) ? (array) $_POST['tax_input'][ $taxonomy->name ] : array(); 565 580 } 581 566 582 $checked_categories = array_map( 'absint', (array) $post_category ); 567 583 $popular_ids = wp_popular_terms_checklist( $taxonomy->name, 0, 10, false ); … … 570 586 $cat_name = trim( $cat_name ); 571 587 $category_nicename = sanitize_title( $cat_name ); 588 572 589 if ( '' === $category_nicename ) { 573 590 continue; … … 575 592 576 593 $cat_id = wp_insert_term( $cat_name, $taxonomy->name, array( 'parent' => $parent ) ); 594 577 595 if ( ! $cat_id || is_wp_error( $cat_id ) ) { 578 596 continue; … … 580 598 $cat_id = $cat_id['term_id']; 581 599 } 600 582 601 $checked_categories[] = $cat_id; 602 583 603 if ( $parent ) { // Do these all at once in a second 584 604 continue; … … 671 691 672 692 $comment = get_comment( $id ); 693 673 694 if ( ! $comment ) { 674 695 wp_die( time() ); 675 696 } 697 676 698 if ( ! current_user_can( 'edit_comment', $comment->comment_ID ) ) { 677 699 wp_die( -1 ); … … 680 702 check_ajax_referer( "delete-comment_$id" ); 681 703 $status = wp_get_comment_status( $comment ); 682 683 $delta = -1; 704 $delta = -1; 705 684 706 if ( isset( $_POST['trash'] ) && 1 == $_POST['trash'] ) { 685 707 if ( 'trash' == $status ) { 686 708 wp_die( time() ); 687 709 } 710 688 711 $r = wp_trash_comment( $comment ); 689 712 } elseif ( isset( $_POST['untrash'] ) && 1 == $_POST['untrash'] ) { … … 691 714 wp_die( time() ); 692 715 } 716 693 717 $r = wp_untrash_comment( $comment ); 718 694 719 if ( ! isset( $_POST['comment_status'] ) || $_POST['comment_status'] != 'trash' ) { // undo trash, not in trash 695 720 $delta = 1; … … 699 724 wp_die( time() ); 700 725 } 726 701 727 $r = wp_spam_comment( $comment ); 702 728 } elseif ( isset( $_POST['unspam'] ) && 1 == $_POST['unspam'] ) { … … 704 730 wp_die( time() ); 705 731 } 732 706 733 $r = wp_unspam_comment( $comment ); 734 707 735 if ( ! isset( $_POST['comment_status'] ) || $_POST['comment_status'] != 'spam' ) { // undo spam, not in spam 708 736 $delta = 1; … … 717 745 _wp_ajax_delete_comment_response( $comment->comment_ID, $delta ); 718 746 } 747 719 748 wp_die( 0 ); 720 749 } … … 735 764 $taxonomy = ! empty( $_POST['taxonomy'] ) ? $_POST['taxonomy'] : 'post_tag'; 736 765 $tag = get_term( $tag_id, $taxonomy ); 766 737 767 if ( ! $tag || is_wp_error( $tag ) ) { 738 768 wp_die( 1 ); … … 755 785 756 786 check_ajax_referer( "delete-bookmark_$id" ); 787 757 788 if ( ! current_user_can( 'manage_links' ) ) { 758 789 wp_die( -1 ); … … 781 812 check_ajax_referer( "delete-meta_$id" ); 782 813 $meta = get_metadata_by_mid( 'post', $id ); 814 783 815 if ( ! $meta ) { 784 816 wp_die( 1 ); … … 788 820 wp_die( -1 ); 789 821 } 822 790 823 if ( delete_meta( $meta->meta_id ) ) { 791 824 wp_die( 1 ); 792 825 } 826 793 827 wp_die( 0 ); 794 828 } … … 805 839 $action = 'delete-post'; 806 840 } 841 807 842 $id = isset( $_POST['id'] ) ? (int) $_POST['id'] : 0; 808 809 843 check_ajax_referer( "{$action}_$id" ); 844 810 845 if ( ! current_user_can( 'delete_post', $id ) ) { 811 846 wp_die( -1 ); … … 834 869 $action = 'trash-post'; 835 870 } 871 836 872 $id = isset( $_POST['id'] ) ? (int) $_POST['id'] : 0; 837 838 873 check_ajax_referer( "{$action}_$id" ); 874 839 875 if ( ! current_user_can( 'delete_post', $id ) ) { 840 876 wp_die( -1 ); … … 869 905 $action = 'untrash-post'; 870 906 } 907 871 908 wp_ajax_trash_post( $action ); 872 909 } … … 883 920 $action = 'delete-page'; 884 921 } 922 885 923 $id = isset( $_POST['id'] ) ? (int) $_POST['id'] : 0; 886 887 924 check_ajax_referer( "{$action}_$id" ); 925 888 926 if ( ! current_user_can( 'delete_page', $id ) ) { 889 927 wp_die( -1 ); … … 907 945 */ 908 946 function wp_ajax_dim_comment() { 909 $id = isset( $_POST['id'] ) ? (int) $_POST['id'] : 0; 910 947 $id = isset( $_POST['id'] ) ? (int) $_POST['id'] : 0; 911 948 $comment = get_comment( $id ); 949 912 950 if ( ! $comment ) { 913 951 $x = new WP_Ajax_Response( … … 929 967 930 968 $current = wp_get_comment_status( $comment ); 969 931 970 if ( isset( $_POST['new'] ) && $_POST['new'] == $current ) { 932 971 wp_die( time() ); … … 934 973 935 974 check_ajax_referer( "approve-comment_$id" ); 975 936 976 if ( in_array( $current, array( 'unapproved', 'spam' ) ) ) { 937 977 $result = wp_set_comment_status( $comment, 'approve', true ); … … 966 1006 $action = 'add-link-category'; 967 1007 } 1008 968 1009 check_ajax_referer( $action ); 969 1010 $tax = get_taxonomy( 'link_category' ); 1011 970 1012 if ( ! current_user_can( $tax->cap->manage_terms ) ) { 971 1013 wp_die( -1 ); 972 1014 } 1015 973 1016 $names = explode( ',', wp_unslash( $_POST['newcat'] ) ); 974 1017 $x = new WP_Ajax_Response(); 1018 975 1019 foreach ( $names as $cat_name ) { 976 1020 $cat_name = trim( $cat_name ); 977 1021 $slug = sanitize_title( $cat_name ); 1022 978 1023 if ( '' === $slug ) { 979 1024 continue; … … 981 1026 982 1027 $cat_id = wp_insert_term( $cat_name, 'link_category' ); 1028 983 1029 if ( ! $cat_id || is_wp_error( $cat_id ) ) { 984 1030 continue; … … 986 1032 $cat_id = $cat_id['term_id']; 987 1033 } 1034 988 1035 $cat_name = esc_html( $cat_name ); 1036 989 1037 $x->add( 990 1038 array( … … 1023 1071 if ( ! $tag || is_wp_error( $tag ) ) { 1024 1072 $message = __( 'An error has occurred. Please reload the page and try again.' ); 1073 1025 1074 if ( is_wp_error( $tag ) && $tag->get_error_message() ) { 1026 1075 $message = $tag->get_error_message(); … … 1058 1107 ) 1059 1108 ); 1109 1060 1110 $x->add( 1061 1111 array( … … 1065 1115 ) 1066 1116 ); 1117 1067 1118 $x->send(); 1068 1119 } … … 1080 1131 $taxonomy = sanitize_key( $_POST['tax'] ); 1081 1132 $tax = get_taxonomy( $taxonomy ); 1133 1082 1134 if ( ! $tax ) { 1083 1135 wp_die( 0 ); … … 1124 1176 1125 1177 echo $return; 1126 1127 1178 wp_die(); 1128 1179 } … … 1139 1190 function wp_ajax_get_comments( $action ) { 1140 1191 global $post_id; 1192 1141 1193 if ( empty( $action ) ) { 1142 1194 $action = 'get-comments'; 1143 1195 } 1196 1144 1197 check_ajax_referer( $action ); 1145 1198 … … 1168 1221 1169 1222 $x = new WP_Ajax_Response(); 1223 1170 1224 ob_start(); 1171 1225 foreach ( $wp_list_table->items as $comment ) { … … 1184 1238 ) 1185 1239 ); 1240 1186 1241 $x->send(); 1187 1242 } … … 1203 1258 $comment_post_ID = (int) $_POST['comment_post_ID']; 1204 1259 $post = get_post( $comment_post_ID ); 1260 1205 1261 if ( ! $post ) { 1206 1262 wp_die( -1 ); … … 1218 1274 1219 1275 $user = wp_get_current_user(); 1276 1220 1277 if ( $user->exists() ) { 1221 1278 $user_ID = $user->ID; … … 1225 1282 $comment_content = trim( $_POST['content'] ); 1226 1283 $comment_type = isset( $_POST['comment_type'] ) ? trim( $_POST['comment_type'] ) : ''; 1284 1227 1285 if ( current_user_can( 'unfiltered_html' ) ) { 1228 1286 if ( ! isset( $_POST['_wp_unfiltered_html_comment'] ) ) { … … 1246 1304 1247 1305 $comment_parent = 0; 1306 1248 1307 if ( isset( $_POST['comment_ID'] ) ) { 1249 1308 $comment_parent = absint( $_POST['comment_ID'] ); 1250 1309 } 1310 1251 1311 $comment_auto_approved = false; 1252 1312 $commentdata = compact( 'comment_post_ID', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_content', 'comment_type', 'comment_parent', 'user_ID' ); … … 1274 1334 1275 1335 $comment = get_comment( $comment_id ); 1336 1276 1337 if ( ! $comment ) { 1277 1338 wp_die( 1 ); … … 1335 1396 1336 1397 $comment_id = (int) $_POST['comment_ID']; 1398 1337 1399 if ( ! current_user_can( 'edit_comment', $comment_id ) ) { 1338 1400 wp_die( -1 ); … … 1353 1415 1354 1416 $comment = get_comment( $comment_id ); 1417 1355 1418 if ( empty( $comment->comment_ID ) ) { 1356 1419 wp_die( -1 ); … … 1391 1454 // For performance reasons, we omit some object properties from the checklist. 1392 1455 // The following is a hacky way to restore them when adding non-custom items. 1393 1394 1456 $menu_items_data = array(); 1457 1395 1458 foreach ( (array) $_POST['menu-item'] as $menu_item_data ) { 1396 1459 if ( … … 1432 1495 foreach ( (array) $item_ids as $menu_item_id ) { 1433 1496 $menu_obj = get_post( $menu_item_id ); 1497 1434 1498 if ( ! empty( $menu_obj->ID ) ) { 1435 1499 $menu_obj = wp_setup_nav_menu_item( $menu_obj ); … … 1455 1519 'walker' => new $walker_class_name, 1456 1520 ); 1521 1457 1522 echo walk_nav_menu_tree( $menu_items, 0, (object) $args ); 1458 1523 } 1524 1459 1525 wp_die(); 1460 1526 } … … 1475 1541 wp_die( -1 ); 1476 1542 } 1543 1477 1544 if ( isset( $_POST['metakeyselect'] ) && '#NONE#' == $_POST['metakeyselect'] && empty( $_POST['metakeyinput'] ) ) { 1478 1545 wp_die( 1 ); … … 1491 1558 1492 1559 $pid = edit_post( $post_data ); 1560 1493 1561 if ( $pid ) { 1494 1562 if ( is_wp_error( $pid ) ) { … … 1519 1587 $pid = (int) $meta->post_id; 1520 1588 $meta = get_object_vars( $meta ); 1521 $x = new WP_Ajax_Response( 1589 1590 $x = new WP_Ajax_Response( 1522 1591 array( 1523 1592 'what' => 'meta', … … 1532 1601 $key = wp_unslash( $_POST['meta'][ $mid ]['key'] ); 1533 1602 $value = wp_unslash( $_POST['meta'][ $mid ]['value'] ); 1603 1534 1604 if ( '' == trim( $key ) ) { 1535 1605 wp_die( __( 'Please provide a custom field name.' ) ); 1536 1606 } 1607 1537 1608 $meta = get_metadata_by_mid( 'post', $mid ); 1609 1538 1610 if ( ! $meta ) { 1539 1611 wp_die( 0 ); // if meta doesn't exist 1540 1612 } 1541 if ( is_protected_meta( $meta->meta_key, 'post' ) || is_protected_meta( $key, 'post' ) || 1613 1614 if ( 1615 is_protected_meta( $meta->meta_key, 'post' ) || is_protected_meta( $key, 'post' ) || 1542 1616 ! current_user_can( 'edit_post_meta', $meta->post_id, $meta->meta_key ) || 1543 ! current_user_can( 'edit_post_meta', $meta->post_id, $key ) ) { 1617 ! current_user_can( 'edit_post_meta', $meta->post_id, $key ) 1618 ) { 1544 1619 wp_die( -1 ); 1545 1620 } 1621 1546 1622 if ( $meta->meta_value != $value || $meta->meta_key != $key ) { 1547 1623 $u = update_metadata_by_mid( 'post', $mid, $value, $key ); … … 1585 1661 1586 1662 check_ajax_referer( $action ); 1663 1587 1664 if ( ! current_user_can( 'create_users' ) ) { 1588 1665 wp_die( -1 ); 1589 1666 } 1667 1590 1668 $user_id = edit_user(); 1669 1591 1670 if ( ! $user_id ) { 1592 1671 wp_die( 0 ); … … 1600 1679 $x->send(); 1601 1680 } 1602 $user_object = get_userdata( $user_id ); 1603 1681 1682 $user_object = get_userdata( $user_id ); 1604 1683 $wp_list_table = _get_list_table( 'WP_Users_List_Table' ); 1605 1684 … … 1800 1879 wp_die( -1 ); 1801 1880 } 1881 1802 1882 check_ajax_referer( 'add-menu_item', 'menu-settings-column-nonce' ); 1883 1803 1884 if ( ! isset( $_POST['menu-locations'] ) ) { 1804 1885 wp_die( 0 ); 1805 1886 } 1887 1806 1888 set_theme_mod( 'nav_menu_locations', array_map( 'absint', $_POST['menu-locations'] ) ); 1807 1889 wp_die( 1 ); … … 1958 2040 $data['comment_status'] = 'closed'; 1959 2041 } 2042 1960 2043 if ( empty( $data['ping_status'] ) ) { 1961 2044 $data['ping_status'] = 'closed'; … … 2013 2096 $taxonomy = sanitize_key( $_POST['taxonomy'] ); 2014 2097 $tax = get_taxonomy( $taxonomy ); 2098 2015 2099 if ( ! $tax ) { 2016 2100 wp_die( 0 ); … … 2033 2117 2034 2118 $updated = wp_update_term( $id, $taxonomy, $_POST ); 2119 2035 2120 if ( $updated && ! is_wp_error( $updated ) ) { 2036 2121 $tag = get_term( $updated['term_id'], $taxonomy ); … … 2047 2132 wp_die( __( 'Item not updated.' ) ); 2048 2133 } 2134 2049 2135 $level = 0; 2050 2136 $parent = $tag->parent; 2137 2051 2138 while ( $parent > 0 ) { 2052 2139 $parent_tag = get_term( $parent, $taxonomy ); … … 2054 2141 $level++; 2055 2142 } 2143 2056 2144 $wp_list_table->single_row( $tag, $level ); 2057 2145 wp_die(); … … 2077 2165 'posts_per_page' => 50, 2078 2166 ); 2167 2079 2168 if ( '' !== $s ) { 2080 2169 $args['s'] = $s; … … 2142 2231 if ( is_array( $_POST['sidebars'] ) ) { 2143 2232 $sidebars = array(); 2233 2144 2234 foreach ( wp_unslash( $_POST['sidebars'] ) as $key => $val ) { 2145 2235 $sb = array(); 2236 2146 2237 if ( ! empty( $val ) ) { 2147 2238 $val = explode( ',', $val ); 2239 2148 2240 foreach ( $val as $k => $v ) { 2149 2241 if ( strpos( $v, 'widget-' ) === false ) { … … 2156 2248 $sidebars[ $key ] = $sb; 2157 2249 } 2250 2158 2251 wp_set_sidebars_widgets( $sidebars ); 2159 2252 wp_die( 1 ); … … 2319 2412 2320 2413 wp_die(); 2414 } 2415 2416 /** 2417 * Ajax handler for creating missing image sub-sizes for just uploaded images. 2418 * 2419 * @since 5.3.0 2420 */ 2421 function wp_ajax_media_create_image_subsizes() { 2422 check_ajax_referer( 'media-form' ); 2423 2424 if ( ! current_user_can( 'upload_files' ) ) { 2425 wp_send_json_error( array( 'message' => __( 'Sorry, you are not allowed to upload files.' ) ) ); 2426 } 2427 2428 // Using Plupload `file.id` as ref. 2429 if ( ! empty( $_POST['_wp_temp_image_ref'] ) ) { 2430 $image_ref = preg_replace( '/[^a-zA-Z0-9_]/', '', $_POST['_wp_temp_image_ref'] ); 2431 } else { 2432 wp_send_json_error( array( 'message' => __( 'Invalid file reference.' ) ) ); 2433 } 2434 2435 // Uploading of images usually fails while creating the sub-sizes, either because of a timeout or out of memory. 2436 // At this point the file has been uploaded and an attachment post created, but because of the PHP fatal error 2437 // the cliend doesn't know the attachment ID yet. 2438 // To be able to find the new attachment_id in these cases we temporarily store an upload reference sent by the client 2439 // in the original upload request. It is used to save a transient with the attachment_id as value. 2440 // That reference currently is Plupload's `file.id` but can be any sufficiently random alpha-numeric string. 2441 $attachment_id = get_transient( '_wp_temp_image_ref:' . $image_ref ); 2442 2443 if ( empty( $attachment_id ) ) { 2444 wp_send_json_error( array( 'message' => __( 'Upload failed. Please reload and try again.' ) ) ); 2445 } 2446 2447 if ( ! empty( $_POST['_wp_upload_failed_cleanup'] ) ) { 2448 // Upload failed. Cleanup. 2449 if ( wp_attachment_is_image( $attachment_id ) ) { 2450 $attachment = get_post( $attachment_id ); 2451 2452 // Posted at most 10 min ago. 2453 if ( $attachment && ( time() - strtotime( $attachment->post_date_gmt ) < 600 ) ) { 2454 /** 2455 * Runs when an image upload fails during the post-processing phase, 2456 * and the newly created attachment post is about to be deleted. 2457 * 2458 * @since 5.3.0 2459 * 2460 * @param int $attachment_id The attachment post ID. 2461 */ 2462 do_action( 'wp_upload_failed_cleanup', $attachment_id ); 2463 2464 wp_delete_attachment( $attachment_id, true ); 2465 wp_send_json_success(); 2466 } 2467 } 2468 } 2469 2470 // This can still be pretty slow and cause timeout or out of memory errors. 2471 // The js that handles the response would need to also handle HTTP 500 errors. 2472 wp_update_image_subsizes( $attachment_id ); 2473 2474 if ( ! empty( $_POST['_legasy_support'] ) ) { 2475 // The old (inline) uploader. Only needs the attachment_id. 2476 $response = array( 'id' => $attachment_id ); 2477 } else { 2478 // Media modal and Media Library grid view. 2479 $response = wp_prepare_attachment_for_js( $attachment_id ); 2480 2481 if ( ! $response ) { 2482 wp_send_json_error( array( 'message' => __( 'Upload failed.' ) ) ); 2483 } 2484 } 2485 2486 // At this point the image has been uploaded successfully. 2487 delete_transient( '_wp_temp_image_ref:' . $image_ref ); 2488 2489 wp_send_json_success( $response ); 2321 2490 } 2322 2491 … … 2350 2519 if ( isset( $_REQUEST['post_id'] ) ) { 2351 2520 $post_id = $_REQUEST['post_id']; 2521 2352 2522 if ( ! current_user_can( 'edit_post', $post_id ) ) { 2353 2523 echo wp_json_encode( … … 2376 2546 if ( isset( $post_data['context'] ) && in_array( $post_data['context'], array( 'custom-header', 'custom-background' ) ) ) { 2377 2547 $wp_filetype = wp_check_filetype_and_ext( $_FILES['async-upload']['tmp_name'], $_FILES['async-upload']['name'] ); 2548 2378 2549 if ( ! wp_match_mime_types( 'image', $wp_filetype['type'] ) ) { 2379 2550 echo wp_json_encode( … … 2439 2610 function wp_ajax_image_editor() { 2440 2611 $attachment_id = intval( $_POST['postid'] ); 2612 2441 2613 if ( empty( $attachment_id ) || ! current_user_can( 'edit_post', $attachment_id ) ) { 2442 2614 wp_die( -1 ); … … 2650 2822 wp_die( 0 ); 2651 2823 } 2824 2652 2825 $post_id = (int) $_POST['post_ID']; 2653 2826 $post = get_post( $post_id ); 2827 2654 2828 if ( ! $post ) { 2655 2829 wp_die( 0 ); … … 2663 2837 2664 2838 $active_lock = array_map( 'absint', explode( ':', $_POST['active_post_lock'] ) ); 2839 2665 2840 if ( $active_lock[1] != get_current_user_id() ) { 2666 2841 wp_die( 0 ); … … 2687 2862 function wp_ajax_dismiss_wp_pointer() { 2688 2863 $pointer = $_POST['pointer']; 2864 2689 2865 if ( $pointer != sanitize_key( $pointer ) ) { 2690 2866 wp_die( 0 ); … … 2767 2943 'monthnum', 2768 2944 ); 2945 2769 2946 foreach ( get_taxonomies_for_attachments( 'objects' ) as $t ) { 2770 2947 if ( $t->query_var && isset( $query[ $t->query_var ] ) ) { … … 2775 2952 $query = array_intersect_key( $query, array_flip( $keys ) ); 2776 2953 $query['post_type'] = 'attachment'; 2777 if ( MEDIA_TRASH 2778 && ! empty( $_REQUEST['query']['post_status'] ) 2779 && 'trash' === $_REQUEST['query']['post_status'] ) { 2954 2955 if ( 2956 MEDIA_TRASH && 2957 ! empty( $_REQUEST['query']['post_status'] ) && 2958 'trash' === $_REQUEST['query']['post_status'] 2959 ) { 2780 2960 $query['post_status'] = 'trash'; 2781 2961 } else { … … 2870 3050 $changed = false; 2871 3051 $id3data = wp_get_attachment_metadata( $post['ID'] ); 3052 2872 3053 if ( ! is_array( $id3data ) ) { 2873 3054 $changed = true; 2874 3055 $id3data = array(); 2875 3056 } 3057 2876 3058 foreach ( wp_get_attachment_id3_keys( (object) $post, 'edit' ) as $key => $label ) { 2877 3059 if ( isset( $changes[ $key ] ) ) { … … 2913 3095 wp_send_json_error(); 2914 3096 } 3097 2915 3098 $attachment_data = $_REQUEST['attachments'][ $id ]; 2916 3099 … … 2944 3127 2945 3128 $attachment = wp_prepare_attachment_for_js( $id ); 3129 2946 3130 if ( ! $attachment ) { 2947 3131 wp_send_json_error(); … … 2982 3166 continue; 2983 3167 } 3168 2984 3169 $attachment = get_post( $attachment_id ); 3170 2985 3171 if ( ! $attachment ) { 2986 3172 continue; 2987 3173 } 3174 2988 3175 if ( 'attachment' != $attachment->post_type ) { 2989 3176 continue; … … 3029 3216 // If this attachment is unattached, attach it. Primarily a back compat thing. 3030 3217 $insert_into_post_id = intval( $_POST['post_id'] ); 3218 3031 3219 if ( 0 == $post->post_parent && $insert_into_post_id ) { 3032 3220 wp_update_post( … … 3347 3535 3348 3536 $update_php = network_admin_url( 'update.php?action=install-theme' ); 3537 3349 3538 foreach ( $api->themes as &$theme ) { 3350 3539 $theme->install_url = add_query_arg( … … 3391 3580 $theme->version = wp_kses( $theme->version, $themes_allowedtags ); 3392 3581 $theme->description = wp_kses( $theme->description, $themes_allowedtags ); 3393 $theme->stars = wp_star_rating( 3582 3583 $theme->stars = wp_star_rating( 3394 3584 array( 3395 3585 'rating' => $theme->rating, … … 3399 3589 ) 3400 3590 ); 3591 3401 3592 $theme->num_ratings = number_format_i18n( $theme->num_ratings ); 3402 3593 $theme->preview_url = set_url_scheme( $theme->preview_url ); … … 3422 3613 wp_send_json_error(); 3423 3614 } 3615 3424 3616 $post_id = isset( $_POST['post_ID'] ) ? intval( $_POST['post_ID'] ) : 0; 3617 3425 3618 if ( $post_id > 0 ) { 3426 3619 $post = get_post( $post_id ); 3620 3427 3621 if ( ! $post || ! current_user_can( 'edit_post', $post->ID ) ) { 3428 3622 wp_send_json_error(); … … 3437 3631 preg_match( '/' . get_shortcode_regex() . '/s', $shortcode, $matches ); 3438 3632 $atts = shortcode_parse_atts( $matches[3] ); 3633 3439 3634 if ( ! empty( $matches[5] ) ) { 3440 3635 $url = $matches[5]; … … 3494 3689 $styles = ''; 3495 3690 $mce_styles = wpview_media_sandbox_styles(); 3691 3496 3692 foreach ( $mce_styles as $style ) { 3497 3693 $styles .= sprintf( '<link rel="stylesheet" href="%s"/>', $style ); … … 3501 3697 3502 3698 global $wp_scripts; 3699 3503 3700 if ( ! empty( $wp_scripts ) ) { 3504 3701 $wp_scripts->done = array(); 3505 3702 } 3703 3506 3704 ob_start(); 3507 3705 wp_print_scripts( array( 'mediaelement-vimeo', 'wp-mediaelement' ) ); … … 3618 3816 function wp_ajax_destroy_sessions() { 3619 3817 $user = get_userdata( (int) $_POST['user_id'] ); 3818 3620 3819 if ( $user ) { 3621 3820 if ( ! current_user_can( 'edit_user', $user->ID ) ) { … … 3657 3856 3658 3857 check_ajax_referer( 'image_editor-' . $attachment_id, 'nonce' ); 3858 3659 3859 if ( empty( $attachment_id ) || ! current_user_can( 'edit_post', $attachment_id ) ) { 3660 3860 wp_send_json_error(); … … 4047 4247 // Check filesystem credentials. `delete_theme()` will bail otherwise. 4048 4248 $url = wp_nonce_url( 'themes.php?action=delete&stylesheet=' . urlencode( $stylesheet ), 'delete-theme_' . $stylesheet ); 4249 4049 4250 ob_start(); 4050 4251 $credentials = request_filesystem_credentials( $url ); 4051 4252 ob_end_clean(); 4253 4052 4254 if ( false === $credentials || ! WP_Filesystem( $credentials ) ) { 4053 4255 global $wp_filesystem; … … 4340 4542 // Check filesystem credentials. `delete_plugins()` will bail otherwise. 4341 4543 $url = wp_nonce_url( 'plugins.php?action=delete-selected&verify-delete=1&checked[]=' . $plugin, 'bulk-plugins' ); 4544 4342 4545 ob_start(); 4343 4546 $credentials = request_filesystem_credentials( $url ); 4344 4547 ob_end_clean(); 4548 4345 4549 if ( false === $credentials || ! WP_Filesystem( $credentials ) ) { 4346 4550 global $wp_filesystem; … … 4482 4686 function wp_ajax_edit_theme_plugin_file() { 4483 4687 $r = wp_edit_theme_plugin_file( wp_unslash( $_POST ) ); // Validation of args is done in wp_edit_theme_plugin_file(). 4688 4484 4689 if ( is_wp_error( $r ) ) { 4485 4690 wp_send_json_error( … … 4511 4716 wp_send_json_error( __( 'Missing request ID.' ) ); 4512 4717 } 4718 4513 4719 $request_id = (int) $_POST['id']; 4514 4720 … … 4538 4744 wp_send_json_error( __( 'Missing exporter index.' ) ); 4539 4745 } 4746 4540 4747 $exporter_index = (int) $_POST['exporter']; 4541 4748 … … 4543 4750 wp_send_json_error( __( 'Missing page index.' ) ); 4544 4751 } 4752 4545 4753 $page = (int) $_POST['page']; 4546 4754 … … 4596 4804 ); 4597 4805 } 4806 4598 4807 if ( ! array_key_exists( 'exporter_friendly_name', $exporter ) ) { 4599 4808 wp_send_json_error( … … 4611 4820 ); 4612 4821 } 4822 4613 4823 if ( ! is_callable( $exporter['callback'] ) ) { 4614 4824 wp_send_json_error( … … 4631 4841 ); 4632 4842 } 4843 4633 4844 if ( ! array_key_exists( 'data', $response ) ) { 4634 4845 wp_send_json_error( … … 4637 4848 ); 4638 4849 } 4850 4639 4851 if ( ! is_array( $response['data'] ) ) { 4640 4852 wp_send_json_error( … … 4643 4855 ); 4644 4856 } 4857 4645 4858 if ( ! array_key_exists( 'done', $response ) ) { 4646 4859 wp_send_json_error(
Note: See TracChangeset
for help on using the changeset viewer.