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.

Built from https://develop.svn.wordpress.org/trunk@38295


git-svn-id: http://core.svn.wordpress.org/trunk@38236 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Scott Taylor 2016-08-20 23:45:28 +00:00
parent 7ac88c02fa
commit 76540c6010
2 changed files with 10 additions and 4 deletions

View File

@ -1445,11 +1445,13 @@ function the_attachment_link( $id = 0, $fullsize = false, $deprecated = false, $
function wp_get_attachment_link( $id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false, $attr = '' ) {
$_post = get_post( $id );
if ( empty( $_post ) || ( 'attachment' != $_post->post_type ) || ! $url = wp_get_attachment_url( $_post->ID ) )
if ( empty( $_post ) || ( 'attachment' !== $_post->post_type ) || ! $url = wp_get_attachment_url( $_post->ID ) ) {
return __( 'Missing Attachment' );
}
if ( $permalink )
if ( $permalink ) {
$url = get_attachment_link( $_post->ID );
}
if ( $text ) {
$link_text = $text;
@ -1459,9 +1461,13 @@ function wp_get_attachment_link( $id = 0, $size = 'thumbnail', $permalink = fals
$link_text = '';
}
if ( trim( $link_text ) == '' )
if ( '' === trim( $link_text ) ) {
$link_text = $_post->post_title;
}
if ( '' === trim( $link_text ) ) {
$link_text = esc_html( pathinfo( get_attached_file( $_post->ID ), PATHINFO_FILENAME ) );
}
/**
* Filters a retrieved attachment page link.
*

View File

@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '4.7-alpha-38294';
$wp_version = '4.7-alpha-38295';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.