Make WordPress Core

Changeset 48496


Ignore:
Timestamp:
07/16/2020 09:29:05 PM (4 years ago)
Author:
whyisjake
Message:

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.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/media.php

    r48454 r48496  
    22512251        $output = "\n";
    22522252        foreach ( $attachments as $att_id => $attachment ) {
    2253             $output .= wp_get_attachment_link( $att_id, $atts['size'], true ) . "\n";
     2253            if ( ! empty( $atts['link'] ) ) {
     2254                if ( 'none' === $atts['link'] ) {
     2255                    $output .= wp_get_attachment_image( $att_id, $atts['size'], false, $attr );
     2256                } else {
     2257                    $output .= wp_get_attachment_link( $att_id, $atts['size'], false );
     2258                }
     2259            } else {
     2260                $output .= wp_get_attachment_link( $att_id, $atts['size'], true );
     2261            }
     2262            $output .= "\n";
    22542263        }
    22552264        return $output;
  • trunk/tests/phpunit/tests/media.php

    r48454 r48496  
    29472947        $this->assertTrue( wp_image_file_matches_image_meta( $image_src, $image_meta ) );
    29482948    }
     2949
     2950        /**
     2951         * @ticket 22101
     2952         */
     2953    function test_gallery_shortcode_when_is_feed_true() {
     2954
     2955        $this->go_to( '/?feed=rss2' );
     2956
     2957        // Default: Links to image attachment page url
     2958        $actual = gallery_shortcode(
     2959            array(
     2960                'ids' => self::$large_id,
     2961            )
     2962        );
     2963        $this->assertContains( '?attachment_id=', $actual );
     2964
     2965        // File: Links to image file url
     2966        $actual = gallery_shortcode(
     2967            array(
     2968                'ids'  => self::$large_id,
     2969                'link' => 'file',
     2970            )
     2971        );
     2972        $this->assertTrue( 2 === substr_count( $actual, '.jpg' ) );
     2973
     2974        // None: Does not link
     2975        $actual = gallery_shortcode(
     2976            array(
     2977                'ids'  => self::$large_id,
     2978                'link' => 'none',
     2979            )
     2980        );
     2981        $this->assertFalse( strpos( $actual, '<a ' ) );
     2982    }
     2983
    29492984}
    29502985
Note: See TracChangeset for help on using the changeset viewer.