函数文档

get_comment_statuses()

💡 云策文档标注

概述

get_comment_statuses() 函数用于检索 WordPress 支持的所有评论状态。它返回一个数组,包含状态值和对应的标签描述。

关键要点

  • 函数返回一个字符串数组,键为评论状态(如 'hold'、'approve'),值为翻译后的状态标签。
  • 评论状态包括:'hold'(未批准)、'approve'(已批准)、'spam'(垃圾)和 'trash'(回收站)。
  • 该函数自 WordPress 2.7.0 版本引入,用于提供评论状态的标准化列表。

代码示例

function get_comment_statuses() {
    $status = array(
        'hold'    => __( 'Unapproved' ),
        'approve' => _x( 'Approved', 'comment status' ),
        'spam'    => _x( 'Spam', 'comment status' ),
        'trash'   => _x( 'Trash', 'comment status' ),
    );

    return $status;
}

注意事项

  • 状态标签使用 __() 和 _x() 函数进行翻译,确保国际化支持。
  • 该函数在 wp_xmlrpc_server 类中被用于编辑评论和获取评论状态列表。

📄 原文内容

Retrieves all of the WordPress supported comment statuses.

Description

Comments have a limited set of valid status values, this provides the comment status values and descriptions.

Return

string[] List of comment status labels keyed by status.

Source

function get_comment_statuses() {
	$status = array(
		'hold'    => __( 'Unapproved' ),
		'approve' => _x( 'Approved', 'comment status' ),
		'spam'    => _x( 'Spam', 'comment status' ),
		'trash'   => _x( 'Trash', 'comment status' ),
	);

	return $status;
}

Changelog

Version Description
2.7.0 Introduced.