Make WordPress Core

Ticket #10928: the_post_image_attr.diff

File the_post_image_attr.diff, 2.3 KB (added by scribu, 15 years ago)

Add $attr parameter to the_post_image()

  • post-template.php

     
    909909        return get_post_meta( $post_id, '_thumbnail_id', true );
    910910}
    911911
    912 function the_post_image( $size = 'thumbnail' ) {
    913         echo get_the_post_image( $size );
     912function the_post_image( $size = 'thumbnail', $attr = '' ) {
     913        echo get_the_post_image($size, $attr);
    914914}
    915915
    916 function get_the_post_image( $size = 'thumbnail', $post_id = NULL ) {
     916function get_the_post_image( $size = 'thumbnail', $attr = '', $post_id = NULL ) {
    917917        global $id;
    918918        $post_id = ( NULL === $post_id ) ? $id : $post_id;
    919919        $post_image_id = get_post_image_id( $post_id );
    920920        $size = apply_filters( 'post_image_size', $size );
    921921        if ( $post_image_id ) {
    922922                do_action( 'begin_fetch_post_image_html', $post_id, $post_image_id, $size ); // for "Just In Time" filtering of all of wp_get_attachment_image()'s filters
    923                 $html = wp_get_attachment_image( $post_image_id, $size );
     923                $html = wp_get_attachment_image( $post_image_id, $size, false, $attr );
    924924                do_action( 'end_fetch_post_image_html', $post_id, $post_image_id, $size );
    925925        } else {
    926926                $html = '';
  • media.php

     
    527527 * @param bool $icon Optional, default is false. Whether it is an icon.
    528528 * @return string HTML img element or empty string on failure.
    529529 */
    530 function wp_get_attachment_image($attachment_id, $size = 'thumbnail', $icon = false) {
     530function wp_get_attachment_image($attachment_id, $size = 'thumbnail', $icon = false, $attr = '') {
    531531
    532532        $html = '';
    533533        $image = wp_get_attachment_image_src($attachment_id, $size, $icon);
     
    537537                if ( is_array($size) )
    538538                        $size = join('x', $size);
    539539                $attachment =& get_post($attachment_id);
    540                 $attr = array(
     540                $default_attr = array(
    541541                        'src'   => $src,
    542542                        'class' => "attachment-$size",
    543543                        'alt'   => trim(strip_tags( $attachment->post_excerpt )),
    544544                        'title' => trim(strip_tags( $attachment->post_title )),
    545                         );
     545                );
     546                $attr = wp_parse_args($attr, $default_attr);
    546547                $attr = apply_filters( 'wp_get_attachment_image_attributes', $attr, $attachment );
    547548                $attr = array_map( 'esc_attr', $attr );
    548549                $html = rtrim("<img $hwstring");