WordPress.org

Make WordPress Core

Ticket #21114: media.php.2.patch

File media.php.2.patch, 2.1 KB (added by robertstaddon, 6 years ago)
  • media.php

     
    778778        elseif ( $url_type == 'post' )
    779779                $url = $link;
    780780
    781         return "
    782         <input type='text' class='text urlfield' name='attachments[$post->ID][url]' value='" . esc_attr($url) . "' /><br />
    783         <button type='button' class='button urlnone' data-link-url=''>" . __('None') . "</button>
    784         <button type='button' class='button urlfile' data-link-url='" . esc_attr($file) . "'>" . __('File URL') . "</button>
    785         <button type='button' class='button urlpost' data-link-url='" . esc_attr($link) . "'>" . __('Attachment Post URL') . "</button>
    786 ";
     781        if ( substr($post->post_mime_type, 0, 5) == 'image' ) {
     782                $large_image_array = wp_get_attachment_image_src( $post->ID, 'large' );
     783                $large_image = $large_image_array[0];
     784                $url = $large_image;
     785                $enabled = ( $file != $large_image ); // Disable the large image button if it is the same as the full size image
     786        }
     787       
     788        $image_link_input_fields_html = "
     789                <input type='text' class='text urlfield' name='attachments[$post->ID][url]' value='" . esc_attr( $url ) . "' /><br />
     790                <button type='button' class='button urlnone' data-link-url=''>" . __( 'None' ) . "</button>
     791        ";
     792        if ( ! empty( $large_image ) )
     793                $image_link_input_fields_html .= "
     794                <button type='button' class='button urlfile' data-link-url='" . esc_attr( $large_image ) . "'" . disabled( $enabled, false, false ) . ">" . __( 'Large Image' ) . "</button>
     795                <button type='button' class='button urlfile' data-link-url='" . esc_attr( $file ) . "'>" . __( 'Full Size Image' ) . "</button>
     796        "; else
     797                $image_link_input_fields_html .= "
     798                <button type='button' class='button urlfile' data-link-url='" . esc_attr( $file ) . "'>" . __( 'File URL' ) . "</button>
     799        ";
     800        $image_link_input_fields_html .= "
     801                <button type='button' class='button urlpost' data-link-url='" . esc_attr( $link ) . "'>" . __( 'Attachment Post URL' ) . "</button>
     802        ";
     803       
     804        return $image_link_input_fields_html;
    787805}
    788806
    789807function wp_caption_input_textarea($edit_post) {