diff --git a/admin/hooks/admin-init.php b/admin/hooks/admin-init.php index 1dc3c75c..5f39597e 100644 --- a/admin/hooks/admin-init.php +++ b/admin/hooks/admin-init.php @@ -1,38 +1,4 @@ dispatch(); -} - -function sportspress_player_importer() { - require_once ABSPATH . 'wp-admin/includes/import.php'; - - if ( ! class_exists( 'WP_Importer' ) ) { - $class_wp_importer = ABSPATH . 'wp-admin/includes/class-wp-importer.php'; - if ( file_exists( $class_wp_importer ) ) - require $class_wp_importer; - } - - // includes - require dirname( SPORTSPRESS_PLUGIN_FILE ) . '/admin/importers/player-importer.php'; - - // Dispatch - $importer = new SP_Player_Importer(); - $importer->dispatch(); -} - function sportspress_admin_init() { $post_types = array( 'sp_event', @@ -69,9 +35,5 @@ function sportspress_admin_init() { $administrator->add_cap( $cap . '_' . $post_type . 's' ); endforeach; endforeach; - - // Importers - register_importer( 'sportspress_team_csv', __( 'SportsPress Teams (CSV)', 'sportspress' ), __( 'Import teams from a csv file.', 'sportspress'), 'sportspress_team_importer' ); - register_importer( 'sportspress_player_csv', __( 'SportsPress Players (CSV)', 'sportspress' ), __( 'Import players from a csv file.', 'sportspress'), 'sportspress_player_importer' ); } add_action( 'admin_init', 'sportspress_admin_init' ); diff --git a/admin/hooks/admin-menu.php b/admin/hooks/admin-menu.php index d4872485..49bb94ca 100644 --- a/admin/hooks/admin-menu.php +++ b/admin/hooks/admin-menu.php @@ -3,15 +3,15 @@ function sportspress_admin_menu( $position ) { global $menu, $submenu; - // Find where our placeholder is in the menu + // Find where our separator is in the menu foreach( $menu as $key => $data ): if ( is_array( $data ) && array_key_exists( 2, $data ) && $data[2] == 'edit.php?post_type=sp_separator' ) - $seperator_position = $key; + $separator_position = $key; endforeach; - // Swap our placeholder post type with a menu separator - if ( $seperator_position ): - $menu[ $seperator_position ] = array( '', 'read', 'separator-sportspress', '', 'wp-menu-separator sportspress' ); + // Swap our separator post type with a menu separator + if ( isset( $separator_position ) ): + $menu[ $separator_position ] = array( '', 'read', 'separator-sportspress', '', 'wp-menu-separator sportspress' ); endif; // Remove "Venues" and "Positions" links from Media submenu @@ -41,6 +41,12 @@ function sportspress_admin_menu( $position ) { } add_action( 'admin_menu', 'sportspress_admin_menu' ); +if ( ! function_exists( 'sportspress_admin_menu_remove_add_new' ) ) { + function sportspress_admin_menu_remove_add_new( $arr = array() ) { + return $arr[0] != __( 'Add New', 'sportspress' ); + } +} + if ( ! function_exists( 'sportspress_admin_menu_remove_leagues' ) ) { function sportspress_admin_menu_remove_leagues( $arr = array() ) { return $arr[0] != __( 'Leagues', 'sportspress' ); diff --git a/admin/hooks/admin-print-styles.php b/admin/hooks/admin-print-styles.php index a234803b..20f848be 100644 --- a/admin/hooks/admin-print-styles.php +++ b/admin/hooks/admin-print-styles.php @@ -1,10 +1,8 @@ id != 'settings_page_sportspress' ): - if ( isset( $_REQUEST['sportspress_installed'] ) ): update_option( 'sportspress_installed', $_REQUEST['sportspress_installed'] ); endif; @@ -12,13 +10,11 @@ function sportspress_admin_notices_styles() { if ( ! get_option( 'sportspress_installed' ) ): add_action( 'admin_notices', 'sportspress_admin_install_notices' ); endif; - endif; $template = get_option( 'template' ); if ( ! current_theme_supports( 'sportspress' ) && ! in_array( $template, array( 'twentyfourteen', 'twentythirteen', 'twentyeleven', 'twentytwelve', 'twentyten' ) ) ): - if ( ! empty( $_GET['hide_sportspress_theme_support_check'] ) ): update_option( 'sportspress_theme_support_check', $template ); return; @@ -27,9 +23,7 @@ function sportspress_admin_notices_styles() { if ( get_option( 'sportspress_theme_support_check' ) !== $template ): add_action( 'admin_notices', 'sportspress_theme_check_notice' ); endif; - endif; - } add_action( 'admin_print_styles', 'sportspress_admin_notices_styles' ); @@ -50,5 +44,5 @@ function sportspress_admin_install_notices() { * @return void */ function sportspress_theme_check_notice() { - include( dirname( SPORTSPRESS_PLUGIN_FILE ) . '/admin/includes/notice-theme-support.php' ); +// include( dirname( SPORTSPRESS_PLUGIN_FILE ) . '/admin/includes/notice-theme-support.php' ); } diff --git a/admin/hooks/save-post.php b/admin/hooks/save-post.php index 6b6bda34..046798fb 100644 --- a/admin/hooks/save-post.php +++ b/admin/hooks/save-post.php @@ -95,15 +95,18 @@ function sportspress_save_post( $post_id ) { // Update seasons teams to show update_post_meta( $post_id, 'sp_leagues', sportspress_array_value( $_POST, 'sp_leagues', array() ) ); + // Update current team + update_post_meta( $post_id, 'sp_current_team', sportspress_array_value( $_POST, 'sp_current_team', null ) ); + + // Update past team array + sportspress_update_post_meta_recursive( $post_id, 'sp_past_team', sportspress_array_value( $_POST, 'sp_past_team', array() ) ); + // Update team array - sportspress_update_post_meta_recursive( $post_id, 'sp_team', sportspress_array_value( $_POST, 'sp_team', array() ) ); + sportspress_update_post_meta_recursive( $post_id, 'sp_team', array_merge( array( sportspress_array_value( $_POST, 'sp_current_team', null ) ), sportspress_array_value( $_POST, 'sp_past_team', array() ) ) ); // Update player number update_post_meta( $post_id, 'sp_number', sportspress_array_value( $_POST, 'sp_number', '' ) ); - // Update current team - update_post_meta( $post_id, 'sp_current_team', sportspress_array_value( $_POST, 'sp_current_team', '' ) ); - // Update nationality update_post_meta( $post_id, 'sp_nationality', sportspress_array_value( $_POST, 'sp_nationality', '' ) ); diff --git a/admin/includes/notice-theme-support.php b/admin/includes/notice-theme-support.php index cbeb37e2..ccf9d3be 100644 --- a/admin/includes/notice-theme-support.php +++ b/admin/includes/notice-theme-support.php @@ -1,12 +1,10 @@ -
-

Your theme does not declare SportsPress support – if you encounter layout issues please read our integration guide or choose a SportsPress theme :)', 'sportspress' ); ?>

