Skip to content

Commit

Permalink
Carousel: ensure a post is an attachment (#25400)
Browse files Browse the repository at this point in the history
Co-authored-by: Brandon Kraft <[email protected]>
Co-authored-by: Samiff <[email protected]>
  • Loading branch information
3 people authored Aug 9, 2022
1 parent ad9dfcb commit 3f8ec78
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
4 changes: 4 additions & 0 deletions projects/plugins/jetpack/changelog/update-iterable-carousel
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: bugfix

Carousel: resolve a PHP warning when non-attachments are processed.
11 changes: 11 additions & 0 deletions projects/plugins/jetpack/modules/carousel/jetpack-carousel.php
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,17 @@ class_exists( 'Jetpack_AMP_Support' )
);

foreach ( $attachments as $attachment ) {
/*
* If the item from get_posts isn't an attachment, skip. This can occur when copy-pasta from another WP site.
* For example, if one copies "<img class="wp-image-7 size-full" src="https://twentysixteendemo.files.wordpress.com/2015/11/post.png" alt="post" width="1000" height="563" />"
* then, we're going to look up post 7 below, which making sure it is an attachment.
*
* This is meant as a relatively quick fix, as a better fix is likely to update the get_posts call above to only
* include attachments.
*/
if ( ! isset( $attachment->ID ) || ! wp_attachment_is_image( $attachment->ID ) ) {
continue;
}
$image_elements = $selected_images[ $attachment->ID ];

$attributes = $this->add_data_to_images( array(), $attachment );
Expand Down

0 comments on commit 3f8ec78

Please sign in to comment.