Ticket #14110: wp_get_attachment_image.diff
File wp_get_attachment_image.diff, 3.4 KB (added by , 14 years ago) |
---|
-
wordpress/wp-includes/media.php
79 79 } 80 80 81 81 /** 82 * Retrieve width and height attributes using given width and height values.83 *84 * Both attributes are required in the sense that both parameters must have a85 * value, but are optional in that if you set them to false or null, then they86 * will not be added to the returned string.87 *88 * You can set the value using a string, but it will only take numeric values.89 * If you wish to put 'px' after the numbers, then it will be stripped out of90 * the return.91 *92 * @since 2.5.093 *94 * @param int|string $width Optional. Width attribute value.95 * @param int|string $height Optional. Height attribute value.96 * @return string HTML attributes for width and, or height.97 */98 function image_hwstring($width, $height) {99 $out = '';100 if ($width)101 $out .= 'width="'.intval($width).'" ';102 if ($height)103 $out .= 'height="'.intval($height).'" ';104 return $out;105 }106 107 /**108 82 * Scale an image to fit a particular size (such as 'thumb' or 'medium'). 109 83 * 110 84 * Array with image url, width, height, and whether is intermediate size, in … … 218 192 function get_image_tag($id, $alt, $title, $align, $size='medium') { 219 193 220 194 list( $img_src, $width, $height ) = image_downsize($id, $size); 221 $hwstring = image_hwstring($width, $height);222 223 $class = 'align' . esc_attr($align) .' size-' . esc_attr($size) . ' wp-image-' . $id;224 $class = apply_filters('get_image_tag_class', $class, $id, $align, $size);225 226 $html = '<img src="' . esc_attr($img_src) . '" alt="' . esc_attr($alt) . '" title="' . esc_attr($title).'" '.$hwstring.'class="'.$class.'" />';227 195 196 $class = "align$align size-$size wp-image-$id"; 197 $attr = array( 198 'src' => $img_src, 199 'width' => intval($width), 200 'height' => intval(height), 201 'class' => $class, 202 'alt' => $alt, 203 'title' => $title 204 ); 205 $attr = array_map( 'esc_attr', $attr ); 206 $attr['class'] = apply_filters('get_image_tag_class', $attr['class'], $id, $align, $size); 207 208 $html = rtrim("<img "); 209 foreach ( $attr as $name => $value ) { 210 $html .= " $name=" . '"' . $value . '"'; 211 } 212 $html .= ' />'; 228 213 $html = apply_filters( 'get_image_tag', $html, $id, $alt, $title, $align, $size ); 229 214 230 215 return $html; … … 633 618 * @return string HTML img element or empty string on failure. 634 619 */ 635 620 function wp_get_attachment_image($attachment_id, $size = 'thumbnail', $icon = false, $attr = '') { 636 637 621 $html = ''; 638 622 $image = wp_get_attachment_image_src($attachment_id, $size, $icon); 639 623 if ( $image ) { 640 624 list($src, $width, $height) = $image; 641 $hwstring = image_hwstring($width, $height);642 625 if ( is_array($size) ) 643 626 $size = join('x', $size); 644 627 $attachment =& get_post($attachment_id); 645 628 $default_attr = array( 646 629 'src' => $src, 630 'height' => intval($height), 631 'width' => intval($width), 647 632 'class' => "attachment-$size", 648 633 'alt' => trim(strip_tags( get_post_meta($attachment_id, '_wp_attachment_image_alt', true) )), // Use Alt field first 649 634 'title' => trim(strip_tags( $attachment->post_title )), … … 656 641 $attr = wp_parse_args($attr, $default_attr); 657 642 $attr = apply_filters( 'wp_get_attachment_image_attributes', $attr, $attachment ); 658 643 $attr = array_map( 'esc_attr', $attr ); 659 $html = rtrim("<img $hwstring");644 $html = rtrim("<img "); 660 645 foreach ( $attr as $name => $value ) { 661 646 $html .= " $name=" . '"' . $value . '"'; 662 647 }