+

Your theme does not declare SportsPress support – if you encounter layout issues please read our integration guide or choose a SportsPress theme :)', 'sportspress' ); ?>

-
- \ No newline at end of file diff --git a/admin/post-types/player.php b/admin/post-types/player.php index ad38d66b..110d151e 100644 --- a/admin/post-types/player.php +++ b/admin/post-types/player.php @@ -96,7 +96,7 @@ function sportspress_player_details_meta( $post ) { endif; $teams = get_posts( array( 'post_type' => 'sp_team', 'posts_per_page' => -1 ) ); - $the_teams = array_filter( get_post_meta( $post->ID, 'sp_team', false ) ); + $past_teams = array_filter( get_post_meta( $post->ID, 'sp_past_team', false ) ); $current_team = get_post_meta( $post->ID, 'sp_current_team', true ); ?>

@@ -114,6 +114,51 @@ function sportspress_player_details_meta( $post ) {

+

+

'sp_position', + 'name' => 'tax_input[sp_position][]', + 'selected' => $position_ids, + 'values' => 'term_id', + 'placeholder' => __( 'Select Positions', 'sportspress' ), + 'class' => 'widefat', + 'property' => 'multiple', + 'chosen' => true, + ); + sportspress_dropdown_taxonomies( $args ); + ?>

+ +

+

'sp_team', + 'name' => 'sp_current_team', + 'show_option_blank' => true, + 'selected' => $current_team, + 'values' => 'ID', + 'placeholder' => __( 'Select Team', 'sportspress' ), + 'class' => 'sp-current-team widefat', + 'chosen' => true, + ); + sportspress_dropdown_pages( $args ); + ?>

