3772 | | if ( preg_match_all( '/' . get_shortcode_regex() . '/s', $post->post_content, $matches, PREG_SET_ORDER ) ) { |
3773 | | foreach ( $matches as $shortcode ) { |
3774 | | if ( 'gallery' === $shortcode[2] ) { |
3775 | | $srcs = array(); |
3776 | | |
3777 | | $shortcode_attrs = shortcode_parse_atts( $shortcode[3] ); |
3778 | | if ( ! is_array( $shortcode_attrs ) ) { |
3779 | | $shortcode_attrs = array(); |
| 3769 | |
| 3770 | // For backward compatibility, check shortcode. |
| 3771 | if ( has_shortcode( $post->post_content, 'gallery' ) ) { |
| 3772 | if ( preg_match_all( '/' . get_shortcode_regex() . '/s', $post->post_content, $matches, PREG_SET_ORDER ) ) { |
| 3773 | foreach ( $matches as $shortcode ) { |
| 3774 | if ( 'gallery' === $shortcode[2] ) { |
| 3775 | $srcs = array(); |
| 3776 | |
| 3777 | $shortcode_attrs = shortcode_parse_atts( $shortcode[3] ); |
| 3778 | if ( ! is_array( $shortcode_attrs ) ) { |
| 3779 | $shortcode_attrs = array(); |
| 3780 | } |
| 3781 | |
| 3782 | // Specify the post id of the gallery we're viewing if the shortcode doesn't reference another post already. |
| 3783 | if ( ! isset( $shortcode_attrs['id'] ) ) { |
| 3784 | $shortcode[3] .= ' id="' . intval( $post->ID ) . '"'; |
| 3785 | } |
| 3786 | |
| 3787 | $gallery = do_shortcode_tag( $shortcode ); |
| 3788 | if ( $html ) { |
| 3789 | $galleries[] = $gallery; |
| 3790 | } else { |
| 3791 | preg_match_all( '#src=([\'"])(.+?)\1#is', $gallery, $src, PREG_SET_ORDER ); |
| 3792 | if ( ! empty( $src ) ) { |
| 3793 | foreach ( $src as $s ) { |
| 3794 | $srcs[] = $s[2]; |
| 3795 | } |
| 3796 | } |
| 3797 | |
| 3798 | $galleries[] = array_merge( |
| 3799 | $shortcode_attrs, |
| 3800 | array( |
| 3801 | 'src' => array_values( array_unique( $srcs ) ) |
| 3802 | ) |
| 3803 | ); |
| 3804 | } |
3781 | | |
3782 | | // Specify the post id of the gallery we're viewing if the shortcode doesn't reference another post already. |
3783 | | if ( ! isset( $shortcode_attrs['id'] ) ) { |
3784 | | $shortcode[3] .= ' id="' . intval( $post->ID ) . '"'; |
3785 | | } |
3786 | | |
3787 | | $gallery = do_shortcode_tag( $shortcode ); |
| 3806 | } |
| 3807 | } |
| 3808 | } |
| 3809 | |
| 3810 | // Check gutenberg gallery block. |
| 3811 | if ( false !== strpos( $post->post_content, '<!-- wp:gallery' ) ) { |
| 3812 | if ( preg_match_all( '/<!-- wp:gallery([^>]*)-->(.*?)<!-- \/wp:gallery -->/s', $post->post_content, $blocks, PREG_SET_ORDER ) ) { |
| 3813 | foreach ( $blocks as $block ) { |