Make WordPress Core

Opened 22 months ago

Last modified 22 months ago

#38192 new defect (bug)

Linking directly into Edit Image mode breaks cropping; imageEdit.init not triggered.

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


I've noticed for a while that when jumping directly into Edit Image mode on an attachment (namely when clicking the "Edit Image" link for an attachment inside the Media Manager), trying to crop the image doesn't work.

To reproduce, simply visit the edit link for any attachment with "&image-editor" tacked onto the URL. (e.g. /wp-admin/post.php?post=123&action=edit&image-editor)

When you drag to create the crop box, the Selection values keep saying NaN, and so trying to confirm your selection won't do anything, not even give you a visible error.

Currently, the only solution when when this occurs is to click cancel, then the Edit Image button on the screen there, where it properly initializes.

After some debugging in wp-admin/js/image-edit.js, I found the cause was that imageEdit.hold.sizer was undefined, which is set by imageEdit.init(). This method is called when the Edit Image button is clicked manually, but it never get's called on page load when it's triggered automatically.

Not entirely sure where the call should go, but that should be the only adjustment needed to make it work.

Attachments (1)

image-edit.php.diff (1.5 KB) - added by jbotte 22 months ago.
diff for image-edit.php to trigger imageEdit.init() if linking directly to the image editor.

Download all attachments as: .zip

Change History (4)

#1 @jbotte
22 months ago

Working on a patch, still going down the rabbit hole. Will try and post something next week.

22 months ago

diff for image-edit.php to trigger imageEdit.init() if linking directly to the image editor.

#2 @jbotte
22 months ago

  • Keywords has-patch needs-testing added

I attached a small patch above. First patch so if things aren't up to snuff I appreciate feedback to help improve.

On php page load i check for the 'image-editor' key in the $_GET array.

If the key exists I populate $image_edit_additional_js with the JS that will trigger imageEdit.init();

I then echo that js in the image-preview onload.

Let me know if you have any questions. Please test!

hope this helps you @dougwollison

#3 @jbotte
22 months ago

  • Component changed from Editor to Media
Note: See TracTickets for help on using tickets.