Skip to:

Opened 2 years ago

Closed 2 years ago

#8641 closed defect (bug) (fixed)

Post thumbnail can never be fetched inside BP_Blogs_Blog::get_blog_extras()

Reported by: boonebgorges's profile boonebgorges Owned by: imath's profile imath
Milestone: 11.0.0 Priority: normal
Severity: normal Version:
Component: Blogs Keywords: has-patch commit


In #4570 [6472], some logic was introduced to BP_Blogs_Blog::get_blog_extras() that fetches post thumbnails for use in the loop. It uses get_post_thumbnail_id() and has_post_thumbnail(). However, these are always used in the scope of the root blog, so they always reference the root blog and never the correct blog.

In order to work, they need to be moved inside of a switch_to_blog() block.

Perhaps additionally, it ought to be possible to disable this fetching. I've never used these images (never knew they were supposed to be there until today!!), and I'd prefer to avoid the queries. Perhaps we can have a filter bp_blogs_fetch_latest_post_thumbnails or something like that.

Attachments (1)

8641.diff (3.5 KB) - added by boonebgorges 2 years ago.

Download all attachments as: .zip

Change History (6)

#1 @imath
2 years ago

  • Keywords needs-patch added
  • Milestone changed from Awaiting Review to 11.0.0


Thanks for your suggestions @boonebgorges I agree we need to fetch the right post thumbnails and introduce such a filter to disable the extra query

2 years ago

#2 @boonebgorges
2 years ago

  • Keywords has-patch needs-testing added; dev-feedback needs-patch removed

Thanks, @imath. This bug has been in BP so long, I had to squint to see whether I was misunderstanding it. My suggested approach is in 8641.diff

#3 @imath
2 years ago

Thanks for the patch @boonebgorges It looks nice after a first sight, I'll test it asap. I can imagine the code is there for quite a long time, there's not many brackets used into the conditions 😁

#4 @imath
2 years ago

  • Keywords commit added; needs-testing removed

Just tested the patch, I confirm it's fixing the issue, thanks again for your patch. I'm going to commit it asap.

#5 @imath
2 years ago

  • Owner set to imath
  • Resolution set to fixed
  • Status changed from new to closed

In 13307:

Blogs: improve the way post featured image are fetched in blogs loop

  1. Make sure to switch blog before using has_post_thumbnail() so that post featured image about sub blogs are fetched.
  2. Introduce the bp_blogs_fetch_latest_post_thumbnails filter to let advanced users skip queries about these post featured images by returning false.

Props boonebgorges

Fixes #8641

Note: See TracTickets for help on using tickets.