Last active
March 4, 2019 18:28
-
-
Save chrisvanpatten/1f8e036f90f0154ab1146acded0a4894 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| wp.Uploader.queue.on('change', function(image) { | |
| // This event runs whenever the upload percentage changes, so | |
| // we need to check if the image ID has been assigned yet (which | |
| // indicates that the upload has completed). | |
| if (typeof image.attributes.id === 'undefined') { | |
| return | |
| } | |
| // Check for the minimum width and height. | |
| // In a _real_ implementation, these values, and the associated | |
| // error messages, should be implemented via a wp_localize_script | |
| // call to ensure future flexibility. | |
| if (image.attributes.width > 1244 && image.attributes.height > 1244) { | |
| return | |
| } | |
| const message = 'This image is the wrong size. Would you like to continue uploading anyway?' | |
| // If the user says to continue uploading, stop now. Otherwise, delete the image. | |
| if (window.confirm(message)) { | |
| return | |
| } | |
| // Delete the newly-uploaded image. | |
| wp.apiRequest({ | |
| path: `wp/v2/media/${image.attributes.id}?force=true`, | |
| method: 'DELETE', | |
| }) | |
| // Refresh the modal. | |
| wp.media.frame.content.get().collection.props.set({ignore: (+ new Date())}) | |
| wp.media.frame.content.get().options.selection.reset() | |
| return | |
| }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment