From 33069f395d202b2d9b791474ba5b5c4247365131 Mon Sep 17 00:00:00 2001 From: Brian Miyaji Date: Thu, 19 Jun 2014 15:37:16 +1000 Subject: [PATCH] Enable individual sport mode --- includes/admin/class-sp-admin-assets.php | 5 + includes/admin/class-sp-admin-settings.php | 7 +- .../post-types/class-sp-admin-meta-boxes.php | 4 +- .../class-sp-meta-box-event-teams.php | 20 +- .../settings/class-sp-settings-config.php | 24 ++- .../settings/class-sp-settings-events.php | 2 +- .../settings/class-sp-settings-general.php | 10 + .../settings/class-sp-settings-players.php | 17 +- includes/class-sp-post-types.php | 174 +++++++++--------- includes/sp-core-functions.php | 29 ++- includes/sp-template-functions.php | 2 +- sportspress.php | 47 +++++ 12 files changed, 217 insertions(+), 124 deletions(-) diff --git a/includes/admin/class-sp-admin-assets.php b/includes/admin/class-sp-admin-assets.php index 672dabd3..c442afa8 100644 --- a/includes/admin/class-sp-admin-assets.php +++ b/includes/admin/class-sp-admin-assets.php @@ -60,6 +60,11 @@ class SP_Admin_Assets { wp_enqueue_style( 'sportspress-admin-equation-styles', SP()->plugin_url() . '/assets/css/equation.css', array(), SP_VERSION ); } + if ( SP()->mode == 'player' ): + $custom_css = '#adminmenu #menu-posts-sp_team .menu-icon-sp_team div.wp-menu-image:before,.sp-icon-shield:before{content: "\f307"}'; + wp_add_inline_style( 'sportspress-admin-menu-styles', $custom_css ); + endif; + do_action( 'sportspress_admin_css' ); } diff --git a/includes/admin/class-sp-admin-settings.php b/includes/admin/class-sp-admin-settings.php index 7d159f79..fc634123 100644 --- a/includes/admin/class-sp-admin-settings.php +++ b/includes/admin/class-sp-admin-settings.php @@ -34,8 +34,11 @@ class SP_Admin_Settings { $settings[] = include( 'settings/class-sp-settings-general.php' ); $settings[] = include( 'settings/class-sp-settings-events.php' ); $settings[] = include( 'settings/class-sp-settings-teams.php' ); - $settings[] = include( 'settings/class-sp-settings-players.php' ); - $settings[] = include( 'settings/class-sp-settings-staff.php' ); + + if ( SP()->mode == 'team' ): + $settings[] = include( 'settings/class-sp-settings-players.php' ); + $settings[] = include( 'settings/class-sp-settings-staff.php' ); + endif; $settings = apply_filters( 'sportspress_get_settings_pages', $settings ); diff --git a/includes/admin/post-types/class-sp-admin-meta-boxes.php b/includes/admin/post-types/class-sp-admin-meta-boxes.php index ea53be26..44e67b1e 100644 --- a/includes/admin/post-types/class-sp-admin-meta-boxes.php +++ b/includes/admin/post-types/class-sp-admin-meta-boxes.php @@ -52,7 +52,7 @@ class SP_Admin_Meta_Boxes { add_action( 'sportspress_process_sp_event_meta', 'SP_Meta_Box_Event_Teams::save', 30, 2 ); add_action( 'sportspress_process_sp_event_meta', 'SP_Meta_Box_Event_Video::save', 40, 2 ); add_action( 'sportspress_process_sp_event_meta', 'SP_Meta_Box_Event_Results::save', 50, 2 ); - add_action( 'sportspress_process_sp_event_meta', 'SP_Meta_Box_Event_Performance::save', 60, 2 ); + if ( SP()->mode == 'team' ) add_action( 'sportspress_process_sp_event_meta', 'SP_Meta_Box_Event_Performance::save', 60, 2 ); // Save Calendar Meta Boxes add_action( 'sportspress_process_sp_calendar_meta', 'SP_Meta_Box_Calendar_Format::save', 10, 2 ); @@ -114,7 +114,7 @@ class SP_Admin_Meta_Boxes { add_meta_box( 'sp_teamdiv', __( 'Teams', 'sportspress' ), 'SP_Meta_Box_Event_Teams::output', 'sp_event', 'side', 'default' ); add_meta_box( 'sp_videodiv', __( 'Video', 'sportspress' ), 'SP_Meta_Box_Event_Video::output', 'sp_event', 'side', 'low' ); add_meta_box( 'sp_resultsdiv', __( 'Team Results', 'sportspress' ), 'SP_Meta_Box_Event_Results::output', 'sp_event', 'normal', 'high' ); - add_meta_box( 'sp_performancediv', __( 'Player Performance', 'sportspress' ), 'SP_Meta_Box_Event_Performance::output', 'sp_event', 'normal', 'high' ); + if ( SP()->mode == 'team' ) add_meta_box( 'sp_performancediv', __( 'Player Performance', 'sportspress' ), 'SP_Meta_Box_Event_Performance::output', 'sp_event', 'normal', 'high' ); add_meta_box( 'sp_editordiv', __( 'Article', 'sportspress' ), 'SP_Meta_Box_Event_Editor::output', 'sp_event', 'normal', 'high' ); // Calendars diff --git a/includes/admin/post-types/meta-boxes/class-sp-meta-box-event-teams.php b/includes/admin/post-types/meta-boxes/class-sp-meta-box-event-teams.php index 0f2e0d8d..df53f3f8 100644 --- a/includes/admin/post-types/meta-boxes/class-sp-meta-box-event-teams.php +++ b/includes/admin/post-types/meta-boxes/class-sp-meta-box-event-teams.php @@ -5,7 +5,7 @@ * @author ThemeBoy * @category Admin * @package SportsPress/Admin/Meta_Boxes - * @version 0.8.6 + * @version 1.1 */ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly @@ -37,13 +37,17 @@ class SP_Meta_Box_Event_Teams { wp_dropdown_pages( $args ); ?>

- - ID, 'sp_player', 'block', 'sp_current_team', $i ); - sp_post_checklist( $post->ID, 'sp_staff', 'none', 'sp_current_team', $i ); + mode == 'team' ): + ?> + + ID, 'sp_player', 'block', 'sp_current_team', $i ); + sp_post_checklist( $post->ID, 'sp_staff', 'none', 'sp_current_team', $i ); + endif; ?> __( 'Configure SportsPress', 'sportspress' ), 'type' => 'title','desc' => '', 'id' => 'config_options' ), array( 'type' => 'outcomes' ), - + array( 'type' => 'results' ), + ); - array( 'type' => 'performance' ), + if ( SP()->mode == 'team' ) $settings[] = array( 'type' => 'performance' ); - array( 'type' => 'columns' ), + $settings[] = array( 'type' => 'columns' ); - array( 'type' => 'metrics' ), + if ( SP()->mode == 'team' ): + $settings = array_merge( $settings, array( + array( 'type' => 'metrics' ), - array( 'type' => 'statistics' ), + array( 'type' => 'statistics' ), + )); + endif; - array( 'type' => 'sectionend', 'id' => 'config_options' ), + $settings[] = array( 'type' => 'sectionend', 'id' => 'config_options' ); // End event settings - )); // End event settings + return apply_filters( 'sportspress_config_settings', $settings ); } /** diff --git a/includes/admin/settings/class-sp-settings-events.php b/includes/admin/settings/class-sp-settings-events.php index 89a901a6..cbd1ab90 100644 --- a/includes/admin/settings/class-sp-settings-events.php +++ b/includes/admin/settings/class-sp-settings-events.php @@ -5,7 +5,7 @@ * @author ThemeBoy * @category Admin * @package SportsPress/Admin - * @version 1.0 + * @version 1.1 */ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly diff --git a/includes/admin/settings/class-sp-settings-general.php b/includes/admin/settings/class-sp-settings-general.php index df7c7b52..132019da 100644 --- a/includes/admin/settings/class-sp-settings-general.php +++ b/includes/admin/settings/class-sp-settings-general.php @@ -53,6 +53,16 @@ class SP_Settings_General extends SP_Settings_Page { 'type' => 'select', 'options' => $presets, ), + array( + 'title' => __( 'Mode', 'sportspress' ), + 'id' => 'sportspress_mode', + 'default' => 'team', + 'type' => 'select', + 'options' => array( + 'team' => __( 'Team', 'sportspress' ), + 'player' => __( 'Individual', 'sportspress' ), + ), + ), array( 'title' => __( 'Google Maps', 'sportspress' ), diff --git a/includes/admin/settings/class-sp-settings-players.php b/includes/admin/settings/class-sp-settings-players.php index 6787805a..b4f1e4a3 100644 --- a/includes/admin/settings/class-sp-settings-players.php +++ b/includes/admin/settings/class-sp-settings-players.php @@ -5,7 +5,7 @@ * @author ThemeBoy * @category Admin * @package SportsPress/Admin - * @version 1.0 + * @version 1.1 */ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly @@ -35,9 +35,7 @@ class SP_Settings_Players extends SP_Settings_Page { * @return array */ public function get_settings() { - - return apply_filters( 'sportspress_player_settings', array( - + $settings = array( array( 'title' => __( 'Player Options', 'sportspress' ), 'type' => 'title','desc' => '', 'id' => 'player_options' ), array( @@ -59,15 +57,19 @@ class SP_Settings_Players extends SP_Settings_Page { 'default' => 'yes', 'type' => 'checkbox', ), + ); - array( + if ( SP()->mode == 'team' ): + $settings[] = array( 'title' => __( 'Teams', 'sportspress' ), 'desc' => __( 'Link teams', 'sportspress' ), 'id' => 'sportspress_list_link_teams', 'default' => 'no', 'type' => 'checkbox', - ), + ); + endif; + $settings = array_merge( $settings, array( array( 'title' => __( 'Pagination', 'sportspress' ), 'desc' => __( 'Paginate', 'sportspress' ), @@ -90,8 +92,9 @@ class SP_Settings_Players extends SP_Settings_Page { ), array( 'type' => 'sectionend', 'id' => 'list_options' ), - )); // End player settings + + return apply_filters( 'sportspress_player_settings', $settings ); } } diff --git a/includes/class-sp-post-types.php b/includes/class-sp-post-types.php index ad43bea5..057e3896 100644 --- a/includes/class-sp-post-types.php +++ b/includes/class-sp-post-types.php @@ -456,97 +456,99 @@ class SP_Post_types { ) ); - register_post_type( 'sp_player', - apply_filters( 'sportspress_register_post_type_player', - array( - 'labels' => array( - 'name' => __( 'Players', 'sportspress' ), - 'singular_name' => __( 'Player', 'sportspress' ), - 'add_new_item' => __( 'Add New Player', 'sportspress' ), - 'edit_item' => __( 'Edit Player', 'sportspress' ), - 'new_item' => __( 'New', 'sportspress' ), - 'view_item' => __( 'View', 'sportspress' ), - 'search_items' => __( 'Search', 'sportspress' ), - 'not_found' => __( 'No results found.', 'sportspress' ), - 'not_found_in_trash' => __( 'No results found.', 'sportspress' ), - ), - 'public' => true, - 'show_ui' => true, - 'capability_type' => 'sp_player', - 'map_meta_cap' => true, - 'publicly_queryable' => true, - 'exclude_from_search' => false, - 'hierarchical' => false, - 'rewrite' => array( 'slug' => get_option( 'sportspress_player_slug', 'player' ) ), - 'supports' => array( 'title', 'author', 'thumbnail', 'excerpt', 'page-attributes' ), - 'has_archive' => false, - 'show_in_nav_menus' => true, - 'menu_icon' => 'dashicons-groups', + if ( SP()->mode == 'team' ): + register_post_type( 'sp_player', + apply_filters( 'sportspress_register_post_type_player', + array( + 'labels' => array( + 'name' => __( 'Players', 'sportspress' ), + 'singular_name' => __( 'Player', 'sportspress' ), + 'add_new_item' => __( 'Add New Player', 'sportspress' ), + 'edit_item' => __( 'Edit Player', 'sportspress' ), + 'new_item' => __( 'New', 'sportspress' ), + 'view_item' => __( 'View', 'sportspress' ), + 'search_items' => __( 'Search', 'sportspress' ), + 'not_found' => __( 'No results found.', 'sportspress' ), + 'not_found_in_trash' => __( 'No results found.', 'sportspress' ), + ), + 'public' => true, + 'show_ui' => true, + 'capability_type' => 'sp_player', + 'map_meta_cap' => true, + 'publicly_queryable' => true, + 'exclude_from_search' => false, + 'hierarchical' => false, + 'rewrite' => array( 'slug' => get_option( 'sportspress_player_slug', 'player' ) ), + 'supports' => array( 'title', 'author', 'thumbnail', 'excerpt', 'page-attributes' ), + 'has_archive' => false, + 'show_in_nav_menus' => true, + 'menu_icon' => 'dashicons-groups', + ) ) - ) - ); + ); - register_post_type( 'sp_list', - apply_filters( 'sportspress_register_post_type_list', - array( - 'labels' => array( - 'name' => __( 'Player Lists', 'sportspress' ), - 'singular_name' => __( 'Player List', 'sportspress' ), - 'add_new_item' => __( 'Add New Player List', 'sportspress' ), - 'edit_item' => __( 'Edit Player List', 'sportspress' ), - 'new_item' => __( 'New', 'sportspress' ), - 'view_item' => __( 'View', 'sportspress' ), - 'search_items' => __( 'Search', 'sportspress' ), - 'not_found' => __( 'No results found.', 'sportspress' ), - 'not_found_in_trash' => __( 'No results found.', 'sportspress' ), - ), - 'public' => true, - 'show_ui' => true, - 'capability_type' => 'sp_list', - 'map_meta_cap' => true, - 'publicly_queryable' => true, - 'exclude_from_search' => false, - 'hierarchical' => false, - 'rewrite' => array( 'slug' => get_option( 'sportspress_list_slug', 'list' ) ), - 'supports' => array( 'title', 'author', 'thumbnail' ), - 'has_archive' => false, - 'show_in_nav_menus' => true, - 'show_in_menu' => 'edit.php?post_type=sp_player', - 'show_in_admin_bar' => true, + register_post_type( 'sp_list', + apply_filters( 'sportspress_register_post_type_list', + array( + 'labels' => array( + 'name' => __( 'Player Lists', 'sportspress' ), + 'singular_name' => __( 'Player List', 'sportspress' ), + 'add_new_item' => __( 'Add New Player List', 'sportspress' ), + 'edit_item' => __( 'Edit Player List', 'sportspress' ), + 'new_item' => __( 'New', 'sportspress' ), + 'view_item' => __( 'View', 'sportspress' ), + 'search_items' => __( 'Search', 'sportspress' ), + 'not_found' => __( 'No results found.', 'sportspress' ), + 'not_found_in_trash' => __( 'No results found.', 'sportspress' ), + ), + 'public' => true, + 'show_ui' => true, + 'capability_type' => 'sp_list', + 'map_meta_cap' => true, + 'publicly_queryable' => true, + 'exclude_from_search' => false, + 'hierarchical' => false, + 'rewrite' => array( 'slug' => get_option( 'sportspress_list_slug', 'list' ) ), + 'supports' => array( 'title', 'author', 'thumbnail' ), + 'has_archive' => false, + 'show_in_nav_menus' => true, + 'show_in_menu' => 'edit.php?post_type=sp_player', + 'show_in_admin_bar' => true, + ) ) - ) - ); + ); - register_post_type( 'sp_staff', - apply_filters( 'sportspress_register_post_type_staff', - array( - 'labels' => array( - 'name' => __( 'Staff', 'sportspress' ), - 'singular_name' => __( 'Staff', 'sportspress' ), - 'add_new_item' => __( 'Add New Staff', 'sportspress' ), - 'edit_item' => __( 'Edit Staff', 'sportspress' ), - 'new_item' => __( 'New', 'sportspress' ), - 'view_item' => __( 'View', 'sportspress' ), - 'search_items' => __( 'Search', 'sportspress' ), - 'not_found' => __( 'No results found.', 'sportspress' ), - 'not_found_in_trash' => __( 'No results found.', 'sportspress' ), - ), - 'public' => true, - 'show_ui' => true, - 'capability_type' => 'sp_staff', - 'map_meta_cap' => true, - 'publicly_queryable' => true, - 'exclude_from_search' => false, - 'hierarchical' => false, - 'rewrite' => array( 'slug' => get_option( 'sportspress_staff_slug', 'staff' ) ), - 'supports' => array( 'title', 'author', 'thumbnail', 'excerpt' ), - 'has_archive' => false, - 'show_in_nav_menus' => true, - 'show_in_menu' => 'edit.php?post_type=sp_player', - 'show_in_admin_bar' => true, + register_post_type( 'sp_staff', + apply_filters( 'sportspress_register_post_type_staff', + array( + 'labels' => array( + 'name' => __( 'Staff', 'sportspress' ), + 'singular_name' => __( 'Staff', 'sportspress' ), + 'add_new_item' => __( 'Add New Staff', 'sportspress' ), + 'edit_item' => __( 'Edit Staff', 'sportspress' ), + 'new_item' => __( 'New', 'sportspress' ), + 'view_item' => __( 'View', 'sportspress' ), + 'search_items' => __( 'Search', 'sportspress' ), + 'not_found' => __( 'No results found.', 'sportspress' ), + 'not_found_in_trash' => __( 'No results found.', 'sportspress' ), + ), + 'public' => true, + 'show_ui' => true, + 'capability_type' => 'sp_staff', + 'map_meta_cap' => true, + 'publicly_queryable' => true, + 'exclude_from_search' => false, + 'hierarchical' => false, + 'rewrite' => array( 'slug' => get_option( 'sportspress_staff_slug', 'staff' ) ), + 'supports' => array( 'title', 'author', 'thumbnail', 'excerpt' ), + 'has_archive' => false, + 'show_in_nav_menus' => true, + 'show_in_menu' => 'edit.php?post_type=sp_player', + 'show_in_admin_bar' => true, + ) ) - ) - ); + ); + endif; } public function display_scheduled_events( $posts ) { diff --git a/includes/sp-core-functions.php b/includes/sp-core-functions.php index acf38879..3506bf30 100644 --- a/includes/sp-core-functions.php +++ b/includes/sp-core-functions.php @@ -229,6 +229,15 @@ if ( !function_exists( 'sp_nonce' ) ) { } } +if ( !function_exists( 'sp_get_option' ) ) { + function sp_get_option( $option, $default = null ) { + if ( isset( $_POST[ $option ] ) ) + return $_POST[ $option ]; + else + return get_option( $option, $default ); + } +} + if ( !function_exists( 'sp_array_between' ) ) { function sp_array_between ( $array = array(), $delimiter = 0, $index = 0 ) { $keys = array_keys( $array, $delimiter ); @@ -2482,25 +2491,19 @@ function sp_get_sport_presets() { function sp_get_text_options() { $strings = apply_filters( 'sportspress_text', array( __( 'Article', 'sportspress' ), - __( 'Current Team', 'sportspress' ), __( 'Date', 'sportspress' ), __( 'Details', 'sportspress' ), __( 'Event', 'sportspress' ), __( 'League', 'sportspress' ), __( 'Nationality', 'sportspress' ), __( 'Outcome', 'sportspress' ), - __( 'Past Teams', 'sportspress' ), __( 'Played', 'sportspress' ), - __( 'Player', 'sportspress' ), __( 'Pos', 'sportspress' ), - __( 'Position', 'sportspress' ), __( 'Preview', 'sportspress' ), __( 'Rank', 'sportspress' ), __( 'Recap', 'sportspress' ), __( 'Team Results', 'sportspress' ), __( 'Season', 'sportspress' ), - __( 'Staff', 'sportspress' ), - __( 'Substitutes', 'sportspress' ), __( 'Team', 'sportspress' ), __( 'Teams', 'sportspress' ), __( 'Time', 'sportspress' ), @@ -2508,9 +2511,21 @@ function sp_get_text_options() { __( 'Total', 'sportspress' ), __( 'Venue', 'sportspress' ), __( 'View all events', 'sportspress' ), - __( 'View all players', 'sportspress' ), __( 'View full table', 'sportspress' ), )); + + if ( SP()->mode == 'team' ): + $strings = array_merge( $strings, array( + __( 'Current Team', 'sportspress' ), + __( 'Past Teams', 'sportspress' ), + __( 'Player', 'sportspress' ), + __( 'Position', 'sportspress' ), + __( 'Staff', 'sportspress' ), + __( 'Substitutes', 'sportspress' ), + __( 'View all players', 'sportspress' ), + )); + endif; + asort( $strings ); return $strings; } diff --git a/includes/sp-template-functions.php b/includes/sp-template-functions.php index 72f9813e..98ea58b7 100644 --- a/includes/sp-template-functions.php +++ b/includes/sp-template-functions.php @@ -133,7 +133,7 @@ if ( ! function_exists( 'sportspress_output_event_performance' ) ) { * @return void */ function sportspress_output_event_performance() { - sp_get_template( 'event-performance.php' ); + if ( SP()->mode == 'team' ) sp_get_template( 'event-performance.php' ); } } diff --git a/sportspress.php b/sportspress.php index 116edd9f..45c7ebc3 100644 --- a/sportspress.php +++ b/sportspress.php @@ -56,6 +56,11 @@ final class SportsPress { */ public $text = array(); + /** + * @var string + */ + public $mode = 'team'; + /** * Main SportsPress Instance * @@ -117,6 +122,7 @@ final class SportsPress { add_action( 'init', array( $this, 'include_template_functions' ) ); add_action( 'init', array( 'SP_Shortcodes', 'init' ) ); add_action( 'after_setup_theme', array( $this, 'setup_environment' ) ); + add_filter( 'gettext', array( $this, 'gettext' ), 20, 3 ); // Loaded action do_action( 'sportspress_loaded' ); @@ -264,6 +270,9 @@ final class SportsPress { // Load string options $this->text = get_option( 'sportspress_text', array() ); + // Get mode option + $this->mode = sp_get_option( 'sportspress_mode', 'team' ); + // Init action do_action( 'sportspress_init' ); } @@ -307,6 +316,44 @@ final class SportsPress { add_image_size( 'sportspress-fit-mini', 32, 32, false ); } + /** + * Replace team strings with player if individual mode. + */ + public function gettext( $translated_text, $untranslated_text, $domain ) { + if ( SP()->mode == 'player' && $domain == 'sportspress' ): + switch ( $untranslated_text ): + case 'Teams': + return __( 'Players', 'sportspress' ); + case 'Team': + return __( 'Player', 'sportspress' ); + case 'teams': + return __( 'players', 'sportspress' ); + case 'Add New Team': + return __( 'Add New Player', 'sportspress' ); + case 'Edit Team': + return __( 'Edit Player', 'sportspress' ); + case 'Team Options': + return __( 'Player Options', 'sportspress' ); + case 'Team Results': + return __( 'Player Performance', 'sportspress' ); + case 'Logo': + return __( 'Photo', 'sportspress' ); + case 'Add logo': + return __( 'Add photo', 'sportspress' ); + case 'Remove logo': + return __( 'Remove photo', 'sportspress' ); + case 'Select Logo': + return __( 'Select Photo', 'sportspress' ); + case 'Display logos': + return __( 'Display photos', 'sportspress' ); + case 'Link teams': + return __( 'Link players', 'sportspress' ); + endswitch; + endif; + + return $translated_text; + } + /** Helper functions ******************************************************/ /**