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.

Built from https://develop.svn.wordpress.org/trunk@40070


git-svn-id: http://core.svn.wordpress.org/trunk@40007 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Dion Hulse 2017-02-17 06:46:42 +00:00
parent c50113dc8d
commit 30cb64a011
2 changed files with 19 additions and 5 deletions

View File

@ -3681,19 +3681,33 @@ function get_post_galleries( $post, $html = true ) {
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 )
foreach ( $src as $s ) {
$srcs[] = $s[2];
}
}
$data = shortcode_parse_atts( $shortcode[3] );
$data['src'] = array_values( array_unique( $srcs ) );
$galleries[] = $data;
$galleries[] = array_merge(
$shortcode_attrs,
array(
'src' => array_values( array_unique( $srcs ) )
)
);
}
}
}

View File

@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '4.8-alpha-40068';
$wp_version = '4.8-alpha-40070';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.