Make WordPress Core

Changeset 38235

Timestamp:
08/09/2016 09:53:12 PM (8 years ago)
Author:
ocean90
Message:

Media: In _wp_handle_upload() use call_user_func_array() to call the upload error handler.

The default error handler wp_handle_upload_error() expects a reference for the first parameter but call_user_func() doesn't pass parameters by reference. The current code didn't produce any issues until now. PHP 7.0.9 (and PHP 7.1) is now stricter and prevents calling the error handler with a warning:

PHP Warning: Parameter 1 to wp_handle_upload_error() expected to be a reference, value given.

To restore the error handler _wp_handle_upload() now uses call_user_func_array().

Props jbrinley.
Props jorbin for review.
Fixes #37570.

File:
1 edited

Legend:

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

    r38151 r38235  
    271271    // You may have had one or more 'wp_handle_upload_prefilter' functions error out the file. Handle that gracefully.
    272272    if ( isset( $file['error'] ) && ! is_numeric( $file['error'] ) && $file['error'] ) {
    273         return $upload_error_handler( $file, $file['error'] );
     273        return );
    274274    }
    275275
     
    313313    // A correct form post will pass this test.
    314314    if ( $test_form && ( ! isset( $_POST['action'] ) || ( $_POST['action'] != $action ) ) ) {
    315         return call_user_func( $upload_error_handler, $file, __( 'Invalid form submission.' ) );
     315        return call_user_func ) );
    316316    }
    317317    // A successful upload will pass this test. It makes no sense to override this one.
    318318    if ( isset( $file['error'] ) && $file['error'] > 0 ) {
    319         return call_user_func( $upload_error_handler, $file, $upload_error_strings[ $file['error'] ] );
     319        return call_user_func );
    320320    }
    321321
     
    328328            $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.' );
    329329        }
    330         return call_user_func( $upload_error_handler, $file, $error_msg );
     330        return call_user_func );
    331331    }
    332332
     
    334334    $test_uploaded_file = 'wp_handle_upload' === $action ? @ is_uploaded_file( $file['tmp_name'] ) : @ is_file( $file['tmp_name'] );
    335335    if ( ! $test_uploaded_file ) {
    336         return call_user_func( $upload_error_handler, $file, __( 'Specified file failed upload test.' ) );
     336        return call_user_func ) );
    337337    }
    338338
     
    349349        }
    350350        if ( ( ! $type || !$ext ) && ! current_user_can( 'unfiltered_upload' ) ) {
    351             return call_user_func( $upload_error_handler, $file, __( 'Sorry, this file type is not permitted for security reasons.' ) );
     351            return call_user_func ) );
    352352        }
    353353        if ( ! $type ) {
     
    363363     */
    364364    if ( ! ( ( $uploads = wp_upload_dir( $time ) ) && false === $uploads['error'] ) ) {
    365         return call_user_func( $upload_error_handler, $file, $uploads['error'] );
     365        return call_user_func );
    366366    }
    367367
Note: See TracChangeset for help on using the changeset viewer.