mirror of
https://github.com/WordPress/WordPress.git
synced 2025-02-16 11:35:48 +00:00
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:
parent
c50113dc8d
commit
30cb64a011
@ -3681,19 +3681,33 @@ function get_post_galleries( $post, $html = true ) {
|
|||||||
if ( 'gallery' === $shortcode[2] ) {
|
if ( 'gallery' === $shortcode[2] ) {
|
||||||
$srcs = array();
|
$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 );
|
$gallery = do_shortcode_tag( $shortcode );
|
||||||
if ( $html ) {
|
if ( $html ) {
|
||||||
$galleries[] = $gallery;
|
$galleries[] = $gallery;
|
||||||
} else {
|
} else {
|
||||||
preg_match_all( '#src=([\'"])(.+?)\1#is', $gallery, $src, PREG_SET_ORDER );
|
preg_match_all( '#src=([\'"])(.+?)\1#is', $gallery, $src, PREG_SET_ORDER );
|
||||||
if ( ! empty( $src ) ) {
|
if ( ! empty( $src ) ) {
|
||||||
foreach ( $src as $s )
|
foreach ( $src as $s ) {
|
||||||
$srcs[] = $s[2];
|
$srcs[] = $s[2];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$data = shortcode_parse_atts( $shortcode[3] );
|
$galleries[] = array_merge(
|
||||||
$data['src'] = array_values( array_unique( $srcs ) );
|
$shortcode_attrs,
|
||||||
$galleries[] = $data;
|
array(
|
||||||
|
'src' => array_values( array_unique( $srcs ) )
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @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.
|
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user