Make WordPress Core

Changeset 38295


Ignore:
Timestamp:
08/20/2016 11:44:07 PM (8 years ago)
Author:
wonderboymusic
Message:

Media: wp_get_attachment_link() fails to output text for non-images if the attachment post doesn't have a title and $text (argument #5) was not passed to the func. In this case, use the filename.

Props Jonnyauk, henry.wright.
Fixes #37343.

File:
1 edited

Legend:

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

    r37985 r38295  
    14461446    $_post = get_post( $id );
    14471447
    1448     if ( empty( $_post ) || ( 'attachment' != $_post->post_type ) || ! $url = wp_get_attachment_url( $_post->ID ) )
     1448    if ( empty( $_post ) || ( 'attachment' !== $_post->post_type ) || ! $url = wp_get_attachment_url( $_post->ID ) ) {
    14491449        return __( 'Missing Attachment' );
    1450 
    1451     if ( $permalink )
     1450    }
     1451
     1452    if ( $permalink ) {
    14521453        $url = get_attachment_link( $_post->ID );
     1454    }
    14531455
    14541456    if ( $text ) {
     
    14601462    }
    14611463
    1462     if ( trim( $link_text ) == '' )
     1464    if ( '' === trim( $link_text ) ) {
    14631465        $link_text = $_post->post_title;
    1464 
     1466    }
     1467
     1468    if ( '' === trim( $link_text ) ) {
     1469        $link_text = esc_html( pathinfo( get_attached_file( $_post->ID ), PATHINFO_FILENAME ) );
     1470    }
    14651471    /**
    14661472     * Filters a retrieved attachment page link.
Note: See TracChangeset for help on using the changeset viewer.