Birthday widget options for showing and formatting the DoB and Age.

This commit is contained in:
savvasha
2020-08-31 07:52:47 +03:00
parent 41601ced07
commit 063c33a21d
2 changed files with 34 additions and 15 deletions

View File

@@ -16,10 +16,9 @@ $defaults = array(
'icontag' => 'dt',
'captiontag' => 'dd',
'size' => 'sportspress-fit-medium',
'birthday_format' => 'birthday',
'show_player_birthday' => get_option( 'sportspress_player_show_birthday', 'no' ) == 'yes' ? true : false,
'show_player_age' => get_option( 'sportspress_player_show_age', 'no' ) == 'yes' ? true : false,
'show_staff_birthday' => get_option( 'sportspress_staff_show_birthday', 'no' ) == 'yes' ? true : false,
'sportspress_staff_show_age' => get_option( 'sportspress_staff_show_age', 'no' ) == 'yes' ? true : false,
'link_players' => get_option( 'sportspress_link_players', 'yes' ) == 'yes' ? true : false,
'link_staff' => get_option( 'sportspress_link_staff', 'yes' ) == 'yes' ? true : false,
);
@@ -86,23 +85,26 @@ foreach ( $posts as $post ) {
if ( 'sp_staff' == $post->post_type ) {
$link_posts = $link_staff;
$show_birthday = $show_staff_birthday;
$show_age = $sportspress_staff_show_age;
} else {
$link_posts = $link_players;
$show_birthday = $show_player_birthday;
$show_age = $show_player_age;
}
$birthday = get_the_date( get_option( 'date_format') , $post->ID );
$heading = null;
if ( $show_birthday && $birthday ) {
if ( ( $show_birthday || 'birthday' == $birthday_format ) && $birthday && 'hide' != $birthday_format ) {
$heading = '<h4 class="sp-table-caption">' . $birthday . '</h4>';
}
if ( $show_birthday && $show_age && $birthday ) {
if ( 'age' == $birthday_format && $birthday ) {
$sp_birthdays = new SportsPress_Birthdays();
$age = $sp_birthdays->get_age( get_the_date( 'm-d-Y', $post->ID ) );
$heading = '<h4 class="sp-table-caption">' . $age . __( ' years old', 'sportspress' ) . '</h4>';
$heading = '<h4 class="sp-table-caption">' . $age . '</h4>';
}
if ( 'birthdayage' == $birthday_format && $birthday ) {
$sp_birthdays = new SportsPress_Birthdays();
$age = $sp_birthdays->get_age( get_the_date( 'm-d-Y', $post->ID ) );
$heading = '<h4 class="sp-table-caption">' . $birthday . ' (' . $age . ')</h4>';
}
echo $heading;