From 76540c6010423d6b48d32afbf670f8799f290e7e Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Sat, 20 Aug 2016 23:45:28 +0000 Subject: [PATCH] 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 --- wp-includes/post-template.php | 12 +++++++++--- wp-includes/version.php | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/wp-includes/post-template.php b/wp-includes/post-template.php index be152523f0..50667a71a5 100644 --- a/wp-includes/post-template.php +++ b/wp-includes/post-template.php @@ -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. * diff --git a/wp-includes/version.php b/wp-includes/version.php index 24df26c38f..d18d1839bb 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -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.