From 77f46b23b01ddf1571aa69b3e04f1ac1722f58d6 Mon Sep 17 00:00:00 2001 From: Brian Miyaji Date: Sat, 18 Nov 2017 18:57:23 +1100 Subject: [PATCH] Require box score importer to be accessed from within an event --- includes/admin/class-sp-admin-importers.php | 14 +++++++++----- includes/admin/class-sp-admin.php | 10 ---------- .../class-sp-event-performance-importer.php | 15 +++++++++++---- 3 files changed, 20 insertions(+), 19 deletions(-) diff --git a/includes/admin/class-sp-admin-importers.php b/includes/admin/class-sp-admin-importers.php index 4f75becf..8220bb61 100644 --- a/includes/admin/class-sp-admin-importers.php +++ b/includes/admin/class-sp-admin-importers.php @@ -28,6 +28,7 @@ class SP_Admin_Importers { * Add menu items */ public function register_importers() { + global $pagenow; $importers = apply_filters( 'sportspress_importers', array( 'sp_event_csv' => array( 'name' => __( 'SportsPress Events (CSV)', 'sportspress' ), @@ -39,11 +40,6 @@ class SP_Admin_Importers { 'description' => __( 'Import upcoming events from a csv file.', 'sportspress'), 'callback' => array( $this, 'fixtures_importer' ), ), - 'sp_event_performance_csv' => array( - 'name' => __( 'SportsPress Box Score (CSV)', 'sportspress' ), - 'description' => __( 'Import event box scores from a csv file.', 'sportspress'), - 'callback' => array( $this, 'event_performance_importer' ), - ), 'sp_team_csv' => array( 'name' => __( 'SportsPress Teams (CSV)', 'sportspress' ), 'description' => __( 'Import teams from a csv file.', 'sportspress'), @@ -61,6 +57,14 @@ class SP_Admin_Importers { ), ) ); + if ( 'import.php' !== $pagenow ) { + $importers['sp_event_performance_csv'] = array( + 'name' => __( 'SportsPress Box Score (CSV)', 'sportspress' ), + 'description' => '' . sprintf( __( 'Select %s', 'sportspress' ), __( 'Event', 'sportspress' ) ) . '', + 'callback' => array( $this, 'event_performance_importer' ), + ); + } + foreach ( $importers as $id => $importer ) { register_importer( $id, $importer['name'], $importer['description'], $importer['callback'] ); } diff --git a/includes/admin/class-sp-admin.php b/includes/admin/class-sp-admin.php index 0f9b1a07..4cdadc50 100644 --- a/includes/admin/class-sp-admin.php +++ b/includes/admin/class-sp-admin.php @@ -116,16 +116,6 @@ class SP_Admin { })(jQuery); - - 'sp_event_performance_csv', 'step' => '1' ) ); + $event = sp_array_value( $_REQUEST, 'event', 0 ); echo '
'; - echo '

' . __( 'Hi there! Choose a .csv file to upload, then click "Upload file and import".', 'sportspress' ).'

'; - echo '

' . sprintf( __( 'Box scores need to be defined with columns in a specific order. Click here to download a sample.', 'sportspress' ), plugin_dir_url( SP_PLUGIN_FILE ) . 'dummy-data/event-performance-sample.csv' ) . '

'; - wp_import_upload_form( add_query_arg( $args, 'admin.php' ) ); + + if ( $event ) { + $args = array_merge( $_REQUEST, array( 'import' => 'sp_event_performance_csv', 'step' => '1' ) ); + echo '

' . __( 'Hi there! Choose a .csv file to upload, then click "Upload file and import".', 'sportspress' ).'

'; + echo '

' . sprintf( __( 'Box scores need to be defined with columns in a specific order. Click here to download a sample.', 'sportspress' ), plugin_dir_url( SP_PLUGIN_FILE ) . 'dummy-data/event-performance-sample.csv' ) . '

'; + wp_import_upload_form( add_query_arg( $args, 'admin.php' ) ); + } else { + echo '

' . sprintf( __( 'Select %s', 'sportspress' ), __( 'Event', 'sportspress' ) ) . '

'; + } + echo '
'; }