Add options to widgets

This commit is contained in:
Brian Miyaji
2014-03-17 22:55:24 +11:00
parent da10162988
commit b885665f21
4 changed files with 25 additions and 4 deletions

View File

@@ -197,7 +197,7 @@ if ( !function_exists( 'sportspress_events_calendar' ) ) {
$calendar_output .= "\n\t</tr>\n\t</tbody>\n\t</table>"; $calendar_output .= "\n\t</tr>\n\t</tbody>\n\t</table>";
if ( $id && $r['show_all_events_link'] ) if ( $id && $r['show_all_events_link'] )
$calendar_output .= '<a class="sp-all-events-link" href="' . get_permalink( $id ) . '">' . __( 'View all events', 'sportspress' ) . '</a>'; $calendar_output .= '<a class="sp-calendar-link" href="' . get_permalink( $id ) . '">' . __( 'View all events', 'sportspress' ) . '</a>';
return apply_filters( 'sportspress_events_calendar', $calendar_output ); return apply_filters( 'sportspress_events_calendar', $calendar_output );

View File

@@ -117,7 +117,7 @@ if ( !function_exists( 'sportspress_events_list' ) ) {
$output .= '</tbody>' . '</table>'; $output .= '</tbody>' . '</table>';
if ( $id && $r['show_all_events_link'] ) if ( $id && $r['show_all_events_link'] )
$output .= '<a class="sp-all-events-link" href="' . get_permalink( $id ) . '">' . __( 'View all events', 'sportspress' ) . '</a>'; $output .= '<a class="sp-calendar-link" href="' . get_permalink( $id ) . '">' . __( 'View all events', 'sportspress' ) . '</a>';
$output .= '</div>'; $output .= '</div>';

View File

@@ -6,9 +6,11 @@ if ( !function_exists( 'sportspress_player_list' ) ) {
$id = get_the_ID(); $id = get_the_ID();
$defaults = array( $defaults = array(
'number' => -1,
'statistics' => null, 'statistics' => null,
'orderby' => 'default', 'orderby' => 'default',
'order' => 'ASC', 'order' => 'ASC',
'show_all_players_link' => false,
); );
$r = wp_parse_args( $args, $defaults ); $r = wp_parse_args( $args, $defaults );
@@ -55,7 +57,11 @@ if ( !function_exists( 'sportspress_player_list' ) ) {
$i = 0; $i = 0;
if ( is_int( $r['number'] ) && $r['number'] > 0 )
$limit = $r['number'];
foreach( $data as $player_id => $row ): foreach( $data as $player_id => $row ):
if ( isset( $limit ) && $i >= $limit ) continue;
$name = sportspress_array_value( $row, 'name', null ); $name = sportspress_array_value( $row, 'name', null );
if ( ! $name ) continue; if ( ! $name ) continue;
@@ -89,6 +95,9 @@ if ( !function_exists( 'sportspress_player_list' ) ) {
$output .= '</tbody>' . '</table>' . '</div>'; $output .= '</tbody>' . '</table>' . '</div>';
if ( $r['show_all_players_link'] )
$output .= '<a class="sp-player-list-link" href="' . get_permalink( $id ) . '">' . __( 'View all players', 'sportspress' ) . '</a>';
return apply_filters( 'sportspress_player_list', $output ); return apply_filters( 'sportspress_player_list', $output );
} }

View File

@@ -10,14 +10,16 @@ class SportsPress_Widget_Player_list 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);
$id = empty($instance['id']) ? null : $instance['id']; $id = empty($instance['id']) ? null : $instance['id'];
$number = empty($instance['number']) ? null : $instance['number'];
$statistics = $instance['statistics']; $statistics = $instance['statistics'];
$orderby = empty($instance['orderby']) ? 'default' : $instance['orderby']; $orderby = empty($instance['orderby']) ? 'default' : $instance['orderby'];
$order = empty($instance['order']) ? 'ASC' : $instance['order']; $order = empty($instance['order']) ? 'ASC' : $instance['order'];
$show_all_players_link = empty($instance['show_all_players_link']) ? false : $instance['show_all_players_link'];
echo $before_widget; echo $before_widget;
if ( $title ) if ( $title )
echo $before_title . $title . $after_title; echo $before_title . $title . $after_title;
echo '<div id="sp_player_list_wrap">'; echo '<div id="sp_player_list_wrap">';
echo sportspress_player_list( $id, array( 'statistics' => $statistics, 'orderby' => $orderby , 'order' => $order ) ); echo sportspress_player_list( $id, array( 'number' => $number, 'statistics' => $statistics, 'orderby' => $orderby , 'order' => $order, 'show_all_players_link' => $show_all_players_link ) );
echo '</div>'; echo '</div>';
echo $after_widget; echo $after_widget;
} }
@@ -26,20 +28,24 @@ class SportsPress_Widget_Player_list extends WP_Widget {
$instance = $old_instance; $instance = $old_instance;
$instance['title'] = strip_tags($new_instance['title']); $instance['title'] = strip_tags($new_instance['title']);
$instance['id'] = intval($new_instance['id']); $instance['id'] = intval($new_instance['id']);
$instance['number'] = intval($new_instance['number']);
$instance['statistics'] = (array)$new_instance['statistics']; $instance['statistics'] = (array)$new_instance['statistics'];
$instance['orderby'] = strip_tags($new_instance['orderby']); $instance['orderby'] = strip_tags($new_instance['orderby']);
$instance['order'] = strip_tags($new_instance['order']); $instance['order'] = strip_tags($new_instance['order']);
$instance['show_all_players_link'] = $new_instance['show_all_players_link'];
return $instance; return $instance;
} }
function form( $instance ) { function form( $instance ) {
$instance = wp_parse_args( (array) $instance, array( 'title' => '', 'id' => '', 'statistics' => null, 'orderby' => 'default', 'order' => 'ASC' ) ); $instance = wp_parse_args( (array) $instance, array( 'title' => '', 'id' => '', 'number' => 5, 'statistics' => null, 'orderby' => 'default', 'order' => 'ASC', 'show_all_players_link' => true ) );
$title = strip_tags($instance['title']); $title = strip_tags($instance['title']);
$id = intval($instance['id']); $id = intval($instance['id']);
$number = intval($instance['number']);
$statistics = $instance['statistics']; $statistics = $instance['statistics'];
$orderby = strip_tags($instance['orderby']); $orderby = strip_tags($instance['orderby']);
$order = strip_tags($instance['order']); $order = strip_tags($instance['order']);
$show_all_players_link = $instance['show_all_players_link'];
?> ?>
<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e( 'Title:', 'sportspress' ); ?></label> <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e( 'Title:', 'sportspress' ); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" /></p> <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" /></p>
@@ -60,6 +66,9 @@ class SportsPress_Widget_Player_list extends WP_Widget {
?> ?>
</p> </p>
<p><label for="<?php echo $this->get_field_id('number'); ?>"><?php _e( 'Number of players to show:', 'sportspress' ); ?></label>
<input id="<?php echo $this->get_field_id('number'); ?>" name="<?php echo $this->get_field_name('number'); ?>" type="text" value="<?php echo esc_attr($number); ?>" size="3"></p>
<p class="sp-prefs"> <p class="sp-prefs">
<?php _e( 'Statistics:', 'sportspress' ); ?><br> <?php _e( 'Statistics:', 'sportspress' ); ?><br>
<?php <?php
@@ -108,6 +117,9 @@ class SportsPress_Widget_Player_list extends WP_Widget {
<option value="ASC" <?php selected( 'ASC', $order ); ?>><?php _e( 'Ascending', 'sportspress' ); ?></option> <option value="ASC" <?php selected( 'ASC', $order ); ?>><?php _e( 'Ascending', 'sportspress' ); ?></option>
<option value="DESC" <?php selected( 'DESC', $order ); ?>><?php _e( 'Descending', 'sportspress' ); ?></option> <option value="DESC" <?php selected( 'DESC', $order ); ?>><?php _e( 'Descending', 'sportspress' ); ?></option>
</select></p> </select></p>
<p><input class="checkbox" type="checkbox" id="<?php echo $this->get_field_id('show_all_players_link'); ?>" name="<?php echo $this->get_field_name('show_all_players_link'); ?>" value="1" <?php checked( $show_all_players_link, 1 ); ?>>
<label for="<?php echo $this->get_field_id('show_all_players_link'); ?>"><?php _e( 'Display link to view all players', 'sportspress' ); ?></label></p>
<?php <?php
} }
} }