From 1f57f61326eb65e7d4dfbb37852ede7bae6e5462 Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Wed, 8 Jul 2020 12:21:27 +0200 Subject: [PATCH] Try loading remote image if local is not present (#23742) Fixes https://github.com/WordPress/gutenberg/issues/23686 Inspired by existing core functionality: https://github.com/WordPress/wordpress-develop/blob/88c91eeaa6ab8d73bb3f5b301f9a0faf41e8e3e2/src/wp-admin/includes/image.php#L27-L37 Changes originally introduced to handle this case in: https://core.trac.wordpress.org/changeset/20384 --- lib/class-wp-rest-image-editor-controller.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/class-wp-rest-image-editor-controller.php b/lib/class-wp-rest-image-editor-controller.php index cdb05b498f98f..ebf3ea1b916c9 100644 --- a/lib/class-wp-rest-image-editor-controller.php +++ b/lib/class-wp-rest-image-editor-controller.php @@ -147,7 +147,15 @@ public function apply_edits( $request ) { return new WP_Error( 'rest_image_not_edited', $error, array( 'status' => 400 ) ); } - $image_editor = wp_get_image_editor( $image_file ); + // If the file doesn't exist, attempt a URL fopen on the src link. + // This can occur with certain file replication plugins. + // Keep the original file path to get a modified name later. + $image_file_to_edit = $image_file; + if ( ! file_exists( $image_file_to_edit ) ) { + $image_file_to_edit = _load_image_to_edit_path( $attachment_id ); + } + + $image_editor = wp_get_image_editor( $image_file_to_edit ); if ( is_wp_error( $image_editor ) ) { // This image cannot be edited.