$post =
get_post( $post );
if ( !
$post ) { return array
();
} if ( !
has_shortcode( $post->post_content, 'gallery'
) && !
has_block( 'gallery',
$post->post_content
) ) { 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
();
} // Specify the post ID of the gallery we're viewing if the shortcode doesn't reference another post already.
if ( !
isset( $shortcode_attrs['id'
] ) ) {