Skip to content

Commit

Permalink
Coding Standards: Use consistent formatting for error messages in `WP…
Browse files Browse the repository at this point in the history
…_Image_Editor_Imagick::write_image()` and `::strip_meta()`.

See #50767.

git-svn-id: https://develop.svn.wordpress.org/trunk@49546 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information
SergeyBiryukov committed Nov 9, 2020
1 parent 1bba686 commit 2e01c76
Showing 1 changed file with 28 additions and 10 deletions.
38 changes: 28 additions & 10 deletions src/wp-includes/class-wp-image-editor-imagick.php
Expand Up @@ -735,22 +735,28 @@ private function write_image( $image, $filename ) {
* Checks for exact type due to: https://www.php.net/manual/en/function.file-put-contents.php
*/
if ( file_put_contents( $filename, $image->getImageBlob() ) === false ) {
/* translators: %s: PHP function name. */
return new WP_Error( 'image_save_error', sprintf( __( '%s failed while writing image to stream.' ), '<code>file_put_contents()</code>' ), $filename );
return new WP_Error(
'image_save_error',
sprintf(
/* translators: %s: PHP function name. */
__( '%s failed while writing image to stream.' ),
'<code>file_put_contents()</code>'
),
$filename
);
} else {
return true;
}
} else {
$dir_name = dirname( $filename );
$dir_exists = wp_mkdir_p( $dir_name );
$dirname = dirname( $filename );

if ( ! $dir_exists ) {
if ( ! wp_mkdir_p( $dirname ) ) {
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 )
esc_html( $dirname )
)
);
}
Expand Down Expand Up @@ -801,13 +807,25 @@ public function stream( $mime_type = null ) {
protected function strip_meta() {

if ( ! is_callable( array( $this->image, 'getImageProfiles' ) ) ) {
/* translators: %s: ImageMagick method name. */
return new WP_Error( 'image_strip_meta_error', sprintf( __( '%s is required to strip image meta.' ), '<code>Imagick::getImageProfiles()</code>' ) );
return new WP_Error(
'image_strip_meta_error',
sprintf(
/* translators: %s: ImageMagick method name. */
__( '%s is required to strip image meta.' ),
'<code>Imagick::getImageProfiles()</code>'
)
);
}

if ( ! is_callable( array( $this->image, 'removeImageProfile' ) ) ) {
/* translators: %s: ImageMagick method name. */
return new WP_Error( 'image_strip_meta_error', sprintf( __( '%s is required to strip image meta.' ), '<code>Imagick::removeImageProfile()</code>' ) );
return new WP_Error(
'image_strip_meta_error',
sprintf(
/* translators: %s: ImageMagick method name. */
__( '%s is required to strip image meta.' ),
'<code>Imagick::removeImageProfile()</code>'
)
);
}

/*
Expand Down

0 comments on commit 2e01c76

Please sign in to comment.