wp_get_comment_status

函式
wp_get_comment_status ( $comment_id )
引數
  • (int|WP_Comment) $comment_id Comment ID or WP_Comment object
    Required:
返回值
  • (string|false) Status might be 'trash', 'approved', 'unapproved', 'spam'. False on failure.
定義位置
相關方法
wp_set_comment_statusget_comment_statuseswp_transition_comment_statusget_default_comment_statusget_comment_text
引入
1.0.0
棄用
-

wp_get_comment_status: 這個函式檢索一個評論的狀態。它接受評論ID作為引數,並返回一個包含評論狀態的字串。

通過評論ID檢索評論的狀態。

function wp_get_comment_status( $comment_id ) {
	$comment = get_comment( $comment_id );
	if ( ! $comment ) {
		return false;
	}

	$approved = $comment->comment_approved;

	if ( null == $approved ) {
		return false;
	} elseif ( '1' == $approved ) {
		return 'approved';
	} elseif ( '0' == $approved ) {
		return 'unapproved';
	} elseif ( 'spam' === $approved ) {
		return 'spam';
	} elseif ( 'trash' === $approved ) {
		return 'trash';
	} else {
		return false;
	}
}

常見問題

FAQs
檢視更多 >