返回介绍

wp_transition_comment_status()

发布于 2017-09-11 13:00:22 字数 4139 浏览 898 评论 0 收藏 0

wp_transition_comment_status( string $new_status,  string $old_status,  object $comment )

Call hooks for when a comment status transition occurs.


description

Calls hooks for comment status transitions. If the new comment status is not the same as the previous comment status, then two hooks will be ran, the first is ‘transition_comment_status’ with new status, old status, and comment data. The next action called is comment_$old_status_to_$new_status’. It has the comment data.

The final action will run whether or not the comment statuses are the same. The action is named ‘comment_$new_status_$comment->comment_type’.


参数

$new_status

(string) (Required) New comment status.

$old_status

(string) (Required) Previous comment status.

$comment

(object) (Required) Comment data.


源代码

File: wp-includes/comment.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 );
}

更新日志

Versiondescription
2.7.0Introduced.

相关函数

Uses

  • wp-includes/plugin.php: do_action()
  • wp-includes/comment.php: transition_comment_status
  • wp-includes/comment.php: comment_{$old_status}_to_{$new_status}
  • wp-includes/comment.php: comment_{$new_status}_{$comment->comment_type}

Used By

  • wp-includes/comment.php: wp_set_comment_status()
  • wp-includes/comment.php: wp_update_comment()
  • wp-includes/comment.php: wp_delete_comment()

User Contributed Notes

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文