diff --git a/admin/hooks/save-post.php b/admin/hooks/save-post.php index 24e46eca..6b6bda34 100644 --- a/admin/hooks/save-post.php +++ b/admin/hooks/save-post.php @@ -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() ) ); diff --git a/admin/post-types/list.php b/admin/post-types/list.php index 59835600..436f7822 100644 --- a/admin/post-types/list.php +++ b/admin/post-types/list.php @@ -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 ); ?>

@@ -98,6 +100,32 @@ function sportspress_list_player_meta( $post ) { endif; ?>

+

+

+ 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; + ?> +

+

+

+ +

ID, 'sp_player', 'block', 'sp_team' ); diff --git a/admin/templates/player-list.php b/admin/templates/player-list.php index ea97349c..d6a98aad 100644 --- a/admin/templates/player-list.php +++ b/admin/templates/player-list.php @@ -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 .= '#'; else: $output .= '' . __( 'Rank', 'sportspress' ) . ''; diff --git a/admin/widgets/player-list.php b/admin/widgets/player-list.php index 15ae752c..54bc3f0f 100644 --- a/admin/widgets/player-list.php +++ b/admin/widgets/player-list.php @@ -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 {

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 {

- >

diff --git a/assets/js/admin.js b/assets/js/admin.js index 10c2666d..66f71ae0 100644 --- a/assets/js/admin.js +++ b/assets/js/admin.js @@ -20,6 +20,11 @@ jQuery(document).ready(function($){ // Activate auto key placeholder $("#poststuff #title").keyup(); + // Orderby affects order select in widget options + $("body.widgets-php").on("change", ".sp-select-orderby", function() { + $(this).closest(".widget-content").find(".sp-select-order").prop("disabled", $(this).val() == "default"); + }); + // Tab switcher $(".sp-tab-panel").siblings(".sp-tab-bar").find("a").click(function() { $(this).closest("li").removeClass("wp-tab").addClass("wp-tab-active").siblings().removeClass("wp-tab-active").addClass("wp-tab").closest(".wp-tab-bar").siblings($(this).attr("href")).show().siblings(".wp-tab-panel").hide(); diff --git a/functions.php b/functions.php index ca47985a..29e23be7 100644 --- a/functions.php +++ b/functions.php @@ -262,6 +262,8 @@ if ( !function_exists( 'sportspress_dropdown_taxonomies' ) ) { if ( !function_exists( 'sportspress_dropdown_pages' ) ) { function sportspress_dropdown_pages( $args = array() ) { $defaults = array( + 'prepend_options' => null, + 'append_options' => null, 'show_option_all' => false, 'show_option_none' => false, 'show_dates' => false, @@ -305,7 +307,7 @@ if ( !function_exists( 'sportspress_dropdown_pages' ) ) { unset( $args['selected'] ); $posts = get_posts( $args ); - if ( $posts ): + if ( $posts || $prepend || $append ): printf( '' ); return true; else: @@ -1840,6 +1852,8 @@ if ( !function_exists( 'sportspress_get_player_list_data' ) ) { $team_id = get_post_meta( $post_id, 'sp_team', true ); $player_ids = (array)get_post_meta( $post_id, 'sp_player', false ); $stats = (array)get_post_meta( $post_id, 'sp_players', true ); + $orderby = get_post_meta( $post_id, 'sp_orderby', true ); + $order = get_post_meta( $post_id, 'sp_order', true ); // Get labels from result variables $columns = (array)sportspress_get_var_labels( 'sp_statistic' ); @@ -2057,6 +2071,17 @@ if ( !function_exists( 'sportspress_get_player_list_data' ) ) { endforeach; endforeach; + if ( $orderby != 'number' || $order != 'ASC' ): + global $sportspress_statistic_priorities; + $sportspress_statistic_priorities = array( + array( + 'statistic' => $orderby, + 'order' => $order, + ), + ); + uasort( $merged, 'sportspress_sort_list_players' ); + endif; + // Rearrange data array to reflect statistics $data = array(); foreach( $merged as $key => $value ): @@ -2064,7 +2089,7 @@ if ( !function_exists( 'sportspress_get_player_list_data' ) ) { endforeach; if ( $admin ): - return array( $columns, $tempdata, $placeholders, $merged ); + return array( $columns, $data, $placeholders, $merged ); else: $labels = array_merge( array( 'name' => __( 'Player', 'sportspress' ) ), $columns ); $merged[0] = $labels; @@ -2084,8 +2109,16 @@ if ( !function_exists( 'sportspress_sort_list_players' ) ) { // Proceed if columns are not equal if ( sportspress_array_value( $a, $priority['statistic'], 0 ) != sportspress_array_value( $b, $priority['statistic'], 0 ) ): - // Compare statistic values - $output = sportspress_array_value( $a, $priority['statistic'], 0 ) - sportspress_array_value( $b, $priority['statistic'], 0 ); + if ( $priority['statistic'] == 'name' ): + + $output = strcmp( sportspress_array_value( $a, 'name', null ), sportspress_array_value( $b, 'name', null ) ); + + else: + + // Compare statistic values + $output = sportspress_array_value( $a, $priority['statistic'], 0 ) - sportspress_array_value( $b, $priority['statistic'], 0 ); + + endif; // Flip value if descending order if ( $priority['order'] == 'DESC' ) $output = 0 - $output; @@ -2097,7 +2130,7 @@ if ( !function_exists( 'sportspress_sort_list_players' ) ) { endforeach; // Default sort by number - return strcmp( sportspress_array_value( $a, 'number', '' ), sportspress_array_value( $b, 'number', '' ) ); + return sportspress_array_value( $a, 'number', 0 ) - sportspress_array_value( $b, 'number', 0 ); } } diff --git a/readme.txt b/readme.txt index 07f21c5e..f81db732 100644 --- a/readme.txt +++ b/readme.txt @@ -4,7 +4,7 @@ Tags: sports, sports journalism, teams, team management, fixtures, results, stan Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business=support@themeboy.com&item_name=Donation+for+SportsPress Requires at least: 3.8 Tested up to: 3.8.1 -Stable tag: 0.3.1 +Stable tag: 0.3.3 License: GPLv3 License URI: http://www.gnu.org/licenses/gpl-3.0.html @@ -14,6 +14,18 @@ SportsPress is a fully configurable sports plugin that seemlessly automates leag Add schedules, results, league tables, player profiles and statistics to your team or league site with SportsPress. It is designed to work with virtually every WordPress theme, and includes several language translations. += Features = +* Team Profiles +* League Tables +* Events (Fixtures & Results) +* Events Calendar +* Player Profiles & Statistics Per Position +* Player Lists +* Staff Profiles +* Season Archives +* Venue Information & Maps +* Statistics & League Table Columns Configuration + = Customizable = League table columns, player statistics, and match results can be customized to fit any sport. Presets are available for some of the most popular sports including soccer, rugby, American football, Australian Rules football, baseball, basketball, cricket, and hockey. @@ -94,6 +106,14 @@ SportsPress is currently in beta and is undergoing testing. We are still activel == Changelog == += 0.3.3 = +* Feature - Add default sorting options per player list. +* Feature - Add option to sort player list alphabetically by name or by default. + += 0.3.2 = +* Feature - Add England, Scotland, Northern Ireland, and Wales to countries selector. +* Feature - Enable searching for countries in dropdown. + = 0.3.1 = * Feature - Import tool added for importing teams from CSV file. * Tweak - Added option to select custom sport and enter sport name. diff --git a/sportspress.php b/sportspress.php index 51155afd..ffb2a5a0 100644 --- a/sportspress.php +++ b/sportspress.php @@ -6,7 +6,7 @@ Plugin Name: SportsPress Plugin URI: http://themeboy.com/sportspress Description: Manage your club and its players, staff, events, league tables, and player lists. -Version: 0.3.1 +Version: 0.3.3 Author: ThemeBoy Author URI: http://themeboy.com/ License: GPLv3 @@ -18,7 +18,7 @@ if ( !function_exists( 'add_action' ) ) { exit; } -define( 'SPORTSPRESS_VERSION', '0.3.1' ); +define( 'SPORTSPRESS_VERSION', '0.3.3' ); define( 'SPORTSPRESS_PLUGIN_URL', plugin_dir_url( __FILE__ ) ); define( 'SPORTSPRESS_PLUGIN_BASENAME', plugin_basename( __FILE__ ) ); define( 'SPORTSPRESS_PLUGIN_FILE', __FILE__ );