+ +

+

'sp_team', + 'name' => 'sp_past_team[]', + 'selected' => $past_teams, + 'values' => 'ID', + 'placeholder' => __( 'Select Teams', 'sportspress' ), + 'class' => 'sp-past-teams widefat', + 'property' => 'multiple', + 'chosen' => true, + ); + sportspress_dropdown_pages( $args ); + ?>

+

- -

-

'sp_team', - 'name' => 'sp_team[]', - 'selected' => $the_teams, - 'values' => 'ID', - 'placeholder' => __( 'Select Teams', 'sportspress' ), - 'class' => 'sp-team widefat', - 'property' => 'multiple', - 'chosen' => true, - ); - sportspress_dropdown_pages( $args ); - ?>

- -

-

'sp_team', - 'name' => 'sp_current_team', - 'show_option_blank' => true, - 'selected' => $current_team, - 'values' => 'ID', - 'placeholder' => __( 'Select Team', 'sportspress' ), - 'class' => 'sp-current-team widefat', - 'chosen' => true, - ); - sportspress_dropdown_pages( $args ); - ?>

- -

-

'sp_position', - 'name' => 'tax_input[sp_position][]', - 'selected' => $position_ids, - 'values' => 'term_id', - 'placeholder' => __( 'Select Positions', 'sportspress' ), - 'class' => 'widefat', - 'property' => 'multiple', - 'chosen' => true, - ); - sportspress_dropdown_taxonomies( $args ); - ?>

