From ceccb7b3b11e04ff015d37bc9f89265fb334a29e Mon Sep 17 00:00:00 2001 From: Jake Spurlock Date: Thu, 16 Jul 2020 21:29:05 +0000 Subject: [PATCH] Feeds: Ensure that galleries can be output as a list of links in feeds. Adjusts the gallery shortcode handler to check for the `link` attribute when outputting to a feed. Fixes #22101. Props ifrins, mdgl, SergeyBiryukov, chriscct7, stevenkword, iworks, DrewAPicture, birgire, whyisjake. git-svn-id: https://develop.svn.wordpress.org/trunk@48496 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/media.php | 11 ++++++++++- tests/phpunit/tests/media.php | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/media.php b/src/wp-includes/media.php index 4f1eed831f..c25ac99ed9 100644 --- a/src/wp-includes/media.php +++ b/src/wp-includes/media.php @@ -2250,7 +2250,16 @@ function gallery_shortcode( $attr ) { if ( is_feed() ) { $output = "\n"; foreach ( $attachments as $att_id => $attachment ) { - $output .= wp_get_attachment_link( $att_id, $atts['size'], true ) . "\n"; + if ( ! empty( $atts['link'] ) ) { + if ( 'none' === $atts['link'] ) { + $output .= wp_get_attachment_image( $att_id, $atts['size'], false, $attr ); + } else { + $output .= wp_get_attachment_link( $att_id, $atts['size'], false ); + } + } else { + $output .= wp_get_attachment_link( $att_id, $atts['size'], true ); + } + $output .= "\n"; } return $output; } diff --git a/tests/phpunit/tests/media.php b/tests/phpunit/tests/media.php index 14794a90e1..e5fd11dadc 100644 --- a/tests/phpunit/tests/media.php +++ b/tests/phpunit/tests/media.php @@ -2946,6 +2946,41 @@ EOF; $this->assertTrue( wp_image_file_matches_image_meta( $image_src, $image_meta ) ); } + + /** + * @ticket 22101 + */ + function test_gallery_shortcode_when_is_feed_true() { + + $this->go_to( '/?feed=rss2' ); + + // Default: Links to image attachment page url + $actual = gallery_shortcode( + array( + 'ids' => self::$large_id, + ) + ); + $this->assertContains( '?attachment_id=', $actual ); + + // File: Links to image file url + $actual = gallery_shortcode( + array( + 'ids' => self::$large_id, + 'link' => 'file', + ) + ); + $this->assertTrue( 2 === substr_count( $actual, '.jpg' ) ); + + // None: Does not link + $actual = gallery_shortcode( + array( + 'ids' => self::$large_id, + 'link' => 'none', + ) + ); + $this->assertFalse( strpos( $actual, '