钩子文档

wp_anonymize_comment

💡 云策文档标注

概述

wp_anonymize_comment 是一个 WordPress 过滤器,用于控制评论是否被匿名化处理。它允许开发者自定义匿名化行为或消息。

关键要点

  • 这是一个过滤器 Hook,用于在评论匿名化过程中进行干预。
  • 参数包括 $anon_message(布尔值或字符串,控制匿名化或自定义消息)、$comment(WP_Comment 对象)和 $anonymized_comment(匿名化评论数据数组)。
  • 默认返回 true,表示应用匿名化;可返回 false 或自定义字符串消息来修改行为。
  • 在 WordPress 4.9.6 版本中引入。

代码示例

$anon_message = apply_filters( 'wp_anonymize_comment', true, $comment, $anonymized_comment );

注意事项

  • 此过滤器与 wp_comments_personal_data_eraser() 函数相关,用于从评论表中擦除个人数据。
  • 使用时需确保正确处理参数类型,以避免意外行为。

📄 原文内容

Filters whether to anonymize the comment.

Parameters

$anon_messagebool|string
Whether to apply the comment anonymization (bool) or a custom message (string). Default true.
$commentWP_Comment
WP_Comment object.
$anonymized_commentarray
Anonymized comment data.

Source

$anon_message = apply_filters( 'wp_anonymize_comment', true, $comment, $anonymized_comment );

Changelog

Version Description
4.9.6 Introduced.