WordPress.org

Make WordPress Core

Changeset 19210


Ignore:
Timestamp:
11/08/2011 02:08:25 PM (9 years ago)
Author:
ryan
Message:

Avoid warning when non-existent ID pass to wp_get_attachment_link(). Tidy formatting of wp_get_attachment_link(). Props SergeyBiryukov, Jayjdk. fixes #18491

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/post-template.php

    r19081 r19210  
    11531153 * @return string HTML content.
    11541154 */
    1155 function wp_get_attachment_link($id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false) {
    1156     $id = intval($id);
     1155function wp_get_attachment_link( $id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false ) {
     1156    $id = intval( $id );
    11571157    $_post = & get_post( $id );
    11581158
    1159     if ( ('attachment' != $_post->post_type) || !$url = wp_get_attachment_url($_post->ID) )
    1160         return __('Missing Attachment');
     1159    if ( empty( $_post ) || ( 'attachment' != $_post->post_type ) || ! $url = wp_get_attachment_url( $_post->ID ) )
     1160        return __( 'Missing Attachment' );
    11611161
    11621162    if ( $permalink )
    1163         $url = get_attachment_link($_post->ID);
    1164 
    1165     $post_title = esc_attr($_post->post_title);
    1166 
    1167     if ( $text ) {
    1168         $link_text = esc_attr($text);
    1169     } elseif ( ( is_int($size) && $size != 0 ) or ( is_string($size) && $size != 'none' ) or $size != false ) {
    1170         $link_text = wp_get_attachment_image($id, $size, $icon);
    1171     } else {
     1163        $url = get_attachment_link( $_post->ID );
     1164
     1165    $post_title = esc_attr( $_post->post_title );
     1166
     1167    if ( $text )
     1168        $link_text = esc_attr( $text );
     1169    elseif ( ( is_int( $size ) && $size != 0 ) || ( is_string( $size ) && $size != 'none' ) || $size != false )
     1170        $link_text = wp_get_attachment_image( $id, $size, $icon );
     1171    else
    11721172        $link_text = '';
    1173     }
    1174 
    1175     if( trim($link_text) == '' )
     1173
     1174    if ( trim( $link_text ) == '' )
    11761175        $link_text = $_post->post_title;
    11771176
Note: See TracChangeset for help on using the changeset viewer.