Ticket #6086: attachment-images-r7145-3.patch

File attachment-images-r7145-3.patch, 5.8 KB (added by tellyworth, 4 years ago)
  • wordpress/wp-includes/post-template.php

     
    362362// Attachments 
    363363// 
    364364 
    365 function the_attachment_link($id = 0, $fullsize = false, $max_dims = false, $permalink = false) { 
    366         echo get_the_attachment_link($id, $fullsize, $max_dims, $permalink); 
     365function the_attachment_link($id = 0, $fullsize = false, $deprecated = false, $permalink = false) { 
     366        if ( $fullsize ) 
     367                echo wp_get_attachment_link($id, 'full', $permalink); 
     368        else 
     369                echo wp_get_attachment_link($id, 'thumbnail', $permalink); 
    367370} 
    368371 
     372// get an attachment page link using an image or icon if possible 
     373function wp_get_attachment_link($id = 0, $size = 'thumbnail', $permalink = false) { 
     374        $_post = & get_post( intval($id) ); 
     375 
     376        if ( ('attachment' != $_post->post_type) || !$url = wp_get_attachment_url($_post->ID) ) 
     377                return __('Missing Attachment'); 
     378 
     379        if ( $permalink ) 
     380                $url = get_attachment_link($_post->ID); 
     381 
     382        $post_title = attribute_escape($_post->post_title); 
     383 
     384        $link_text = wp_get_attachment_image($attachment_id, $size); 
     385        if ( !$link_text ) 
     386                $link_text = $_post->post_title; 
     387 
     388        return "<a href='$url' title='$post_title'>$link_text</a>"; 
     389 
     390} 
     391 
     392// deprecated - use wp_get_attachment_link() 
    369393function get_the_attachment_link($id = 0, $fullsize = false, $max_dims = false, $permalink = false) { 
    370394        $id = (int) $id; 
    371395        $_post = & get_post($id); 
     
    382406        return "<a href='$url' title='$post_title'>$innerHTML</a>"; 
    383407} 
    384408 
     409 
     410// deprecated: use wp_get_attachment_image_src() 
    385411function get_attachment_icon_src( $id = 0, $fullsize = false ) { 
    386412        $id = (int) $id; 
    387413        if ( !$post = & get_post($id) ) 
     
    413439        return array($src, $src_file); 
    414440} 
    415441 
     442// deprecated: use wp_get_attachment_image() 
    416443function get_attachment_icon( $id = 0, $fullsize = false, $max_dims = false ) { 
    417444        $id = (int) $id; 
    418445        if ( !$post = & get_post($id) ) 
    419446                return false; 
    420  
     447                 
    421448        if ( !$src = get_attachment_icon_src( $post->ID, $fullsize ) ) 
    422449                return false; 
    423450 
     
    456483        return apply_filters( 'attachment_icon', $icon, $post->ID ); 
    457484} 
    458485 
     486// deprecated: use wp_get_attachment_image() 
    459487function get_attachment_innerHTML($id = 0, $fullsize = false, $max_dims = false) { 
    460488        $id = (int) $id; 
    461489        if ( !$post = & get_post($id) ) 
     
    472500 
    473501function prepend_attachment($content) { 
    474502        $p = '<p class="attachment">'; 
    475         $p .= get_the_attachment_link(false, true, array(400, 300)); 
     503        // show the medium sized image representation of the attachment if available, and link to the raw file 
     504        $p .= wp_get_attachment_link(0, 'medium', false); 
    476505        $p .= '</p>'; 
    477506        $p = apply_filters('prepend_attachment', $p); 
    478507 
  • wordpress/wp-includes/media.php

     
    1818                $max_width = intval(get_option('medium_size_w')); 
    1919                $max_height = intval(get_option('medium_size_h')); 
    2020                // if no width is set, default to the theme content width if available 
    21                 if ( !$max_width ) { 
    22                         // $content_width might be set in the current theme's functions.php 
    23                         if ( !empty($GLOBALS['content_width']) ) { 
    24                                 $max_width = $GLOBALS['content_width']; 
    25                         } 
    26                         else 
    27                                 $max_width = 500; 
    28                 } 
    2921        } 
    3022        else { // $size == 'full' 
    31                 $max_width = 0; 
    32                 $max_height = 0; 
     23                // we're inserting a full size image into the editor.  if it's a really big image we'll scale it down to fit reasonably 
     24                // within the editor itself, and within the theme's content width if it's known.  the user can resize it in the editor 
     25                // if they wish. 
     26                if ( !empty($GLOBALS['content_width']) ) { 
     27                        $max_width = $GLOBALS['content_width']; 
     28                } 
     29                else 
     30                        $max_width = 500; 
    3331        } 
    3432 
    3533        list( $max_width, $max_height ) = apply_filters( 'editor_max_image_size', array( $max_width, $max_height ), $size ); 
     
    258256        return $imagedata['sizes'][$size]; 
    259257} 
    260258 
     259// get an image to represent an attachment - a mime icon for files, thumbnail or intermediate size for images 
     260// returns an array (url, width, height), or false if no image is available 
     261function wp_get_attachment_image_src($attachment_id, $size='thumbnail') { 
     262         
     263        // get a thumbnail or intermediate image if there is one 
     264        $image = image_downsize($attachment_id, $size); 
     265        if ( $image ) { 
     266                list ( $src, $width, $height ) = $image; 
     267        } 
     268        elseif ( $src = wp_mime_type_icon($attachment_id) ) { 
     269                $icon_dir = apply_filters( 'icon_dir', get_template_directory() . '/images' ); 
     270                $src_file = $icon_dir . '/' . basename($src); 
     271                @list($width, $height) = getimagesize($src_file); 
     272        } 
     273         
     274        if ( $src && $width && $height ) 
     275                return array( $src, $width, $height ); 
     276        return false; 
     277} 
    261278 
     279// as per wp_get_attachment_image_src, but returns an <img> tag 
     280function wp_get_attachment_image($attachment_id, $size='thumbnail') { 
     281 
     282        $html = ''; 
     283        $image = wp_get_attachment_image_src($attachment_id, $size); 
     284        if ( $image ) { 
     285                list($src, $width, $height) = $image; 
     286                $hwstring = image_hwstring($width, $height); 
     287                $html = '<img src="'.attribute_escape($src).'" '.$hwstring.'class="attachment-'.attribute_escape($size).'" />'; 
     288        } 
     289         
     290        return $html; 
     291} 
     292 
    262293?> 
  • wordpress/wp-admin/includes/schema.php

     
    247247        add_option('thumbnail_size_w', 150); 
    248248        add_option('thumbnail_size_h', 150); 
    249249        add_option('thumbnail_crop', 1); 
    250         add_option('medium_size_w', ''); 
    251         add_option('medium_size_h', ''); 
     250        add_option('medium_size_w', 300); 
     251        add_option('medium_size_h', 300); 
    252252        add_option('autosave_interval', 60); 
    253253 
    254254        // Delete unused options