diff --git a/dummy-data/players-sample.csv b/dummy-data/players-sample.csv index b43df364..6e1898be 100644 --- a/dummy-data/players-sample.csv +++ b/dummy-data/players-sample.csv @@ -1,5 +1,5 @@ -Number,Name,Positions,Teams,Leagues,Seasons,Nationality -1,Joe Allen,Goalkeeper,Eagles,Primary League|Secondary League,2014,aus -3,Steven Gerrard,Defender,Kangaroos,Primary League,2014|2013,usa -5,Daniel Sturridge,Midfielder|Forward,Sharks,Primary League|Secondary League,2014|2013,eng -6,Gabrielle Gonzalez,Forward,Kangaroos|Sharks,Primary League,2014,esp \ No newline at end of file +Number,Name,Positions,Teams,Leagues,Seasons,Nationality,DoB +1,Joe Allen,Goalkeeper,Eagles,Primary League|Secondary League,2014,aus,1983/05/05 +3,Steven Gerrard,Defender,Kangaroos,Primary League,2014|2013,usa,1970/03/10 +5,Daniel Sturridge,Midfielder|Forward,Sharks,Primary League|Secondary League,2014|2013,eng,1990/02/15 +6,Gabrielle Gonzalez,Forward,Kangaroos|Sharks,Primary League,2014,esp,1987/01/20 \ No newline at end of file diff --git a/includes/admin/importers/class-sp-player-importer.php b/includes/admin/importers/class-sp-player-importer.php index 6b76ee5a..f329b167 100644 --- a/includes/admin/importers/class-sp-player-importer.php +++ b/includes/admin/importers/class-sp-player-importer.php @@ -30,6 +30,7 @@ if ( class_exists( 'WP_Importer' ) ) { 'sp_league' => __( 'Leagues', 'sportspress' ), 'sp_season' => __( 'Seasons', 'sportspress' ), 'sp_nationality' => __( 'Nationality', 'sportspress' ), + 'post_date' => __( 'Date of Birth', 'sportspress' ), ); parent::__construct(); } @@ -51,6 +52,9 @@ if ( class_exists( 'WP_Importer' ) ) { endif; $rows = array_chunk( $array, sizeof( $columns ) ); + + // Get Date of Birth format from post vars + $date_format = ( empty( $_POST['sp_date_format'] ) ? 'yyyy/mm/dd' : $_POST['sp_date_format'] ); foreach ( $rows as $row ): @@ -77,6 +81,27 @@ if ( class_exists( 'WP_Importer' ) ) { endforeach; $name = sp_array_value( $meta, 'post_title' ); + $date = sp_array_value( $meta, 'post_date' ); + + // Format date of birth + $date = str_replace( '/', '-', trim( $date ) ); + $date_array = explode( '-', $date ); + switch ( $date_format ): + case 'dd/mm/yyyy': + $date = substr( str_pad( sp_array_value( $date_array, 2, '0000' ), 4, '0', STR_PAD_LEFT ), 0, 4 ) . '-' . + substr( str_pad( sp_array_value( $date_array, 1, '00' ), 2, '0', STR_PAD_LEFT ), 0, 2 ) . '-' . + substr( str_pad( sp_array_value( $date_array, 0, '00' ), 2, '0', STR_PAD_LEFT ), 0, 2 ); + break; + case 'mm/dd/yyyy': + $date = substr( str_pad( sp_array_value( $date_array, 2, '0000' ), 4, '0', STR_PAD_LEFT ), 0, 4 ) . '-' . + substr( str_pad( sp_array_value( $date_array, 0, '00' ), 2, '0', STR_PAD_LEFT ), 0, 2 ) . '-' . + substr( str_pad( sp_array_value( $date_array, 1, '00' ), 2, '0', STR_PAD_LEFT ), 0, 2 ); + break; + default: + $date = substr( str_pad( sp_array_value( $date_array, 0, '0000' ), 4, '0', STR_PAD_LEFT ), 0, 4 ) . '-' . + substr( str_pad( sp_array_value( $date_array, 1, '00' ), 2, '0', STR_PAD_LEFT ), 0, 2 ) . '-' . + substr( str_pad( sp_array_value( $date_array, 2, '00' ), 2, '0', STR_PAD_LEFT ), 0, 2 ); + endswitch; if ( ! $name ): $this->skipped++; @@ -97,6 +122,10 @@ if ( class_exists( 'WP_Importer' ) ) { } else: $args = array( 'post_type' => 'sp_player', 'post_status' => 'publish', 'post_title' => wp_strip_all_tags( $name ) ); + // Check if a DoB was set + if( '0000-00-00' !== $date ){ + $args['post_date'] = $date; + } $id = wp_insert_post( $args ); // Flag as import @@ -195,7 +224,7 @@ if ( class_exists( 'WP_Importer' ) ) { function greet() { echo '
'; echo '

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

'; - echo '

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

'; + echo '

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

'; wp_import_upload_form( 'admin.php?import=sp_player_csv&step=1' ); echo '
'; } @@ -210,6 +239,26 @@ if ( class_exists( 'WP_Importer' ) ) { ?> + + + +
+ + +
+
    +
  • + +
  • +
  • + +
  • +
  • + +
  • +
+
+