функция since 2.0.0

get_comment()

Проверено на WordPress 6.9, обновлено Источник: WordPress Developer Resources.

Сигнатура

get_comment( WP_Comment|string|int $comment = null, string $output = OBJECT ): WP_Comment|array|null

Описание

Если передан объект, данные комментария кэшируются и возвращаются после прохождения через фильтр. Если комментарий пуст, используется глобальная переменная комментария, если она задана.

Оригинал (английский)

If an object is passed then the comment data will be cached and then returned after being passed through a filter. If the comment is empty, then the global comment variable will be used, if it is set.

Параметры

$comment WP_Comment|string|int необязательный = null
Комментарий для получения.
$output string необязательный = OBJECT
Требуемый тип возвращаемого значения. Одно из OBJECT, ARRAY_A или ARRAY_N, что соответствует объекту WP_Comment, ассоциативному массиву или числовому массиву соответственно.

Возвращаемое значение

WP_Comment|array|null

Исходный код

wp-includes/comment.php:221

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|null $_comment Comment data.
	 */
	$_comment = apply_filters( 'get_comment', $_comment );
	if ( ! ( $_comment instanceof WP_Comment ) ) {
		return null;
	}

	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;
}

История изменений

ВерсияОписание
2.0.0 Introduced.

Что будем искать? Например,Продвижение

Этот сайт использует куки-файлы. Оставаясь на сайте, Вы соглашаетесь на их использование. Для получения дополнительной информации, пожалуйста, ознакомьтесь с политикой в отношении персональных данных.