From 75e238360adb60f525490b3ee103de6b5b4d5ed1 Mon Sep 17 00:00:00 2001 From: ryan Date: Tue, 8 Nov 2011 14:08:25 +0000 Subject: [PATCH] Avoid warning when non-existent ID pass to wp_get_attachment_link(). Tidy formatting of wp_get_attachment_link(). Props SergeyBiryukov, Jayjdk. fixes #18491 git-svn-id: http://svn.automattic.com/wordpress/trunk@19210 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/post-template.php | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/wp-includes/post-template.php b/wp-includes/post-template.php index b4e0c9ae35..36e1d437b6 100644 --- a/wp-includes/post-template.php +++ b/wp-includes/post-template.php @@ -1152,27 +1152,26 @@ function the_attachment_link( $id = 0, $fullsize = false, $deprecated = false, $ * @param string $text Optional, default is false. If string, then will be link text. * @return string HTML content. */ -function wp_get_attachment_link($id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false) { - $id = intval($id); +function wp_get_attachment_link( $id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false ) { + $id = intval( $id ); $_post = & get_post( $id ); - if ( ('attachment' != $_post->post_type) || !$url = wp_get_attachment_url($_post->ID) ) - return __('Missing Attachment'); + if ( empty( $_post ) || ( 'attachment' != $_post->post_type ) || ! $url = wp_get_attachment_url( $_post->ID ) ) + return __( 'Missing Attachment' ); if ( $permalink ) - $url = get_attachment_link($_post->ID); + $url = get_attachment_link( $_post->ID ); - $post_title = esc_attr($_post->post_title); + $post_title = esc_attr( $_post->post_title ); - if ( $text ) { - $link_text = esc_attr($text); - } elseif ( ( is_int($size) && $size != 0 ) or ( is_string($size) && $size != 'none' ) or $size != false ) { - $link_text = wp_get_attachment_image($id, $size, $icon); - } else { + if ( $text ) + $link_text = esc_attr( $text ); + elseif ( ( is_int( $size ) && $size != 0 ) || ( is_string( $size ) && $size != 'none' ) || $size != false ) + $link_text = wp_get_attachment_image( $id, $size, $icon ); + else $link_text = ''; - } - if( trim($link_text) == '' ) + if ( trim( $link_text ) == '' ) $link_text = $_post->post_title; return apply_filters( 'wp_get_attachment_link', "$link_text", $id, $size, $permalink, $icon, $text );