Make WordPress Core

Ticket #39304: 39304.diff

File 39304.diff, 1.9 KB (added by dd32, 8 years ago)

Hacky-ish approach, but also includes a fix for #39277

  • src/wp-includes/media.php

    function get_media_embedded_in_content(  
    36673667 *               from the expanded shortcode.
    36683668 */
    36693669function get_post_galleries( $post, $html = true ) {
    36703670        if ( ! $post = get_post( $post ) )
    36713671                return array();
    36723672
    36733673        if ( ! has_shortcode( $post->post_content, 'gallery' ) )
    36743674                return array();
    36753675
    36763676        $galleries = array();
    36773677        if ( preg_match_all( '/' . get_shortcode_regex() . '/s', $post->post_content, $matches, PREG_SET_ORDER ) ) {
    36783678                foreach ( $matches as $shortcode ) {
    36793679                        if ( 'gallery' === $shortcode[2] ) {
    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                                // force-specify the post id of the gallery we want to view.
     3688                                if ( empty( $shortcode_atts['id'] ) ) {
     3689                                        $shortcode[3] .= ' id="' . $post->ID . '"';
     3690                                }
     3691
    36823692                                $gallery = do_shortcode_tag( $shortcode );
    36833693                                if ( $html ) {
    36843694                                        $galleries[] = $gallery;
    36853695                                } else {
    36863696                                        preg_match_all( '#src=([\'"])(.+?)\1#is', $gallery, $src, PREG_SET_ORDER );
    36873697                                        if ( ! empty( $src ) ) {
    36883698                                                foreach ( $src as $s )
    36893699                                                        $srcs[] = $s[2];
    36903700                                        }
    36913701
    3692                                         $data = shortcode_parse_atts( $shortcode[3] );
    3693                                         $data['src'] = array_values( array_unique( $srcs ) );
    3694                                         $galleries[] = $data;
     3702                                        $shortcode_attrs['src'] = array_values( array_unique( $srcs ) );
     3703                                        $galleries[] = $shortcode_attrs;
    36953704                                }
    36963705                        }
    36973706                }
    36983707        }
    36993708
    37003709        /**
    37013710         * Filters the list of all found galleries in the given post.
    37023711         *
    37033712         * @since 3.6.0
    37043713         *
    37053714         * @param array   $galleries Associative array of all found post galleries.
    37063715         * @param WP_Post $post      Post object.
    37073716         */
    37083717        return apply_filters( 'get_post_galleries', $galleries, $post );
    37093718}