Ticket #6430: thumbnail.patch

File thumbnail.patch, 1.3 KB (added by jonquark, 3 years ago)

Patch to return urls for smaller images for xmlrpc uploads

  • xmlrpc.php

     
    28272827 
    28282828                // Save the data 
    28292829                $id = wp_insert_attachment( $attachment, $upload[ 'file' ], $post_id ); 
    2830                 wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $upload['file'] ) ); 
     2830                $metadata = wp_generate_attachment_metadata( $id, $upload['file'] ); 
     2831                wp_update_attachment_metadata( $id, $metadata ); 
     2832         
    28312833 
    2832                 return apply_filters( 'wp_handle_upload', array( 'file' => $name, 'url' => $upload[ 'url' ], 'type' => $type ), 'upload' ); 
     2834                //setup the data to be returned 
     2835                $returneddata = array( 'file' => $name,  
     2836                                       'url' => $upload[ 'url' ], 
     2837                                       'type' => $type ); 
     2838 
     2839                //Get the URLs for each image we generated       
     2840                if(    isset($metadata['sizes']) 
     2841                    && is_array($metadata['sizes']) ) { 
     2842                        foreach( $metadata['sizes'] as $size => $size_data ) { 
     2843                                if( isset($size_data['file']) ) { 
     2844                                        $resized_url  =  str_replace(  $name,  
     2845                                                                       $size_data['file'], 
     2846                                                                       $upload[ 'url' ]) ; 
     2847                                        $returneddata[ $size.'_url' ] = $resized_url; 
     2848                                } 
     2849                        } 
     2850                } 
     2851                return apply_filters( 'wp_handle_upload', $returneddata ); 
    28332852        } 
    28342853 
    28352854        /* MovableType API functions