在发生评论状态转换时调用挂钩。
原型
wp_transition_comment_status( string $new_status, string $old_status, object $comment )
描述
调用注释状态转换的挂钩。如果新评论状态与先前评论状态不同,则将运行两个挂钩,第一个是具有新状态,旧状态和评论数据的“transition_comment_status”。调用的下一个操作是comment_ $ old_status_to_ $ new_status’。它有评论数据。
参数
$new_status
(string)
(Required)
新评论状态。
$old_status
(string)
(Required)
以前的评论状态。
$comment
(object)
(Required)
评论数据。
源文件
路径:wp-includes/comment.php
<?php
...
function wp_transition_comment_status($new_status, $old_status, $comment) {
/*
* Translate raw statuses to human readable formats for the hooks.
* This is not a complete list of comment status, it's only the ones
* that need to be renamed
*/
$comment_statuses = array(
0 => 'unapproved',
'hold' => 'unapproved', // wp_set_comment_status() uses "hold"
1 => 'approved',
'approve' => 'approved', // wp_set_comment_status() uses "approve"
);
if ( isset($comment_statuses[$new_status]) ) $new_status = $comment_statuses[$new_status];
if ( isset($comment_statuses[$old_status]) ) $old_status = $comment_statuses[$old_status];
// Call the hooks
if ( $new_status != $old_status ) {
/**
* Fires when the comment status is in transition.
*
* @since 2.7.0
*
* @param int|string $new_status The new comment status.
* @param int|string $old_status The old comment status.
* @param object $comment The comment data.
*/
do_action( 'transition_comment_status', $new_status, $old_status, $comment );
/**
* Fires when the comment status is in transition from one specific status to another.
*
* The dynamic portions of the hook name, `$old_status`, and `$new_status`,
* refer to the old and new comment statuses, respectively.
*
* @since 2.7.0
*
* @param WP_Comment $comment Comment object.
*/
do_action( "comment_{$old_status}_to_{$new_status}", $comment );
}
/**
* Fires when the status of a specific comment type is in transition.
*
* The dynamic portions of the hook name, `$new_status`, and `$comment->comment_type`,
* refer to the new comment status, and the type of comment, respectively.
*
* Typical comment types include an empty string (standard comment), 'pingback',
* or 'trackback'.
*
* @since 2.7.0
*
* @param int $comment_ID The comment ID.
* @param WP_Comment $comment Comment object.
*/
do_action( "comment_{$new_status}_{$comment->comment_type}", $comment->comment_ID, $comment );
}
...
?>
其他
英文文档:https://developer.wordpress.org/reference/functions/wp_transition_comment_status/