Birthday widget options for showing and formatting the DoB and Age.
This commit is contained in:
@@ -10,6 +10,7 @@ class SP_Widget_Birthdays extends WP_Widget {
|
|||||||
extract($args);
|
extract($args);
|
||||||
$title = apply_filters( 'widget_title', empty($instance['title']) ? '' : $instance['title'], $instance, $this->id_base );
|
$title = apply_filters( 'widget_title', empty($instance['title']) ? '' : $instance['title'], $instance, $this->id_base );
|
||||||
$date = empty( $instance['date']) ? 'day' : strip_tags($instance['date'] );
|
$date = empty( $instance['date']) ? 'day' : strip_tags($instance['date'] );
|
||||||
|
$birthday_format = empty( $instance['birthday_format']) ? 'birthday' : strip_tags( $instance['birthday_format'] );
|
||||||
|
|
||||||
do_action( 'sportspress_before_widget', $args, $instance, 'birthdays' );
|
do_action( 'sportspress_before_widget', $args, $instance, 'birthdays' );
|
||||||
echo $before_widget;
|
echo $before_widget;
|
||||||
@@ -20,7 +21,7 @@ class SP_Widget_Birthdays extends WP_Widget {
|
|||||||
// Action to hook into
|
// Action to hook into
|
||||||
do_action( 'sportspress_before_widget_template', $args, $instance, 'birthdays' );
|
do_action( 'sportspress_before_widget_template', $args, $instance, 'birthdays' );
|
||||||
|
|
||||||
sp_get_template( 'birthdays.php', array( 'date' => $date ) );
|
sp_get_template( 'birthdays.php', array( 'date' => $date, 'birthday_format' => $birthday_format ) );
|
||||||
|
|
||||||
// Action to hook into
|
// Action to hook into
|
||||||
do_action( 'sportspress_after_widget_template', $args, $instance, 'birthdays' );
|
do_action( 'sportspress_after_widget_template', $args, $instance, 'birthdays' );
|
||||||
@@ -33,6 +34,7 @@ class SP_Widget_Birthdays extends WP_Widget {
|
|||||||
$instance = $old_instance;
|
$instance = $old_instance;
|
||||||
$instance['title'] = strip_tags( $new_instance['title'] );
|
$instance['title'] = strip_tags( $new_instance['title'] );
|
||||||
$instance['date'] = strip_tags( $new_instance['date'] );
|
$instance['date'] = strip_tags( $new_instance['date'] );
|
||||||
|
$instance['birthday_format'] = strip_tags( $new_instance['birthday_format'] );
|
||||||
|
|
||||||
// Filter to hook into
|
// Filter to hook into
|
||||||
$instance = apply_filters( 'sportspress_widget_update', $instance, $new_instance, $old_instance, 'birthdays' );
|
$instance = apply_filters( 'sportspress_widget_update', $instance, $new_instance, $old_instance, 'birthdays' );
|
||||||
@@ -41,7 +43,7 @@ class SP_Widget_Birthdays extends WP_Widget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function form( $instance ) {
|
function form( $instance ) {
|
||||||
$instance = wp_parse_args( (array) $instance, array( 'title' => '', 'date' => 'day' ) );
|
$instance = wp_parse_args( (array) $instance, array( 'title' => '', 'date' => 'day', 'birthday_format' => 'birthday' ) );
|
||||||
$title = strip_tags( $instance['title'] );
|
$title = strip_tags( $instance['title'] );
|
||||||
$date = strip_tags( $instance['date'] );
|
$date = strip_tags( $instance['date'] );
|
||||||
$options = array(
|
$options = array(
|
||||||
@@ -49,6 +51,13 @@ class SP_Widget_Birthdays extends WP_Widget {
|
|||||||
'week' => __( 'This week', 'sportspress' ),
|
'week' => __( 'This week', 'sportspress' ),
|
||||||
'month' => __( 'This month', 'sportspress' ),
|
'month' => __( 'This month', 'sportspress' ),
|
||||||
);
|
);
|
||||||
|
$birthday_format = strip_tags( $instance['birthday_format'] );
|
||||||
|
$birthday_options = array(
|
||||||
|
'hide' => __( 'Hide', 'sportspress' ),
|
||||||
|
'birthday' => __( 'Birthday', 'sportspress' ),
|
||||||
|
'age' => __( 'Age', 'sportspress' ),
|
||||||
|
'birthdayage' => __( 'Birthday (Age)', 'sportspress' ),
|
||||||
|
);
|
||||||
|
|
||||||
// Action to hook into
|
// Action to hook into
|
||||||
do_action( 'sportspress_before_widget_template_form', $this, $instance, 'birthdays' );
|
do_action( 'sportspress_before_widget_template_form', $this, $instance, 'birthdays' );
|
||||||
@@ -64,6 +73,14 @@ class SP_Widget_Birthdays extends WP_Widget {
|
|||||||
<?php } ?>
|
<?php } ?>
|
||||||
</select>
|
</select>
|
||||||
</p>
|
</p>
|
||||||
|
<p>
|
||||||
|
<label for="<?php echo $this->get_field_id('birthday_format'); ?>"><?php _e( 'Format:', 'sportspress' ); ?></label>
|
||||||
|
<select name="<?php echo $this->get_field_name('birthday_format'); ?>" id="<?php echo $this->get_field_id('birthday_format'); ?>" class="postform widefat">
|
||||||
|
<?php foreach ( $birthday_options as $value => $label ) { ?>
|
||||||
|
<option value="<?php echo $value; ?>" <?php selected( $value, $birthday_format ); ?>><?php echo $label; ?></option>
|
||||||
|
<?php } ?>
|
||||||
|
</select>
|
||||||
|
</p>
|
||||||
<?php
|
<?php
|
||||||
// Action to hook into
|
// Action to hook into
|
||||||
do_action( 'sportspress_after_widget_template_form', $this, $instance, 'birthdays' );
|
do_action( 'sportspress_after_widget_template_form', $this, $instance, 'birthdays' );
|
||||||
|
|||||||
@@ -16,10 +16,9 @@ $defaults = array(
|
|||||||
'icontag' => 'dt',
|
'icontag' => 'dt',
|
||||||
'captiontag' => 'dd',
|
'captiontag' => 'dd',
|
||||||
'size' => 'sportspress-fit-medium',
|
'size' => 'sportspress-fit-medium',
|
||||||
|
'birthday_format' => 'birthday',
|
||||||
'show_player_birthday' => get_option( 'sportspress_player_show_birthday', 'no' ) == 'yes' ? true : false,
|
'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,
|
'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_players' => get_option( 'sportspress_link_players', 'yes' ) == 'yes' ? true : false,
|
||||||
'link_staff' => get_option( 'sportspress_link_staff', '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 ) {
|
if ( 'sp_staff' == $post->post_type ) {
|
||||||
$link_posts = $link_staff;
|
$link_posts = $link_staff;
|
||||||
$show_birthday = $show_staff_birthday;
|
$show_birthday = $show_staff_birthday;
|
||||||
$show_age = $sportspress_staff_show_age;
|
|
||||||
} else {
|
} else {
|
||||||
$link_posts = $link_players;
|
$link_posts = $link_players;
|
||||||
$show_birthday = $show_player_birthday;
|
$show_birthday = $show_player_birthday;
|
||||||
$show_age = $show_player_age;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$birthday = get_the_date( get_option( 'date_format') , $post->ID );
|
$birthday = get_the_date( get_option( 'date_format') , $post->ID );
|
||||||
|
|
||||||
$heading = null;
|
$heading = null;
|
||||||
if ( $show_birthday && $birthday ) {
|
if ( ( $show_birthday || 'birthday' == $birthday_format ) && $birthday && 'hide' != $birthday_format ) {
|
||||||
$heading = '<h4 class="sp-table-caption">' . $birthday . '</h4>';
|
$heading = '<h4 class="sp-table-caption">' . $birthday . '</h4>';
|
||||||
}
|
}
|
||||||
if ( $show_birthday && $show_age && $birthday ) {
|
if ( 'age' == $birthday_format && $birthday ) {
|
||||||
$sp_birthdays = new SportsPress_Birthdays();
|
$sp_birthdays = new SportsPress_Birthdays();
|
||||||
$age = $sp_birthdays->get_age( get_the_date( 'm-d-Y', $post->ID ) );
|
$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;
|
echo $heading;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user