函数文档

taxonomy_meta_box_sanitize_cb_checkboxes()

💡 云策文档标注

概述

taxonomy_meta_box_sanitize_cb_checkboxes() 函数用于清理来自复选框分类法元框的 POST 值,将原始术语数据转换为整数数组。

关键要点

  • 函数接受两个参数:$taxonomy(分类法名称,字符串,必需)和 $terms(来自 'tax_input' 字段的原始术语数据,数组,必需)。
  • 返回值为 int[] 类型,即清理后的术语 ID 数组。
  • 函数内部使用 array_map() 和 intval() 将 $terms 数组中的每个值转换为整数。

代码示例

function taxonomy_meta_box_sanitize_cb_checkboxes( $taxonomy, $terms ) {
	return array_map( 'intval', $terms );
}

注意事项

  • 此函数自 WordPress 5.1.0 版本引入。
  • 适用于处理复选框分类法元框的输入数据,确保术语 ID 为整数类型。

📄 原文内容

Sanitizes POST values from a checkbox taxonomy metabox.

Parameters

$taxonomystringrequired
The taxonomy name.
$termsarrayrequired
Raw term data from the 'tax_input' field.

Return

int[] Array of sanitized term IDs.

Source

function taxonomy_meta_box_sanitize_cb_checkboxes( $taxonomy, $terms ) {
	return array_map( 'intval', $terms );
}

Changelog

Version Description
5.1.0 Introduced.