WordPress.org

Make WordPress Core

Opened 4 years ago

Last modified 23 months ago

#35959 new defect (bug)

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

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

Description

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:
https://core.trac.wordpress.org/browser/trunk/src/wp-admin/includes/image.php?rev=36429#L123

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:
https://core.trac.wordpress.org/changeset/22192

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 4 years ago.
Attaching patch to mitigate this problem.
35959.patch (2.2 KB) - added by grapplerulrich 23 months ago.

Download all attachments as: .zip

Change History (7)

@maratbn
4 years ago

Attaching patch to mitigate this problem.

#1 @maratbn
4 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
3 years ago

  • Version changed from trunk to 3.5

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


2 years ago

#4 @desrosj
2 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 https://make.wordpress.org/core/handbook/contribute/#patches 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 https://make.wordpress.org/core/handbook/best-practices/coding-standards/php/#brace-style).

#5 @grapplerulrich
23 months 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) {
  ["errors"]=>
  array(1) {
    ["image_no_editor"]=>
    array(1) {
      [0]=>
      string(41) "No editor could be selected."
    }
  }
  ["error_data"]=>
  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.