Filter hook 'image_editor_save_pre'

in WP Core File wp-admin/includes/image-edit.php at line 434

View Source

image_editor_save_pre

Filter Hook
Description
Saves image to file. Array on success or WP_Error if the file failed to save. When called with a deprecated value for the `$image` parameter, i.e. a non-`WP_Image_Editor` image resource or `GdImage` instance, the function will return true on success, false on failure. }

Hook Information

File Location wp-admin/includes/image-edit.php View on GitHub
Hook Type Filter
Line Number 434

Hook Parameters

Type Name Description
string $filename Name of the file to be saved.
WP_Image_Editor $image The image editor instance.
string $mime_type The mime type of the image.
int $post_id Attachment post ID.

Usage Examples

Basic Usage
<?php
// Hook into image_editor_save_pre
add_filter('image_editor_save_pre', 'my_custom_filter', 10, 4);

function my_custom_filter($filename, $image, $mime_type, $post_id) {
    // Your custom filtering logic here
    return $filename;
}

Source Code Context

wp-admin/includes/image-edit.php:434 - How this hook is used in WordPress core
<?php
 429   */
 430  function wp_save_image_file( $filename, $image, $mime_type, $post_id ) {
 431  	if ( $image instanceof WP_Image_Editor ) {
 432  
 433  		/** This filter is documented in wp-admin/includes/image-edit.php */
 434  		$image = apply_filters( 'image_editor_save_pre', $image, $post_id );
 435  
 436  		/**
 437  		 * Filters whether to skip saving the image file.
 438  		 *
 439  		 * Returning a non-null value will short-circuit the save method,

PHP Documentation

<?php
/**
 * Saves image to file.
 *
 * @since 2.9.0
 * @since 3.5.0 The `$image` parameter expects a `WP_Image_Editor` instance.
 * @since 6.0.0 The `$filesize` value was added to the returned array.
 *
 * @param string          $filename  Name of the file to be saved.
 * @param WP_Image_Editor $image     The image editor instance.
 * @param string          $mime_type The mime type of the image.
 * @param int             $post_id   Attachment post ID.
 * @return array|WP_Error|bool {
 *     Array on success or WP_Error if the file failed to save.
 *     When called with a deprecated value for the `$image` parameter,
 *     i.e. a non-`WP_Image_Editor` image resource or `GdImage` instance,
 *     the function will return true on success, false on failure.
 *
 *     @type string $path      Path to the image file.
 *     @type string $file      Name of the image file.
 *     @type int    $width     Image width.
 *     @type int    $height    Image height.
 *     @type string $mime-type The mime type of the image.
 *     @type int    $filesize  File size of the image.
 * }
 */
Quick Info
  • Hook Type: Filter
  • Parameters: 4
  • File: wp-admin/includes/image-edit.php
Related Hooks

Related hooks will be displayed here in future updates.