Merge pull request #381 from ThemeBoy/feature-dob-age-player-lists

Feature dob age player lists
This commit is contained in:
Brian Miyaji
2020-04-09 22:07:28 +10:00
committed by GitHub
3 changed files with 45 additions and 0 deletions

View File

@@ -48,6 +48,7 @@ class SP_Meta_Box_List_Columns {
<?php _e( 'Position', 'sportspress' ); ?>
</label>
</li>
<?php do_action( 'sportspress_list_general_columns', $selected ); ?>
</ul>
<p><strong><?php _e( 'Data', 'sportspress' ); ?></strong></p>
<div class="sp-instance">

View File

@@ -406,6 +406,8 @@ class SP_Player_List extends SP_Secondary_Post {
$team_performance = get_post_meta( $event->ID, 'sp_players', true );
$timeline = (array)get_post_meta( $event->ID, 'sp_timeline', true );
$minutes = get_post_meta( $event->ID, 'sp_minutes', true );
$showdob = get_option( 'sportspress_player_show_birthday', 'no' );
$showage = get_option( 'sportspress_player_show_age', 'no' );
if ( $minutes === '' ) $minutes = get_option( 'sportspress_event_minutes', 90 );
// Add all team performance
@@ -628,6 +630,15 @@ class SP_Player_List extends SP_Secondary_Post {
// Merge the data and placeholders arrays
foreach( $placeholders as $player_id => $player_data ):
if ( in_array( 'dob', $this->columns ) ):
$player_data['dob'] = get_the_date( get_option( 'date_format') , $player_id );
endif;
if ( in_array( 'age', $this->columns ) ):
$birthdayclass = new SportsPress_Birthdays();
$player_data['age'] = $birthdayclass->get_age( get_the_date( 'm-d-Y', $player_id ) );
endif;
$player_data = array_merge( $column_order, $player_data );
$placeholders[ $player_id ] = $player_data;
@@ -715,6 +726,10 @@ class SP_Player_List extends SP_Secondary_Post {
$labels[ $key ] = __( 'Team', 'sportspress' );
elseif ( $key == 'position' ):
$labels[ $key ] = __( 'Position', 'sportspress' );
elseif ( $key == 'dob' && $showdob ):
$labels[ $key ] = __( 'Date of Birth', 'sportspress' );
elseif ( $key == 'age' && $showage ):
$labels[ $key ] = __( 'Age', 'sportspress' );
elseif ( array_key_exists( $key, $columns ) ):
$labels[ $key ] = $columns[ $key ];
endif;
@@ -764,6 +779,12 @@ class SP_Player_List extends SP_Secondary_Post {
if ( in_array( 'position', $this->columns ) ) {
$labels['position'] = __( 'Position', 'sportspress' );
}
if ( in_array( 'dob', $this->columns ) && $showdob ) {
$labels['dob'] = __( 'Date of Birth', 'sportspress' );
}
if ( in_array( 'age', $this->columns ) && $showage ) {
$labels['age'] = __( 'Age', 'sportspress' );
}
$merged[0] = array_merge( $labels, $columns );
return $merged;

View File

@@ -36,6 +36,7 @@ class SportsPress_Birthdays {
add_filter( 'sportspress_staff_details', array( $this, 'add_staff_details' ), 20, 2 );
add_action( 'sportspress_widgets', array( $this, 'widgets' ) );
add_action( 'sportspress_list_general_columns', array( $this, 'columns' ), 10, 1 );
}
/**
@@ -187,6 +188,28 @@ class SportsPress_Birthdays {
public static function widgets() {
include_once( SP()->plugin_path() . '/includes/widgets/class-sp-widget-birthdays.php' );
}
/**
* Add more General Columns at Player Lists
*/
public static function columns( $selected ) {
if ( 'yes' == get_option( 'sportspress_player_show_birthday', 'no' ) ) { ?>
<li>
<label class="selectit">
<input value="dob" type="checkbox" name="sp_columns[]" id="sp_columns_dob" <?php checked( in_array( 'dob', $selected ) ); ?>>
<?php _e( 'Date of Birth', 'sportspress' ); ?>
</label>
</li>
<?php } ?>
<?php if ( 'yes' == get_option( 'sportspress_player_show_age', 'no' ) ) { ?>
<li>
<label class="selectit">
<input value="age" type="checkbox" name="sp_columns[]" id="sp_columns_age" <?php checked( in_array( 'age', $selected ) ); ?>>
<?php _e( 'Age', 'sportspress' ); ?>
</label>
</li>
<?php }
}
/**
* Get age from date.