Skip to content

Commit e8b869b

Browse files
Joey Kudishdereksmart
Joey Kudish
authored andcommitted
Jetpack Media Summary: prevent a post from returning a type of gallery when it doesn't have any images retrieved in the post.
I discovered that it was possible for a post's media summary to find a gallery but fail to extract the images from it, in which case the type would be gallery but no images would be found. This caused problems for Publicize which, for some services (like Path) expects there to be an image when the type is `gallery`. As a result we tried to send an empty to Path which caused Publicize to fail for that service for the affected posts. This fix makes it so that if no images are extracted, the type is returned as `standard`. I'll see if it's possible to fix the image extraction bug in a separate commit. Merges r111005-wpcom.
1 parent 46ec820 commit e8b869b

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

class.media-summary.php

+5-7
Original file line numberDiff line numberDiff line change
@@ -152,17 +152,15 @@ static function get( $post_id, $blog_id = 0, $args = array() ) {
152152

153153
// If we don't have any prioritized embed...
154154
if ( 'standard' == $return['type'] ) {
155-
if ( !empty( $extract['has']['gallery'] ) || ! empty( $extract['shortcode']['gallery']['count'] ) ) {
155+
if ( ( ! empty( $extract['has']['gallery'] ) || ! empty( $extract['shortcode']['gallery']['count'] ) ) && ! empty( $extract['image'] ) ) {
156156
//... Then we prioritize galleries first (multiple images returned)
157157
$return['type'] = 'gallery';
158-
if ( isset( $extract['image'] ) || ! empty( $extract['image'] ) ) {
159158
$return['images'] = $extract['image'];
160-
foreach ( $return['images'] as $image ) {
161-
$return['secure']['images'][] = array( 'url' => self::ssl_img( $image['url'] ) );
162-
$return['count']['image']++;
163-
}
159+
foreach ( $return['images'] as $image ) {
160+
$return['secure']['images'][] = array( 'url' => self::ssl_img( $image['url'] ) );
161+
$return['count']['image']++;
164162
}
165-
} else if ( !empty( $extract['has']['image'] ) ) {
163+
} else if ( ! empty( $extract['has']['image'] ) ) {
166164
// ... Or we try and select a single image that would make sense
167165
$content = wpautop( strip_tags( $post->post_content ) );
168166
$paragraphs = explode( '</p>', $content );

0 commit comments

Comments
 (0)