Skip to content

Commit a14324c

Browse files
Docs: Improve documentation for WP_Image_Editor::save() and related functions.
Includes: * Documenting the returned array using hash notation. * Adding a `@since` note for the `$filesize` value being included in the returned array. This affects: * `wp_generate_attachment_metadata()` * `wp_get_attachment_metadata()` * `WP_Image_Editor::save()` * `WP_Image_Editor_GD::save()` and `::_save()` * `WP_Image_Editor_Imagick::save()` and `::_save()` Follow-up to [22094], [22619], [52837], [53546]. See #55646. git-svn-id: https://develop.svn.wordpress.org/trunk@53547 602fd350-edb4-49c9-b593-d223f7449a82
1 parent d27deea commit a14324c

5 files changed

Lines changed: 65 additions & 8 deletions

File tree

src/wp-admin/includes/image.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ function wp_update_image_subsizes( $attachment_id ) {
190190
* Updates the attached file and image meta data when the original image was edited.
191191
*
192192
* @since 5.3.0
193+
* @since 6.0.0 The `$filesize` value was added to the returned array.
193194
* @access private
194195
*
195196
* @param array $saved_data The data returned from WP_Image_Editor after successfully saving an image.
@@ -211,12 +212,12 @@ function _wp_image_meta_replace_original( $saved_data, $original_file, $image_me
211212
// Make the file path relative to the upload dir.
212213
$image_meta['file'] = _wp_relative_upload_path( $new_file );
213214

214-
// Store the original image file name in image_meta.
215-
$image_meta['original_image'] = wp_basename( $original_file );
216-
217215
// Add image file size.
218216
$image_meta['filesize'] = wp_filesize( $new_file );
219217

218+
// Store the original image file name in image_meta.
219+
$image_meta['original_image'] = wp_basename( $original_file );
220+
220221
return $image_meta;
221222
}
222223

@@ -477,6 +478,7 @@ function _wp_make_subsizes( $new_sizes, $file, $image_meta, $attachment_id ) {
477478
* Generate attachment meta data and create image sub-sizes for images.
478479
*
479480
* @since 2.1.0
481+
* @since 6.0.0 The `$filesize` value was added to the returned array.
480482
*
481483
* @param int $attachment_id Attachment ID to process.
482484
* @param string $file Filepath of the attached image.

src/wp-includes/class-wp-image-editor-gd.php

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -425,10 +425,20 @@ public function flip( $horz, $vert ) {
425425
* @since 3.5.0
426426
* @since 5.9.0 Renamed `$filename` to `$destfilename` to match parent class
427427
* for PHP 8 named parameter support.
428+
* @since 6.0.0 The `$filesize` value was added to the returned array.
428429
*
429430
* @param string|null $destfilename Optional. Destination filename. Default null.
430431
* @param string|null $mime_type Optional. The mime-type. Default null.
431-
* @return array|WP_Error {'path'=>string, 'file'=>string, 'width'=>int, 'height'=>int, 'mime-type'=>string}
432+
* @return array|WP_Error {
433+
* Array on success or WP_Error if the file failed to save.
434+
*
435+
* @type string $path Path to the image file.
436+
* @type string $file Name of the image file.
437+
* @type int $width Image width.
438+
* @type int $height Image height.
439+
* @type string $mime-type The mime type of the image.
440+
* @type int $filesize File size of the image.
441+
* }
432442
*/
433443
public function save( $destfilename = null, $mime_type = null ) {
434444
$saved = $this->_save( $this->image, $destfilename, $mime_type );
@@ -442,10 +452,22 @@ public function save( $destfilename = null, $mime_type = null ) {
442452
}
443453

444454
/**
455+
* @since 3.5.0
456+
* @since 6.0.0 The `$filesize` value was added to the returned array.
457+
*
445458
* @param resource|GdImage $image
446459
* @param string|null $filename
447460
* @param string|null $mime_type
448-
* @return array|WP_Error
461+
* @return array|WP_Error {
462+
* Array on success or WP_Error if the file failed to save.
463+
*
464+
* @type string $path Path to the image file.
465+
* @type string $file Name of the image file.
466+
* @type int $width Image width.
467+
* @type int $height Image height.
468+
* @type string $mime-type The mime type of the image.
469+
* @type int $filesize File size of the image.
470+
* }
449471
*/
450472
protected function _save( $image, $filename = null, $mime_type = null ) {
451473
list( $filename, $extension, $mime_type ) = $this->get_output_format( $filename, $mime_type );

src/wp-includes/class-wp-image-editor-imagick.php

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -661,10 +661,20 @@ public function maybe_exif_rotate() {
661661
* Saves current image to file.
662662
*
663663
* @since 3.5.0
664+
* @since 6.0.0 The `$filesize` value was added to the returned array.
664665
*
665666
* @param string $destfilename Optional. Destination filename. Default null.
666667
* @param string $mime_type Optional. The mime-type. Default null.
667-
* @return array|WP_Error {'path'=>string, 'file'=>string, 'width'=>int, 'height'=>int, 'mime-type'=>string}
668+
* @return array|WP_Error {
669+
* Array on success or WP_Error if the file failed to save.
670+
*
671+
* @type string $path Path to the image file.
672+
* @type string $file Name of the image file.
673+
* @type int $width Image width.
674+
* @type int $height Image height.
675+
* @type string $mime-type The mime type of the image.
676+
* @type int $filesize File size of the image.
677+
* }
668678
*/
669679
public function save( $destfilename = null, $mime_type = null ) {
670680
$saved = $this->_save( $this->image, $destfilename, $mime_type );
@@ -684,10 +694,22 @@ public function save( $destfilename = null, $mime_type = null ) {
684694
}
685695

686696
/**
697+
* @since 3.5.0
698+
* @since 6.0.0 The `$filesize` value was added to the returned array.
699+
*
687700
* @param Imagick $image
688701
* @param string $filename
689702
* @param string $mime_type
690-
* @return array|WP_Error
703+
* @return array|WP_Error {
704+
* Array on success or WP_Error if the file failed to save.
705+
*
706+
* @type string $path Path to the image file.
707+
* @type string $file Name of the image file.
708+
* @type int $width Image width.
709+
* @type int $height Image height.
710+
* @type string $mime-type The mime type of the image.
711+
* @type int $filesize File size of the image.
712+
* }
691713
*/
692714
protected function _save( $image, $filename = null, $mime_type = null ) {
693715
list( $filename, $extension, $mime_type ) = $this->get_output_format( $filename, $mime_type );

src/wp-includes/class-wp-image-editor.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,21 @@ abstract public function load();
7575
* Saves current image to file.
7676
*
7777
* @since 3.5.0
78+
* @since 6.0.0 The `$filesize` value was added to the returned array.
7879
* @abstract
7980
*
8081
* @param string $destfilename Optional. Destination filename. Default null.
8182
* @param string $mime_type Optional. The mime-type. Default null.
82-
* @return array|WP_Error {'path'=>string, 'file'=>string, 'width'=>int, 'height'=>int, 'mime-type'=>string}
83+
* @return array|WP_Error {
84+
* Array on success or WP_Error if the file failed to save.
85+
*
86+
* @type string $path Path to the image file.
87+
* @type string $file Name of the image file.
88+
* @type int $width Image width.
89+
* @type int $height Image height.
90+
* @type string $mime-type The mime type of the image.
91+
* @type int $filesize File size of the image.
92+
* }
8393
*/
8494
abstract public function save( $destfilename = null, $mime_type = null );
8595

src/wp-includes/post.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6508,6 +6508,7 @@ function wp_delete_attachment_files( $post_id, $meta, $backup_sizes, $file ) {
65086508
* Retrieves attachment metadata for attachment ID.
65096509
*
65106510
* @since 2.1.0
6511+
* @since 6.0.0 The `$filesize` value was added to the returned array.
65116512
*
65126513
* @param int $attachment_id Attachment post ID. Defaults to global $post.
65136514
* @param bool $unfiltered Optional. If true, filters are not run. Default false.

0 commit comments

Comments
 (0)