Index: src/wp-includes/media.php
===================================================================
--- src/wp-includes/media.php	(リビジョン 43862)
+++ src/wp-includes/media.php	(作業コピー)
@@ -3765,42 +3765,65 @@
 	if ( ! $post = get_post( $post ) )
 		return array();
 
-	if ( ! has_shortcode( $post->post_content, 'gallery' ) )
-		return array();
-
 	$galleries = array();
-	if ( preg_match_all( '/' . get_shortcode_regex() . '/s', $post->post_content, $matches, PREG_SET_ORDER ) ) {
-		foreach ( $matches as $shortcode ) {
-			if ( 'gallery' === $shortcode[2] ) {
-				$srcs = array();
-
-				$shortcode_attrs = shortcode_parse_atts( $shortcode[3] );
-				if ( ! is_array( $shortcode_attrs ) ) {
-					$shortcode_attrs = array();
+	
+	// For backward compatibility, check shortcode.
+	if ( has_shortcode( $post->post_content, 'gallery' ) ) {
+		if ( preg_match_all( '/' . get_shortcode_regex() . '/s', $post->post_content, $matches, PREG_SET_ORDER ) ) {
+			foreach ( $matches as $shortcode ) {
+				if ( 'gallery' === $shortcode[2] ) {
+					$srcs = array();
+					
+					$shortcode_attrs = shortcode_parse_atts( $shortcode[3] );
+					if ( ! is_array( $shortcode_attrs ) ) {
+						$shortcode_attrs = array();
+					}
+					
+					// Specify the post id of the gallery we're viewing if the shortcode doesn't reference another post already.
+					if ( ! isset( $shortcode_attrs['id'] ) ) {
+						$shortcode[3] .= ' id="' . intval( $post->ID ) . '"';
+					}
+					
+					$gallery = do_shortcode_tag( $shortcode );
+					if ( $html ) {
+						$galleries[] = $gallery;
+					} else {
+						preg_match_all( '#src=([\'"])(.+?)\1#is', $gallery, $src, PREG_SET_ORDER );
+						if ( ! empty( $src ) ) {
+							foreach ( $src as $s ) {
+								$srcs[] = $s[2];
+							}
+						}
+						
+						$galleries[] = array_merge(
+							$shortcode_attrs,
+							array(
+								'src' => array_values( array_unique( $srcs ) )
+							)
+						);
+					}
 				}
-
-				// Specify the post id of the gallery we're viewing if the shortcode doesn't reference another post already.
-				if ( ! isset( $shortcode_attrs['id'] ) ) {
-					$shortcode[3] .= ' id="' . intval( $post->ID ) . '"';
-				}
-
-				$gallery = do_shortcode_tag( $shortcode );
+			}
+		}
+	}
+	
+	// Check gutenberg gallery block.
+	if ( false !== strpos( $post->post_content, '<!-- wp:gallery' ) ) {
+		if ( preg_match_all( '/<!-- wp:gallery([^>]*)-->(.*?)<!-- \/wp:gallery -->/s', $post->post_content, $blocks, PREG_SET_ORDER ) ) {
+			foreach ( $blocks as $block ) {
 				if ( $html ) {
-					$galleries[] = $gallery;
+					$galleries[] = $block[2];
 				} else {
-					preg_match_all( '#src=([\'"])(.+?)\1#is', $gallery, $src, PREG_SET_ORDER );
-					if ( ! empty( $src ) ) {
-						foreach ( $src as $s ) {
-							$srcs[] = $s[2];
-						}
+					$attributes = (array) json_decode( trim( $block[1] ), true );
+					$src = array();
+					if ( preg_match_all( '/src="([^"]+)"/s', $block[2], $imgs ) ) {
+						$src = $imgs[1];
+						$src = array_unique( $src );
 					}
-
-					$galleries[] = array_merge(
-						$shortcode_attrs,
-						array(
-							'src' => array_values( array_unique( $srcs ) )
-						)
-					);
+					if ( $src ) {
+						$attributes['src'] = $src;
+						$galleries[] = $attributes;
+					}
 				}
 			}
 		}
