WordPress.org

Make WordPress Core

Changeset 22170


Ignore:
Timestamp:
10/10/12 21:54:21 (18 months ago)
Author:
koopersmith
Message:

Correctly insert non-image attachments as links.

  • Adds wp.media.string.link( attachment ) for printing attachment links.
  • Adds the link attribute to Attachment models that corresponds to the link to the attachment post.

see #21390, #21836.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/js/media-upload.js

    r22156 r22170  
    109109 
    110110            workflow.on( 'update:insert', function( selection ) { 
    111                 this.insert( '\n' + selection.map( function( attachment ) { 
    112                     return wp.media.string.image( attachment ); 
    113                 }).join('\n\n') + '\n' ); 
     111                this.insert( selection.map( function( attachment ) { 
     112                    if ( 'image' === attachment.get('type') ) 
     113                        return '\n' + wp.media.string.image( attachment ) + '\n'; 
     114                    else 
     115                        return wp.media.string.link( attachment ) + ' '; 
     116                }).join('') ); 
    114117            }, this ); 
    115118 
  • trunk/wp-includes/js/mce-view.js

    r22162 r22170  
    372372 
    373373    wp.media.string = {}; 
     374 
     375    wp.media.string.link = function( attachment ) { 
     376        var linkTo  = getUserSetting( 'urlbutton', 'post' ), 
     377            options = { 
     378                tag:     'a', 
     379                content: attachment.get('title') || attachment.get('filename'), 
     380                attrs:   { 
     381                    rel: 'attachment wp-att-' + attachment.id 
     382                } 
     383            }; 
     384 
     385        // Attachments can be linked to attachment post pages or to the direct 
     386        // URL. `none` is not a valid option. 
     387        options.attrs.href = ( linkTo === 'file' ) ? attachment.get('url') : attachment.get('link'); 
     388 
     389        return wp.html.string( options ); 
     390    }; 
     391 
    374392    wp.media.string.image = function( attachment, props ) { 
    375393        var classes, img, options, size; 
  • trunk/wp-includes/media.php

    r22160 r22170  
    12471247        'filename'    => basename( $attachment->guid ), 
    12481248        'url'         => $attachment_url, 
     1249        'link'        => get_attachment_link( $attachment->ID ), 
    12491250        'alt'         => get_post_meta( $attachment->ID, '_wp_attachment_image_alt', true ), 
    12501251        'author'      => $attachment->post_author, 
Note: See TracChangeset for help on using the changeset viewer.