钩子文档

wp_calculate_image_srcset_meta

💡 云策文档标注

概述

wp_calculate_image_srcset_meta 是一个 WordPress 过滤器,用于在计算图像 srcset 属性前预处理图像元数据,以修正存储数据中的不一致性。

关键要点

  • 这是一个过滤器,允许开发者在计算 srcset 前修改图像元数据。
  • 参数包括图像元数据数组、请求的尺寸数组、图像 src 字符串和附件 ID。
  • 主要用于 wp_calculate_image_srcset() 函数中,以优化响应式图像处理。

代码示例

$image_meta = apply_filters( 'wp_calculate_image_srcset_meta', $image_meta, $size_array, $image_src, $attachment_id );

注意事项

  • 该过滤器从 WordPress 4.5.0 版本开始引入。
  • 图像元数据通常来自 wp_get_attachment_metadata() 函数。
  • 附件 ID 可能为 0,表示未提供。

📄 原文内容

Pre-filters the image meta to be able to fix inconsistencies in the stored data.

Parameters

$image_metaarray
The image meta data as returned by ‘wp_get_attachment_metadata() ‘.
$size_arrayint[]
An array of requested width and height values.

  • 0 int
    The width in pixels.
  • 1 int
    The height in pixels.

$image_srcstring
The 'src' of the image.
$attachment_idint
The image attachment ID or 0 if not supplied.

Source

$image_meta = apply_filters( 'wp_calculate_image_srcset_meta', $image_meta, $size_array, $image_src, $attachment_id );

Changelog

Version Description
4.5.0 Introduced.