/** * 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; } } }
/** * Queue admin page */ function queue() { $queue = TP_CSV_Queue::get(); ?> <div class="wrap tp-csv-importer"> <h2> <?php _e('Import queue', 'tp-csv-importer'); ?> </h2> <table class="wp-list-table widefat"> <thead> <tr> <th> <?php _e('File', 'tp-csv-importer'); ?> </th> <th> <?php _e('Status', 'tp-csv-importer'); ?> </th> <th class="actions"></th> </tr> </thead> <tbody> <?php if (0 === count($queue)) { ?> <tr> <td colspan="2"> <?php printf(__('The queue is currently empty. <a href="%1$s">Add new file</a>', 'tp-csv-importer'), admin_url('admin.php?page=' . $this->page_add_file)); ?> </td> </tr> <?php } else { foreach ($queue as $file) { $attachment = get_post($file->attachment_id); ?> <tr> <td> <a href="<?php echo wp_get_attachment_url($file->attachment_id); ?> " target="_blank"> <?php echo $attachment->post_title; ?> </a> </td> <td> <?php $status = $file->status; if ('waiting' === $status['code']) { _e('Waiting', 'tp-csv-importer'); } else { if ('processing' === $status['code']) { printf(__('Processing (%1$s)', 'tp-csv-importer'), $status['progress'] . '%'); } else { if ('failed' === $status['code']) { printf(__('Failed: %1$s', 'tp-csv-importer'), $status['message']); } else { if ('success' === $status['code']) { printf(__('Done', 'tp')); } } } } ?> </td> <td> <?php if ('processing' !== $status['code'] && 'success' !== $status['code']) { ?> <a href="<?php echo wp_nonce_url(admin_url('admin.php?page=' . $this->page_queue . '&tp-csv-importer-remove-file=' . $file->attachment_id), 'tp-csv-importer-remove'); ?> " class="dashicons dashicons-trash tp-csv-importer-remove-file"></a> <?php } ?> </td> </tr> <?php /** * Remove file after seen 'success' */ if ('success' === $status['code']) { TP_CSV_Queue::remove($file->attachment_id); } } } ?> </tbody> </table> </div> <?php }