Make WordPress Core

Opened 8 years ago

Last modified 7 years ago

#35959 new defect (bug)

Functon 'wp_generate_attachment_metadata(...)' silently swallowing errors from 'wp_get_image_editor(...)'.

Reported by: maratbn's profile maratbn Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 3.5
Component: Media Keywords: has-patch needs-testing
Focuses: Cc:


So the function wp_generate_attachment_metadata(...) in wp-admin/includes/image.php is silently ignoring / swallowing errors from the function wp_get_image_editor(...).

The logic is here:

This ignoring of these particular errors prevents user notification in the UI when image thumbnails could not be regenerated due to error "No editor could be selected" that is returned from the function wp_get_image_editor(...) when the PHP environment on the server is lacking graphics support. So the thumbnails are not getting regenerated, and because of this bug, there is notification to the user as to that fact or as to why.

I looked this up in the history, and noticed that this bug is present since this revision:

What's odd is that this revision does add logic to relay these errors in its 1st change (to the function wp_crop_image(...)) in trunk/wp-admin/includes/image.php, but not in the 3rd change in that file (to the function wp_generate_attachment_metadata(...)). Not sure why the error is not being relayed there as well.

Attachments (2)

2016-02-25--01--patch--relay-editor-error.txt (866 bytes) - added by maratbn 8 years ago.
Attaching patch to mitigate this problem.
35959.patch (2.2 KB) - added by grapplerulrich 7 years ago.

Download all attachments as: .zip

Change History (7)

8 years ago

Attaching patch to mitigate this problem.

#1 @maratbn
8 years ago

Err meant to say "...So the thumbnails are not getting regenerated, and because of this bug, there is NO notification to the user as to that fact or as to why..."

Whoever has the permissions, please insert "no" into that part of the description.

#2 @obenland
8 years ago

  • Version changed from trunk to 3.5

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

7 years ago

#4 @desrosj
7 years ago

  • Keywords has-patch needs-refresh needs-testing added

@maratbn Thanks for the ticket! Are you able to recreate the patch as a .diff or .patch file? See for help.

There are also a few minor style issues in the patch. if statements should always contain braces, and inline control structures are prohibited (See

#5 @grapplerulrich
7 years ago

  • Keywords needs-refresh removed

The attached patch should fix the issue.

I realized this problem with wp media regenerate 892 would not work on PDF. When running wp eval "var_dump(wp_generate_attachment_metadata(892,get_attached_file(892)));" I would get an empty array which did not make sense.

With the patch when I run wp eval "var_dump(wp_generate_attachment_metadata(892,get_attached_file(892)));" I get

object(WP_Error)#11341 (2) {
  array(1) {
    array(1) {
      string(41) "No editor could be selected."
  array(0) {

Or for wp media regenerate 892

Found 1 image to regenerate.
Warning: No editor could be selected.
Error: No images regenerated.

The patch also makes sure that $uploaded = $editor->save( $preview_file, 'image/jpeg' ); does not fail silently too. Though I have not been able to test this.

Note: See TracTickets for help on using tickets.