get_comment

函式
get_comment ( $comment = null, $output = OBJECT )
引數
  • (WP_Comment|string|int) $comment Comment to retrieve.
    Required:
    Default: null
  • (string) $output 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.
    Required:
    Default: OBJECT
返回值
  • (WP_Comment|array|null) Depends on $output value.
定義位置
相關方法
get_commentsget_comment_idedit_commentget_commentdatathe_comment
引入
2.0.0
棄用
-

get_comment: 這個函式用來檢索一個評論物件。它需要一個引數,$comment_ID,這是你想檢索的評論的ID。

檢索評論資料,給定一個評論ID或評論物件。

如果一個物件被傳遞,那麼評論資料將被快取,並在通過一個過濾器後返回。如果評論是空的,那麼將使用全域性評論變數,如果它被設定的話。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
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;
}
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; }
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;
}

常見問題

FAQs
檢視更多 >