Add Age in player list
-
Hi, can I add players’ age (or year of birth) to the player list? Like this: https://ibb.co/rxz9Q6Y
I guess it could be done using the player metric. What is the value of a variable? https://ibb.co/R0nVP4X
Thanx maarty
-
Hi!
That’s great, let’s go for it then.
Please keep in mind that these changes will be lost in future updates. There’s no easy way to do this via hooks or with filters at the moment, so be careful with when you update your files.
Open
wp-content/plugins/sportspress/includes/class-sp-player-list.php
Then around line 396 where you see this:
// Event loop foreach ( $events as $i => $event ): $results = (array)get_post_meta( $event->ID, 'sp_results', true ); $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 );
Add this after minutes:
//AGE NEW $showdob = get_option( 'sportspress_player_show_birthday', 'no' ); $showage = get_option( 'sportspress_player_show_age', 'no' ); // /AGE
Around line 626, where you see this:
// Merge the data and placeholders arrays foreach( $placeholders as $player_id => $player_data ):
Add this after the foreach:
//AGE NEW 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; // / AGE
Around line 724, where you see this:
$labels = array(); foreach( $this->columns as $key ): if ( $key == 'number' ): $labels[ $key ] = '#'; elseif ( $key == 'team' ): $labels[ $key ] = __( 'Team', 'sportspress' ); elseif ( $key == 'position' ): $labels[ $key ] = __( 'Position', 'sportspress' );
Add this right after the position:
//AGE NEW elseif ( $key == 'dob' && $showdob ): $labels[ $key ] = __( 'Date of Birth', 'sportspress' ); elseif ( $key == 'age' && $showage ): $labels[ $key ] = __( 'Age', 'sportspress' ); // /AGE
Around line 780 where you see this:
$labels = array(); if ( in_array( 'number', $this->columns ) ) $labels['number'] = '#'; $labels['name'] = __( 'Player', 'sportspress' ); if ( in_array( 'team', $this->columns ) ) { $labels['team'] = __( 'Team', 'sportspress' ); } if ( in_array( 'position', $this->columns ) ) { $labels['position'] = __( 'Position', 'sportspress' ); }
Add this after the last if:
//AGE NEW if ( in_array( 'dob', $this->columns ) && $showdob ) { $labels['dob'] = __( 'Date of Birth', 'sportspress' ); } if ( in_array( 'age', $this->columns ) && $showage ) { $labels['age'] = __( 'Age', 'sportspress' ); } // /AGE
Now let’s edit a different file. Open
wp-content\plugins\sportspress\includes\admin\post-types\meta-boxes\class-sp-meta-box-list-columns.php
Then around line 50, where you see this:
<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>
Add this after the closing li:
<?php //AGE NEW do_action( 'sportspress_list_general_columns', $selected ); //AGE NEW END ?>
And now the last bit. Open
wp-content\plugins\sportspress\modules\sportspress-birthdays.php
Around line 38 where you see this:
add_action( 'sportspress_widgets', array( $this, 'widgets' ) );
Add this:
//AGE NEW add_action( 'sportspress_list_general_columns', array( $this, 'columns' ), 10, 1 ); //AGE NEW END
Now the last bit, around line 194, where you have this:
public static function widgets() { include_once( SP()->plugin_path() . '/includes/widgets/class-sp-widget-birthdays.php' ); }
Add this:
//AGE NEW /** * 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 } } //AGE NEW END
Wow, that’s it! Please notice that all these are just additions to the current code. You won’t delete anything from your current files, only add.
Please try this and let us know how it works for you.
Thanks!
Hi @rochesterj
It works great. Fantastic!
Last question: Updating the SportPress will delete it? Do I have to do the same again after each update?
Thanks!
Hi @maarty ,
Unfortunately is not yet added to the core code. So yes, if you update SportsPress you will need to manually made those changes again. I already Open a Pull request to include that in the core code, so keep looking at the changelogs of each update to check if it is added ??
Thanks,
SavvasHi Maarty
That’s awesome, I’m glad it worked for you. And kudos to Savvas for making such an awesome edit that works even after quite a long time ??
It would be a great addition to core indeed.
Thanks!
- The topic ‘Add Age in player list’ is closed to new replies.