import_page = 'sp_team_csv'; $this->import_label = __( 'Import Teams', 'sportspress' ); $this->columns = array( 'post_title' => __( 'Name', 'sportspress' ), 'sp_league' => __( 'Competitions', 'sportspress' ), 'sp_season' => __( 'Seasons', 'sportspress' ), 'sp_url' => __( 'Site URL', 'sportspress' ), 'sp_abbreviation' => __( 'Abbreviation', 'sportspress' ), 'sp_venue' => __( 'Home', 'sportspress' ), ); parent::__construct(); } /** * import function. * * @access public * @param array $array * @param array $columns * @return void */ function import( $array = array(), $columns = array( 'post_title' ) ) { $this->imported = $this->skipped = 0; if ( ! is_array( $array ) || ! sizeof( $array ) ): $this->footer(); die(); endif; $rows = array_chunk( $array, sizeof( $columns ) ); foreach ( $rows as $row ): $row = array_filter( $row ); if ( empty( $row ) ) continue; $meta = array(); foreach ( $columns as $index => $key ): $meta[ $key ] = sp_array_value( $row, $index ); endforeach; $name = sp_array_value( $meta, 'post_title' ); if ( ! $name ): $this->skipped++; continue; endif; $args = array( 'post_type' => 'sp_team', 'post_status' => 'publish', 'post_title' => $name ); $id = wp_insert_post( $args ); // Flag as import update_post_meta( $id, '_sp_import', 1 ); // Update leagues $leagues = explode( '|', sp_array_value( $meta, 'sp_league' ) ); wp_set_object_terms( $id, $leagues, 'sp_league', false ); // Update seasons $seasons = explode( '|', sp_array_value( $meta, 'sp_season' ) ); wp_set_object_terms( $id, $seasons, 'sp_season', false ); // Update venues $venues = explode( '|', sp_array_value( $meta, 'sp_venue' ) ); wp_set_object_terms( $id, $venues, 'sp_venue', false ); // Update meta update_post_meta( $id, 'sp_url', sp_array_value( $meta, 'sp_url' ) ); update_post_meta( $id, 'sp_abbreviation', sp_array_value( $meta, 'sp_abbreviation' ) ); $this->imported++; endforeach; // Show Result echo '
'.sprintf( __( 'Import complete - imported %s teams and skipped %s.', 'sportspress' ), $this->imported, $this->skipped ).'
' . __( 'All done!', 'sportspress' ) . ' ' . __( 'View Teams', 'sportspress' ) . '' . '
'; do_action( 'import_end' ); } /** * greet function. * * @access public * @return void */ function greet() { echo '' . __( 'Hi there! Choose a .csv file to upload, then click "Upload file and import".', 'sportspress' ).'
'; echo '' . sprintf( __( 'Teams need to be defined with columns in a specific order (3 columns). Click here to download a sample.', 'sportspress' ), plugin_dir_url( SP_PLUGIN_FILE ) . 'dummy-data/teams-sample.csv' ) . '
'; wp_import_upload_form( 'admin.php?import=sp_team_csv&step=1' ); echo '