Ticket #22075: 22075.2.diff
File 22075.2.diff, 2.2 KB (added by , 12 years ago) |
---|
-
wp-includes/post-template.php
1161 1161 * 1162 1162 * @since 2.5.0 1163 1163 * @uses apply_filters() Calls 'wp_get_attachment_link' filter on HTML content with same parameters as function. 1164 * @uses apply_filters() Calls 'wp_get_attachment_link_attributes' hook on attributes array 1165 * @uses wp_parse_args() Merges the defaults with those defined by $args and allows for strings. 1164 1166 * 1165 1167 * @param int $id Optional. Post ID. 1166 1168 * @param string $size Optional, default is 'thumbnail'. Size of image, either array or string. 1167 1169 * @param bool $permalink Optional, default is false. Whether to add permalink to image. 1168 1170 * @param bool $icon Optional, default is false. Whether to include icon. 1169 1171 * @param string|bool $text Optional, default is false. If string, then will be link text. 1172 * @param string|array $attr Optional, default is empty string. 1170 1173 * @return string HTML content. 1171 1174 */ 1172 function wp_get_attachment_link( $id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false ) {1175 function wp_get_attachment_link( $id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false, $attr='' ) { 1173 1176 $id = intval( $id ); 1174 1177 $_post = get_post( $id ); 1178 $attr_html = ''; 1175 1179 1176 1180 if ( empty( $_post ) || ( 'attachment' != $_post->post_type ) || ! $url = wp_get_attachment_url( $_post->ID ) ) 1177 1181 return __( 'Missing Attachment' ); … … 1191 1195 if ( trim( $link_text ) == '' ) 1192 1196 $link_text = $_post->post_title; 1193 1197 1194 return apply_filters( 'wp_get_attachment_link', "<a href='$url' title='$post_title'>$link_text</a>", $id, $size, $permalink, $icon, $text ); 1198 $default_attr = array( 1199 'href' => $url, 1200 'title' => $post_title, 1201 ); 1202 1203 $attr = wp_parse_args($attr, $default_attr); 1204 $attr = apply_filters( 'wp_get_attachment_link_attributes', $attr, $_post ); 1205 $attr = array_map( 'esc_attr', $attr ); 1206 1207 foreach ( $attr as $name => $value ) { 1208 $attr_html .= " {$name}=\"{$value}\""; 1209 } 1210 return apply_filters( 'wp_get_attachment_link', "<a $attr_html>$link_text</a>", $id, $size, $permalink, $icon, $text, $attr ); 1195 1211 } 1196 1212 1197 1213 /**