/** * Perform cronjob */ function perform() { $queue = TP_CSV_Queue::get(); if (0 < count($queue)) { foreach ($queue as $file) { if ('processing' === $file->status['code']) { break; } if ('waiting' !== $file->status['code']) { continue; } /** * Do import */ $importer = new TP_CSV_Import($file->attachment_id, $file->taxonomy, $file->term); $result = $importer->start(); /** * Set new status */ TP_CSV_Queue::set_status($file->attachment_id, $result->status); break; } } }
/** * Set progress * * @param int $progress */ function set_progress($progress) { wp_cache_flush(); TP_CSV_Queue::set_status($this->attachment_id, array('code' => 'processing', 'progress' => $progress)); }
/** * Actions: Add / remove file */ function actions() { /** * Add file */ if (isset($_FILES['tp-csv-importer-file']) && check_admin_referer('tp-csv-importer-add')) { $added = TP_CSV_Queue::add('tp-csv-importer-file'); if ($added) { wp_redirect(admin_url('admin.php?page=' . $this->page_queue . '&message=tp-csv-importer-added')); } else { wp_redirect(admin_url('admin.php?page=' . $this->page_add_file . '&message=tp-csv-importer-not-added')); } die; } /** * Remove file */ if (isset($_GET['tp-csv-importer-remove-file']) && check_admin_referer('tp-csv-importer-remove')) { TP_CSV_Queue::remove($_GET['tp-csv-importer-remove-file']); wp_redirect(admin_url('admin.php?page=' . $this->page_queue . '&message=tp-csv-importer-removed')); die; } }