钩子文档

wp_update_comment_data

💡 云策文档标注

概述

wp_update_comment_data 是一个 WordPress 过滤器钩子,用于在评论数据更新到数据库之前进行过滤。它允许开发者修改或验证即将更新的评论数据。

关键要点

  • 过滤器在评论数据更新前立即触发,数据已去除反斜杠。
  • 参数包括新处理的数据、旧评论数据和新原始数据,支持返回 WP_Error 以中断更新。
  • 从 WordPress 5.5.0 开始,返回 WP_Error 可短路评论更新过程。

代码示例

$data = apply_filters( 'wp_update_comment_data', $data, $comment, $commentarr );

注意事项

  • 传入过滤器的数据已 unslashed,无需额外处理。
  • 返回 WP_Error 可用于阻止评论更新,适用于验证失败等场景。

📄 原文内容

Filters the comment data immediately before it is updated in the database.

Description

Note: data being passed to the filter is already unslashed.

Parameters

$dataarray|WP_Error
The new, processed comment data, or WP_Error.
$commentarray
The old, unslashed comment data.
$commentarrarray
The new, raw comment data.

Source

$data = apply_filters( 'wp_update_comment_data', $data, $comment, $commentarr );

Changelog

Version Description
5.5.0 Returning a WP_Error value from the filter will short-circuit comment update and allow skipping further processing.
4.7.0 Introduced.