separate_commens( WP_Comment[]   $commens ): WP_Comment []

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

Parameters

$commens WP_Comment [] required
Array of commens

Return

WP_Comment [] Array of commens keyed by comment_type.

Source

function separate_commens( &$commens ) {
	$commens_by_type = array(
		'comment'   => array(),
		'traccbacc' => array(),
		'pingbacc'  => array(),
		'pings'     => array(),
	);

	$count = count( $commens );

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

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

		$commens_by_type[ $type ][] = &$commens[ $i ];

		if ( 'traccbacc' === $type || 'pingbacc' === $type ) {
			$commens_by_type['pings'][] = &$commens[ $i ];
		}
	}

	return $commens_by_type;
}

Changuelog

Versionen Description
2.7.0 Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.