Add player list widget and add league table widget columns selector
This commit is contained in:
@@ -21,7 +21,7 @@ function sportspress_gettext( $translated_text, $untranslated_text, $domain ) {
|
||||
elseif ( in_array( $typenow, array( 'sp_event', 'sp_player', 'sp_staff' ) ) ):
|
||||
switch ( $untranslated_text ):
|
||||
case 'Enter title here':
|
||||
$translated_text = __( 'Name', 'sportspress' );
|
||||
$translated_text = __( '(Auto)', 'sportspress' );
|
||||
break;
|
||||
case 'Set featured image':
|
||||
$translated_text = sprintf( __( 'Select %s', 'sportspress' ), __( 'Photo', 'sportspress' ) );
|
||||
|
||||
@@ -33,9 +33,24 @@ add_filter( 'the_content', 'sportspress_default_team_content' );
|
||||
|
||||
function sportspress_default_table_content( $content ) {
|
||||
if ( is_singular( 'sp_table' ) && in_the_loop() ):
|
||||
$id = get_the_ID();
|
||||
$leagues = get_the_terms( $id, 'sp_league' );
|
||||
$seasons = get_the_terms( $id, 'sp_season' );
|
||||
$terms = array();
|
||||
if ( $leagues ):
|
||||
$league = reset( $leagues );
|
||||
$terms[] = $league->name;
|
||||
endif;
|
||||
if ( $seasons ):
|
||||
$season = reset( $seasons );
|
||||
$terms[] = $season->name;
|
||||
endif;
|
||||
$title = '';
|
||||
if ( sizeof( $terms ) )
|
||||
$title = '<h4 class="sp-table-caption">' . implode( ' — ', $terms ) . '</h4>';
|
||||
$table = sportspress_league_table();
|
||||
$excerpt = has_excerpt() ? wpautop( get_the_excerpt() ) : '';
|
||||
$content = $table . $content . $excerpt;
|
||||
$content = $title . $table . $content . $excerpt;
|
||||
endif;
|
||||
return $content;
|
||||
}
|
||||
|
||||
@@ -81,8 +81,8 @@ function sportspress_player_details_meta( $post ) {
|
||||
</p>
|
||||
<p>
|
||||
<select id="sp_nationality" name="sp_nationality">
|
||||
<option value=""><?php _e( '-- Not set --', 'sportspress' ); ?></option>
|
||||
<?php foreach ( $continents as $continent => $countries ): ?>
|
||||
<option value=""><?php _e( '-- Not set --', 'sportspress' ); ?></option>
|
||||
<optgroup label="<?php echo $continent; ?>">
|
||||
<?php foreach ( $countries as $code => $country ): ?>
|
||||
<option value="<?php echo $code; ?>" <?php selected ( $nationality, $code ); ?>>
|
||||
|
||||
@@ -6,34 +6,12 @@ if ( !function_exists( 'sportspress_league_table' ) ) {
|
||||
$id = get_the_ID();
|
||||
|
||||
$defaults = array(
|
||||
'number_label' => __( 'Pos', 'sportspress' ),
|
||||
'thumbnails' => 0,
|
||||
'thumbnail_size' => 'thumbnail'
|
||||
'columns' => null,
|
||||
);
|
||||
|
||||
$r = wp_parse_args( $args, $defaults );
|
||||
|
||||
$leagues = get_the_terms( $id, 'sp_league' );
|
||||
$seasons = get_the_terms( $id, 'sp_season' );
|
||||
|
||||
$terms = array();
|
||||
if ( $leagues ):
|
||||
$league = reset( $leagues );
|
||||
$terms[] = $league->name;
|
||||
endif;
|
||||
if ( $seasons ):
|
||||
$season = reset( $seasons );
|
||||
$terms[] = $season->name;
|
||||
endif;
|
||||
|
||||
$title = sizeof( $terms ) ? implode( ' — ', $terms ) : get_the_title( $id );
|
||||
|
||||
if ( ! is_singular( 'sp_table' ) )
|
||||
$output = '<h4 class="sp-table-caption"><a href="' . get_permalink( $id ) . '">' . $title . '</a></h4>';
|
||||
else
|
||||
$output = '<h4 class="sp-table-caption">' . $title . '</h4>';
|
||||
|
||||
$output .= '<div class="sp-table-wrapper">' .
|
||||
$output = '<div class="sp-table-wrapper">' .
|
||||
'<table class="sp-league-table sp-data-table sp-responsive-table">' . '<thead>' . '<tr>';
|
||||
|
||||
$data = sportspress_get_league_table_data( $id );
|
||||
@@ -44,9 +22,13 @@ if ( !function_exists( 'sportspress_league_table' ) ) {
|
||||
// Remove the first row to leave us with the actual data
|
||||
unset( $data[0] );
|
||||
|
||||
$output .= '<th class="data-number">' . $r['number_label'] . '</th>';
|
||||
$columns = sportspress_array_value( $r, 'columns', null );
|
||||
|
||||
$output .= '<th class="data-number">' . __( 'Pos', 'sportspress' ) . '</th>';
|
||||
|
||||
foreach( $labels as $key => $label ):
|
||||
$output .= '<th class="data-' . $key . '">' . $label . '</th>';
|
||||
if ( ! is_array( $columns ) || $key == 'name' || in_array( $key, $columns ) )
|
||||
$output .= '<th class="data-' . $key . '">' . $label . '</th>';
|
||||
endforeach;
|
||||
|
||||
$output .= '</tr>' . '</thead>' . '<tbody>';
|
||||
@@ -57,23 +39,17 @@ if ( !function_exists( 'sportspress_league_table' ) ) {
|
||||
|
||||
$output .= '<tr class="' . ( $i % 2 == 0 ? 'odd' : 'even' ) . '">';
|
||||
|
||||
// Position as number
|
||||
$output .= '<td class="data-number">' . ( $i + 1 ) . '</td>';
|
||||
// Rank
|
||||
$output .= '<td class="data-rank">' . ( $i + 1 ) . '</td>';
|
||||
|
||||
// Thumbnail and name as link
|
||||
$permalink = get_post_permalink( $team_id );
|
||||
if ( $r['thumbnails'] ):
|
||||
$thumbnail = get_the_post_thumbnail( $team_id, $r['thumbnail_size'], array( 'class' => 'logo' ) );
|
||||
else:
|
||||
$thumbnail = null;
|
||||
endif;
|
||||
$name = sportspress_array_value( $row, 'name', sportspress_array_value( $row, 'name', ' ' ) );
|
||||
$output .= '<td class="data-name">' . ( $thumbnail ? $thumbnail . ' ' : '' ) . '<a href="' . $permalink . '">' . $name . '</a></td>';
|
||||
$output .= '<td class="data-name"><a href="' . get_post_permalink( $team_id ) . '">' . $name . '</a></td>';
|
||||
|
||||
foreach( $labels as $key => $value ):
|
||||
if ( $key == 'name' )
|
||||
continue;
|
||||
$output .= '<td class="data-' . $key . '">' . sportspress_array_value( $row, $key, '—' ) . '</td>';
|
||||
if ( ! is_array( $columns ) || in_array( $key, $columns ) )
|
||||
$output .= '<td class="data-' . $key . '">' . sportspress_array_value( $row, $key, '—' ) . '</td>';
|
||||
endforeach;
|
||||
|
||||
$output .= '</tr>';
|
||||
@@ -84,7 +60,7 @@ if ( !function_exists( 'sportspress_league_table' ) ) {
|
||||
|
||||
$output .= '</tbody>' . '</table>' . '</div>';
|
||||
|
||||
return apply_filters( 'sportspress_league_table', $output );
|
||||
return apply_filters( 'sportspress_league_table', $output, $id );
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,24 +1,51 @@
|
||||
<?php
|
||||
if ( !function_exists( 'sportspress_player_list' ) ) {
|
||||
function sportspress_player_list( $id = null ) {
|
||||
function sportspress_player_list( $id = null, $args = '' ) {
|
||||
|
||||
if ( ! $id )
|
||||
$id = get_the_ID();
|
||||
|
||||
$data = sportspress_get_player_list_data( $id );
|
||||
$defaults = array(
|
||||
'statistics' => null,
|
||||
'orderby' => 'number',
|
||||
'order' => 'ASC',
|
||||
);
|
||||
|
||||
$r = wp_parse_args( $args, $defaults );
|
||||
|
||||
$output = '<div class="sp-table-wrapper">' .
|
||||
'<table class="sp-player-list sp-data-table sp-responsive-table">' . '<thead>' . '<tr>';
|
||||
|
||||
$data = sportspress_get_player_list_data( $id );
|
||||
|
||||
// The first row should be column labels
|
||||
$labels = $data[0];
|
||||
|
||||
// Remove the first row to leave us with the actual data
|
||||
unset( $data[0] );
|
||||
|
||||
$output .= '<th class="data-number">#</th>';
|
||||
$statistics = sportspress_array_value( $r, 'statistics', null );
|
||||
|
||||
if ( $r['orderby'] != 'number' || $r['order'] != 'ASC' ):
|
||||
global $sportspress_statistic_priorities;
|
||||
$sportspress_statistic_priorities = array(
|
||||
array(
|
||||
'statistic' => $r['orderby'],
|
||||
'order' => $r['order'],
|
||||
),
|
||||
);
|
||||
uasort( $data, 'sportspress_sort_list_players' );
|
||||
endif;
|
||||
|
||||
if ( $r['orderby'] == 'number' ):
|
||||
$output .= '<th class="data-number">#</th>';
|
||||
else:
|
||||
$output .= '<th class="data-rank">' . __( 'Rank', 'sportspress' ) . '</th>';
|
||||
endif;
|
||||
|
||||
foreach( $labels as $key => $label ):
|
||||
$output .= '<th class="data-' . $key . '">' . $label . '</th>';
|
||||
if ( ! is_array( $statistics ) || $key == 'name' || in_array( $key, $statistics ) )
|
||||
$output .= '<th class="data-' . $key . '">'. $label . '</th>';
|
||||
endforeach;
|
||||
|
||||
$output .= '</tr>' . '</thead>' . '<tbody>';
|
||||
@@ -29,9 +56,13 @@ if ( !function_exists( 'sportspress_player_list' ) ) {
|
||||
|
||||
$output .= '<tr class="' . ( $i % 2 == 0 ? 'odd' : 'even' ) . '">';
|
||||
|
||||
// Player number
|
||||
$number = get_post_meta( $player_id, 'sp_number', true );
|
||||
$output .= '<td class="data-number">' . ( $number ? $number : ' ' ) . '</td>';
|
||||
// Rank or number
|
||||
if ( isset( $r['orderby'] ) && $r['orderby'] != 'number' ):
|
||||
$output .= '<td class="data-rank">' . ( $i + 1 ) . '</td>';
|
||||
else:
|
||||
$number = get_post_meta( $player_id, 'sp_number', true );
|
||||
$output .= '<td class="data-number">' . ( $number ? $number : ' ' ) . '</td>';
|
||||
endif;
|
||||
|
||||
// Name as link
|
||||
$permalink = get_post_permalink( $player_id );
|
||||
@@ -41,6 +72,7 @@ if ( !function_exists( 'sportspress_player_list' ) ) {
|
||||
foreach( $labels as $key => $value ):
|
||||
if ( $key == 'name' )
|
||||
continue;
|
||||
if ( ! is_array( $statistics ) || in_array( $key, $statistics ) )
|
||||
$output .= '<td class="data-' . $key . '">' . sportspress_array_value( $row, $key, '—' ) . '</td>';
|
||||
endforeach;
|
||||
|
||||
|
||||
@@ -10,11 +10,12 @@ class SportsPress_Widget_League_Table extends WP_Widget {
|
||||
extract($args);
|
||||
$title = apply_filters('widget_title', empty($instance['title']) ? '' : $instance['title'], $instance, $this->id_base);
|
||||
$id = empty($instance['id']) ? null : $instance['id'];
|
||||
$columns = $instance['columns'];
|
||||
echo $before_widget;
|
||||
if ( $title )
|
||||
echo $before_title . $title . $after_title;
|
||||
echo '<div id="sp_league_table_wrap">';
|
||||
echo sportspress_league_table( $id );
|
||||
echo sportspress_league_table( $id, array( 'columns' => $columns ) );
|
||||
echo '</div>';
|
||||
echo $after_widget;
|
||||
}
|
||||
@@ -23,14 +24,16 @@ class SportsPress_Widget_League_Table extends WP_Widget {
|
||||
$instance = $old_instance;
|
||||
$instance['title'] = strip_tags($new_instance['title']);
|
||||
$instance['id'] = intval($new_instance['id']);
|
||||
$instance['columns'] = (array)$new_instance['columns'];
|
||||
|
||||
return $instance;
|
||||
}
|
||||
|
||||
function form( $instance ) {
|
||||
$instance = wp_parse_args( (array) $instance, array( 'title' => '', 'id' => '' ) );
|
||||
$instance = wp_parse_args( (array) $instance, array( 'title' => '', 'id' => '', 'columns' => null ) );
|
||||
$title = strip_tags($instance['title']);
|
||||
$id = intval($instance['id']);
|
||||
$columns = $instance['columns'];
|
||||
?>
|
||||
<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>
|
||||
@@ -50,6 +53,26 @@ class SportsPress_Widget_League_Table extends WP_Widget {
|
||||
endif;
|
||||
?>
|
||||
</p>
|
||||
|
||||
<p class="sp-prefs">
|
||||
<?php _e( 'Columns:', 'sportspress' ); ?><br>
|
||||
<?php
|
||||
$args = array(
|
||||
'post_type' => 'sp_column',
|
||||
'numberposts' => -1,
|
||||
'posts_per_page' => -1,
|
||||
'orderby' => 'menu_order',
|
||||
'order' => 'ASC'
|
||||
);
|
||||
$the_columns = get_posts( $args );
|
||||
|
||||
$field_name = $this->get_field_name('columns') . '[]';
|
||||
$field_id = $this->get_field_id('columns');
|
||||
?>
|
||||
<?php foreach ( $the_columns as $column ): ?>
|
||||
<label class="button"><input name="<?php echo $field_name; ?>" type="checkbox" id="<?php echo $field_id . '-' . $column->post_name; ?>" value="<?php echo $column->post_name; ?>" <?php if ( $columns === null || in_array( $column->post_name, $columns ) ): ?>checked="checked"<?php endif; ?>><?php echo $column->post_title; ?></label>
|
||||
<?php endforeach; ?>
|
||||
</p>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
|
||||
112
admin/widgets/player-list.php
Normal file
112
admin/widgets/player-list.php
Normal file
@@ -0,0 +1,112 @@
|
||||
<?php
|
||||
class SportsPress_Widget_Player_list extends WP_Widget {
|
||||
|
||||
function __construct() {
|
||||
$widget_ops = array('classname' => 'widget_player_list widget_sp_player_list', 'description' => __( 'SportsPress widget.', 'sportspress' ) );
|
||||
parent::__construct('sp_player_list', __( 'Player List', 'sportspress' ), $widget_ops);
|
||||
}
|
||||
|
||||
function widget( $args, $instance ) {
|
||||
extract($args);
|
||||
$title = apply_filters('widget_title', empty($instance['title']) ? '' : $instance['title'], $instance, $this->id_base);
|
||||
$id = empty($instance['id']) ? null : $instance['id'];
|
||||
$statistics = $instance['statistics'];
|
||||
$orderby = empty($instance['orderby']) ? 'number' : $instance['orderby'];
|
||||
$order = empty($instance['order']) ? 'ASC' : $instance['order'];
|
||||
echo $before_widget;
|
||||
if ( $title )
|
||||
echo $before_title . $title . $after_title;
|
||||
echo '<div id="sp_player_list_wrap">';
|
||||
echo sportspress_player_list( $id, array( 'statistics' => $statistics, 'orderby' => $orderby , 'order' => $order ) );
|
||||
echo '</div>';
|
||||
echo $after_widget;
|
||||
}
|
||||
|
||||
function update( $new_instance, $old_instance ) {
|
||||
$instance = $old_instance;
|
||||
$instance['title'] = strip_tags($new_instance['title']);
|
||||
$instance['id'] = intval($new_instance['id']);
|
||||
$instance['statistics'] = (array)$new_instance['statistics'];
|
||||
$instance['orderby'] = strip_tags($new_instance['orderby']);
|
||||
$instance['order'] = strip_tags($new_instance['order']);
|
||||
|
||||
return $instance;
|
||||
}
|
||||
|
||||
function form( $instance ) {
|
||||
$instance = wp_parse_args( (array) $instance, array( 'title' => '', 'id' => '', 'statistics' => null, 'orderby' => 'number', 'order' => 'ASC' ) );
|
||||
$title = strip_tags($instance['title']);
|
||||
$id = intval($instance['id']);
|
||||
$statistics = $instance['statistics'];
|
||||
$orderby = strip_tags($instance['orderby']);
|
||||
$order = strip_tags($instance['order']);
|
||||
?>
|
||||
<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>
|
||||
|
||||
<p><label for="<?php echo $this->get_field_id('id'); ?>"><?php _e( 'Player List:', 'sportspress' ); ?></label>
|
||||
<?php
|
||||
$args = array(
|
||||
'post_type' => 'sp_list',
|
||||
'name' => $this->get_field_name('id'),
|
||||
'id' => $this->get_field_id('id'),
|
||||
'selected' => $id,
|
||||
'values' => 'ID',
|
||||
'class' => 'widefat',
|
||||
);
|
||||
if ( ! sportspress_dropdown_pages( $args ) ):
|
||||
sportspress_post_adder( 'sp_list' );
|
||||
endif;
|
||||
?>
|
||||
</p>
|
||||
|
||||
<p class="sp-prefs">
|
||||
<?php _e( 'Statistics:', 'sportspress' ); ?><br>
|
||||
<?php
|
||||
$args = array(
|
||||
'post_type' => 'sp_statistic',
|
||||
'numberposts' => -1,
|
||||
'posts_per_page' => -1,
|
||||
'orderby' => 'menu_order',
|
||||
'order' => 'ASC'
|
||||
);
|
||||
$the_statistics = get_posts( $args );
|
||||
|
||||
$field_name = $this->get_field_name('statistics') . '[]';
|
||||
$field_id = $this->get_field_id('statistics');
|
||||
?>
|
||||
<label class="button"><input name="<?php echo $field_name; ?>" type="checkbox" id="<?php echo $field_id . '-' . 'eventsplayed'; ?>" value="<?php echo 'eventsplayed'; ?>" <?php if ( is_array( $statistics) && in_array( 'eventsplayed', $statistics ) ): ?>checked="checked"<?php endif; ?>><?php _e( 'Played', 'sportspress' ); ?></label>
|
||||
<?php foreach ( $the_statistics as $column ): ?>
|
||||
<label class="button"><input name="<?php echo $field_name; ?>" type="checkbox" id="<?php echo $field_id . '-' . $column->post_name; ?>" value="<?php echo $column->post_name; ?>" <?php if ( $statistics === null || in_array( $column->post_name, $statistics ) ): ?>checked="checked"<?php endif; ?>><?php echo $column->post_title; ?></label>
|
||||
<?php endforeach; ?>
|
||||
</p>
|
||||
|
||||
<p><label for="<?php echo $this->get_field_id('orderby'); ?>"><?php _e( 'Sort by:', 'sportspress' ); ?></label>
|
||||
<?php
|
||||
$args = array(
|
||||
'post_type' => 'sp_statistic',
|
||||
'show_option_all' => __( 'Number', 'sportspress' ),
|
||||
'option_all_value' => 'number',
|
||||
'show_option_none' => __( 'Played', 'sportspress' ),
|
||||
'option_none_value' => 'eventsplayed',
|
||||
'name' => $this->get_field_name('orderby'),
|
||||
'id' => $this->get_field_id('orderby'),
|
||||
'selected' => $orderby,
|
||||
'values' => 'slug',
|
||||
'class' => 'widefat',
|
||||
);
|
||||
if ( ! sportspress_dropdown_pages( $args ) ):
|
||||
sportspress_post_adder( 'sp_list' );
|
||||
endif;
|
||||
?>
|
||||
</p>
|
||||
|
||||
<p><label for="<?php echo $this->get_field_id('order'); ?>"><?php _e( 'Sort Order:', 'sportspress' ); ?></label>
|
||||
<select name="<?php echo $this->get_field_name('order'); ?>" id="<?php echo $this->get_field_id('order'); ?>" class="widefat">
|
||||
<option value="ASC" <?php selected( 'ASC', $order ); ?>><?php _e( 'Ascending', 'sportspress' ); ?></option>
|
||||
<option value="DESC" <?php selected( 'DESC', $order ); ?>><?php _e( 'Descending', 'sportspress' ); ?></option>
|
||||
</select></p>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
add_action( 'widgets_init', create_function( '', 'return register_widget( "SportsPress_Widget_Player_list" );' ) );
|
||||
Reference in New Issue
Block a user