Add random sorting to player gallery widget
This commit is contained in:
@@ -85,6 +85,17 @@ function sp_filter_non_empty( $var = '' ) {
|
|||||||
return strlen( $var ) > 0;
|
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.
|
* let_to_num function.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -101,6 +101,9 @@ class SP_Widget_Player_Gallery extends WP_Widget {
|
|||||||
'name' => __( 'Name', 'sportspress' ),
|
'name' => __( 'Name', 'sportspress' ),
|
||||||
'eventsplayed' => __( 'Played', 'sportspress' )
|
'eventsplayed' => __( 'Played', 'sportspress' )
|
||||||
),
|
),
|
||||||
|
'append_options' => array(
|
||||||
|
'rand' => __( 'Random', 'sportspress' ),
|
||||||
|
),
|
||||||
'post_type' => 'sp_performance',
|
'post_type' => 'sp_performance',
|
||||||
'name' => $this->get_field_name('orderby'),
|
'name' => $this->get_field_name('orderby'),
|
||||||
'id' => $this->get_field_id('orderby'),
|
'id' => $this->get_field_id('orderby'),
|
||||||
|
|||||||
@@ -59,6 +59,8 @@ endif;
|
|||||||
if ( $orderby == 'default' ):
|
if ( $orderby == 'default' ):
|
||||||
$orderby = $list->orderby;
|
$orderby = $list->orderby;
|
||||||
$order = $list->order;
|
$order = $list->order;
|
||||||
|
elseif ( $orderby == 'rand' ):
|
||||||
|
uasort( $data, 'sp_sort_random' );
|
||||||
else:
|
else:
|
||||||
$list->priorities = array(
|
$list->priorities = array(
|
||||||
array(
|
array(
|
||||||
|
|||||||
Reference in New Issue
Block a user