Make WordPress Core

Changeset 30980


Ignore:
Timestamp:
12/20/2014 09:09:11 PM (10 years ago)
Author:
wonderboymusic
Message:

In wp_import_handle_upload():

$file was essentially getting declared/overwritten 3 times. In lieu of this, return an array containing the error immediately instead of doing a short-circuit array key assignment on error. Rename the local variable to $upload and use its properties instead of creating 3 new local vars, one of which stomped the array.

See #30799.

File:
1 edited

Legend:

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

    r29206 r30980  
    7777 */
    7878function wp_import_handle_upload() {
    79     if ( !isset($_FILES['import']) ) {
    80         $file['error'] = __( 'File is empty. Please upload something more substantial. This error could also be caused by uploads being disabled in your php.ini or by post_max_size being defined as smaller than upload_max_filesize in php.ini.' );
    81         return $file;
     79    if ( ! isset( $_FILES['import'] ) ) {
     80        return array(
     81            'error' => __( 'File is empty. Please upload something more substantial. This error could also be caused by uploads being disabled in your php.ini or by post_max_size being defined as smaller than upload_max_filesize in php.ini.' )
     82        );
    8283    }
    8384
    8485    $overrides = array( 'test_form' => false, 'test_type' => false );
    8586    $_FILES['import']['name'] .= '.txt';
    86     $file = wp_handle_upload( $_FILES['import'], $overrides );
    87 
    88     if ( isset( $file['error'] ) )
    89         return $file;
    90 
    91     $url = $file['url'];
    92     $type = $file['type'];
    93     $file = $file['file'];
    94     $filename = basename( $file );
     87    $upload = wp_handle_upload( $_FILES['import'], $overrides );
     88
     89    if ( isset( $upload['error'] ) ) {
     90        return $upload;
     91    }
    9592
    9693    // Construct the object array
    97     $object = array( 'post_title' => $filename,
    98         'post_content' => $url,
    99         'post_mime_type' => $type,
    100         'guid' => $url,
     94    $object = array(
     95        'post_title' => basename( $upload['file'] ),
     96        'post_content' => $upload['url'],
     97        'post_mime_type' => $upload['type'],
     98        'guid' => $upload['url'],
    10199        'context' => 'import',
    102100        'post_status' => 'private'
     
    104102
    105103    // Save the data
    106     $id = wp_insert_attachment( $object, $file );
     104    $id = wp_insert_attachment( $object, $upload['file'] );
    107105
    108106    /*
     
    112110    wp_schedule_single_event( time() + DAY_IN_SECONDS, 'importer_scheduled_cleanup', array( $id ) );
    113111
    114     return array( 'file' => $file, 'id' => $id );
     112    return array( 'file' => $upload['file'], 'id' => $id );
    115113}
    116114
Note: See TracChangeset for help on using the changeset viewer.