函数文档

wp_sizes_attribute_includes_valid_auto()

💡 云策文档标注

概述

wp_sizes_attribute_includes_valid_auto() 函数用于检查给定的 'sizes' 属性是否以 'auto' 关键字作为列表中的第一项。根据 HTML 规范,如果存在 'auto',它必须是第一个条目。

关键要点

  • 函数检查 'sizes' 属性值中是否包含 'auto' 作为第一项。
  • 参数 $sizes_attr 是必需的字符串类型,表示 'sizes' 属性值。
  • 返回布尔值:如果 'auto' 存在且为第一项则返回 true,否则返回 false。
  • 函数在 WordPress 6.7.0 版本中引入。

代码示例

function wp_sizes_attribute_includes_valid_auto( string $sizes_attr ): bool {
	list( $first_size ) = explode( ',', $sizes_attr, 2 );
	return 'auto' === strtolower( trim( $first_size, " tfrn" ) );
}

注意事项

  • 函数遵循 HTML 规范,确保 'auto' 必须是 'sizes' 属性列表中的第一个条目。
  • 相关函数包括 wp_img_tag_add_auto_sizes() 和 wp_get_attachment_image(),用于处理图像标签的 'sizes' 属性。

📄 原文内容

Checks whether the given ‘sizes’ attribute includes the ‘auto’ keyword as the first item in the list.

Description

Per the HTML spec, if present it must be the first entry.

Parameters

$sizes_attrstringrequired
The 'sizes' attribute value.

Return

bool True if the 'auto' keyword is present, false otherwise.

Source

function wp_sizes_attribute_includes_valid_auto( string $sizes_attr ): bool {
	list( $first_size ) = explode( ',', $sizes_attr, 2 );
	return 'auto' === strtolower( trim( $first_size, " tfrn" ) );
}

Changelog

Version Description
6.7.0 Introduced.