import_page = 'sp_official_csv'; $this->import_label = esc_attr__( 'Import Officials', 'sportspress' ); $this->columns = array( 'post_title' => esc_attr__( 'Name', '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_official', 'post_status' => 'publish', 'post_title' => wp_strip_all_tags( $name ), ); $id = wp_insert_post( $args ); $this->imported++; endforeach; // Show Result echo '
' . wp_kses_post( sprintf( __( 'Import complete - imported %1$s officials and skipped %2$s.', 'sportspress' ), esc_html( $this->imported ), esc_html( $this->skipped ) ) ) . '
' . esc_html__( 'All done!', 'sportspress' ) . ' ' . esc_html__( 'View Officials', 'sportspress' ) . '' . '
'; do_action( 'import_end' ); } /** * header function. * * @access public * @return void */ function header() { echo '' . esc_html__( 'Hi there! Choose a .csv file to upload, then click "Upload file and import".', 'sportspress' ) . '
'; echo '' . wp_kses_post( sprintf( __( 'Officials need to be defined with columns in a specific order. Click here to download a sample.', 'sportspress' ), esc_url( plugin_dir_url( SP_PLUGIN_FILE ) ) . 'dummy-data/officials-sample.csv' ) ) . '
'; wp_import_upload_form( 'admin.php?import=sp_official_csv&step=1' ); echo '