Make WordPress Core


Ignore:
Timestamp:
02/17/2017 06:46:45 AM (8 years ago)
Author:
dd32
Message:

Media: Avoid PHP Warnings in get_post_galleries() when processing empty [gallery] shortcodes and avoid returning the incorrect results when the global $post does not match the provided post ID.

Props dd32, joemcgill, seanchayes.
Merges [40070] to the 4.7 branch.
Fixes #39277, #39304.

Location:
branches/4.7
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/4.7

  • branches/4.7/src/wp-includes/media.php

    r39654 r40071  
    36803680                $srcs = array();
    36813681
     3682                $shortcode_attrs = shortcode_parse_atts( $shortcode[3] );
     3683                if ( ! is_array( $shortcode_attrs ) ) {
     3684                    $shortcode_attrs = array();
     3685                }
     3686
     3687                // Specify the post id of the gallery we're viewing if the shortcode doesn't reference another post already.
     3688                if ( ! isset( $shortcode_attrs['id'] ) ) {
     3689                    $shortcode[3] .= ' id="' . intval( $post->ID ) . '"';
     3690                }
     3691
    36823692                $gallery = do_shortcode_tag( $shortcode );
    36833693                if ( $html ) {
     
    36863696                    preg_match_all( '#src=([\'"])(.+?)\1#is', $gallery, $src, PREG_SET_ORDER );
    36873697                    if ( ! empty( $src ) ) {
    3688                         foreach ( $src as $s )
     3698                        foreach ( $src as $s ) {
    36893699                            $srcs[] = $s[2];
     3700                        }
    36903701                    }
    36913702
    3692                     $data = shortcode_parse_atts( $shortcode[3] );
    3693                     $data['src'] = array_values( array_unique( $srcs ) );
    3694                     $galleries[] = $data;
     3703                    $galleries[] = array_merge(
     3704                        $shortcode_attrs,
     3705                        array(
     3706                            'src' => array_values( array_unique( $srcs ) )
     3707                        )
     3708                    );
    36953709                }
    36963710            }
Note: See TracChangeset for help on using the changeset viewer.