钩子文档

sanitize_{$object_type}_meta_{$meta_key}

💡 云策文档标注

概述

sanitize_{$object_type}_meta_{$meta_key} 是一个动态过滤器钩子,用于自定义特定元类型和元键的元数据值清理过程。它允许开发者在保存元数据时,针对具体对象类型和键名应用自定义的清理逻辑。

关键要点

  • 这是一个动态钩子,钩子名称中的 $object_type 和 $meta_key 是变量,分别代表元数据对象类型(如 'blog'、'post'、'comment'、'term'、'user')和元键值。
  • 钩子参数包括 $meta_value(要清理的元数据值)、$meta_key(元键)和 $object_type(对象类型)。
  • 主要用于 sanitize_meta() 函数中,在保存元数据前过滤和清理值,确保数据安全性和一致性。
  • 自 WordPress 3.3.0 版本引入,支持扩展其他对象类型,只要其有相关的元表。

📄 原文内容

Filters the sanitization of a specific meta key of a specific meta type.

Description

The dynamic portions of the hook name, $meta_type, and $meta_key, refer to the metadata object type (blog, comment, post, term, or user) and the meta key value, respectively.

Parameters

$meta_valuemixed
Metadata value to sanitize.
$meta_keystring
Metadata key.
$object_typestring
Type of object metadata is for. Accepts 'blog', 'post', 'comment', 'term', 'user', or any other object type with an associated meta table.

Source

return apply_filters( "sanitize_{$object_type}_meta_{$meta_key}", $meta_value, $meta_key, $object_type );

Changelog

Version Description
3.3.0 Introduced.