WordPress.org

Make WordPress Core

Ticket #12278: 12278.diff

File 12278.diff, 5.0 KB (added by ryan, 4 years ago)
  • wp-admin/includes/file.php

     
    227227 */ 
    228228function wp_handle_upload( &$file, $overrides = false, $time = null ) { 
    229229        // The default error handler. 
    230         if (! function_exists( 'wp_handle_upload_error' ) ) { 
     230        if ( ! function_exists( 'wp_handle_upload_error' ) ) { 
    231231                function wp_handle_upload_error( &$file, $message ) { 
    232232                        return array( 'error'=>$message ); 
    233233                } 
     
    262262        // All tests are on by default. Most can be turned off by $override[{test_name}] = false; 
    263263        $test_form = true; 
    264264        $test_size = true; 
     265        $test_upload = true; 
    265266 
    266267        // If you override this, you must provide $ext and $type!!!! 
    267268        $test_type = true; 
     
    273274 
    274275        // A correct form post will pass this test. 
    275276        if ( $test_form && (!isset( $_POST['action'] ) || ($_POST['action'] != $action ) ) ) 
    276                 return $upload_error_handler( $file, __( 'Invalid form submission.' )); 
     277                return call_user_func($upload_error_handler, $file, __( 'Invalid form submission.' )); 
    277278 
    278279        // A successful upload will pass this test. It makes no sense to override this one. 
    279280        if ( $file['error'] > 0 ) 
    280                 return $upload_error_handler( $file, $upload_error_strings[$file['error']] ); 
     281                return call_user_func($upload_error_handler, $file, $upload_error_strings[$file['error']] ); 
    281282 
    282283        // A non-empty file will pass this test. 
    283         if ( $test_size && !($file['size'] > 0 ) ) 
    284                 return $upload_error_handler( $file, __( '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.' )); 
     284        if ( $test_size && !($file['size'] > 0 ) ) { 
     285                if ( is_multisite() ) 
     286                        $error_msg = __( 'File is empty. Please upload something more substantial.' ); 
     287                else 
     288                        $error_msg = __( '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.' ); 
     289                return call_user_func($upload_error_handler, $file, $error_msg); 
     290        } 
    285291 
    286292        // A properly uploaded file will pass this test. There should be no reason to override this one. 
    287         if (! @ is_uploaded_file( $file['tmp_name'] ) ) 
    288                 return $upload_error_handler( $file, __( 'Specified file failed upload test.' )); 
     293        if ( $test_upload && ! @ is_uploaded_file( $file['tmp_name'] ) ) 
     294                return call_user_func($upload_error_handler, $file, __( 'Specified file failed upload test.' )); 
    289295 
    290296        // A correct MIME type will pass this test. Override $mimes or use the upload_mimes filter. 
    291297        if ( $test_type ) { 
     
    294300                extract( $wp_filetype ); 
    295301 
    296302                if ( ( !$type || !$ext ) && !current_user_can( 'unfiltered_upload' ) ) 
    297                         return $upload_error_handler( $file, __( 'File type does not meet security guidelines. Try another.' )); 
     303                        return call_user_func($upload_error_handler, $file, __( 'File type does not meet security guidelines. Try another.' )); 
    298304 
    299305                if ( !$ext ) 
    300306                        $ext = ltrim(strrchr($file['name'], '.'), '.'); 
     
    307313 
    308314        // A writable uploads dir will pass this test. Again, there's no point overriding this one. 
    309315        if ( ! ( ( $uploads = wp_upload_dir($time) ) && false === $uploads['error'] ) ) 
    310                 return $upload_error_handler( $file, $uploads['error'] ); 
     316                return call_user_func($upload_error_handler, $file, $uploads['error'] );  
    311317 
    312318        $filename = wp_unique_filename( $uploads['path'], $file['name'], $unique_filename_callback ); 
    313319 
    314320        // Move the file to the uploads dir 
    315321        $new_file = $uploads['path'] . "/$filename"; 
    316         if ( false === @ move_uploaded_file( $file['tmp_name'], $new_file ) ) { 
     322        if ( false === @ move_uploaded_file( $file['tmp_name'], $new_file ) ) 
    317323                return $upload_error_handler( $file, sprintf( __('The uploaded file could not be moved to %s.' ), $uploads['path'] ) ); 
    318         } 
    319324 
    320325        // Set correct file permissions 
    321326        $stat = stat( dirname( $new_file )); 
  • wp-admin/includes/media.php

     
    177177 * 
    178178 * @since unknown 
    179179 * 
    180  * @param unknown_type $file_id 
    181  * @param unknown_type $post_id 
    182  * @param unknown_type $post_data 
    183  * @return unknown 
     180 * @param string $file_id Index into the {@link $_FILES} array of the upload 
     181 * @param int $post_id The post ID the media is associated with 
     182 * @param array $post_data allows you to overwrite some of the attachment 
     183 * @param array $overrides allows you to override the {@link wp_handle_upload()} behavior 
     184 * @return int the ID of the attachment 
    184185 */ 
    185 function media_handle_upload($file_id, $post_id, $post_data = array()) { 
    186         $overrides = array('test_form'=>false); 
     186function media_handle_upload($file_id, $post_id, $post_data = array(), $overrides = array( 'test_form' => false )) { 
    187187 
    188188        $time = current_time('mysql'); 
    189189        if ( $post = get_post($post_id) ) {