/wp-content/plugins/recent-posts-widget-with-thumbnails/recent-posts-widget-with-thumbnails.php:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
/** * Returns the id of the first image on gallery in the content, else 0 * * @access private * @since 6.5.0, 2019-06-01 * * @return integer the post id of the first content image */ function get_first_gallery_image_id() { $post = get_post(); $content = $post->post_content; if (!preg_match('/\[gallery\s+[^\]]*ids=.*?"([0-9,]+).*?"[^\]]*\]/', $content, $matches)) { return 0; } $ids = explode(',', $matches[1]); return $ids[0]; } /** * Echoes the thumbnail of first post's image and returns success * * @access private * @since 2.0 * * @return bool success on finding an image */ private function the_first_post_image () { // look for first image $thumb_id = $this->get_first_content_image_id(); // if there is first image then show first image if ( $thumb_id ) : echo wp_get_attachment_image( $thumb_id, $this->customs[ 'thumb_dimensions' ] ); return true; else : $thumb_id = $this->get_first_gallery_image_id(); if ( $thumb_id ) : echo wp_get_attachment_image( $thumb_id, $this->customs[ 'thumb_dimensions' ] ); return true; else : return false; endif; endif; // thumb_id } |