Add league table and players settings
This commit is contained in:
@@ -1,4 +1,9 @@
|
|||||||
|
<h3 class="title"><?php _e( 'Player Settings', 'sportspress' ); ?></h3>
|
||||||
<?php
|
<?php
|
||||||
|
settings_fields( 'sportspress_players' );
|
||||||
|
do_settings_sections( 'sportspress_players' );
|
||||||
|
submit_button();
|
||||||
|
|
||||||
$args = array(
|
$args = array(
|
||||||
'post_type' => 'sp_metric',
|
'post_type' => 'sp_metric',
|
||||||
'numberposts' => -1,
|
'numberposts' => -1,
|
||||||
|
|||||||
@@ -42,14 +42,16 @@ function sportspress_sport_callback() {
|
|||||||
$selected = sportspress_array_value( $options, 'sport', null );
|
$selected = sportspress_array_value( $options, 'sport', null );
|
||||||
$custom_sport_name = sportspress_array_value( $options, 'custom_sport_name', null );
|
$custom_sport_name = sportspress_array_value( $options, 'custom_sport_name', null );
|
||||||
?>
|
?>
|
||||||
<select id="sportspress_sport" name="sportspress[sport]">
|
<fieldset>
|
||||||
<option value><?php _e( '— Select —', 'sportspress' ); ?></option>
|
<select id="sportspress_sport" name="sportspress[sport]">
|
||||||
<?php foreach( $sportspress_sports as $slug => $sport ): ?>
|
<option value><?php _e( '— Select —', 'sportspress' ); ?></option>
|
||||||
<option value="<?php echo $slug; ?>" <?php selected( $selected, $slug ); ?>><?php echo $sport['name']; ?></option>
|
<?php foreach( $sportspress_sports as $slug => $sport ): ?>
|
||||||
<?php endforeach; ?>
|
<option value="<?php echo $slug; ?>" <?php selected( $selected, $slug ); ?>><?php echo $sport['name']; ?></option>
|
||||||
<option value="custom" <?php selected( $selected, 'custom' ); ?>><?php _e( 'Custom', 'sportspress' ); ?></option>
|
<?php endforeach; ?>
|
||||||
</select>
|
<option value="custom" <?php selected( $selected, 'custom' ); ?>><?php _e( 'Custom', 'sportspress' ); ?></option>
|
||||||
<input id="sportspress_custom_sport_name" name="sportspress[custom_sport_name]" type="text" placeholder="<?php _e( 'Sport', 'sportspress' ); ?>" value="<?php echo $custom_sport_name; ?>"<?php if ( $selected != 'custom' ): ?> class="hidden"<?php endif; ?>>
|
</select>
|
||||||
|
<input id="sportspress_custom_sport_name" name="sportspress[custom_sport_name]" type="text" placeholder="<?php _e( 'Sport', 'sportspress' ); ?>" value="<?php echo $custom_sport_name; ?>"<?php if ( $selected != 'custom' ): ?> class="hidden"<?php endif; ?>>
|
||||||
|
</fieldset>
|
||||||
<?php
|
<?php
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,7 +66,26 @@ function sportspress_result_callback() {
|
|||||||
'selected' => $selected,
|
'selected' => $selected,
|
||||||
'values' => 'slug',
|
'values' => 'slug',
|
||||||
);
|
);
|
||||||
sportspress_dropdown_pages( $args );
|
?>
|
||||||
|
<fieldset>
|
||||||
|
<? sportspress_dropdown_pages( $args ); ?>
|
||||||
|
</fieldset>
|
||||||
|
<?php
|
||||||
|
}
|
||||||
|
|
||||||
|
function sportspress_team_logos_callback() {
|
||||||
|
$options = get_option( 'sportspress' );
|
||||||
|
|
||||||
|
$show_team_logo = sportspress_array_value( $options, 'league_table_show_team_logo', false );
|
||||||
|
?>
|
||||||
|
<fieldset>
|
||||||
|
<label for="sportspress_league_table_show_team_logo">
|
||||||
|
<input id="sportspress_league_table_show_team_logo_default" name="sportspress[league_table_show_team_logo]" type="hidden" value="0">
|
||||||
|
<input id="sportspress_league_table_show_team_logo" name="sportspress[league_table_show_team_logo]" type="checkbox" value="1" <?php checked( $show_team_logo ); ?>>
|
||||||
|
<?php _e( 'Display logos', 'sportspress' ); ?>
|
||||||
|
</label>
|
||||||
|
</fieldset>
|
||||||
|
<?php
|
||||||
}
|
}
|
||||||
|
|
||||||
function sportspress_team_stats_callback() {
|
function sportspress_team_stats_callback() {
|
||||||
@@ -126,13 +147,57 @@ function sportspress_settings_init() {
|
|||||||
'sportspress_events',
|
'sportspress_events',
|
||||||
'events'
|
'events'
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// League Table Settings
|
||||||
|
register_setting(
|
||||||
|
'sportspress_tables',
|
||||||
|
'sportspress',
|
||||||
|
'sportspress_options_validate'
|
||||||
|
);
|
||||||
|
|
||||||
|
add_settings_section(
|
||||||
|
'tables',
|
||||||
|
'',
|
||||||
|
'',
|
||||||
|
'sportspress_tables'
|
||||||
|
);
|
||||||
|
|
||||||
|
add_settings_field(
|
||||||
|
'result',
|
||||||
|
__( 'Teams', 'sportspress' ),
|
||||||
|
'sportspress_team_logos_callback',
|
||||||
|
'sportspress_tables',
|
||||||
|
'tables'
|
||||||
|
);
|
||||||
|
|
||||||
|
// Player Settings
|
||||||
|
register_setting(
|
||||||
|
'sportspress_players',
|
||||||
|
'sportspress',
|
||||||
|
'sportspress_options_validate'
|
||||||
|
);
|
||||||
|
|
||||||
|
add_settings_section(
|
||||||
|
'players',
|
||||||
|
'',
|
||||||
|
'',
|
||||||
|
'sportspress_players'
|
||||||
|
);
|
||||||
|
|
||||||
|
add_settings_field(
|
||||||
|
'result',
|
||||||
|
__( 'Main Result', 'sportspress' ),
|
||||||
|
'sportspress_result_callback',
|
||||||
|
'sportspress_players',
|
||||||
|
'players'
|
||||||
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
add_action( 'admin_init', 'sportspress_settings_init', 1 );
|
add_action( 'admin_init', 'sportspress_settings_init', 1 );
|
||||||
|
|
||||||
function sportspress_options_validate( $input ) {
|
function sportspress_options_validate( $input ) {
|
||||||
|
|
||||||
$options = get_option( 'sportspress' );
|
$options = (array)get_option( 'sportspress' );
|
||||||
|
|
||||||
if ( isset( $input['sport'] ) && sportspress_array_value( $options, 'sport', null ) != sportspress_array_value( $input, 'sport', null ) ):
|
if ( isset( $input['sport'] ) && sportspress_array_value( $options, 'sport', null ) != sportspress_array_value( $input, 'sport', null ) ):
|
||||||
|
|
||||||
@@ -232,6 +297,9 @@ function sportspress_options_validate( $input ) {
|
|||||||
|
|
||||||
endif;
|
endif;
|
||||||
|
|
||||||
|
if ( ! is_array( $input ) )
|
||||||
|
$input = array();
|
||||||
|
|
||||||
// Merge with existing options
|
// Merge with existing options
|
||||||
return array_merge( $options, $input );
|
return array_merge( $options, $input );
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,9 @@
|
|||||||
|
<h3 class="title"><?php _e( 'League Table Settings', 'sportspress' ); ?></h3>
|
||||||
<?php
|
<?php
|
||||||
|
settings_fields( 'sportspress_tables' );
|
||||||
|
do_settings_sections( 'sportspress_tables' );
|
||||||
|
submit_button();
|
||||||
|
|
||||||
$args = array(
|
$args = array(
|
||||||
'post_type' => 'sp_column',
|
'post_type' => 'sp_column',
|
||||||
'numberposts' => -1,
|
'numberposts' => -1,
|
||||||
|
|||||||
@@ -5,9 +5,12 @@ if ( !function_exists( 'sportspress_league_table' ) ) {
|
|||||||
if ( ! $id )
|
if ( ! $id )
|
||||||
$id = get_the_ID();
|
$id = get_the_ID();
|
||||||
|
|
||||||
|
$options = get_option( 'sportspress' );
|
||||||
|
|
||||||
$defaults = array(
|
$defaults = array(
|
||||||
'columns' => null,
|
'columns' => null,
|
||||||
'show_full_table_link' => false,
|
'show_full_table_link' => false,
|
||||||
|
'show_team_logo' => sportspress_array_value( $options, 'league_table_show_team_logo', false ),
|
||||||
);
|
);
|
||||||
|
|
||||||
$r = wp_parse_args( $args, $defaults );
|
$r = wp_parse_args( $args, $defaults );
|
||||||
@@ -44,7 +47,11 @@ if ( !function_exists( 'sportspress_league_table' ) ) {
|
|||||||
$output .= '<td class="data-rank">' . ( $i + 1 ) . '</td>';
|
$output .= '<td class="data-rank">' . ( $i + 1 ) . '</td>';
|
||||||
|
|
||||||
$name = sportspress_array_value( $row, 'name', sportspress_array_value( $row, 'name', ' ' ) );
|
$name = sportspress_array_value( $row, 'name', sportspress_array_value( $row, 'name', ' ' ) );
|
||||||
$output .= '<td class="data-name"><a href="' . get_post_permalink( $team_id ) . '">' . $name . '</a></td>';
|
|
||||||
|
if ( $r['show_team_logo'] )
|
||||||
|
$name = get_the_post_thumbnail( $team_id, 'sportspress-fit-icon' ) . ' ' . $name;
|
||||||
|
|
||||||
|
$output .= '<td class="data-name">' . $name . '</td>';
|
||||||
|
|
||||||
foreach( $labels as $key => $value ):
|
foreach( $labels as $key => $value ):
|
||||||
if ( $key == 'name' )
|
if ( $key == 'name' )
|
||||||
|
|||||||
@@ -11,12 +11,13 @@ class SportsPress_Widget_League_Table extends WP_Widget {
|
|||||||
$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'];
|
||||||
$columns = empty($instance['columns']) ? null : $instance['columns'];
|
$columns = empty($instance['columns']) ? null : $instance['columns'];
|
||||||
|
$show_team_logo = empty($instance['show_team_logo']) ? false : $instance['show_team_logo'];
|
||||||
$show_full_table_link = empty($instance['show_full_table_link']) ? false : $instance['show_full_table_link'];
|
$show_full_table_link = empty($instance['show_full_table_link']) ? false : $instance['show_full_table_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_league_table_wrap">';
|
echo '<div id="sp_league_table_wrap">';
|
||||||
echo sportspress_league_table( $id, array( 'columns' => $columns, 'show_full_table_link' => $show_full_table_link ) );
|
echo sportspress_league_table( $id, array( 'columns' => $columns, 'show_full_table_link' => $show_full_table_link, 'show_team_logo' => $show_team_logo ) );
|
||||||
echo '</div>';
|
echo '</div>';
|
||||||
echo $after_widget;
|
echo $after_widget;
|
||||||
}
|
}
|
||||||
@@ -26,16 +27,18 @@ class SportsPress_Widget_League_Table extends WP_Widget {
|
|||||||
$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['columns'] = (array)$new_instance['columns'];
|
$instance['columns'] = (array)$new_instance['columns'];
|
||||||
|
$instance['show_team_logo'] = $new_instance['show_team_logo'];
|
||||||
$instance['show_full_table_link'] = $new_instance['show_full_table_link'];
|
$instance['show_full_table_link'] = $new_instance['show_full_table_link'];
|
||||||
|
|
||||||
return $instance;
|
return $instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
function form( $instance ) {
|
function form( $instance ) {
|
||||||
$instance = wp_parse_args( (array) $instance, array( 'title' => '', 'id' => '', 'columns' => null, 'show_full_table_link' => true ) );
|
$instance = wp_parse_args( (array) $instance, array( 'title' => '', 'id' => '', 'columns' => null, 'show_team_logo' => false, 'show_full_table_link' => true ) );
|
||||||
$title = strip_tags($instance['title']);
|
$title = strip_tags($instance['title']);
|
||||||
$id = intval($instance['id']);
|
$id = intval($instance['id']);
|
||||||
$columns = $instance['columns'];
|
$columns = $instance['columns'];
|
||||||
|
$show_team_logo = $instance['show_team_logo'];
|
||||||
$show_full_table_link = $instance['show_full_table_link'];
|
$show_full_table_link = $instance['show_full_table_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>
|
||||||
@@ -77,7 +80,10 @@ class SportsPress_Widget_League_Table extends WP_Widget {
|
|||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p><input class="checkbox" type="checkbox" id="<?php echo $this->get_field_id('show_full_table_link'); ?>" name="<?php echo $this->get_field_name('show_full_table_link'); ?>" value="1" <?php checked( $show_full_table_link, 1 ); ?>>
|
<p><input class="checkbox" type="checkbox" id="<?php echo $this->get_field_id('show_team_logo'); ?>" name="<?php echo $this->get_field_name('show_team_logo'); ?>" value="1" <?php checked( $show_team_logo, 1 ); ?>>
|
||||||
|
<label for="<?php echo $this->get_field_id('show_team_logo'); ?>"><?php _e( 'Display logos', 'sportspress' ); ?></label><br>
|
||||||
|
|
||||||
|
<input class="checkbox" type="checkbox" id="<?php echo $this->get_field_id('show_full_table_link'); ?>" name="<?php echo $this->get_field_name('show_full_table_link'); ?>" value="1" <?php checked( $show_full_table_link, 1 ); ?>>
|
||||||
<label for="<?php echo $this->get_field_id('show_full_table_link'); ?>"><?php _e( 'Display link to view full table', 'sportspress' ); ?></label></p>
|
<label for="<?php echo $this->get_field_id('show_full_table_link'); ?>"><?php _e( 'Display link to view full table', 'sportspress' ); ?></label></p>
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
|
|||||||
Reference in New Issue
Block a user