header(); if ( empty( $_GET['step'] ) ) { $step = 1; } else { $step = (int) $_GET['step']; } switch ($step) { case 1: $this->step1(); break; case 2: if ( isset( $_GET['import-id'] ) ) { $inserted_posts = History::get_imported_post_ids( $_GET['import-id'] ); } else { check_admin_referer( 'acsv-import-upload' ); set_time_limit( 0 ); $inserted_posts = $this->step2(); } if ( is_wp_error( $inserted_posts ) ) { echo '
' . $inserted_posts->get_error_message() . '
'; } else { self::delete_form( $inserted_posts ); } break; case 3: check_admin_referer( 'acsv-import-delete' ); if ( isset( $_POST['acsv-import-id'] ) && count( $_POST['acsv-import-id'] ) ) { foreach ( $_POST['acsv-import-id'] as $post_id ) { if ( intval( $post_id ) ) { wp_delete_post( $post_id, false ); } } echo ''; if ( count( $_POST['acsv-import-id'] ) === 1 ) { echo '1 post moved to the Trash.'; } else { echo count( $_POST['acsv-import-id'] ) . ' posts moved to the Trash.'; } echo '
'; } else { echo 'Nothing to do.
'; } break; } $this->footer(); } /** * The form of the second step. * * @param none * @return none */ private function step2() { $file = wp_import_handle_upload(); if ( isset( $file['error'] ) ) { return new WP_Error( 'Error', esc_html( $file['error'] ) ); } else if ( ! file_exists( $file['file'] ) ) { return new WP_Error( 'Error', sprintf( __( 'The export file could not be found at%s. It is likely that this was caused by a permissions problem.', 'advanced-csv-importer' ), esc_html( $file['file'] ) ) );
}
$csv_file = get_attached_file( $file['id'] );
$post_objects = Main::get_post_objects( $csv_file );
if ( is_wp_error( $post_objects ) ) {
echo ''.__( 'Failed to open file.', 'advanced-csv-importer' ).'
'; wp_import_cleanup( $file['id'] ); return $post_objects; } else { $inserted_posts = Main::insert_posts( $post_objects ); wp_import_cleanup( $file['id'] ); return $inserted_posts; } } /** * The form of the first step. * * @param none * @return none */ private function step1() { $bytes = apply_filters( 'acsv_import_upload_size_limit', wp_max_upload_size() ); $size = size_format( $bytes ); $upload_dir = wp_upload_dir(); echo '
| ID | Title | Date | Success | Failure |
|---|---|---|---|---|
'; printf( __( 'A new version of this importer is available. Please update to version %s to ensure compatibility with newer export files.', 'advanced-csv-importer' ), $update->update->new_version ); echo '
Posts were already deleted.
'; return; } $success = History::get_num_success( $inserted_posts ); $fail = History::get_num_fail( $inserted_posts ); echo ''; if ( $success === 1 ) { echo $success . ' post imported. '; } else { echo $success . ' posts imported. '; } if ( $fail === 1 ) { echo $fail . ' post failed to import. '; } else { echo $fail . ' posts failed to import. '; } echo '
'; echo ''; } }