WordPress.org

Make WordPress Core

Changeset 13290


Ignore:
Timestamp:
02/22/10 16:54:51 (5 years ago)
Author:
ryan
Message:

Pass overrides. Allow ref array calling. Props tychay. fixes #12278

Location:
trunk/wp-admin/includes
Files:
2 edited

Legend:

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

    r13223 r13290  
    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 ); 
     
    263263    $test_form = true; 
    264264    $test_size = true; 
     265    $test_upload = true; 
    265266 
    266267    // If you override this, you must provide $ext and $type!!!! 
     
    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. 
     
    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 ) 
     
    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 ); 
     
    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 
  • trunk/wp-admin/includes/media.php

    r13283 r13290  
    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 
    184  */ 
    185 function media_handle_upload($file_id, $post_id, $post_data = array()) { 
    186     $overrides = array('test_form'=>false); 
     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 
     185 */ 
     186function media_handle_upload($file_id, $post_id, $post_data = array(), $overrides = array( 'test_form' => false )) { 
    187187 
    188188    $time = current_time('mysql'); 
     
    462462        $html = $attachment['post_title']; 
    463463        if ( !empty($attachment['url']) ) { 
     464            $rel = ''; 
    464465            if ( strpos($attachment['url'], 'attachment_id') || false !== strpos($attachment['url'], get_permalink($_POST['post_id'])) ) 
    465466                $rel = " rel='attachment wp-att-" . esc_attr($send_id)."'"; 
Note: See TracChangeset for help on using the changeset viewer.