/** * 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. */ 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>'); exit; } // Run the importer $importer = new Importer(); $importer->setLogger(new WP_CLI_Logger()); $importer->import($data, $skip_sleep, $import_ignored); WP_CLI::line(); }
/** * Import the PHPDoc $data into WordPress posts and taxonomies * * @param array $data * @param bool $skip_sleep Optional; defaults to false. If true, the sleep() calls are skipped. * @param bool $import_ignored_functions Optional; defaults to false. If true, functions marked `@ignore` will be imported. * Disabled, not remove to prevent PHP Warning */ public function import(array $data, $skip_sleep = false, $import_ignored_functions = false) { parent::import($data, $skip_sleep); global $wpdb; // Delete orphans posts $post_types = $post_ids = array(); foreach ($this->imported as $post_type => $l) { $post_types[] = "'{$post_type}'"; $post_ids = array_merge($post_ids, array_map('absint', $l)); } $post_types = implode(',', $post_types); $post_ids = implode(',', $post_ids); if ($post_ids = $wpdb->get_col("SELECT DISTINCT ID FROM {$wpdb->posts} WHERE post_type IN ({$post_types}) AND ID NOT IN ({$post_ids})")) { $progress = \WP_CLI\Utils\make_progress_bar('Deleting orphans posts.', count($post_ids)); foreach ($post_ids as $post_id) { wp_delete_post($post_id, true); $progress->tick(); } $progress->finish(); } // Delete empty taxonomies if ($terms = $wpdb->get_results("SELECT tt.term_id, tt.taxonomy FROM {$wpdb->term_taxonomy} AS tt WHERE tt.taxonomy LIKE '%wp-parser-%' AND tt.count = 0")) { $progress = \WP_CLI\Utils\make_progress_bar('Deleting empty taxonomies.', count($terms)); foreach ($terms as $term) { wp_delete_term($term->term_id, $term->taxonomy); $progress->tick(); } $progress->finish(); } }
/** * Set up before the tests. */ public function setUp() { parent::setUp(); $this->importer = new \WP_Parser\Importer(); $this->importer->import(array($this->export_data)); }