Skip to content

Commit d27deea

Browse files
Docs: Correct the return type for wp_save_image_file().
Since WordPress 3.5, `wp_save_image_file()` uses `WP_Image_Editor` classes under the hood to save the images. While the `save()` method in those instances returns `array|WP_Error` and is documented as such, the return type of the `wp_save_image_file()` function was still left as `bool`. A better solution would be to adjust the function to return the documented boolean type. However, doing that after 20+ major WP releases would be a backward compatibility break, so the documentation is now updated instead. Includes: * Documenting the returned array using hash notation. * Adding a `@since` note for the `$image` parameter expecting a `WP_Image_Editor` instance. * Adding a `@since` note for the `$filesize` value being included in the returned array. Follow-up to [22094], [22619], [52837]. Props jrf, SergeyBiryukov. See #55646. git-svn-id: https://develop.svn.wordpress.org/trunk@53546 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 53372fd commit d27deea

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

src/wp-admin/includes/image-edit.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,12 +351,26 @@ function wp_stream_image( $image, $mime_type, $attachment_id ) {
351351
* Saves image to file.
352352
*
353353
* @since 2.9.0
354+
* @since 3.5.0 The `$image` parameter expects a `WP_Image_Editor` instance.
355+
* @since 6.0.0 The `$filesize` value was added to the returned array.
354356
*
355357
* @param string $filename Name of the file to be saved.
356358
* @param WP_Image_Editor $image The image editor instance.
357359
* @param string $mime_type The mime type of the image.
358360
* @param int $post_id Attachment post ID.
359-
* @return bool True on success, false on failure.
361+
* @return array|WP_Error|bool {
362+
* Array on success or WP_Error if the file failed to save.
363+
* When called with a deprecated value for the `$image` parameter,
364+
* i.e. a non-`WP_Image_Editor` image resource or `GdImage` instance,
365+
* the function will return true on success, false on failure.
366+
*
367+
* @type string $path Path to the image file.
368+
* @type string $file Name of the image file.
369+
* @type int $width Image width.
370+
* @type int $height Image height.
371+
* @type string $mime-type The mime type of the image.
372+
* @type int $filesize File size of the image.
373+
* }
360374
*/
361375
function wp_save_image_file( $filename, $image, $mime_type, $post_id ) {
362376
if ( $image instanceof WP_Image_Editor ) {

0 commit comments

Comments
 (0)