Add random sorting to player gallery widget

This commit is contained in:
Brian Miyaji
2015-06-21 00:29:43 +10:00
parent 22b263f527
commit f03b72167d
3 changed files with 16 additions and 0 deletions

View File

@@ -85,6 +85,17 @@ function sp_filter_non_empty( $var = '' ) {
return strlen( $var ) > 0;
}
/**
* Sort array randomly and maintain index association.
*
* @access public
* @param array $array
* @return bool
*/
function sp_sort_random() {
return rand() > rand();
}
/**
* let_to_num function.
*

View File

@@ -101,6 +101,9 @@ class SP_Widget_Player_Gallery extends WP_Widget {
'name' => __( 'Name', 'sportspress' ),
'eventsplayed' => __( 'Played', 'sportspress' )
),
'append_options' => array(
'rand' => __( 'Random', 'sportspress' ),
),
'post_type' => 'sp_performance',
'name' => $this->get_field_name('orderby'),
'id' => $this->get_field_id('orderby'),

View File

@@ -59,6 +59,8 @@ endif;
if ( $orderby == 'default' ):
$orderby = $list->orderby;
$order = $list->order;
elseif ( $orderby == 'rand' ):
uasort( $data, 'sp_sort_random' );
else:
$list->priorities = array(
array(