/** * Import the PHPDoc $data into WordPress posts and taxonomies * * @param array $data * @param bool $skip_sleep If true, the sleep() calls are skipped. * @param bool $import_ignored If true, functions marked `@ignore` will be imported * Disabled, not remove to prevent PHP Warning */ protected function _do_import(array $data, $skip_sleep = false, $import_ignored = false) { if (!wp_get_current_user()->exists()) { WP_CLI::error('Please specify a valid user: --user=<id|login>'); } /** * Delete posts before import * Warning!!! This filter takes a long time to complete, * * Default: false */ if (apply_filters('sublime_delete_import_before_create', false)) { global $wpdb; $posts_id = $wpdb->get_col("SELECT DISTINCT ID FROM {$wpdb->posts} WHERE post_type LIKE '%wp-parser-%'"); if ($posts_id) { $total_count = count($posts_id); $progress = \WP_CLI\Utils\make_progress_bar(sprintf('Deleting %s posts.', $total_count), $total_count); $deleted_with_error = array(); foreach ($posts_id as $count => $post_id) { if (!wp_delete_post((int) $post_id, true)) { $deleted_with_error[] = $post_id; } $progress->tick(); if (!$skip_sleep && 0 == $count % 10) { // TODO figure our why are we still doing this sleep(3); } } $progress->finish(); if ($deleted_with_error) { WP_CLI::error(sprintf('Not deleting %s of the %s. This import not continue, please try again.', count($deleted_with_error), $total_count)); } } } // Run the importer Importer::run($data, $skip_sleep); }
public static function run(array $data, $skip_sleep = false) { $importer = new Importer(); $importer->setLogger(new WP_CLI_Logger()); $importer->import($data, $skip_sleep); }