Ticket #18178: media.php.galleryshortcodelinknone.diff

File media.php.galleryshortcodelinknone.diff, 1.4 KB (added by chipbennett, 22 months ago)

Add link="none" support to [gallery] shortcode, to enable output of flat/unlinked images

Line 
1Index: media.php
2===================================================================
3--- media.php   (revision 18444)
4+++ media.php   (working copy)
5@@ -850,12 +850,27 @@
6 
7        $i = 0;
8        foreach ( $attachments as $id => $attachment ) {
9-               $link = isset($attr['link']) && 'file' == $attr['link'] ? wp_get_attachment_link($id, $size, false, false) : wp_get_attachment_link($id, $size, true, false);
10+               /*
11+                * Output image link. By default, image links to
12+                * attachment page. If link="file" is passed to
13+                * the shortcode, the image links directly to
14+                * the file.
15+                */
16+               $image_link = isset( $attr['link'] ) && 'file' == $attr['link'] ? wp_get_attachment_link( $id, $size, false, false ) : wp_get_attachment_link( $id, $size, true, false );
17+               /*
18+                * Output flat image. By default, image links to
19+                * attachment page. If link="none" is passed to
20+                * the shortcode, a flat (unlinked) image is
21+                * output.
22+                */
23+               $flat_image = ( isset( $attr['link'] ) && 'none' == $attr['link'] ? wp_get_attachment_image( $id, $size, false ) : false );
24+               // Determine whether to output a linked or flat image
25+               $image_output = ( $flat_image ? $flat_image : $image_link );
26 
27                $output .= "<{$itemtag} class='gallery-item'>";
28                $output .= "
29                        <{$icontag} class='gallery-icon'>
30-                               $link
31+                               $image_output
32                        </{$icontag}>";
33                if ( $captiontag && trim($attachment->post_excerpt) ) {
34                        $output .= "