函数原型
get_comment( WP_Comment|string|int $comment = null, string $output = OBJECT ): WP_Comment|array|null
函数描述
Retrieves comment data given a comment ID or comment object.
是否弃用
未弃用
函数参数
-
$comment
WP_Comment|string|int
Optional - Comment to retrieve.
Default:
null -
$output
string
Optional - The required return type. One of OBJECT, ARRAY_A, or ARRAY_N, which correspond to a WP_Comment object, an associative array, or a numeric array, respectively.
Default:
OBJECT
函数返回值
WP_Comment|array|null Depends on $output value.
函数位置
File: wp-includes/comment.php.
函数源码
function get_comment( $comment = null, $output = OBJECT ) {
if ( empty( $comment ) && isset( $GLOBALS['comment'] ) ) {
$comment = $GLOBALS['comment'];
}
if ( $comment instanceof WP_Comment ) {
$_comment = $comment;
} elseif ( is_object( $comment ) ) {
$_comment = new WP_Comment( $comment );
} else {
$_comment = WP_Comment::get_instance( $comment );
}
if ( ! $_comment ) {
return null;
}
/**
* Fires after a comment is retrieved.
*
* @since 2.3.0
*
* @param WP_Comment $_comment Comment data.
*/
$_comment = apply_filters( 'get_comment', $_comment );
if ( OBJECT === $output ) {
return $_comment;
} elseif ( ARRAY_A === $output ) {
return $_comment->to_array();
} elseif ( ARRAY_N === $output ) {
return array_values( $_comment->to_array() );
}
return $_comment;
}
源码链接
变更日志
| Version | Description |
|---|---|
| 2.0.0 | Introduced. |

