From 3688a9394e53f37de8f0bb74e5b368931b8556db Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Mon, 9 Nov 2020 13:18:04 +0000 Subject: [PATCH] Media: Restore the ability of `WP_Image_Editor_Imagick->save()` to create a missing directory when needed. Props eemitch, mikeschroder, hellofromTonya, p00ya, johnbillion Fixes #51665 Built from https://develop.svn.wordpress.org/trunk@49542 git-svn-id: http://core.svn.wordpress.org/trunk@49280 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/class-wp-image-editor-imagick.php | 14 ++++++++++++++ wp-includes/version.php | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/wp-includes/class-wp-image-editor-imagick.php b/wp-includes/class-wp-image-editor-imagick.php index ab9d302070..a03ccf9760 100644 --- a/wp-includes/class-wp-image-editor-imagick.php +++ b/wp-includes/class-wp-image-editor-imagick.php @@ -741,6 +741,20 @@ class WP_Image_Editor_Imagick extends WP_Image_Editor { return true; } } else { + $dir_name = dirname( $filename ); + $dir_exists = wp_mkdir_p( $dir_name ); + + if ( ! $dir_exists ) { + return new WP_Error( + 'image_save_error', + sprintf( + /* translators: %s: Directory path. */ + __( 'Unable to create directory %s. Is its parent directory writable by the server?' ), + esc_html( $dir_name ) + ) + ); + } + try { return $image->writeImage( $filename ); } catch ( Exception $e ) { diff --git a/wp-includes/version.php b/wp-includes/version.php index 03b76ce81b..f3752a8f84 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.6-beta3-49541'; +$wp_version = '5.6-beta3-49542'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.