Make WordPress Core


Ignore:
Timestamp:
02/17/2017 06:45:31 AM (9 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.
Fixes #39277, #39304.

File:
1 edited

Legend:

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

    r39638 r40070  
    36823682                                $srcs = array();
    36833683
     3684                                $shortcode_attrs = shortcode_parse_atts( $shortcode[3] );
     3685                                if ( ! is_array( $shortcode_attrs ) ) {
     3686                                        $shortcode_attrs = array();
     3687                                }
     3688
     3689                                // Specify the post id of the gallery we're viewing if the shortcode doesn't reference another post already.
     3690                                if ( ! isset( $shortcode_attrs['id'] ) ) {
     3691                                        $shortcode[3] .= ' id="' . intval( $post->ID ) . '"';
     3692                                }
     3693
    36843694                                $gallery = do_shortcode_tag( $shortcode );
    36853695                                if ( $html ) {
     
    36883698                                        preg_match_all( '#src=([\'"])(.+?)\1#is', $gallery, $src, PREG_SET_ORDER );
    36893699                                        if ( ! empty( $src ) ) {
    3690                                                 foreach ( $src as $s )
     3700                                                foreach ( $src as $s ) {
    36913701                                                        $srcs[] = $s[2];
     3702                                                }
    36923703                                        }
    36933704
    3694                                         $data = shortcode_parse_atts( $shortcode[3] );
    3695                                         $data['src'] = array_values( array_unique( $srcs ) );
    3696                                         $galleries[] = $data;
     3705                                        $galleries[] = array_merge(
     3706                                                $shortcode_attrs,
     3707                                                array(
     3708                                                        'src' => array_values( array_unique( $srcs ) )
     3709                                                )
     3710                                        );
    36973711                                }
    36983712                        }
Note: See TracChangeset for help on using the changeset viewer.