separate_comments()WP 2.7.0

Separates an array of comments into an array keyed by comment_type.

Хуков нет.

Возвращает

WP_Comment[]. Array of comments keyed by comment_type.

Использование

separate_comments( $comments );
$comments(WP_Comment[]) (обязательный) (передается по ссылке — &)
Array of comments

Список изменений

С версии 2.7.0 Введена.

Код separate_comments() WP 6.6.2

function separate_comments( &$comments ) {
	$comments_by_type = array(
		'comment'   => array(),
		'trackback' => array(),
		'pingback'  => array(),
		'pings'     => array(),
	);

	$count = count( $comments );

	for ( $i = 0; $i < $count; $i++ ) {
		$type = $comments[ $i ]->comment_type;

		if ( empty( $type ) ) {
			$type = 'comment';
		}

		$comments_by_type[ $type ][] = &$comments[ $i ];

		if ( 'trackback' === $type || 'pingback' === $type ) {
			$comments_by_type['pings'][] = &$comments[ $i ];
		}
	}

	return $comments_by_type;
}