WP_Plugins_List_Table::_order_callbackpublicWP 3.1.0

Callback to sort plugins by a given column.

Method of the class: WP_Plugins_List_Table{}

No Hooks.

Returns

int. Negative if $plugin_a sorts before $plugin_b, positive if after, 0 if equal.

Usage

$WP_Plugins_List_Table = new WP_Plugins_List_Table();
$WP_Plugins_List_Table->_order_callback( $plugin_a, $plugin_b );
$plugin_a(array<string, mixed>) (required)
First plugin data array to compare.
$plugin_b(array<string, mixed>) (required)
Second plugin data array to compare.

Notes

Global. String. $orderby The column name to sort by.
Global. String. $order The sort direction ('ASC' or 'DESC').

Changelog

Since 3.1.0 Introduced.

WP_Plugins_List_Table::_order_callback() code WP 7.1

public function _order_callback( $plugin_a, $plugin_b ) {
	global $orderby, $order;

	$a = $plugin_a[ $orderby ];
	$b = $plugin_b[ $orderby ];

	if ( $a === $b ) {
		return 0;
	}

	if ( 'DESC' === $order ) {
		return strcasecmp( $b, $a );
	} else {
		return strcasecmp( $a, $b );
	}
}