Require box score importer to be accessed from within an event
This commit is contained in:
@@ -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 <strong>upcoming events</strong> from a csv file.', 'sportspress'),
|
||||
'callback' => array( $this, 'fixtures_importer' ),
|
||||
),
|
||||
'sp_event_performance_csv' => array(
|
||||
'name' => __( 'SportsPress Box Score (CSV)', 'sportspress' ),
|
||||
'description' => __( 'Import <strong>event box scores</strong> from a csv file.', 'sportspress'),
|
||||
'callback' => array( $this, 'event_performance_importer' ),
|
||||
),
|
||||
'sp_team_csv' => array(
|
||||
'name' => __( 'SportsPress Teams (CSV)', 'sportspress' ),
|
||||
'description' => __( 'Import <strong>teams</strong> 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' => '<a href="' . admin_url( add_query_arg( array( 'post_type' => 'sp_event' ), 'edit.php' ) ) . '">' . sprintf( __( 'Select %s', 'sportspress' ), __( 'Event', 'sportspress' ) ) . '</a>',
|
||||
'callback' => array( $this, 'event_performance_importer' ),
|
||||
);
|
||||
}
|
||||
|
||||
foreach ( $importers as $id => $importer ) {
|
||||
register_importer( $id, $importer['name'], $importer['description'], $importer['callback'] );
|
||||
}
|
||||
|
||||
@@ -116,16 +116,6 @@ class SP_Admin {
|
||||
})(jQuery);
|
||||
</script>
|
||||
<?php
|
||||
} elseif ( 'post.php' === $pagenow ) {
|
||||
?>
|
||||
<script type="text/javascript">
|
||||
(function($) {
|
||||
$(".wrap .page-title-action").first().after(
|
||||
$("<a class=\"add-new-h2\" href=\"<?php echo esc_url( admin_url( add_query_arg( array( 'import' => 'sp_event_performance_csv' ), 'admin.php' ) ) ); ?>\"><?php _e( 'Import Box Score', 'sportspress' ); ?></a>")
|
||||
);
|
||||
})(jQuery);
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
} else {
|
||||
if ( 'edit.php' === $pagenow ) {
|
||||
|
||||
@@ -144,12 +144,19 @@ if ( class_exists( 'WP_Importer' ) ) {
|
||||
* @return void
|
||||
*/
|
||||
function greet() {
|
||||
$args = array_merge( $_REQUEST, array( 'import' => 'sp_event_performance_csv', 'step' => '1' ) );
|
||||
$event = sp_array_value( $_REQUEST, 'event', 0 );
|
||||
|
||||
echo '<div class="narrow">';
|
||||
|
||||
if ( $event ) {
|
||||
$args = array_merge( $_REQUEST, array( 'import' => 'sp_event_performance_csv', 'step' => '1' ) );
|
||||
echo '<p>' . __( 'Hi there! Choose a .csv file to upload, then click "Upload file and import".', 'sportspress' ).'</p>';
|
||||
echo '<p>' . sprintf( __( 'Box scores need to be defined with columns in a specific order. <a href="%s">Click here to download a sample</a>.', 'sportspress' ), plugin_dir_url( SP_PLUGIN_FILE ) . 'dummy-data/event-performance-sample.csv' ) . '</p>';
|
||||
wp_import_upload_form( add_query_arg( $args, 'admin.php' ) );
|
||||
} else {
|
||||
echo '<p><a href="' . admin_url( add_query_arg( array( 'post_type' => 'sp_event' ), 'edit.php' ) ) . '">' . sprintf( __( 'Select %s', 'sportspress' ), __( 'Event', 'sportspress' ) ) . '</a></p>';
|
||||
}
|
||||
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user