WordPress.org

Make WordPress Core


Ignore:
Timestamp:
09/04/2019 01:10:57 AM (7 weeks ago)
Author:
azaozz
Message:

Uploads: After an image is uploaded and PHP times out or runs out of memory during post-processing (the server response is HTTP 500 error), try to resize it three more times. Then, if all attempts fail, do a cleanup of any sub-sizes that may have been created and show an error message asking the user to scale the image and upload it again.

See #47872.

File:
1 edited

Legend:

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

    r45932 r45934  
    112112    $taxonomy = sanitize_key( $_GET['tax'] );
    113113    $tax      = get_taxonomy( $taxonomy );
     114
    114115    if ( ! $tax ) {
    115116        wp_die( 0 );
     
    126127        $s = str_replace( $comma, ',', $s );
    127128    }
     129
    128130    if ( false !== strpos( $s, ',' ) ) {
    129131        $s = explode( ',', $s );
    130132        $s = $s[ count( $s ) - 1 ];
    131133    }
     134
    132135    $s = trim( $s );
    133136
     
    194197                wp_die( -1 );
    195198            }
     199
    196200            if ( false !== stripos( $_SERVER['HTTP_ACCEPT_ENCODING'], 'deflate' ) && function_exists( 'gzdeflate' ) && ! $force_gzip ) {
    197201                header( 'Content-Encoding: deflate' );
     
    203207                wp_die( -1 );
    204208            }
     209
    205210            echo $out;
    206211            wp_die();
     
    231236
    232237    include_once( ABSPATH . 'wp-admin/includes/image-edit.php' );
     238
    233239    if ( ! stream_preview_image( $post_id ) ) {
    234240        wp_die( -1 );
     
    296302        )
    297303    ) : array() );
     304
    298305    $exclude_blog_users = ( $type == 'add' ? get_users(
    299306        array(
     
    482489        $status = 'all';
    483490        $parsed = parse_url( $url );
     491
    484492        if ( isset( $parsed['query'] ) ) {
    485493            parse_str( $parsed['query'], $query_vars );
     494
    486495            if ( ! empty( $query_vars['comment_status'] ) ) {
    487496                $status = $query_vars['comment_status'];
    488497            }
     498
    489499            if ( ! empty( $query_vars['p'] ) ) {
    490500                $post_id = (int) $query_vars['p'];
    491501            }
     502
    492503            if ( ! empty( $query_vars['comment_type'] ) ) {
    493504                $type = $query_vars['comment_type'];
     
    551562    $taxonomy = get_taxonomy( substr( $action, 4 ) );
    552563    check_ajax_referer( $action, '_ajax_nonce-add-' . $taxonomy->name );
     564
    553565    if ( ! current_user_can( $taxonomy->cap->edit_terms ) ) {
    554566        wp_die( -1 );
    555567    }
     568
    556569    $names  = explode( ',', $_POST[ 'new' . $taxonomy->name ] );
    557570    $parent = isset( $_POST[ 'new' . $taxonomy->name . '_parent' ] ) ? (int) $_POST[ 'new' . $taxonomy->name . '_parent' ] : 0;
     571
    558572    if ( 0 > $parent ) {
    559573        $parent = 0;
    560574    }
     575
    561576    if ( $taxonomy->name == 'category' ) {
    562577        $post_category = isset( $_POST['post_category'] ) ? (array) $_POST['post_category'] : array();
     
    564579        $post_category = ( isset( $_POST['tax_input'] ) && isset( $_POST['tax_input'][ $taxonomy->name ] ) ) ? (array) $_POST['tax_input'][ $taxonomy->name ] : array();
    565580    }
     581
    566582    $checked_categories = array_map( 'absint', (array) $post_category );
    567583    $popular_ids        = wp_popular_terms_checklist( $taxonomy->name, 0, 10, false );
     
    570586        $cat_name          = trim( $cat_name );
    571587        $category_nicename = sanitize_title( $cat_name );
     588
    572589        if ( '' === $category_nicename ) {
    573590            continue;
     
    575592
    576593        $cat_id = wp_insert_term( $cat_name, $taxonomy->name, array( 'parent' => $parent ) );
     594
    577595        if ( ! $cat_id || is_wp_error( $cat_id ) ) {
    578596            continue;
     
    580598            $cat_id = $cat_id['term_id'];
    581599        }
     600
    582601        $checked_categories[] = $cat_id;
     602
    583603        if ( $parent ) { // Do these all at once in a second
    584604            continue;
     
    671691
    672692    $comment = get_comment( $id );
     693
    673694    if ( ! $comment ) {
    674695        wp_die( time() );
    675696    }
     697
    676698    if ( ! current_user_can( 'edit_comment', $comment->comment_ID ) ) {
    677699        wp_die( -1 );
     
    680702    check_ajax_referer( "delete-comment_$id" );
    681703    $status = wp_get_comment_status( $comment );
    682 
    683     $delta = -1;
     704    $delta  = -1;
     705
    684706    if ( isset( $_POST['trash'] ) && 1 == $_POST['trash'] ) {
    685707        if ( 'trash' == $status ) {
    686708            wp_die( time() );
    687709        }
     710
    688711        $r = wp_trash_comment( $comment );
    689712    } elseif ( isset( $_POST['untrash'] ) && 1 == $_POST['untrash'] ) {
     
    691714            wp_die( time() );
    692715        }
     716
    693717        $r = wp_untrash_comment( $comment );
     718
    694719        if ( ! isset( $_POST['comment_status'] ) || $_POST['comment_status'] != 'trash' ) { // undo trash, not in trash
    695720            $delta = 1;
     
    699724            wp_die( time() );
    700725        }
     726
    701727        $r = wp_spam_comment( $comment );
    702728    } elseif ( isset( $_POST['unspam'] ) && 1 == $_POST['unspam'] ) {
     
    704730            wp_die( time() );
    705731        }
     732
    706733        $r = wp_unspam_comment( $comment );
     734
    707735        if ( ! isset( $_POST['comment_status'] ) || $_POST['comment_status'] != 'spam' ) { // undo spam, not in spam
    708736            $delta = 1;
     
    717745        _wp_ajax_delete_comment_response( $comment->comment_ID, $delta );
    718746    }
     747
    719748    wp_die( 0 );
    720749}
     
    735764    $taxonomy = ! empty( $_POST['taxonomy'] ) ? $_POST['taxonomy'] : 'post_tag';
    736765    $tag      = get_term( $tag_id, $taxonomy );
     766
    737767    if ( ! $tag || is_wp_error( $tag ) ) {
    738768        wp_die( 1 );
     
    755785
    756786    check_ajax_referer( "delete-bookmark_$id" );
     787
    757788    if ( ! current_user_can( 'manage_links' ) ) {
    758789        wp_die( -1 );
     
    781812    check_ajax_referer( "delete-meta_$id" );
    782813    $meta = get_metadata_by_mid( 'post', $id );
     814
    783815    if ( ! $meta ) {
    784816        wp_die( 1 );
     
    788820        wp_die( -1 );
    789821    }
     822
    790823    if ( delete_meta( $meta->meta_id ) ) {
    791824        wp_die( 1 );
    792825    }
     826
    793827    wp_die( 0 );
    794828}
     
    805839        $action = 'delete-post';
    806840    }
     841
    807842    $id = isset( $_POST['id'] ) ? (int) $_POST['id'] : 0;
    808 
    809843    check_ajax_referer( "{$action}_$id" );
     844
    810845    if ( ! current_user_can( 'delete_post', $id ) ) {
    811846        wp_die( -1 );
     
    834869        $action = 'trash-post';
    835870    }
     871
    836872    $id = isset( $_POST['id'] ) ? (int) $_POST['id'] : 0;
    837 
    838873    check_ajax_referer( "{$action}_$id" );
     874
    839875    if ( ! current_user_can( 'delete_post', $id ) ) {
    840876        wp_die( -1 );
     
    869905        $action = 'untrash-post';
    870906    }
     907
    871908    wp_ajax_trash_post( $action );
    872909}
     
    883920        $action = 'delete-page';
    884921    }
     922
    885923    $id = isset( $_POST['id'] ) ? (int) $_POST['id'] : 0;
    886 
    887924    check_ajax_referer( "{$action}_$id" );
     925
    888926    if ( ! current_user_can( 'delete_page', $id ) ) {
    889927        wp_die( -1 );
     
    907945 */
    908946function wp_ajax_dim_comment() {
    909     $id = isset( $_POST['id'] ) ? (int) $_POST['id'] : 0;
    910 
     947    $id      = isset( $_POST['id'] ) ? (int) $_POST['id'] : 0;
    911948    $comment = get_comment( $id );
     949
    912950    if ( ! $comment ) {
    913951        $x = new WP_Ajax_Response(
     
    929967
    930968    $current = wp_get_comment_status( $comment );
     969
    931970    if ( isset( $_POST['new'] ) && $_POST['new'] == $current ) {
    932971        wp_die( time() );
     
    934973
    935974    check_ajax_referer( "approve-comment_$id" );
     975
    936976    if ( in_array( $current, array( 'unapproved', 'spam' ) ) ) {
    937977        $result = wp_set_comment_status( $comment, 'approve', true );
     
    9661006        $action = 'add-link-category';
    9671007    }
     1008
    9681009    check_ajax_referer( $action );
    9691010    $tax = get_taxonomy( 'link_category' );
     1011
    9701012    if ( ! current_user_can( $tax->cap->manage_terms ) ) {
    9711013        wp_die( -1 );
    9721014    }
     1015
    9731016    $names = explode( ',', wp_unslash( $_POST['newcat'] ) );
    9741017    $x     = new WP_Ajax_Response();
     1018
    9751019    foreach ( $names as $cat_name ) {
    9761020        $cat_name = trim( $cat_name );
    9771021        $slug     = sanitize_title( $cat_name );
     1022
    9781023        if ( '' === $slug ) {
    9791024            continue;
     
    9811026
    9821027        $cat_id = wp_insert_term( $cat_name, 'link_category' );
     1028
    9831029        if ( ! $cat_id || is_wp_error( $cat_id ) ) {
    9841030            continue;
     
    9861032            $cat_id = $cat_id['term_id'];
    9871033        }
     1034
    9881035        $cat_name = esc_html( $cat_name );
     1036
    9891037        $x->add(
    9901038            array(
     
    10231071    if ( ! $tag || is_wp_error( $tag ) ) {
    10241072        $message = __( 'An error has occurred. Please reload the page and try again.' );
     1073
    10251074        if ( is_wp_error( $tag ) && $tag->get_error_message() ) {
    10261075            $message = $tag->get_error_message();
     
    10581107        )
    10591108    );
     1109
    10601110    $x->add(
    10611111        array(
     
    10651115        )
    10661116    );
     1117
    10671118    $x->send();
    10681119}
     
    10801131    $taxonomy = sanitize_key( $_POST['tax'] );
    10811132    $tax      = get_taxonomy( $taxonomy );
     1133
    10821134    if ( ! $tax ) {
    10831135        wp_die( 0 );
     
    11241176
    11251177    echo $return;
    1126 
    11271178    wp_die();
    11281179}
     
    11391190function wp_ajax_get_comments( $action ) {
    11401191    global $post_id;
     1192
    11411193    if ( empty( $action ) ) {
    11421194        $action = 'get-comments';
    11431195    }
     1196
    11441197    check_ajax_referer( $action );
    11451198
     
    11681221
    11691222    $x = new WP_Ajax_Response();
     1223
    11701224    ob_start();
    11711225    foreach ( $wp_list_table->items as $comment ) {
     
    11841238        )
    11851239    );
     1240
    11861241    $x->send();
    11871242}
     
    12031258    $comment_post_ID = (int) $_POST['comment_post_ID'];
    12041259    $post            = get_post( $comment_post_ID );
     1260
    12051261    if ( ! $post ) {
    12061262        wp_die( -1 );
     
    12181274
    12191275    $user = wp_get_current_user();
     1276
    12201277    if ( $user->exists() ) {
    12211278        $user_ID              = $user->ID;
     
    12251282        $comment_content      = trim( $_POST['content'] );
    12261283        $comment_type         = isset( $_POST['comment_type'] ) ? trim( $_POST['comment_type'] ) : '';
     1284
    12271285        if ( current_user_can( 'unfiltered_html' ) ) {
    12281286            if ( ! isset( $_POST['_wp_unfiltered_html_comment'] ) ) {
     
    12461304
    12471305    $comment_parent = 0;
     1306
    12481307    if ( isset( $_POST['comment_ID'] ) ) {
    12491308        $comment_parent = absint( $_POST['comment_ID'] );
    12501309    }
     1310
    12511311    $comment_auto_approved = false;
    12521312    $commentdata           = compact( 'comment_post_ID', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_content', 'comment_type', 'comment_parent', 'user_ID' );
     
    12741334
    12751335    $comment = get_comment( $comment_id );
     1336
    12761337    if ( ! $comment ) {
    12771338        wp_die( 1 );
     
    13351396
    13361397    $comment_id = (int) $_POST['comment_ID'];
     1398
    13371399    if ( ! current_user_can( 'edit_comment', $comment_id ) ) {
    13381400        wp_die( -1 );
     
    13531415
    13541416    $comment = get_comment( $comment_id );
     1417
    13551418    if ( empty( $comment->comment_ID ) ) {
    13561419        wp_die( -1 );
     
    13911454    // For performance reasons, we omit some object properties from the checklist.
    13921455    // The following is a hacky way to restore them when adding non-custom items.
    1393 
    13941456    $menu_items_data = array();
     1457
    13951458    foreach ( (array) $_POST['menu-item'] as $menu_item_data ) {
    13961459        if (
     
    14321495    foreach ( (array) $item_ids as $menu_item_id ) {
    14331496        $menu_obj = get_post( $menu_item_id );
     1497
    14341498        if ( ! empty( $menu_obj->ID ) ) {
    14351499            $menu_obj        = wp_setup_nav_menu_item( $menu_obj );
     
    14551519            'walker'      => new $walker_class_name,
    14561520        );
     1521
    14571522        echo walk_nav_menu_tree( $menu_items, 0, (object) $args );
    14581523    }
     1524
    14591525    wp_die();
    14601526}
     
    14751541            wp_die( -1 );
    14761542        }
     1543
    14771544        if ( isset( $_POST['metakeyselect'] ) && '#NONE#' == $_POST['metakeyselect'] && empty( $_POST['metakeyinput'] ) ) {
    14781545            wp_die( 1 );
     
    14911558
    14921559            $pid = edit_post( $post_data );
     1560
    14931561            if ( $pid ) {
    14941562                if ( is_wp_error( $pid ) ) {
     
    15191587        $pid  = (int) $meta->post_id;
    15201588        $meta = get_object_vars( $meta );
    1521         $x    = new WP_Ajax_Response(
     1589
     1590        $x = new WP_Ajax_Response(
    15221591            array(
    15231592                'what'         => 'meta',
     
    15321601        $key   = wp_unslash( $_POST['meta'][ $mid ]['key'] );
    15331602        $value = wp_unslash( $_POST['meta'][ $mid ]['value'] );
     1603
    15341604        if ( '' == trim( $key ) ) {
    15351605            wp_die( __( 'Please provide a custom field name.' ) );
    15361606        }
     1607
    15371608        $meta = get_metadata_by_mid( 'post', $mid );
     1609
    15381610        if ( ! $meta ) {
    15391611            wp_die( 0 ); // if meta doesn't exist
    15401612        }
    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' ) ||
    15421616            ! 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        ) {
    15441619            wp_die( -1 );
    15451620        }
     1621
    15461622        if ( $meta->meta_value != $value || $meta->meta_key != $key ) {
    15471623            $u = update_metadata_by_mid( 'post', $mid, $value, $key );
     
    15851661
    15861662    check_ajax_referer( $action );
     1663
    15871664    if ( ! current_user_can( 'create_users' ) ) {
    15881665        wp_die( -1 );
    15891666    }
     1667
    15901668    $user_id = edit_user();
     1669
    15911670    if ( ! $user_id ) {
    15921671        wp_die( 0 );
     
    16001679        $x->send();
    16011680    }
    1602     $user_object = get_userdata( $user_id );
    1603 
     1681
     1682    $user_object   = get_userdata( $user_id );
    16041683    $wp_list_table = _get_list_table( 'WP_Users_List_Table' );
    16051684
     
    18001879        wp_die( -1 );
    18011880    }
     1881
    18021882    check_ajax_referer( 'add-menu_item', 'menu-settings-column-nonce' );
     1883
    18031884    if ( ! isset( $_POST['menu-locations'] ) ) {
    18041885        wp_die( 0 );
    18051886    }
     1887
    18061888    set_theme_mod( 'nav_menu_locations', array_map( 'absint', $_POST['menu-locations'] ) );
    18071889    wp_die( 1 );
     
    19582040        $data['comment_status'] = 'closed';
    19592041    }
     2042
    19602043    if ( empty( $data['ping_status'] ) ) {
    19612044        $data['ping_status'] = 'closed';
     
    20132096    $taxonomy = sanitize_key( $_POST['taxonomy'] );
    20142097    $tax      = get_taxonomy( $taxonomy );
     2098
    20152099    if ( ! $tax ) {
    20162100        wp_die( 0 );
     
    20332117
    20342118    $updated = wp_update_term( $id, $taxonomy, $_POST );
     2119
    20352120    if ( $updated && ! is_wp_error( $updated ) ) {
    20362121        $tag = get_term( $updated['term_id'], $taxonomy );
     
    20472132        wp_die( __( 'Item not updated.' ) );
    20482133    }
     2134
    20492135    $level  = 0;
    20502136    $parent = $tag->parent;
     2137
    20512138    while ( $parent > 0 ) {
    20522139        $parent_tag = get_term( $parent, $taxonomy );
     
    20542141        $level++;
    20552142    }
     2143
    20562144    $wp_list_table->single_row( $tag, $level );
    20572145    wp_die();
     
    20772165        'posts_per_page' => 50,
    20782166    );
     2167
    20792168    if ( '' !== $s ) {
    20802169        $args['s'] = $s;
     
    21422231    if ( is_array( $_POST['sidebars'] ) ) {
    21432232        $sidebars = array();
     2233
    21442234        foreach ( wp_unslash( $_POST['sidebars'] ) as $key => $val ) {
    21452235            $sb = array();
     2236
    21462237            if ( ! empty( $val ) ) {
    21472238                $val = explode( ',', $val );
     2239
    21482240                foreach ( $val as $k => $v ) {
    21492241                    if ( strpos( $v, 'widget-' ) === false ) {
     
    21562248            $sidebars[ $key ] = $sb;
    21572249        }
     2250
    21582251        wp_set_sidebars_widgets( $sidebars );
    21592252        wp_die( 1 );
     
    23192412
    23202413    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 */
     2421function 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 );
    23212490}
    23222491
     
    23502519    if ( isset( $_REQUEST['post_id'] ) ) {
    23512520        $post_id = $_REQUEST['post_id'];
     2521
    23522522        if ( ! current_user_can( 'edit_post', $post_id ) ) {
    23532523            echo wp_json_encode(
     
    23762546    if ( isset( $post_data['context'] ) && in_array( $post_data['context'], array( 'custom-header', 'custom-background' ) ) ) {
    23772547        $wp_filetype = wp_check_filetype_and_ext( $_FILES['async-upload']['tmp_name'], $_FILES['async-upload']['name'] );
     2548
    23782549        if ( ! wp_match_mime_types( 'image', $wp_filetype['type'] ) ) {
    23792550            echo wp_json_encode(
     
    24392610function wp_ajax_image_editor() {
    24402611    $attachment_id = intval( $_POST['postid'] );
     2612
    24412613    if ( empty( $attachment_id ) || ! current_user_can( 'edit_post', $attachment_id ) ) {
    24422614        wp_die( -1 );
     
    26502822        wp_die( 0 );
    26512823    }
     2824
    26522825    $post_id = (int) $_POST['post_ID'];
    26532826    $post    = get_post( $post_id );
     2827
    26542828    if ( ! $post ) {
    26552829        wp_die( 0 );
     
    26632837
    26642838    $active_lock = array_map( 'absint', explode( ':', $_POST['active_post_lock'] ) );
     2839
    26652840    if ( $active_lock[1] != get_current_user_id() ) {
    26662841        wp_die( 0 );
     
    26872862function wp_ajax_dismiss_wp_pointer() {
    26882863    $pointer = $_POST['pointer'];
     2864
    26892865    if ( $pointer != sanitize_key( $pointer ) ) {
    26902866        wp_die( 0 );
     
    27672943        'monthnum',
    27682944    );
     2945
    27692946    foreach ( get_taxonomies_for_attachments( 'objects' ) as $t ) {
    27702947        if ( $t->query_var && isset( $query[ $t->query_var ] ) ) {
     
    27752952    $query              = array_intersect_key( $query, array_flip( $keys ) );
    27762953    $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    ) {
    27802960        $query['post_status'] = 'trash';
    27812961    } else {
     
    28703050        $changed = false;
    28713051        $id3data = wp_get_attachment_metadata( $post['ID'] );
     3052
    28723053        if ( ! is_array( $id3data ) ) {
    28733054            $changed = true;
    28743055            $id3data = array();
    28753056        }
     3057
    28763058        foreach ( wp_get_attachment_id3_keys( (object) $post, 'edit' ) as $key => $label ) {
    28773059            if ( isset( $changes[ $key ] ) ) {
     
    29133095        wp_send_json_error();
    29143096    }
     3097
    29153098    $attachment_data = $_REQUEST['attachments'][ $id ];
    29163099
     
    29443127
    29453128    $attachment = wp_prepare_attachment_for_js( $id );
     3129
    29463130    if ( ! $attachment ) {
    29473131        wp_send_json_error();
     
    29823166            continue;
    29833167        }
     3168
    29843169        $attachment = get_post( $attachment_id );
     3170
    29853171        if ( ! $attachment ) {
    29863172            continue;
    29873173        }
     3174
    29883175        if ( 'attachment' != $attachment->post_type ) {
    29893176            continue;
     
    30293216        // If this attachment is unattached, attach it. Primarily a back compat thing.
    30303217        $insert_into_post_id = intval( $_POST['post_id'] );
     3218
    30313219        if ( 0 == $post->post_parent && $insert_into_post_id ) {
    30323220            wp_update_post(
     
    33473535
    33483536    $update_php = network_admin_url( 'update.php?action=install-theme' );
     3537
    33493538    foreach ( $api->themes as &$theme ) {
    33503539        $theme->install_url = add_query_arg(
     
    33913580        $theme->version     = wp_kses( $theme->version, $themes_allowedtags );
    33923581        $theme->description = wp_kses( $theme->description, $themes_allowedtags );
    3393         $theme->stars       = wp_star_rating(
     3582
     3583        $theme->stars = wp_star_rating(
    33943584            array(
    33953585                'rating' => $theme->rating,
     
    33993589            )
    34003590        );
     3591
    34013592        $theme->num_ratings = number_format_i18n( $theme->num_ratings );
    34023593        $theme->preview_url = set_url_scheme( $theme->preview_url );
     
    34223613        wp_send_json_error();
    34233614    }
     3615
    34243616    $post_id = isset( $_POST['post_ID'] ) ? intval( $_POST['post_ID'] ) : 0;
     3617
    34253618    if ( $post_id > 0 ) {
    34263619        $post = get_post( $post_id );
     3620
    34273621        if ( ! $post || ! current_user_can( 'edit_post', $post->ID ) ) {
    34283622            wp_send_json_error();
     
    34373631    preg_match( '/' . get_shortcode_regex() . '/s', $shortcode, $matches );
    34383632    $atts = shortcode_parse_atts( $matches[3] );
     3633
    34393634    if ( ! empty( $matches[5] ) ) {
    34403635        $url = $matches[5];
     
    34943689        $styles     = '';
    34953690        $mce_styles = wpview_media_sandbox_styles();
     3691
    34963692        foreach ( $mce_styles as $style ) {
    34973693            $styles .= sprintf( '<link rel="stylesheet" href="%s"/>', $style );
     
    35013697
    35023698        global $wp_scripts;
     3699
    35033700        if ( ! empty( $wp_scripts ) ) {
    35043701            $wp_scripts->done = array();
    35053702        }
     3703
    35063704        ob_start();
    35073705        wp_print_scripts( array( 'mediaelement-vimeo', 'wp-mediaelement' ) );
     
    36183816function wp_ajax_destroy_sessions() {
    36193817    $user = get_userdata( (int) $_POST['user_id'] );
     3818
    36203819    if ( $user ) {
    36213820        if ( ! current_user_can( 'edit_user', $user->ID ) ) {
     
    36573856
    36583857    check_ajax_referer( 'image_editor-' . $attachment_id, 'nonce' );
     3858
    36593859    if ( empty( $attachment_id ) || ! current_user_can( 'edit_post', $attachment_id ) ) {
    36603860        wp_send_json_error();
     
    40474247    // Check filesystem credentials. `delete_theme()` will bail otherwise.
    40484248    $url = wp_nonce_url( 'themes.php?action=delete&stylesheet=' . urlencode( $stylesheet ), 'delete-theme_' . $stylesheet );
     4249
    40494250    ob_start();
    40504251    $credentials = request_filesystem_credentials( $url );
    40514252    ob_end_clean();
     4253
    40524254    if ( false === $credentials || ! WP_Filesystem( $credentials ) ) {
    40534255        global $wp_filesystem;
     
    43404542    // Check filesystem credentials. `delete_plugins()` will bail otherwise.
    43414543    $url = wp_nonce_url( 'plugins.php?action=delete-selected&verify-delete=1&checked[]=' . $plugin, 'bulk-plugins' );
     4544
    43424545    ob_start();
    43434546    $credentials = request_filesystem_credentials( $url );
    43444547    ob_end_clean();
     4548
    43454549    if ( false === $credentials || ! WP_Filesystem( $credentials ) ) {
    43464550        global $wp_filesystem;
     
    44824686function wp_ajax_edit_theme_plugin_file() {
    44834687    $r = wp_edit_theme_plugin_file( wp_unslash( $_POST ) ); // Validation of args is done in wp_edit_theme_plugin_file().
     4688
    44844689    if ( is_wp_error( $r ) ) {
    44854690        wp_send_json_error(
     
    45114716        wp_send_json_error( __( 'Missing request ID.' ) );
    45124717    }
     4718
    45134719    $request_id = (int) $_POST['id'];
    45144720
     
    45384744        wp_send_json_error( __( 'Missing exporter index.' ) );
    45394745    }
     4746
    45404747    $exporter_index = (int) $_POST['exporter'];
    45414748
     
    45434750        wp_send_json_error( __( 'Missing page index.' ) );
    45444751    }
     4752
    45454753    $page = (int) $_POST['page'];
    45464754
     
    45964804            );
    45974805        }
     4806
    45984807        if ( ! array_key_exists( 'exporter_friendly_name', $exporter ) ) {
    45994808            wp_send_json_error(
     
    46114820            );
    46124821        }
     4822
    46134823        if ( ! is_callable( $exporter['callback'] ) ) {
    46144824            wp_send_json_error(
     
    46314841            );
    46324842        }
     4843
    46334844        if ( ! array_key_exists( 'data', $response ) ) {
    46344845            wp_send_json_error(
     
    46374848            );
    46384849        }
     4850
    46394851        if ( ! is_array( $response['data'] ) ) {
    46404852            wp_send_json_error(
     
    46434855            );
    46444856        }
     4857
    46454858        if ( ! array_key_exists( 'done', $response ) ) {
    46464859            wp_send_json_error(
Note: See TracChangeset for help on using the changeset viewer.