WordPress.org

Make WordPress Core

Ticket #24603: 24603.diff

File 24603.diff, 961 bytes (added by ryan, 10 months ago)
  • wp-admin/includes/file.php

     
    328328 
    329329        // Move the file to the uploads dir 
    330330        $new_file = $uploads['path'] . "/$filename"; 
    331         if ( false === @ move_uploaded_file( $file['tmp_name'], $new_file ) ) 
     331 
     332        // Allow pre-processing of the uploaded file after it has passed all checks. 
     333        // Expected to return true if file was saved as $new_file, false to show the below error, or null if the file doesn't need pre-processing. 
     334        $moved = apply_filters( 'pre_move_uploaded_file', null, $file, $new_file, $type ); 
     335        if ( null === $moved ) 
     336                $moved = @ move_uploaded_file( $file['tmp_name'], $new_file ); 
     337 
     338        if ( false === $moved ) 
    332339                return $upload_error_handler( $file, sprintf( __('The uploaded file could not be moved to %s.' ), $uploads['path'] ) ); 
    333340 
    334341        // Set correct file permissions