Move player list column checkboxes and add position option
This commit is contained in:
@@ -19,7 +19,37 @@ class SP_Meta_Box_List_Columns {
|
||||
* Output the metabox
|
||||
*/
|
||||
public static function output( $post ) {
|
||||
$selected = (array)get_post_meta( $post->ID, 'sp_columns', true );
|
||||
$orderby = get_post_meta( $post->ID, 'sp_orderby', true );
|
||||
?>
|
||||
<p><strong><?php _e( 'General', 'sportspress' ); ?></strong></p>
|
||||
<ul class="categorychecklist form-no-clear">
|
||||
<li>
|
||||
<label class="selectit">
|
||||
<input value="number" type="checkbox" name="sp_columns[]" id="sp_columns_number" <?php checked( in_array( 'number', $selected ) ); ?>>
|
||||
<?php
|
||||
if ( in_array( $orderby, array( 'number', 'name' ) ) ) {
|
||||
_e( 'Squad Number', 'sportspress' );
|
||||
} else {
|
||||
_e( 'Rank', 'sportspress' );
|
||||
}
|
||||
?>
|
||||
</label>
|
||||
</li>
|
||||
<li>
|
||||
<label class="selectit">
|
||||
<input value="team" type="checkbox" name="sp_columns[]" id="sp_columns_team" <?php checked( in_array( 'team', $selected ) ); ?>>
|
||||
<?php _e( 'Team', 'sportspress' ); ?>
|
||||
</label>
|
||||
</li>
|
||||
<li>
|
||||
<label class="selectit">
|
||||
<input value="position" type="checkbox" name="sp_columns[]" id="sp_columns_position" <?php checked( in_array( 'position', $selected ) ); ?>>
|
||||
<?php _e( 'Position', 'sportspress' ); ?>
|
||||
</label>
|
||||
</li>
|
||||
</ul>
|
||||
<p><strong><?php _e( 'Data', 'sportspress' ); ?></strong></p>
|
||||
<div class="sp-instance">
|
||||
<ul id="sp_column-tabs" class="wp-tab-bar sp-tab-bar">
|
||||
<li class="wp-tab-active"><a href="#sp_performance-all"><?php _e( 'Performance', 'sportspress' ); ?></a></li>
|
||||
@@ -27,7 +57,6 @@ class SP_Meta_Box_List_Columns {
|
||||
<li class="wp-tab"><a href="#sp_statistic-all"><?php _e( 'Statistics', 'sportspress' ); ?></a></li>
|
||||
</ul>
|
||||
<?php
|
||||
$selected = (array)get_post_meta( $post->ID, 'sp_columns', true );
|
||||
sp_column_checklist( $post->ID, 'sp_performance', 'block', $selected );
|
||||
sp_column_checklist( $post->ID, 'sp_metric', 'none', $selected );
|
||||
sp_column_checklist( $post->ID, 'sp_statistic', 'none', $selected );
|
||||
|
||||
@@ -47,19 +47,18 @@ class SP_Meta_Box_List_Data {
|
||||
<table class="widefat sp-data-table sp-player-list-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th><label for="sp_columns_number">
|
||||
<input type="checkbox" name="sp_columns[]" value="number" id="sp_columns_number" <?php checked( ! is_array( $columns ) || array_key_exists( 'number', $columns ) ); ?>>
|
||||
<?php echo 'number' == $orderby ? '#' : __( 'Rank', 'sportspress' ); ?>
|
||||
</label></th>
|
||||
<?php if ( array_key_exists( 'number', $columns ) ) { ?>
|
||||
<th><?php echo in_array( $orderby, array( 'number', 'name' ) ) ? '#' : __( 'Rank', 'sportspress' ); ?></th>
|
||||
<?php } ?>
|
||||
<th><?php _e( 'Player', 'sportspress' ); ?></th>
|
||||
<?php if ( apply_filters( 'sportspress_has_teams', true ) ) { ?>
|
||||
<th><label for="sp_columns_team">
|
||||
<input type="checkbox" name="sp_columns[]" value="team" id="sp_columns_team" <?php checked( ! is_array( $columns ) || array_key_exists( 'team', $columns ) ); ?>>
|
||||
<?php _e( 'Team', 'sportspress' ); ?>
|
||||
</label></th>
|
||||
<?php if ( array_key_exists( 'team', $columns ) && apply_filters( 'sportspress_has_teams', true ) ) { ?>
|
||||
<th><?php _e( 'Team', 'sportspress' ); ?></th>
|
||||
<?php } ?>
|
||||
<?php if ( array_key_exists( 'position', $columns ) ) { ?>
|
||||
<th><?php _e( 'Position', 'sportspress' ); ?></th>
|
||||
<?php } ?>
|
||||
<?php foreach ( $columns as $key => $label ): ?>
|
||||
<?php if ( in_array( $key, array( 'number', 'team' ) ) ) continue; ?>
|
||||
<?php if ( in_array( $key, array( 'number', 'team', 'position' ) ) ) continue; ?>
|
||||
<th><label for="sp_columns_<?php echo $key; ?>">
|
||||
<?php echo $label; ?>
|
||||
</label></th>
|
||||
@@ -81,6 +80,7 @@ class SP_Meta_Box_List_Data {
|
||||
$default_name = get_the_title( $player_id );
|
||||
?>
|
||||
<tr class="sp-row sp-post<?php if ( $i % 2 == 0 ) echo ' alternate'; ?>">
|
||||
<?php if ( array_key_exists( 'number', $columns ) ) { ?>
|
||||
<td>
|
||||
<?php
|
||||
if ( 'number' == $orderby ) {
|
||||
@@ -90,6 +90,7 @@ class SP_Meta_Box_List_Data {
|
||||
}
|
||||
?>
|
||||
</td>
|
||||
<?php } ?>
|
||||
<td>
|
||||
<?php if ( $show_player_photo ) echo get_the_post_thumbnail( $player_id, 'sportspress-fit-mini' ); ?>
|
||||
<span class="sp-default-value">
|
||||
@@ -102,7 +103,7 @@ class SP_Meta_Box_List_Data {
|
||||
<a class="button button-primary sp-save"><?php _e( 'Save', 'sportspress' ); ?></a>
|
||||
</span>
|
||||
</td>
|
||||
<?php if ( apply_filters( 'sportspress_has_teams', true ) ) { ?>
|
||||
<?php if ( array_key_exists( 'team', $columns ) && apply_filters( 'sportspress_has_teams', true ) ) { ?>
|
||||
<td>
|
||||
<?php
|
||||
$selected = sp_array_value( $player_stats, 'team', get_post_meta( get_the_ID(), 'sp_team', true ) );
|
||||
@@ -119,8 +120,25 @@ class SP_Meta_Box_List_Data {
|
||||
?>
|
||||
</td>
|
||||
<?php } ?>
|
||||
<?php if ( array_key_exists( 'position', $columns ) ) { ?>
|
||||
<td>
|
||||
<?php
|
||||
$selected = sp_array_value( $player_stats, 'position', null );
|
||||
$args = array(
|
||||
'taxonomy' => 'sp_position',
|
||||
'name' => 'sp_players[' . $player_id . '][position]',
|
||||
'show_option_blank' => __( '(Auto)', 'sportspress' ),
|
||||
'values' => 'term_id',
|
||||
'orderby' => 'slug',
|
||||
'selected' => $selected,
|
||||
'include_children' => ( 'no' == get_option( 'sportspress_event_hide_child_positions', 'no' ) ),
|
||||
);
|
||||
sp_dropdown_taxonomies( $args );
|
||||
?>
|
||||
</td>
|
||||
<?php } ?>
|
||||
<?php foreach( $columns as $column => $label ):
|
||||
if ( in_array( $column, array( 'number', 'team' ) ) ) continue;
|
||||
if ( in_array( $column, array( 'number', 'team', 'position' ) ) ) continue;
|
||||
$value = sp_array_value( $player_stats, $column, '' );
|
||||
$placeholder = sp_array_value( sp_array_value( $placeholders, $player_id, array() ), $column, 0 );
|
||||
?>
|
||||
|
||||
@@ -491,9 +491,19 @@ class SP_Player_List extends SP_Custom_Post {
|
||||
|
||||
// Add player number and name to row
|
||||
$merged[ $player_id ] = array();
|
||||
if ( in_array( 'number', $this->columns ) ):
|
||||
$player_data['number'] = get_post_meta( $player_id, 'sp_number', true );
|
||||
endif;
|
||||
|
||||
$player_data['name'] = get_the_title( $player_id );
|
||||
|
||||
if ( in_array( 'team', $this->columns ) ):
|
||||
$player_data['team'] = get_post_meta( $player_id, 'sp_team', true );
|
||||
endif;
|
||||
|
||||
if ( in_array( 'position', $this->columns ) ):
|
||||
$player_data['position'] = null;
|
||||
endif;
|
||||
|
||||
foreach( $player_data as $key => $value ):
|
||||
|
||||
@@ -530,6 +540,8 @@ class SP_Player_List extends SP_Custom_Post {
|
||||
$labels[ $key ] = '#';
|
||||
elseif ( $key == 'team' && apply_filters( 'sportspress_has_teams', true ) ):
|
||||
$labels[ $key ] = __( 'Team', 'sportspress' );
|
||||
elseif ( $key == 'position' ):
|
||||
$labels[ $key ] = __( 'Position', 'sportspress' );
|
||||
elseif ( array_key_exists( $key, $columns ) ):
|
||||
$labels[ $key ] = $columns[ $key ];
|
||||
endif;
|
||||
@@ -548,6 +560,7 @@ class SP_Player_List extends SP_Custom_Post {
|
||||
if ( in_array( 'number', $this->columns ) ) $labels['number'] = '#';
|
||||
$labels['name'] = __( 'Player', 'sportspress' );
|
||||
if ( in_array( 'team', $this->columns ) && apply_filters( 'sportspress_has_teams', true ) ) $labels['team'] = __( 'Team', 'sportspress' );
|
||||
if ( in_array( 'position', $this->columns ) ) $labels['position'] = __( 'Position', 'sportspress' );
|
||||
|
||||
$merged[0] = array_merge( $labels, $columns );
|
||||
return $merged;
|
||||
|
||||
@@ -177,8 +177,19 @@ foreach ( $groups as $group ):
|
||||
$output .= '<td class="data-team">' . $team_name . '</td>';
|
||||
endif;
|
||||
|
||||
if ( array_key_exists( 'position', $labels ) ):
|
||||
$position = sp_array_value( $row, 'position', null );
|
||||
if ( null === $position || ! $position ):
|
||||
$positions = wp_strip_all_tags( get_the_term_list( $player_id, 'sp_position', '', ', ' ) );
|
||||
else:
|
||||
$position_term = get_term_by( 'id', $position, 'sp_position', ARRAY_A );
|
||||
$positions = sp_array_value( $position_term, 'name', '—' );
|
||||
endif;
|
||||
$output .= '<td class="data-position">' . $positions . '</td>';
|
||||
endif;
|
||||
|
||||
foreach( $labels as $key => $value ):
|
||||
if ( in_array( $key, array( 'number', 'name', 'team' ) ) )
|
||||
if ( in_array( $key, array( 'number', 'name', 'team', 'position' ) ) )
|
||||
continue;
|
||||
if ( ! is_array( $columns ) || in_array( $key, $columns ) )
|
||||
$output .= '<td class="data-' . $key . '">' . sp_array_value( $row, $key, '—' ) . '</td>';
|
||||
|
||||
Reference in New Issue
Block a user