WordPress.org

Make WordPress Core

Opened 6 months ago

Closed 6 months ago

#49751 closed defect (bug) (invalid)

Old Featured Images (Thumbnails) Broken in 5.4

Reported by: ispreview Owned by:
Milestone: Priority: normal
Severity: major Version: 5.4
Component: Post Thumbnails Keywords:
Focuses: Cc:

Description

This is a follow-up to #40096.

The change introduced above has caused older Featured Article Images to appear blank (the HTML IMG code doesn't even render into the page - there's no code at all), such as any posted from a gallery in the 'NextGen Gallery' plugin before at least v2 (including the NextCellent Gallery fork that was also based off the older v1.9 series of NextGen). All of these share the same broad database structure, which has allowed people to upgrade over the years.

None of this seems to affect featured images posted more recently from a gallery under the modern NextGen Gallery plugin, but people may only realise later if their older featured images no longer display on articles (they'd need to check their archives). Simply using the latest version of NextGen does not solve this as the WP code change is the one that directly breaks the older featured images.

For example:

OLD Featured Image Code that no longer exists after WP5.4 (it's just blank / gone):

<img src="https://.../wp-content/gallery/2019-nextgen/thumbs/EXAMPLE.jpg" alt="EXAMPLE" title="2019-nextgen" class="wp-post-image ngg-image-792 ">

NEW Featured Image Code that still exists and works under WP5.4:

<img src="https://.../wp-content/uploads/EXAMPLE2.jpg" class="attachment-thumbnail size-thumbnail wp-post-image" alt="" width="600" height="600">

I can "fix" this by changing the #40096 code in wp-includes/post-thumbnail-template.php back to what it was in WP5.3, which means replacing the WP5.4 line with this 5.3 line but that is obviously far from ideal:

return get_post_meta( $post->ID, '_thumbnail_id', true );

I am posting this here because neither the NextCellent nor older NextGen Gallery code/plugins are supported anymore, but the issue is that many sites will have historically posted several years worth of affected posts with now blank featured images that they can't resolve (ours run between 2012 and 2019 - impacting tens of thousands of articles).

Many other sites will be affected by this and probably just haven't noticed yet. I only spotted it because we moved to NextGen Gallery from NextCellent Gallery last year. I'm not sure what the WordPress team can do here but it does need to be highlighted as others will come across this with time.

Change History (14)

#1 follow-up: @joemcgill
6 months ago

Hi @ispreview, thank you for the report. Can you provide more info about what you mean by "OLD Featured Image Code"? Could you provide some example code about how those featured images were being generated?

This ticket was mentioned in Slack in #core-media by joemcgill. View the logs.


6 months ago

#3 in reply to: ↑ 1 @ispreview
6 months ago

Replying to joemcgill:

Hi @ispreview, thank you for the report. Can you provide more info about what you mean by "OLD Featured Image Code"? Could you provide some example code about how those featured images were being generated?


Sure. I meant the HTML code above, but that HTML is generally output when you make the fairly common thumbnail / featured image requests in the template, such as:

<?php the_post_thumbnail('thumbnail'); ?>

and

<?php the_post_thumbnail('single-post-thumbnail'); ?>

As I say, any featured images added to a post from a recent NextGen Gallery install will show the HTML output from those just fine, but since the thumbnail code change in WP5.4 all images originally added in this way under older gallery plugins like NextGen Gallery pre-v2 or NextCellent Gallery, don't output any HTML code at all and so no images are displayed.

PS - I'm on PHP7.4.

Last edited 6 months ago by ispreview (previous) (diff)

This ticket was mentioned in Slack in #core by azaozz. View the logs.


6 months ago

#5 @SergeyBiryukov
6 months ago

  • Milestone changed from Awaiting Review to 5.4.1

Moving for investigation.

This ticket was mentioned in Slack in #core-media by pbiron. View the logs.


6 months ago

This ticket was mentioned in Slack in #forums by ipstenu. View the logs.


6 months ago

#8 @JeffPaul
6 months ago

I've setup a WP 5.3 install with NextGen Gallery 1.9 and the general settings as noted from Site Health below, but am unable to duplicate this issue. All featured images I've tested setting up follow the structure of

http://test.local/wp-content/uploads/2020/04/testimage.jpg

so getting some more details on the setup that's causing this issue will help us better triage. That said, are your aware of NextGen Gallery or other plugins relying on get_post_thumbnail_id returning a string instead of the new integer?

### wp-core ###

version: 5.3
permalink: /%postname%/
https_status: false
multisite: false

### wp-active-theme ###

name: Twenty Twenty (twentytwenty)
version: 1.2

### wp-plugins-active (2) ###

Classic Editor: version: 1.5, author: WordPress Contributors
NextGEN Gallery: version: 1.9.0, author: Alex Rabe (latest version: 3.3.0)

### wp-media ###

image_editor: WP_Image_Editor_GD
imagick_module_version: Not available
imagemagick_version: Not available
gd_version: bundled (2.1.0 compatible)
ghostscript_version: not available

### wp-server ###

server_architecture: Darwin 19.3.0 x86_64
httpd_software: nginx/1.16.0
php_version: 7.3.5 64bit
php_sapi: fpm-fcgi
max_input_variables: 4000
time_limit: 1200
memory_limit: 256M
max_input_time: 600
upload_max_size: 300M
php_post_max_size: 1000M
curl_version: 7.54.0 LibreSSL/2.6.5
suhosin: false
imagick_availability: false

### wp-database ###

extension: mysqli
server_version: 8.0.16
client_version: mysqlnd 5.0.12-dev - 20150407 - $Id: 7cc7cc96e675f6d72e5cf0f267f48e167c2abb23 $

### wp-constants ###

WP_HOME: undefined
WP_SITEURL: undefined
WP_MAX_MEMORY_LIMIT: 256M
WP_DEBUG: false
WP_DEBUG_DISPLAY: true
WP_DEBUG_LOG: false
SCRIPT_DEBUG: false
WP_CACHE: false
CONCATENATE_SCRIPTS: undefined
COMPRESS_SCRIPTS: undefined
COMPRESS_CSS: undefined
WP_LOCAL_DEV: undefined
DB_CHARSET: utf8
DB_COLLATE: undefined

### wp-filesystem ###

wordpress: writable
wp-content: writable
uploads: writable
plugins: writable
themes: writable

#9 @ispreview
6 months ago

@JeffPaul. The problem for me only shows with WP5.4, not WP5.3 where it works fine.

It might help if I give some extra feedback from my own testing and history of gallery plugins (all use the same database structure so you can move between then):

NextGen Gallery pre v2 (2012-2013) - featured image / thumbnails on posts for these all blank since WP5.4

NextGen Gallery v2+ (2013 - 2014) - featured image / thumbnails on posts for these work normally

NextCellent Gallery (2014 - 2019) - featured image / thumbnails on posts for these all blank since WP5.4

NextGen Gallery v3+ (2019 - Present) - featured image / thumbnails on posts for these work normally

NOTE: With NextGen Gallery pre-v2 and NextCellent I generally used custom gallery folders, while since adopting the latest NextGen Gallery it seems to follow the more standard WordPress default. I'm not sure if this is related to the issue.

I'd be interested to know if you're able to recreate the issue using NextCellent rather than just the old NextGen release. You can try this by making a new gallery when under WP5.3, adding a .JPG image to it, then going to make a new post, click 'Add Image' button at the top (I'm using the Classic Editor in WP), clicking 'NextGen Gallery', select a gallery, choose an image and then click the "Use as featured image" link.

After this it might be a good idea to upgrade the NextGen gallery test from v1.9 to the latest release, then deactivate NextCellent and switch back to NextGen (closest way I can think of to simulate the environment as closely as possible). Assuming all is still working, then try upgrading to WP5.4 and see if you observe the same issue.

https://wordpress.org/plugins/nextcellent-gallery-nextgen-legacy/

Otherwise I can make my private beta test install available in secret to see the issue first hand, if somebody tells me a secure way to do this? I'd rather not post that in public for obvious reasons.

PS - Forgot to mention, as well as being on PHP7.4 I'm also on MySQL 5.7.

Last edited 6 months ago by ispreview (previous) (diff)

#10 @ispreview
6 months ago

I don't know if this helps, but during testing I went back to some of my very earliest posts from 2012 and opened one of them to Edit. I noticed in the 'Feature image' preview box (bottom right in classic editor) that the image wasn't rendered (it's the same on all of the affected posts). I uploaded a picture of what I mean by this here:

http://www.mjon.co.uk/images/featured_image_missing.jpg

No idea what version of NextGen Gallery was being used back then, but I guess it's whatever was the latest release at the time. I also decided to extract the HTML source code from that specific preview so you could see it (domain redacted):

OLD Featured Image Preview Box Code

<div class="inside">
<p class="hide-if-no-js"><a title="Set featured image" href="https://THEDOMAIN/wp-admin/media-upload.php?post_id=304&amp;type=image&amp;TB_iframe=1&amp;width=753&amp;height=941" id="set-post-thumbnail" class="thickbox"><img src="https://THEDOMAIN/index.php?callback=image&amp;pid=669&amp;width=&amp;height=&amp;mode=crop" alt="o2 uk" title="o2 uk" width="266"></a></p><p class="hide-if-no-js"><a href="#" id="remove-post-thumbnail" onclick="WPRemoveThumbnail('de085490c5');return false;">Remove featured image</a></p></div>

..and then as an experiment I went to re-add the exact same feature image, albeit using the modern NextGen Gallery plugin, which produced this HTML code for the same preview box:

<div class="inside">
<p class="hide-if-no-js"><a href="https://THEDOMAIN/wp-admin/media-upload.php?post_id=304&amp;type=image&amp;TB_iframe=1" id="set-post-thumbnail" aria-describedby="set-post-thumbnail-desc" class="thickbox"><img src="https://THEDOMAIN/wp-content/uploads/o2_uk-600x600.gif" class="attachment-266x266 size-266x266" alt="" srcset="https://THEDOMAIN/wp-content/uploads/o2_uk-600x600.gif 600w, https://THEDOMAIN/wp-content/uploads/o2_uk-800x800.gif 800w, https://THEDOMAIN/wp-content/uploads/o2_uk-768x768.gif 768w" sizes="(max-width: 266px) 100vw, 266px" width="266" height="266"></a></p><p class="hide-if-no-js howto" id="set-post-thumbnail-desc">Click the image to edit or update</p><p class="hide-if-no-js"><a href="#" id="remove-post-thumbnail">Remove featured image</a></p><input type="hidden" id="_thumbnail_id" name="_thumbnail_id" value="21846"></div>

#11 @ispreview
6 months ago

Spent the afternoon looking deeper into this and found a possible cause. Older 'Featured images' from very old versions of NextGen/NextCellent Gallery and WP releases seem to have a different ID format.

For example, when looking at one of my older posts under the "postmeta" table in MySQL (old NextGen Gallery system from 2012) I see that the "_thumbnail_id" field gives a record like "ngg-547", which correctly corresponds to the ID number of the image itself in the gallery.

However, if I re-add the same 'Feature image' to that same old post via the current NextGen Gallery and WP5.4 release, then the _thumbnail_id changes to being entirely numeric and a number that is not the same as the original image ID - "21848".

My guess is that WP or NextGen changed how they handled images at some point in the past and this has been exposed by the WP5.4 code change at the root of this. Preference would be to revert the WP5.4 change in wp-includes/post-thumbnail-template.php back to WP5.3 or find another solution, one which doesn't involve manually updating tens of thousands of articles :).

#12 follow-up: @whyisjake
6 months ago

It sounds like this is a plugin issue, not directly related to core changes. I am thinking we can bump from the 5.4.1 milestone and close with invalid.

#13 in reply to: ↑ 12 @ispreview
6 months ago

Replying to whyisjake:

It sounds like this is a plugin issue, not directly related to core changes. I am thinking we can bump from the 5.4.1 milestone and close with invalid.

It is indeed, much as I said earlier, but the issue here is that it's from quite a popular set of image plugins that are no longer supported (at least the way images were handled back then isn't supported anymore with WP5.4's change). Featured images have broken for tens of thousands of articles over many years, so I was just hoping there might be a better solution than to ignore the backwards compatibility issues created.

#14 @whyisjake
6 months ago

  • Milestone 5.4.1 deleted
  • Resolution set to invalid
  • Status changed from new to closed

Yeah, I would reach out the folks of NextGen to see if there is a way they could bring some changes to help support that change into their plugin.

Note: See TracTickets for help on using tickets.