$headers ) + $data; echo \WC_CSV_Import_Suite_Parser::generate_html_rows( $data ); wp_die(); } /** * Get import progress * * @since 3.0.0 */ public function get_progress() { check_ajax_referer( 'get-import-progress', 'security' ); $job_id = isset( $_GET['job_id'] ) ? $_GET['job_id'] : ''; $results_from = isset( $_GET['results_from'] ) ? $_GET['results_from'] : null; if ( ! $job_id ) { wp_send_json_error( array( 'message' => esc_html__( 'Missing import job ID.', 'woocommerce-customer-order-csv-export' ), ) ); } $results = array(); $progress = get_option( 'wc_csv_import_suite_background_import_progress_' . $job_id ); // if the progress option is not found, it most probably means that the // job has completed processing if ( false === $progress ) { $complete = get_option( 'wc_csv_import_suite_background_import_job_' . $job_id ); if ( $complete ) { $job = json_decode( $complete, true ); if ( 'completed' == $job['status'] ) { $progress = $job['file_size']; $results = $job['results']; } } } else { $results = get_option( 'wc_csv_import_suite_background_import_results_' . $job_id ); $results = json_decode( $results, true ); $progress = $progress['pos']; } // optionally return only a subset of results if ( $results_from && is_array( $results ) && ! empty( $results ) ) { $lines = array_keys( $results ); // only return a subset if the requested subset starting line is greater // than the lowest line in the results if ( $results_from >= min( $lines ) ) { $index = array_search( $results_from, $lines ); $results = $index ? array_slice( $results, $index, null, true ) : null; } } wp_send_json( array( 'progress' => $progress, 'results' => $results, ) ); } /** * Handle dismissing admin notices * * Removes any import finished notices from db * * @since 3.1.0 * @param string $message_id * @param int $user_id */ public function handle_dismiss_notice( $message_id, $user_id ) { if ( Framework\SV_WC_Helper::str_starts_with( $message_id, 'wc_csv_import_suite_finished_' ) ) { $parts = explode( '_', $message_id ); $job_id = array_pop( $parts ); wc_csv_import_suite()->remove_import_finished_notice( $job_id, $user_id ); } } }