钩子文档

wp_save_image_file

💡 云策文档标注

概述

wp_save_image_file 是一个已弃用的过滤器,用于控制是否跳过保存图像文件。返回非空值将短路保存方法,直接返回该值。

关键要点

  • 这是一个已弃用的过滤器,自 WordPress 3.5.0 起,建议使用 wp_save_image_editor_file 替代。
  • 过滤器参数包括 $override(覆盖值)、$filename(文件名)、$image(图像资源)、$mime_type(MIME 类型)和 $post_id(附件文章 ID)。
  • 返回非空值(如 true 或 false)可以跳过默认的保存过程,用于自定义图像保存逻辑。

注意事项

由于已弃用,新开发中应避免使用此过滤器,转而使用 wp_save_image_editor_file 以确保兼容性和支持。


📄 原文内容

Filters whether to skip saving the image file.

Description

Returning a non-null value will short-circuit the save method, returning that value instead.

Parameters

$overridebool|null
Value to return instead of saving. Default null.
$filenamestring
Name of the file to be saved.
$imageresource|GdImage
Image resource or GdImage instance.
$mime_typestring
The mime type of the image.
$post_idint
Attachment post ID.

Source

$saved = apply_filters_deprecated(
	'wp_save_image_file',
	array( null, $filename, $image, $mime_type, $post_id ),
	'3.5.0',
	'wp_save_image_editor_file'
);

Changelog

Version Description
3.5.0 Deprecated. Use ‘wp_save_image_editor_file’ instead.
2.9.0 Introduced.