Skip to:
Content

BuddyPress.org

Ticket #8641: 8641.diff

File 8641.diff, 3.5 KB (added by boonebgorges, 4 years ago)
  • src/bp-blogs/classes/class-bp-blogs-blog.php

    diff --git src/bp-blogs/classes/class-bp-blogs-blog.php src/bp-blogs/classes/class-bp-blogs-blog.php
    index 38542e82a..a8dc929cb 100644
    class BP_Blogs_Blog { 
    626626                for ( $i = 0, $count = count( $paged_blogs ); $i < $count; ++$i ) {
    627627                        $blog_prefix = $wpdb->get_blog_prefix( $paged_blogs[$i]->blog_id );
    628628                        $paged_blogs[$i]->latest_post = $wpdb->get_row( "SELECT ID, post_content, post_title, post_excerpt, guid FROM {$blog_prefix}posts WHERE post_status = 'publish' AND post_type = 'post' AND id != 1 ORDER BY id DESC LIMIT 1" );
    629                         $images = array();
    630629
    631                         // Add URLs to any Featured Image this post might have.
    632                         if ( ! empty( $paged_blogs[$i]->latest_post ) && has_post_thumbnail( $paged_blogs[$i]->latest_post->ID ) ) {
    633 
    634                                 // Grab 4 sizes of the image. Thumbnail.
    635                                 $image = wp_get_attachment_image_src( get_post_thumbnail_id( $paged_blogs[$i]->latest_post->ID ), 'thumbnail', false );
    636                                 if ( ! empty( $image ) )
    637                                         $images['thumbnail'] = $image[0];
    638 
    639                                 // Medium.
    640                                 $image = wp_get_attachment_image_src( get_post_thumbnail_id( $paged_blogs[$i]->latest_post->ID ), 'medium', false );
    641                                 if ( ! empty( $image ) )
    642                                         $images['medium'] = $image[0];
    643 
    644                                 // Large.
    645                                 $image = wp_get_attachment_image_src( get_post_thumbnail_id( $paged_blogs[$i]->latest_post->ID ), 'large', false );
    646                                 if ( ! empty( $image ) )
    647                                         $images['large'] = $image[0];
    648 
    649                                 // Post thumbnail.
    650                                 $image = wp_get_attachment_image_src( get_post_thumbnail_id( $paged_blogs[$i]->latest_post->ID ), 'post-thumbnail', false );
    651                                 if ( ! empty( $image ) )
    652                                         $images['post-thumbnail'] = $image[0];
    653 
    654                                 // Add the images to the latest_post object.
    655                                 $paged_blogs[$i]->latest_post->images = $images;
     630                        /**
     631                         * Filters whether to fetch Featured Images for the Sites directory.
     632                         *
     633                         * @since 11.0.0
     634                         *
     635                         * @param bool $fetch_featured_images Defaults to true.
     636                         * @param int  $blog_id               ID of the current blog whose extras are being generated.
     637                         */
     638                        if ( apply_filters( 'bp_blogs_fetch_latest_post_thumbnails', true, $paged_blogs[ $i ]->blog_id ) ) {
     639                                $images = array();
     640
     641                                switch_to_blog( $paged_blogs[ $i ]->blog_id );
     642
     643                                // Add URLs to any Featured Image this post might have.
     644                                if ( ! empty( $paged_blogs[$i]->latest_post ) && has_post_thumbnail( $paged_blogs[$i]->latest_post->ID ) ) {
     645
     646                                        // Grab 4 sizes of the image. Thumbnail.
     647                                        $image = wp_get_attachment_image_src( get_post_thumbnail_id( $paged_blogs[$i]->latest_post->ID ), 'thumbnail', false );
     648                                        if ( ! empty( $image ) )
     649                                                $images['thumbnail'] = $image[0];
     650
     651                                        // Medium.
     652                                        $image = wp_get_attachment_image_src( get_post_thumbnail_id( $paged_blogs[$i]->latest_post->ID ), 'medium', false );
     653                                        if ( ! empty( $image ) )
     654                                                $images['medium'] = $image[0];
     655
     656                                        // Large.
     657                                        $image = wp_get_attachment_image_src( get_post_thumbnail_id( $paged_blogs[$i]->latest_post->ID ), 'large', false );
     658                                        if ( ! empty( $image ) )
     659                                                $images['large'] = $image[0];
     660
     661                                        // Post thumbnail.
     662                                        $image = wp_get_attachment_image_src( get_post_thumbnail_id( $paged_blogs[$i]->latest_post->ID ), 'post-thumbnail', false );
     663                                        if ( ! empty( $image ) )
     664                                                $images['post-thumbnail'] = $image[0];
     665
     666                                        // Add the images to the latest_post object.
     667                                        $paged_blogs[$i]->latest_post->images = $images;
     668                                }
     669
     670                                restore_current_blog();
    656671                        }
    657672                }
    658673