函数文档

sanitize_category()

💡 云策文档标注

概述

sanitize_category() 函数用于根据上下文对分类数据(如对象或数组)进行清理,确保安全使用。它基于 sanitize_term() 实现,专门处理 WordPress 的分类数据。

关键要点

  • 函数接受两个参数:$category(必需,分类数据对象或数组)和 $context(可选,默认为 'display')。
  • 返回与输入 $category 相同类型的数据,但经过清理,适用于指定上下文。
  • 内部调用 sanitize_term() 函数,专门针对 'category' 分类法进行清理。
  • 自 WordPress 2.3.0 版本引入,相关函数包括 sanitize_term()。

📄 原文内容

Sanitizes category data based on context.

Parameters

$categoryobject|arrayrequired
Category data.
$contextstringoptional
Default 'display'.

Return

object|array Same type as $category with sanitized data for safe use.

Source

function sanitize_category( $category, $context = 'display' ) {
	return sanitize_term( $category, 'category', $context );
}

Changelog

Version Description
2.3.0 Introduced.