Make WordPress Core

Changeset 49542


Ignore:
Timestamp:
11/09/2020 01:16:54 PM (6 years ago)
Author:
johnbillion
Message:

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

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-image-editor-imagick.php

    r49233 r49542  
    742742                        }
    743743                } else {
     744                        $dir_name   = dirname( $filename );
     745                        $dir_exists = wp_mkdir_p( $dir_name );
     746
     747                        if ( ! $dir_exists ) {
     748                                return new WP_Error(
     749                                        'image_save_error',
     750                                        sprintf(
     751                                                /* translators: %s: Directory path. */
     752                                                __( 'Unable to create directory %s. Is its parent directory writable by the server?' ),
     753                                                esc_html( $dir_name )
     754                                        )
     755                                );
     756                        }
     757
    744758                        try {
    745759                                return $image->writeImage( $filename );
  • trunk/tests/phpunit/tests/image/editorImagick.php

    r49488 r49542  
    598598                unlink( $temp_file );
    599599        }
     600
     601        /**
     602         * @ticket 51665
     603         */
     604        public function test_directory_creation() {
     605                $file      = realpath( DIR_TESTDATA ) . '/images/a2-small.jpg';
     606                $directory = realpath( DIR_TESTDATA ) . '/images/nonexistent-directory';
     607                $editor    = new WP_Image_Editor_Imagick( $file );
     608
     609                $this->assertFileNotExists( $directory );
     610
     611                $loaded = $editor->load();
     612                $this->assertNotWPError( $loaded );
     613
     614                $resized = $editor->resize( 100, 100, true );
     615                $this->assertNotWPError( $resized );
     616
     617                $saved = $editor->save( $directory . '/a2-small-cropped.jpg' );
     618                $this->assertNotWPError( $saved );
     619
     620                unlink( $directory . '/a2-small-cropped.jpg' );
     621                rmdir( $directory );
     622        }
    600623}
Note: See TracChangeset for help on using the changeset viewer.