@@ -43,13 +43,13 @@ function sportspress_sport_callback() { $custom_sport_name = sportspress_array_value( $options, 'custom_sport_name', null ); ?> - class="hidden">

+ class="hidden"> $terms ): + // Find empty terms and destroy + $allterms = get_terms( $taxonomy, 'hide_empty=0' ); - foreach( $term_groups as $taxonomy => $terms ): - // Find empty terms and destroy - $allterms = get_terms( $taxonomy, 'hide_empty=0' ); + foreach( $allterms as $term ): + if ( $term->count == 0 ) + wp_delete_term( $term->term_id, $taxonomy ); + endforeach; - foreach( $allterms as $term ): - if ( $term->count == 0 ) - wp_delete_term( $term->term_id, $taxonomy ); + // Insert terms + foreach( $terms as $term ): + wp_insert_term( $term['name'], $taxonomy, array( 'slug' => $term['slug'] ) ); + endforeach; endforeach; - // Insert terms - foreach( $terms as $term ): - wp_insert_term( $term['name'], $taxonomy, array( 'slug' => $term['slug'] ) ); - endforeach; - endforeach; + // Get array of post types to insert + $post_groups = sportspress_array_value( sportspress_array_value( $sportspress_sports, sportspress_array_value( $input, 'sport', null ), array() ), 'posts', array() ); - // Get array of post types to insert - $post_groups = sportspress_array_value( sportspress_array_value( $sportspress_sports, sportspress_array_value( $input, 'sport', null ), array() ), 'posts', array() ); + // Loop through each post type + foreach( $post_groups as $post_type => $posts ): - // Loop through each post type - foreach( $post_groups as $post_type => $posts ): - - $args = array( - 'post_type' => $post_type, - 'numberposts' => -1, - 'posts_per_page' => -1, - 'meta_query' => array( - array( - 'key' => '_sp_preset', - 'value' => 1 + $args = array( + 'post_type' => $post_type, + 'numberposts' => -1, + 'posts_per_page' => -1, + 'meta_query' => array( + array( + 'key' => '_sp_preset', + 'value' => 1 + ) ) - ) - ); + ); - // Delete posts - $old_posts = get_posts( $args ); + // Delete posts + $old_posts = get_posts( $args ); - foreach( $old_posts as $post ): - wp_delete_post( $post->ID, true); - endforeach; + foreach( $old_posts as $post ): + wp_delete_post( $post->ID, true); + endforeach; - // Add posts - foreach( $posts as $index => $post ): + // Add posts + foreach( $posts as $index => $post ): - // Make sure post doesn't overlap - if ( ! get_page_by_path( $post['post_name'], OBJECT, $post_type ) ): + // Make sure post doesn't overlap + if ( ! get_page_by_path( $post['post_name'], OBJECT, $post_type ) ): - // Translate post title - $post['post_title'] = __( $post['post_title'], 'sportspress' ); + // Translate post title + $post['post_title'] = __( $post['post_title'], 'sportspress' ); - // Set post type - $post['post_type'] = $post_type; + // Set post type + $post['post_type'] = $post_type; - // Increment menu order by 2 and publish post - $post['menu_order'] = $index * 2 + 2; - $post['post_status'] = 'publish'; - $id = wp_insert_post( $post ); + // Increment menu order by 2 and publish post + $post['menu_order'] = $index * 2 + 2; + $post['post_status'] = 'publish'; + $id = wp_insert_post( $post ); - // Flag as preset - update_post_meta( $id, '_sp_preset', 1 ); + // Flag as preset + update_post_meta( $id, '_sp_preset', 1 ); - // Update meta - if ( array_key_exists( 'meta', $post ) ): + // Update meta + if ( array_key_exists( 'meta', $post ) ): - foreach ( $post['meta'] as $key => $value ): + foreach ( $post['meta'] as $key => $value ): - update_post_meta( $id, $key, $value ); + update_post_meta( $id, $key, $value ); - endforeach; + endforeach; + + endif; + + // Update terms + if ( array_key_exists( 'tax_input', $post ) ): + + foreach ( $post['tax_input'] as $taxonomy => $terms ): + + wp_set_object_terms( $id, $terms, $taxonomy, false ); + + endforeach; + + endif; endif; - // Update terms - if ( array_key_exists( 'tax_input', $post ) ): - - foreach ( $post['tax_input'] as $taxonomy => $terms ): - - wp_set_object_terms( $id, $terms, $taxonomy, false ); - - endforeach; - - endif; - - endif; + endforeach; endforeach; - endforeach; + endif; - return $input; + // Merge with existing options + return array_merge( $options, $input ); } -function sportspress_add_options_page() { +function sportspress_add_menu_page() { add_options_page( __( 'SportsPress', 'sportspress' ), __( 'SportsPress', 'sportspress' ), @@ -244,4 +245,4 @@ function sportspress_add_options_page() { 'sportspress_settings' ); } -add_action( 'admin_menu', 'sportspress_add_options_page' ); +add_action( 'admin_menu', 'sportspress_add_menu_page' ); diff --git a/admin/templates/player-metrics.php b/admin/templates/player-metrics.php index 75eb722c..743718c1 100644 --- a/admin/templates/player-metrics.php +++ b/admin/templates/player-metrics.php @@ -9,15 +9,30 @@ if ( !function_exists( 'sportspress_player_metrics' ) ) { $number = get_post_meta( $id, 'sp_number', true ); $nationality = get_post_meta( $id, 'sp_nationality', true ); + $current_team = get_post_meta( $id, 'sp_current_team', true ); + $past_teams = get_post_meta( $id, 'sp_past_team', false ); $metrics = sportspress_get_player_metrics_data( $id ); - $common = array( - __( 'Number', 'sportspress' ) => $number, - __( 'Nationality', 'sportspress' ) => sportspress_array_value( $sportspress_countries, $nationality, '—' ), - ); + $common = array(); + + if ( $number != null ) + $common[ __( 'Number', 'sportspress' ) ] = $number; + if ( $nationality ) + $common[ __( 'Nationality', 'sportspress' ) ] = sportspress_array_value( $sportspress_countries, $nationality, '—' ); $data = array_merge( $common, $metrics ); + if ( $current_team ) + $data[ __( 'Current Team', 'sportspress' ) ] = '' . get_the_title( $current_team ) . ''; + + if ( $past_teams ): + $teams = array(); + foreach ( $past_teams as $team ): + $teams[] = '' . get_the_title( $team ) . ''; + endforeach; + $data[ __( 'Past Teams', 'sportspress' ) ] = implode( ', ', $teams ); + endif; + $output = '
' . '' . ''; diff --git a/admin/tools/importers.php b/admin/tools/importers.php new file mode 100644 index 00000000..00807a2a --- /dev/null +++ b/admin/tools/importers.php @@ -0,0 +1,40 @@ +dispatch(); +} + +function sportspress_player_importer() { + require_once ABSPATH . 'wp-admin/includes/import.php'; + + if ( ! class_exists( 'WP_Importer' ) ) { + $class_wp_importer = ABSPATH . 'wp-admin/includes/class-wp-importer.php'; + if ( file_exists( $class_wp_importer ) ) + require $class_wp_importer; + } + + // includes + require dirname( SPORTSPRESS_PLUGIN_FILE ) . '/admin/tools/player-importer.php'; + + // Dispatch + $importer = new SP_Player_Importer(); + $importer->dispatch(); +} + +function sportspress_register_importers() { + register_importer( 'sportspress_team_csv', __( 'SportsPress Teams (CSV)', 'sportspress' ), __( 'Import teams from a csv file.', 'sportspress'), 'sportspress_team_importer' ); + register_importer( 'sportspress_player_csv', __( 'SportsPress Players (CSV)', 'sportspress' ), __( 'Import players from a csv file.', 'sportspress'), 'sportspress_player_importer' ); +} +add_action( 'admin_init', 'sportspress_register_importers' ); diff --git a/admin/importers/player-importer.php b/admin/tools/player-importer.php similarity index 100% rename from admin/importers/player-importer.php rename to admin/tools/player-importer.php diff --git a/admin/importers/team-importer.php b/admin/tools/team-importer.php similarity index 100% rename from admin/importers/team-importer.php rename to admin/tools/team-importer.php diff --git a/assets/css/admin.css b/assets/css/admin.css index b1795195..56468ce8 100644 --- a/assets/css/admin.css +++ b/assets/css/admin.css @@ -1,5 +1,50 @@ /* SportsPress admin styles */ +@font-face { + font-family: 'sportspress'; + src:url('../fonts/sportspress.eot?ofuus8'); + src:url('../fonts/sportspress.eot?#iefixofuus8') format('embedded-opentype'), + url('../fonts/sportspress.woff?ofuus8') format('woff'), + url('../fonts/sportspress.ttf?ofuus8') format('truetype'), + url('../fonts/sportspress.svg?ofuus8#sportspress') format('svg'); + font-weight: normal; + font-style: normal; +} + +[class^="icon-"], [class*=" icon-"] { + font-family: 'sportspress'; + speak: none; + font-style: normal; + font-weight: normal; + font-variant: normal; + text-transform: none; + line-height: 1; + + /* Better Font Rendering =========== */ + -webkit-font-smoothing: antialiased; + -moz-osx-font-smoothing: grayscale; +} + +.icon-sportspress:before { + content: "\f111"; +} +.icon-megaphone:before { + content: "\f155"; +} +.icon-calendar:before { + content: "\f145"; +} +.icon-shield:before { + content: "\f334"; +} + +#adminmenu #toplevel_page_sportspress .menu-icon-generic div.wp-menu-image:before, +#adminmenu #menu-posts-sp_event .menu-icon-sp_event div.wp-menu-image:before, +#adminmenu #menu-posts-sp_team .menu-icon-sp_team div.wp-menu-image:before, +#adminmenu #menu-posts-sp_sponsor .menu-icon-sp_sponsor div.wp-menu-image:before { + font-family: sportspress, dashicons !important; +} + .sportspress-message { border-left-color: #6bc2a5 !important; } @@ -7,7 +52,7 @@ .sportspress-message a.button-primary, .sportspress-message a.button-secondary { background: #6bc2a5; - border-color: #3bad87; + border-color: #409e7f; -webkit-box-shadow: inset 0 1px 0 rgba(255,255,255,.25),0 1px 0 rgba(0,0,0,.15); box-shadow: inset 0 1px 0 rgba(255,255,255,.25),0 1px 0 rgba(0,0,0,.15); color: #fff; @@ -164,8 +209,23 @@ table.widefat td.column-sp_number .sp-flag { color: #a00; } -.chosen-container { - margin: 1px; +.chosen-container-single .chosen-single { + -webkit-border-radius: 3px; + border-radius: 3px; + color: #555; + border-color: #ccc; + background: #f7f7f7; + -webkit-box-shadow: inset 0 1px 0 #fff,0 1px 0 rgba(0,0,0,.08); + box-shadow: inset 0 1px 0 #fff,0 1px 0 rgba(0,0,0,.08); +} + +.chosen-container-active.chosen-with-drop .chosen-single { + background: #fff; +} + +.chosen-container-single .chosen-drop { + -webkit-border-radius: 0 0 3px 3px; + border-radius: 0 0 3px 3px; } .chosen-container-multi .chosen-choices { diff --git a/assets/fonts/sportspress.eot b/assets/fonts/sportspress.eot new file mode 100755 index 00000000..14612da7 Binary files /dev/null and b/assets/fonts/sportspress.eot differ diff --git a/assets/fonts/sportspress.svg b/assets/fonts/sportspress.svg new file mode 100755 index 00000000..4ce6edb5 --- /dev/null +++ b/assets/fonts/sportspress.svg @@ -0,0 +1,14 @@ + + + +Generated by IcoMoon + + + + + + + + + + \ No newline at end of file diff --git a/assets/fonts/sportspress.ttf b/assets/fonts/sportspress.ttf new file mode 100755 index 00000000..d3a8d7a9 Binary files /dev/null and b/assets/fonts/sportspress.ttf differ diff --git a/assets/fonts/sportspress.woff b/assets/fonts/sportspress.woff new file mode 100755 index 00000000..d85b77a3 Binary files /dev/null and b/assets/fonts/sportspress.woff differ diff --git a/assets/js/admin.js b/assets/js/admin.js index 81f29e89..5183bda2 100644 --- a/assets/js/admin.js +++ b/assets/js/admin.js @@ -15,9 +15,9 @@ jQuery(document).ready(function($){ single_backstroke_delete: false }); - $('#poststuff #sp_detailsdiv .sp-current-team').on('change', function(evt, params) { + $('#poststuff #sp_detailsdiv .sp-current-team').on('change', function() { $el = $(this).closest('#sp_detailsdiv').find('.sp-team'); - $el.find('option[value='+$(this).val()+']').attr('selected', true); + $el.find('option[value='+$(this).val()+']').attr('selected', false); $el.trigger('chosen:updated'); }); diff --git a/functions.php b/functions.php index c03f97e9..142c6e72 100644 --- a/functions.php +++ b/functions.php @@ -927,7 +927,7 @@ if ( !function_exists( 'sportspress_edit_player_statistics_table' ) ) { $args = array( 'post_type' => 'sp_team', 'name' => 'sp_leagues[' . $league_id . '][' . $div_id . ']', - 'show_option_none' => __( '-- Not set --', 'sportspress' ), + 'show_option_none' => __( '— None —', 'sportspress' ), 'sort_order' => 'ASC', 'sort_column' => 'menu_order', 'selected' => $value, @@ -948,19 +948,7 @@ if ( !function_exists( 'sportspress_edit_player_statistics_table' ) ) { ), ); if ( ! sportspress_dropdown_pages( $args ) ): - $args = array( - 'post_type' => 'sp_team', - 'name' => 'sp_leagues[' . $league_id . '][' . $div_id . ']', - 'show_option_none' => __( '-- Not set --', 'sportspress' ), - 'sort_order' => 'ASC', - 'sort_column' => 'menu_order', - 'selected' => $value, - 'values' => 'ID', - 'include' => $teams, - ); - if ( ! sportspress_dropdown_pages( $args ) ): - echo '—'; - endif; + _e( 'No teams found.', 'sportspress' ); endif; ?> diff --git a/sportspress.php b/sportspress.php index ffb2a5a0..6b263cbd 100644 --- a/sportspress.php +++ b/sportspress.php @@ -81,6 +81,9 @@ require_once dirname( __FILE__ ) . '/admin/widgets/events-calendar.php'; require_once dirname( __FILE__ ) . '/admin/widgets/player-list.php'; require_once dirname( __FILE__ ) . '/admin/widgets/league-table.php'; +// Tools +require_once dirname( __FILE__ ) . '/admin/tools/importers.php'; + // Typical request actions require_once dirname( __FILE__ ) . '/admin/hooks/plugins-loaded.php'; require_once dirname( __FILE__ ) . '/admin/hooks/after-setup-theme.php';