Add checkboxes to each player list column
This commit is contained in:
@@ -150,6 +150,9 @@ function sportspress_save_post( $post_id ) {
|
|||||||
|
|
||||||
case ( 'sp_list' ):
|
case ( 'sp_list' ):
|
||||||
|
|
||||||
|
// Update statistics array
|
||||||
|
update_post_meta( $post_id, 'sp_statistics', sportspress_array_value( $_POST, 'sp_statistics', array() ) );
|
||||||
|
|
||||||
// Update players array
|
// Update players array
|
||||||
update_post_meta( $post_id, 'sp_players', sportspress_array_value( $_POST, 'sp_players', array() ) );
|
update_post_meta( $post_id, 'sp_players', sportspress_array_value( $_POST, 'sp_players', array() ) );
|
||||||
|
|
||||||
|
|||||||
@@ -49,11 +49,7 @@ function sportspress_list_meta_init( $post ) {
|
|||||||
remove_meta_box( 'sp_leaguediv', 'sp_list', 'side' );
|
remove_meta_box( 'sp_leaguediv', 'sp_list', 'side' );
|
||||||
add_meta_box( 'sp_formatdiv', __( 'Format', 'sportspress' ), 'sportspress_list_format_meta', 'sp_list', 'side', 'high' );
|
add_meta_box( 'sp_formatdiv', __( 'Format', 'sportspress' ), 'sportspress_list_format_meta', 'sp_list', 'side', 'high' );
|
||||||
add_meta_box( 'sp_detailsdiv', __( 'Details', 'sportspress' ), 'sportspress_list_details_meta', 'sp_list', 'side', 'high' );
|
add_meta_box( 'sp_detailsdiv', __( 'Details', 'sportspress' ), 'sportspress_list_details_meta', 'sp_list', 'side', 'high' );
|
||||||
|
add_meta_box( 'sp_statsdiv', __( 'Player List', 'sportspress' ), 'sportspress_list_stats_meta', 'sp_list', 'normal', 'high' );
|
||||||
if ( $players && $players != array(0) ):
|
|
||||||
add_meta_box( 'sp_statsdiv', __( 'Player List', 'sportspress' ), 'sportspress_list_stats_meta', 'sp_list', 'normal', 'high' );
|
|
||||||
endif;
|
|
||||||
|
|
||||||
add_meta_box( 'sp_descriptiondiv', __( 'Description', 'sportspress' ), 'sportspress_list_description_meta', 'sp_list', 'normal', 'high' );
|
add_meta_box( 'sp_descriptiondiv', __( 'Description', 'sportspress' ), 'sportspress_list_description_meta', 'sp_list', 'normal', 'high' );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -158,9 +154,9 @@ function sportspress_list_details_meta( $post ) {
|
|||||||
|
|
||||||
function sportspress_list_stats_meta( $post ) {
|
function sportspress_list_stats_meta( $post ) {
|
||||||
|
|
||||||
list( $columns, $data, $placeholders, $merged ) = sportspress_get_player_list_data( $post->ID, true );
|
list( $columns, $usecolumns, $data, $placeholders, $merged ) = sportspress_get_player_list_data( $post->ID, true );
|
||||||
|
|
||||||
sportspress_edit_player_list_table( $columns, $data, $placeholders );
|
sportspress_edit_player_list_table( $columns, $usecolumns, $data, $placeholders );
|
||||||
sportspress_nonce();
|
sportspress_nonce();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -828,7 +828,9 @@ if ( !function_exists( 'sportspress_edit_league_table' ) ) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ( !function_exists( 'sportspress_edit_player_list_table' ) ) {
|
if ( !function_exists( 'sportspress_edit_player_list_table' ) ) {
|
||||||
function sportspress_edit_player_list_table( $columns = array(), $data = array(), $placeholders = array() ) {
|
function sportspress_edit_player_list_table( $columns = array(), $usecolumns = null, $data = array(), $placeholders = array() ) {
|
||||||
|
if ( is_array( $usecolumns ) )
|
||||||
|
$usecolumns = array_filter( $usecolumns );
|
||||||
?>
|
?>
|
||||||
<div class="sp-data-table-container">
|
<div class="sp-data-table-container">
|
||||||
<table class="widefat sp-data-table">
|
<table class="widefat sp-data-table">
|
||||||
@@ -836,8 +838,11 @@ if ( !function_exists( 'sportspress_edit_player_list_table' ) ) {
|
|||||||
<tr>
|
<tr>
|
||||||
<th>#</th>
|
<th>#</th>
|
||||||
<th><?php _e( 'Player', 'sportspress' ); ?></th>
|
<th><?php _e( 'Player', 'sportspress' ); ?></th>
|
||||||
<?php foreach ( $columns as $label ): ?>
|
<?php foreach ( $columns as $key => $label ): ?>
|
||||||
<th><?php echo $label; ?></th>
|
<th><label for="sp_statistics_<?php echo $key; ?>">
|
||||||
|
<input type="checkbox" name="sp_statistics[]" value="<?php echo $key; ?>" id="sp_statistics_<?php echo $key; ?>" <?php checked( ! is_array( $usecolumns) || in_array( $key, $usecolumns ) ); ?>>
|
||||||
|
<?php echo $label; ?>
|
||||||
|
</label></th>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
@@ -1979,6 +1984,7 @@ if ( !function_exists( 'sportspress_get_player_list_data' ) ) {
|
|||||||
$stats = (array)get_post_meta( $post_id, 'sp_players', true );
|
$stats = (array)get_post_meta( $post_id, 'sp_players', true );
|
||||||
$orderby = get_post_meta( $post_id, 'sp_orderby', true );
|
$orderby = get_post_meta( $post_id, 'sp_orderby', true );
|
||||||
$order = get_post_meta( $post_id, 'sp_order', true );
|
$order = get_post_meta( $post_id, 'sp_order', true );
|
||||||
|
$usecolumns = get_post_meta( $post_id, 'sp_statistics', true );
|
||||||
|
|
||||||
// Get labels from result variables
|
// Get labels from result variables
|
||||||
$columns = (array)sportspress_get_var_labels( 'sp_statistic' );
|
$columns = (array)sportspress_get_var_labels( 'sp_statistic' );
|
||||||
@@ -2214,8 +2220,15 @@ if ( !function_exists( 'sportspress_get_player_list_data' ) ) {
|
|||||||
endforeach;
|
endforeach;
|
||||||
|
|
||||||
if ( $admin ):
|
if ( $admin ):
|
||||||
return array( $columns, $data, $placeholders, $merged );
|
return array( $columns, $usecolumns, $data, $placeholders, $merged );
|
||||||
else:
|
else:
|
||||||
|
if ( ! is_array( $usecolumns ) )
|
||||||
|
$usecolumns = array();
|
||||||
|
foreach ( $columns as $key => $label ):
|
||||||
|
if ( ! in_array( $key, $usecolumns ) ):
|
||||||
|
unset( $columns[ $key ] );
|
||||||
|
endif;
|
||||||
|
endforeach;
|
||||||
$labels = array_merge( array( 'name' => __( 'Player', 'sportspress' ) ), $columns );
|
$labels = array_merge( array( 'name' => __( 'Player', 'sportspress' ) ), $columns );
|
||||||
$merged[0] = $labels;
|
$merged[0] = $labels;
|
||||||
return $merged;
|
return $merged;
|
||||||
|
|||||||
Reference in New Issue
Block a user