WordPress at a glance
функция не описана

WP_List_Util::sort_callback() private WP 4.7.0

Callback to sort the list by specific fields.

It's a method of the class: WP_List_Util{}

Хуков нет.

Возвращает

Int. 0 if both objects equal. -1 if second object should come first, 1 otherwise.

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

// private - for code of main (parent) class only
$result = $this->sort_callback( $a, $b );
$a(object/array) (required)
One object to compare.
$b(object/array) (required)
The other object to compare.

Заметки

  • See: WP_List_Util::sort()

Changelog

Since 4.7.0 Introduced.

Код WP_List_Util::sort_callback() WP 5.5.1

<?php
private function sort_callback( $a, $b ) {
	if ( empty( $this->orderby ) ) {
		return 0;
	}

	$a = (array) $a;
	$b = (array) $b;

	foreach ( $this->orderby as $field => $direction ) {
		if ( ! isset( $a[ $field ] ) || ! isset( $b[ $field ] ) ) {
			continue;
		}

		if ( $a[ $field ] == $b[ $field ] ) {
			continue;
		}

		$results = 'DESC' === $direction ? array( 1, -1 ) : array( -1, 1 );

		if ( is_numeric( $a[ $field ] ) && is_numeric( $b[ $field ] ) ) {
			return ( $a[ $field ] < $b[ $field ] ) ? $results[0] : $results[1];
		}

		return 0 > strcmp( $a[ $field ], $b[ $field ] ) ? $results[0] : $results[1];
	}

	return 0;
}