Ticket #22075: 22075.diff
File 22075.diff, 2.2 KB (added by , 12 years ago) |
---|
-
wp-includes/post-template.php
1138 1138 * 1139 1139 * @since 2.5.0 1140 1140 * @uses apply_filters() Calls 'wp_get_attachment_link' filter on HTML content with same parameters as function. 1141 * @uses apply_filters() Calls 'wp_get_attachment_link_attributes' hook on attributes array 1142 * @uses wp_parse_args() Merges the defaults with those defined by $args and allows for strings. 1141 1143 * 1142 1144 * @param int $id Optional. Post ID. 1143 1145 * @param string $size Optional, default is 'thumbnail'. Size of image, either array or string. 1144 1146 * @param bool $permalink Optional, default is false. Whether to add permalink to image. 1145 1147 * @param bool $icon Optional, default is false. Whether to include icon. 1146 1148 * @param string|bool $text Optional, default is false. If string, then will be link text. 1149 * @param string|array $attr Optional, default is empty string. 1147 1150 * @return string HTML content. 1148 1151 */ 1149 function wp_get_attachment_link( $id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false ) {1152 function wp_get_attachment_link( $id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false, $attr='' ) { 1150 1153 $id = intval( $id ); 1151 1154 $_post = get_post( $id ); 1155 $attr_html = ''; 1152 1156 1153 1157 if ( empty( $_post ) || ( 'attachment' != $_post->post_type ) || ! $url = wp_get_attachment_url( $_post->ID ) ) 1154 1158 return __( 'Missing Attachment' ); … … 1168 1172 if ( trim( $link_text ) == '' ) 1169 1173 $link_text = $_post->post_title; 1170 1174 1171 return apply_filters( 'wp_get_attachment_link', "<a href='$url' title='$post_title'>$link_text</a>", $id, $size, $permalink, $icon, $text ); 1175 $default_attr = array( 1176 'href' => $url, 1177 'title' => $post_title, 1178 ); 1179 1180 $attr = wp_parse_args($attr, $default_attr); 1181 $attr = apply_filters( 'wp_get_attachment_link_attributes', $attr, $_post ); 1182 $attr = array_map( 'esc_attr', $attr ); 1183 1184 foreach ( $attr as $name => $value ) { 1185 $attr_html .= " {$name}=\"{$value}\""; 1186 } 1187 return apply_filters( 'wp_get_attachment_link', "<a $attr_html>$link_text</a>", $id, $size, $permalink, $icon, $text ); 1172 1188 } 1173 1189 1174 1190 /**