-1,
'performance' => null,
'orderby' => 'default',
'order' => 'ASC',
'show_all_players_link' => false,
'link_posts' => sportspress_array_value( $sportspress_options, 'player_list_link_posts', true ),
'sortable' => sportspress_array_value( $sportspress_options, 'player_list_sortable', true ),
'responsive' => sportspress_array_value( $sportspress_options, 'player_list_responsive', true ),
);
$r = wp_parse_args( $args, $defaults );
$output = '
' .
'
' . '' . '';
$data = sportspress_get_player_list_data( $id );
// The first row should be column labels
$labels = $data[0];
// Remove the first row to leave us with the actual data
unset( $data[0] );
$performance = sportspress_array_value( $r, 'performance', null );
if ( $r['orderby'] == 'default' ):
$r['orderby'] = get_post_meta( $id, 'sp_orderby', true );
$r['order'] = get_post_meta( $id, 'sp_order', true );
else:
global $sportspress_performance_priorities;
$sportspress_performance_priorities = array(
array(
'key' => $r['orderby'],
'order' => $r['order'],
),
);
uasort( $data, 'sportspress_sort_list_players' );
endif;
if ( in_array( $r['orderby'], array( 'number', 'name' ) ) ):
$output .= '| # | ';
else:
$output .= '' . __( 'Rank', 'sportspress' ) . ' | ';
endif;
foreach( $labels as $key => $label ):
if ( ! is_array( $performance ) || $key == 'name' || in_array( $key, $performance ) )
$output .= ''. $label . ' | ';
endforeach;
$output .= '
' . '' . '';
$i = 0;
if ( is_int( $r['number'] ) && $r['number'] > 0 )
$limit = $r['number'];
foreach( $data as $player_id => $row ):
if ( isset( $limit ) && $i >= $limit ) continue;
$name = sportspress_array_value( $row, 'name', null );
if ( ! $name ) continue;
$output .= '';
// Rank or number
if ( isset( $r['orderby'] ) && $r['orderby'] != 'number' ):
$output .= '| ' . ( $i + 1 ) . ' | ';
else:
$number = get_post_meta( $player_id, 'sp_number', true );
$output .= '' . ( $number ? $number : ' ' ) . ' | ';
endif;
if ( $r['link_posts'] ):
$permalink = get_post_permalink( $player_id );
$name = '' . $name . '';
endif;
$output .= '' . $name . ' | ';
foreach( $labels as $key => $value ):
if ( $key == 'name' )
continue;
if ( ! is_array( $performance ) || in_array( $key, $performance ) )
$output .= '' . sportspress_array_value( $row, $key, '—' ) . ' | ';
endforeach;
$output .= '
';
$i++;
endforeach;
$output .= '' . '
' . '
';
if ( $r['show_all_players_link'] )
$output .= '' . __( 'View all players', 'sportspress' ) . '';
return apply_filters( 'sportspress_player_list', $output );
}
}
function sportspress_player_list_shortcode( $atts ) {
if ( isset( $atts['id'] ) ):
$id = $atts['id'];
unset( $atts['id'] );
elseif( isset( $atts[0] ) ):
$id = $atts[0];
unset( $atts[0] );
else:
$id = null;
endif;
return sportspress_player_list( $id, $atts );
}
add_shortcode('player-list', 'sportspress_player_list_shortcode');