Add append and prepend options to page dropdown, sorting options per player list and default order option to widget
This commit is contained in:
@@ -153,6 +153,12 @@ function sportspress_save_post( $post_id ) {
|
||||
// Update season taxonomy
|
||||
wp_set_post_terms( $post_id, sportspress_array_value( $_POST, 'sp_season', 0 ), 'sp_season' );
|
||||
|
||||
// Update orderby
|
||||
update_post_meta( $post_id, 'sp_orderby', sportspress_array_value( $_POST, 'sp_orderby', array() ) );
|
||||
|
||||
// Update order
|
||||
update_post_meta( $post_id, 'sp_order', sportspress_array_value( $_POST, 'sp_order', array() ) );
|
||||
|
||||
//Update player array
|
||||
sportspress_update_post_meta_recursive( $post_id, 'sp_player', sportspress_array_value( $_POST, 'sp_player', array() ) );
|
||||
|
||||
|
||||
@@ -53,6 +53,8 @@ function sportspress_list_player_meta( $post ) {
|
||||
$league_id = sportspress_get_the_term_id( $post->ID, 'sp_league', 0 );
|
||||
$season_id = sportspress_get_the_term_id( $post->ID, 'sp_season', 0 );
|
||||
$team_id = get_post_meta( $post->ID, 'sp_team', true );
|
||||
$orderby = get_post_meta( $post->ID, 'sp_orderby', true );
|
||||
$order = get_post_meta( $post->ID, 'sp_order', true );
|
||||
?>
|
||||
<div>
|
||||
<p><strong><?php _e( 'League', 'sportspress' ); ?></strong></p>
|
||||
@@ -98,6 +100,32 @@ function sportspress_list_player_meta( $post ) {
|
||||
endif;
|
||||
?>
|
||||
</p>
|
||||
<p><strong><?php _e( 'Sort by:', 'sportspress' ); ?></strong></p>
|
||||
<p>
|
||||
<?php
|
||||
$args = array(
|
||||
'prepend_options' => array(
|
||||
'number' => __( 'Number', 'sportspress' ),
|
||||
'name' => __( 'Name', 'sportspress' ),
|
||||
'eventsplayed' => __( 'Played', 'sportspress' )
|
||||
),
|
||||
'post_type' => 'sp_statistic',
|
||||
'name' => 'sp_orderby',
|
||||
'selected' => $orderby,
|
||||
'values' => 'slug',
|
||||
);
|
||||
if ( ! sportspress_dropdown_pages( $args ) ):
|
||||
sportspress_post_adder( 'sp_list' );
|
||||
endif;
|
||||
?>
|
||||
</p>
|
||||
<p><strong><?php _e( 'Sort Order:', 'sportspress' ); ?></strong></p>
|
||||
<p>
|
||||
<select name="sp_order">
|
||||
<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>
|
||||
<p><strong><?php _e( 'Players', 'sportspress' ); ?></strong></p>
|
||||
<?php
|
||||
sportspress_post_checklist( $post->ID, 'sp_player', 'block', 'sp_team' );
|
||||
|
||||
@@ -7,7 +7,7 @@ if ( !function_exists( 'sportspress_player_list' ) ) {
|
||||
|
||||
$defaults = array(
|
||||
'statistics' => null,
|
||||
'orderby' => 'number',
|
||||
'orderby' => 'default',
|
||||
'order' => 'ASC',
|
||||
);
|
||||
|
||||
@@ -26,7 +26,10 @@ if ( !function_exists( 'sportspress_player_list' ) ) {
|
||||
|
||||
$statistics = sportspress_array_value( $r, 'statistics', null );
|
||||
|
||||
if ( $r['orderby'] != 'number' || $r['order'] != 'ASC' ):
|
||||
if ( $r['orderby'] == 'default' ):
|
||||
$r['orderby'] = get_post_meta( $id, 'sp_orderby', true );
|
||||
$r['order'] = get_post_meta( $id, 'sp_order', true );
|
||||
else:
|
||||
global $sportspress_statistic_priorities;
|
||||
$sportspress_statistic_priorities = array(
|
||||
array(
|
||||
@@ -37,7 +40,7 @@ if ( !function_exists( 'sportspress_player_list' ) ) {
|
||||
uasort( $data, 'sportspress_sort_list_players' );
|
||||
endif;
|
||||
|
||||
if ( $r['orderby'] == 'number' ):
|
||||
if ( in_array( $r['orderby'], array( 'number', 'name' ) ) ):
|
||||
$output .= '<th class="data-number">#</th>';
|
||||
else:
|
||||
$output .= '<th class="data-rank">' . __( 'Rank', 'sportspress' ) . '</th>';
|
||||
|
||||
@@ -11,7 +11,7 @@ class SportsPress_Widget_Player_list extends WP_Widget {
|
||||
$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'];
|
||||
$orderby = empty($instance['orderby']) ? 'default' : $instance['orderby'];
|
||||
$order = empty($instance['order']) ? 'ASC' : $instance['order'];
|
||||
echo $before_widget;
|
||||
if ( $title )
|
||||
@@ -34,7 +34,7 @@ class SportsPress_Widget_Player_list extends WP_Widget {
|
||||
}
|
||||
|
||||
function form( $instance ) {
|
||||
$instance = wp_parse_args( (array) $instance, array( 'title' => '', 'id' => '', 'statistics' => null, 'orderby' => 'number', 'order' => 'ASC' ) );
|
||||
$instance = wp_parse_args( (array) $instance, array( 'title' => '', 'id' => '', 'statistics' => null, 'orderby' => 'default', 'order' => 'ASC' ) );
|
||||
$title = strip_tags($instance['title']);
|
||||
$id = intval($instance['id']);
|
||||
$statistics = $instance['statistics'];
|
||||
@@ -84,16 +84,18 @@ class SportsPress_Widget_Player_list extends WP_Widget {
|
||||
<p><label for="<?php echo $this->get_field_id('orderby'); ?>"><?php _e( 'Sort by:', 'sportspress' ); ?></label>
|
||||
<?php
|
||||
$args = array(
|
||||
'prepend_options' => array(
|
||||
'default' => __( 'Default', 'sportspress' ),
|
||||
'number' => __( 'Number', 'sportspress' ),
|
||||
'name' => __( 'Name', 'sportspress' ),
|
||||
'eventsplayed' => __( 'Played', 'sportspress' )
|
||||
),
|
||||
'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',
|
||||
'class' => 'sp-select-orderby widefat',
|
||||
);
|
||||
if ( ! sportspress_dropdown_pages( $args ) ):
|
||||
sportspress_post_adder( 'sp_list' );
|
||||
@@ -102,7 +104,7 @@ class SportsPress_Widget_Player_list extends WP_Widget {
|
||||
</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">
|
||||
<select name="<?php echo $this->get_field_name('order'); ?>" id="<?php echo $this->get_field_id('order'); ?>" class="sp-select-order widefat" <?php disabled( $orderby, 'default' ); ?>>
|
||||
<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>
|
||||
|
||||
Reference in New Issue
Block a user