WordPress.org

Make WordPress Core

Ticket #22075: 22075.2.diff

File 22075.2.diff, 2.2 KB (added by webord, 7 years ago)
  • wp-includes/post-template.php

     
    11611161 *
    11621162 * @since 2.5.0
    11631163 * @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.
    11641166 *
    11651167 * @param int $id Optional. Post ID.
    11661168 * @param string $size Optional, default is 'thumbnail'. Size of image, either array or string.
    11671169 * @param bool $permalink Optional, default is false. Whether to add permalink to image.
    11681170 * @param bool $icon Optional, default is false. Whether to include icon.
    11691171 * @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.
    11701173 * @return string HTML content.
    11711174 */
    1172 function wp_get_attachment_link( $id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false ) {
     1175function wp_get_attachment_link( $id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false, $attr='' ) {
    11731176        $id = intval( $id );
    11741177        $_post = get_post( $id );
     1178        $attr_html = '';
    11751179
    11761180        if ( empty( $_post ) || ( 'attachment' != $_post->post_type ) || ! $url = wp_get_attachment_url( $_post->ID ) )
    11771181                return __( 'Missing Attachment' );
     
    11911195        if ( trim( $link_text ) == '' )
    11921196                $link_text = $_post->post_title;
    11931197
    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 );
    11951211}
    11961212
    11971213/**