/**
  * Suspend caching and run the converter
  */
 function convert()
 {
     wp_suspend_cache_invalidation(true);
     $this->process_jobs();
     $this->process_taxonomies();
     wp_suspend_cache_invalidation(false);
 }
示例#2
0
 function import_stepped($file, $stepNumber = 1, $numberOfSteps = 1)
 {
     add_filter('import_post_meta_key', array($this, 'is_valid_meta_key'));
     add_filter('http_request_timeout', array(&$this, 'bump_request_timeout'));
     $this->import_start($file);
     $this->get_author_mapping();
     wp_suspend_cache_invalidation(true);
     $this->process_categories();
     $this->process_tags();
     $this->process_terms();
     //the processing of posts is stepped
     $this->process_posts_stepped($stepNumber, $numberOfSteps);
     wp_suspend_cache_invalidation(false);
     //we do this only on the last step
     if ($stepNumber == $numberOfSteps) {
         //we process the menus because there are problems when the pages, posts, etc that don't first exist
         $this->process_menus();
     }
     //		$this->prepare_yarpp();
     // update incorrect/missing information in the DB
     $this->backfill_parents();
     $this->backfill_attachment_urls();
     $this->remap_featured_images();
     $this->import_end();
 }
 /**
  * The main controller for the actual import stage.
  *
  * @param string $file Path to the WXR file for importing
  */
 function import($file)
 {
     add_filter('import_post_meta_key', array($this, 'is_valid_meta_key'));
     add_filter('http_request_timeout', array(&$this, 'bump_request_timeout'));
     $info_star = $this->import_start($file);
     //if error display it
     if (is_wp_error($info_star)) {
         return new WP_Error('import_error', $info_star->get_error_message());
     }
     ob_start();
     $this->get_author_mapping();
     wp_suspend_cache_invalidation(true);
     $this->process_categories();
     $this->process_tags();
     $this->process_terms();
     $this->process_posts();
     wp_suspend_cache_invalidation(false);
     // update incorrect/missing information in the DB
     $this->backfill_parents();
     $this->backfill_attachment_urls();
     $this->remap_featured_images();
     $this->import_end();
     $messages = ob_get_contents();
     ob_end_clean();
     return array('notices' => $messages);
 }
 /**
  * Restores cache invalidation, after the slow term relationship cache invalidation
  * has been skipped
  */
 public function edit_term_action($term_id, $tt_id, $taxonomy)
 {
     // `edit_term` is only called from inside `wp_update_term`, so the backtrace
     // check is not required
     //let's restore the cache invalidation to previous value
     wp_suspend_cache_invalidation($this->was_suspended);
 }
示例#5
0
 /**
  * Generate some terms.
  *
  * ## OPTIONS
  *
  * <taxonomy>
  * : The taxonomy for the generated terms.
  *
  * [--count=<number>]
  * : How many terms to generate. Default: 100
  *
  * [--max_depth=<number>]
  * : Generate child terms down to a certain depth. Default: 1
  *
  * ## EXAMPLES
  *
  *     wp term-gen create category --count=50 --max_depth=6
  */
 public function create($args, $assoc_args)
 {
     global $wpdb;
     list($taxonomy) = $args;
     $defaults = array('count' => 100, 'max_depth' => 1);
     extract(array_merge($defaults, $assoc_args), EXTR_SKIP);
     $notify = \WP_CLI\Utils\make_progress_bar('Generating terms', $count);
     if (!taxonomy_exists($taxonomy)) {
         WP_CLI::error(sprintf("'%s' is not a registered taxonomy.", $taxonomy));
     }
     $label = get_taxonomy($taxonomy)->labels->singular_name;
     $slug = sanitize_title_with_dashes($label);
     $hierarchical = get_taxonomy($taxonomy)->hierarchical;
     $previous_term_id = 0;
     $current_parent = 0;
     $current_depth = 1;
     $max_id = (int) $wpdb->get_var("SELECT term_taxonomy_id FROM {$wpdb->term_taxonomy} ORDER BY term_taxonomy_id DESC LIMIT 1");
     $suspend_cache_invalidation = wp_suspend_cache_invalidation(true);
     $created = array();
     $names = array();
     $this->text = file_get_contents(plugin_dir_path(__FILE__) . '/lorem-terms.txt');
     for ($i = $max_id + 1; $i <= $max_id + $count; $i++) {
         if ($hierarchical) {
             if ($previous_term_id && $this->maybe_make_child() && $current_depth < $max_depth) {
                 $current_parent = $previous_term_id;
                 $current_depth++;
             } else {
                 if ($this->maybe_reset_depth()) {
                     $current_parent = 0;
                     $current_depth = 1;
                 }
             }
         }
         $name = $this->get_random_term_name();
         $name = $this->get_unique_term_name($name, $taxonomy, $names);
         $args = array('parent' => $current_parent, 'slug' => sanitize_title($name));
         $term = wp_insert_term($name, $taxonomy, $args);
         if (is_wp_error($term)) {
             WP_CLI::warning($term);
         } else {
             $created[] = $term['term_id'];
             $previous_term_id = $term['term_id'];
             $names[] = $name;
         }
         $notify->tick();
         if (0 == $i % 200) {
             sleep(3);
         }
     }
     wp_suspend_cache_invalidation($suspend_cache_invalidation);
     clean_term_cache($created, $taxonomy);
     $notify->finish();
     if (count($created)) {
         WP_CLI::success(sprintf("%s terms created.", count($created)));
     } else {
         WP_CLI::warning("No terms created,");
     }
 }
示例#6
0
 /**
  * The main controller for the actual import stage.
  */
 public function import()
 {
     add_filter('http_request_timeout', array($this, 'bump_request_timeout'));
     $this->import_start();
     wp_suspend_cache_invalidation(true);
     $this->import_sliders();
     wp_suspend_cache_invalidation(false);
     $this->import_end();
 }
 /**
  * The main controller for the actual import stage.
  *
  * @param string $file Path to the WXR file for importing
  */
 function import($file)
 {
     add_filter('import_post_meta_key', array($this, 'is_valid_meta_key'));
     add_filter('http_request_timeout', array($this, 'bump_request_timeout'));
     $this->import_start($file);
     wp_suspend_cache_invalidation(true);
     $this->process_nav_menu_meta();
     wp_suspend_cache_invalidation(false);
     $this->import_end();
 }
 /**
  * The main controller for the actual import stage.
  *
  * @since 1.7
  * @param string $file Path to the XML file for importing
  */
 public function import($file)
 {
     $this->import_start($file);
     wp_suspend_cache_invalidation(true);
     $this->process_forms();
     $this->process_fields();
     $this->process_entries();
     $this->process_form_designs();
     $this->process_payments();
     wp_suspend_cache_invalidation(false);
     $this->import_end();
 }
示例#9
0
 /**
  * Active sample data exist!
  *
  */
 function dispatch()
 {
     set_time_limit(0);
     add_filter('import_post_meta_key', array($this, 'is_valid_meta_key'));
     add_filter('http_request_timeout', array(&$this, 'bump_request_timeout'));
     $this->import_start();
     wp_suspend_cache_invalidation(true);
     $this->process_authors();
     $this->process_categories();
     $this->process_tags();
     $this->process_terms();
     $this->process_posts();
     wp_suspend_cache_invalidation(false);
     $this->backfill_parents();
     $this->backfill_attachment_urls();
     $this->remap_featured_images();
     $this->import_end();
 }
示例#10
0
 /**
  * The main controller for the actual import stage.
  *
  * @param string $file Path to the WXR file for importing
  */
 function import($file)
 {
     add_filter('import_post_meta_key', array($this, 'is_valid_meta_key'));
     add_filter('http_request_timeout', array(&$this, 'bump_request_timeout'));
     $this->import_start($file);
     $this->get_author_mapping();
     wp_suspend_cache_invalidation(true);
     $this->process_categories();
     $this->process_tags();
     $this->process_terms();
     $this->process_posts();
     wp_suspend_cache_invalidation(false);
     // update incorrect/missing information in the DB
     $this->backfill_parents();
     $this->backfill_attachment_urls();
     $this->remap_featured_images();
     $this->import_end();
 }
 public function import($file)
 {
     add_filter('wp_import_post_comments', '__return_empty_array');
     add_filter('import_post_meta_key', array($this, 'is_valid_meta_key'));
     add_filter('http_request_timeout', array(&$this, 'bump_request_timeout'));
     $this->import_start($file);
     global $wpdb;
     $this->get_author_mapping();
     wp_suspend_cache_invalidation(true);
     $wpdb->query('SET autocommit = 0');
     $this->process_categories();
     $this->process_tags();
     $this->process_terms();
     $this->process_posts();
     $wpdb->query('COMMIT');
     $wpdb->query('SET autocommit = 1');
     wp_suspend_cache_invalidation(false);
     // update incorrect/missing information in the DB
     $this->backfill_parents();
     $this->import_end();
 }
 public function wpImportAttachments($file, $import_limit = 10)
 {
     $wp_import = new WP_Import();
     $wp_import->fetch_attachments = true;
     // load data from saved option
     $wp_import->post_orphans = get_option('_cri_post_orphans', array());
     $wp_import->processed_posts = get_option('_cri_processed_posts', array());
     $wp_import->url_remap = get_option('_cri_url_remap', array());
     add_filter('import_post_meta_key', array($wp_import, 'is_valid_meta_key'));
     add_filter('http_request_timeout', array(&$wp_import, 'bump_request_timeout'));
     // start buffer
     ob_start();
     // parse file and gather data
     $wp_import->import_start($file);
     // map author
     $wp_import->get_author_mapping();
     // attachment to be imported
     $attachments = array();
     foreach ($wp_import->posts as $post) {
         // only import attachment
         if ($post['post_type'] == 'attachment') {
             // if attachment has been imported already
             if (isset($wp_import->processed_posts[$post['post_id']]) && !empty($post['post_id'])) {
                 continue;
             }
             // if limit exceed, kill the loop
             if ($import_limit < 1) {
                 break;
             } else {
                 $import_limit--;
             }
             $attachments[] = $post;
         }
     }
     // if attachments reach to zero, we are done
     if (empty($attachments)) {
         return true;
     }
     // set importable posts to attachments
     $wp_import->posts = $attachments;
     // this process the attachments, turn off/on cache
     wp_suspend_cache_invalidation(true);
     $wp_import->process_posts();
     wp_suspend_cache_invalidation(false);
     // end has output, so buffer it out
     $wp_import->import_end();
     ob_end_clean();
     // save all post_orphans, processed_posts & url_remap to be used on the next run. also this will run on post import
     update_option('_cri_post_orphans', $wp_import->post_orphans);
     update_option('_cri_processed_posts', $wp_import->processed_posts);
     update_option('_cri_url_remap', $wp_import->url_remap);
     // false means we are going to continue
     return false;
 }
 /**
  * The main controller for the actual import stage.
  */
 public function import()
 {
     global $woocommerce, $wpdb;
     wp_suspend_cache_invalidation(true);
     if (defined('WP_DEBUG') && WP_DEBUG) {
         $this->log->add('csv-import', '---');
     }
     if (defined('WP_DEBUG') && WP_DEBUG) {
         $this->log->add('csv-import', __('Processing products.', 'wc_csv_import'));
     }
     foreach ($this->parsed_data as $key => &$item) {
         $product = $this->parser->parse_product($item, $this->merge_empty_cells);
         if (!is_wp_error($product)) {
             $this->process_product($product);
         } else {
             $this->add_import_result('failed', $product->get_error_message(), 'Not parsed', json_encode($item), '-');
         }
         unset($item, $product);
     }
     if (defined('WP_DEBUG') && WP_DEBUG) {
         $this->log->add('csv-import', __('Finished processing products.', 'wc_csv_import'));
     }
     wp_suspend_cache_invalidation(false);
 }
示例#14
0
 public function die_nicer($batch_code, $batch)
 {
     global $woocsv_product;
     //turn stuff back on again
     if (function_exists('wp_suspend_cache_invalidation')) {
         wp_suspend_cache_invalidation(false);
     }
     if (function_exists('wp_defer_term_counting ')) {
         wp_defer_term_counting(false);
     }
     //are we done?
     if ($batch['status'] == 'done') {
         $post_data['done'] = 1;
     } else {
         $post_data['batch_code'] = $batch_code;
         $post_data['status'] = 0;
     }
     woocsv_batches::update($batch_code, $batch);
     //=============================
     // Check if we need to debug
     //=============================
     if ($this->get_debug() == 0) {
         ob_get_clean();
     }
     $post_data['batch'] = $batch;
     echo json_encode($post_data);
     unset($post_data);
     wp_die();
 }
示例#15
0
/**
 * Split all shared taxonomy terms.
 *
 * @since 4.3.0
 */
function split_all_shared_terms()
{
    global $wpdb;
    // Get a list of shared terms (those with more than one associated row in term_taxonomy).
    $shared_terms = $wpdb->get_results("SELECT tt.term_id, t.*, count(*) as term_tt_count FROM {$wpdb->term_taxonomy} tt\n\t\t LEFT JOIN {$wpdb->terms} t ON t.term_id = tt.term_id\n\t\t GROUP BY t.term_id\n\t\t HAVING term_tt_count > 1");
    if (empty($shared_terms)) {
        return;
    }
    // Rekey shared term array for faster lookups.
    $_shared_terms = array();
    foreach ($shared_terms as $shared_term) {
        $term_id = intval($shared_term->term_id);
        $_shared_terms[$term_id] = $shared_term;
    }
    $shared_terms = $_shared_terms;
    // Get term taxonomy data for all shared terms.
    $shared_term_ids = implode(',', array_keys($shared_terms));
    $shared_tts = $wpdb->get_results("SELECT * FROM {$wpdb->term_taxonomy} WHERE `term_id` IN ({$shared_term_ids})");
    // Split term data recording is slow, so we do it just once, outside the loop.
    $suspend = wp_suspend_cache_invalidation(true);
    $split_term_data = get_option('_split_terms', array());
    $skipped_first_term = $taxonomies = array();
    foreach ($shared_tts as $shared_tt) {
        $term_id = intval($shared_tt->term_id);
        // Don't split the first tt belonging to a given term_id.
        if (!isset($skipped_first_term[$term_id])) {
            $skipped_first_term[$term_id] = 1;
            continue;
        }
        if (!isset($split_term_data[$term_id])) {
            $split_term_data[$term_id] = array();
        }
        // Keep track of taxonomies whose hierarchies need flushing.
        if (!isset($taxonomies[$shared_tt->taxonomy])) {
            $taxonomies[$shared_tt->taxonomy] = 1;
        }
        // Split the term.
        $split_term_data[$term_id][$shared_tt->taxonomy] = _split_shared_term($shared_terms[$term_id], $shared_tt, false);
    }
    // Rebuild the cached hierarchy for each affected taxonomy.
    foreach (array_keys($taxonomies) as $tax) {
        delete_option("{$tax}_children");
        _get_term_hierarchy($tax);
    }
    wp_suspend_cache_invalidation($suspend);
    update_option('_split_terms', $split_term_data);
}
示例#16
0
 /**
  * The main controller for the actual import stage.
  *
  * @param string $file Path to the WXR file for importing
  */
 function import($file)
 {
     //header("Content-Type: text/plain");
     //header("Content-Length: " . ($size * $times));
     add_filter('import_post_meta_key', array($this, 'is_valid_meta_key'));
     add_filter('http_request_timeout', array(&$this, 'bump_request_timeout'));
     $this->import_start($file);
     $this->update_import_status(0);
     $this->get_author_mapping();
     $this->update_import_status(5);
     wp_suspend_cache_invalidation(true);
     $this->process_categories();
     $this->update_import_status(10);
     $this->process_tags();
     $this->update_import_status(20);
     $this->process_terms();
     $this->update_import_status(35);
     $this->process_posts();
     $this->update_import_status(60);
     wp_suspend_cache_invalidation(false);
     // update incorrect/missing information in the DB
     $this->backfill_parents();
     $this->update_import_status(80);
     $this->backfill_attachment_urls();
     $this->update_import_status(90);
     $this->remap_featured_images();
     $this->update_import_status(100);
     $this->import_end();
 }
示例#17
0
function cherry_plugin_import_attachment()
{
    $nonce = $_POST['nonce'];
    if (!wp_verify_nonce($nonce, 'import_ajax-nonce')) {
        exit('instal_error');
    }
    if (session_id() != "import_xml") {
        session_name("import_xml");
        session_start();
    }
    if (!empty($_SESSION['attachment_posts'])) {
        do_action('cherry_plugin_import_attachment');
        $_SESSION['missing_menu_items'] = array();
        $_SESSION['attachment_metapost'] = array();
        $posts_array = $_SESSION['attachment_posts'];
        $posts_array = apply_filters('wp_import_posts', $posts_array);
        $author = (int) get_current_user_id();
        foreach ($posts_array as $post) {
            $post = apply_filters('wp_import_post_data_raw', $post);
            $postdata = array('import_id' => $post['post_id'], 'post_author' => $author, 'post_date' => $post['post_date'], 'post_date_gmt' => $post['post_date_gmt'], 'post_content' => $post['post_content'], 'post_excerpt' => $post['post_excerpt'], 'post_title' => $post['post_title'], 'post_status' => $post['status'], 'post_name' => $post['post_name'], 'comment_status' => $post['comment_status'], 'ping_status' => $post['ping_status'], 'guid' => $post['guid'], 'menu_order' => $post['menu_order'], 'post_type' => $post['post_type'], 'post_password' => $post['post_password']);
            $postdata = apply_filters('wp_import_post_data_processed', $postdata, $post);
            $remote_url = !empty($post['attachment_url']) ? $post['attachment_url'] : $post['guid'];
            // try to use _wp_attached file for upload folder placement to ensure the same location as the export site
            // e.g. location is 2003/05/image.jpg but the attachment post_date is 2010/09, see media_handle_upload()
            $postdata['upload_date'] = $post['post_date'];
            $file_url = UPLOAD_DIR . basename($remote_url);
            if (file_exists($file_url)) {
                cherry_plugin_add_attachment($postdata, $remote_url);
            }
        }
    }
    wp_suspend_cache_invalidation(false);
    exit('generate_attachment_metadata');
}
示例#18
0
文件: cache.php 项目: hscale/webento
 /**
  * Restore the cache invalidation to its previous value.
  *
  * @since bbPress (r4011)
  * @uses wp_suspend_cache_invalidation()
  */
 public function restore_cache_invalidation()
 {
     wp_suspend_cache_invalidation($this->original_cache_invalidation);
 }
 /**
  * Helper method to crop gallery images to the specified sizes.
  *
  * @since 1.0.0
  *
  * @param array $args  Array of args used when cropping the images.
  * @param int $post_id The current post ID.
  */
 public function crop_images($args, $post_id)
 {
     // Gather all available images to crop.
     $gallery_data = get_post_meta($post_id, '_eg_gallery_data', true);
     $images = !empty($gallery_data['gallery']) ? $gallery_data['gallery'] : false;
     $common = Envira_Gallery_Common_Lite::get_instance();
     // Loop through the images and crop them.
     if ($images) {
         // Increase the time limit to account for large image sets and suspend cache invalidations.
         set_time_limit(0);
         wp_suspend_cache_invalidation(true);
         foreach ($images as $id => $item) {
             // Get the full image attachment. If it does not return the data we need, skip over it.
             $image = wp_get_attachment_image_src($id, 'full');
             if (!is_array($image)) {
                 continue;
             }
             // Generate the cropped image.
             $cropped_image = $common->resize_image($image[0], $args['width'], $args['height'], true, $args['position'], $args['quality'], $args['retina']);
             // If there is an error, possibly output error message, otherwise woot!
             if (is_wp_error($cropped_image)) {
                 // If WP_DEBUG is enabled, and we're logged in, output an error to the user
                 if (defined('WP_DEBUG') && WP_DEBUG && is_user_logged_in()) {
                     echo '<pre>Envira: Error occured resizing image (these messages are only displayed to logged in WordPress users):<br />';
                     echo 'Error: ' . $cropped_image->get_error_message() . '<br />';
                     echo 'Image: ' . $image . '<br />';
                     echo 'Args: ' . var_export($args, true) . '</pre>';
                 }
             }
         }
         // Turn off cache suspension and flush the cache to remove any cache inconsistencies.
         wp_suspend_cache_invalidation(false);
         wp_cache_flush();
     }
 }
 public static function runImport()
 {
     global $wooProduct, $woocsvImport, $wpdb;
     wp_suspend_cache_invalidation(true);
     /* ! 1.2.7 disable term counting */
     wp_defer_term_counting(true);
     $postData = $_POST;
     /* ! 1.2.7 solve escape problem when running on windows */
     if (isset($postData['filename'])) {
         //get the filename and save it
         $filename = $postData['filename'];
         update_option('woocsv-importfile', $filename);
         unset($postData['filename']);
     } else {
         $filename = get_option('woocsv-importfile');
     }
     $count = 0;
     $csvcontent = '';
     $handle = fopen($filename, 'r');
     //================================
     //! only import the rows needed.
     //================================
     while (($line = fgetcsv($handle, 0, $woocsvImport->options['seperator'])) !== FALSE) {
         if ($count >= $postData['currentrow'] && $count < (int) $postData['currentrow'] + (int) $postData['blocksize']) {
             $csvContent[$count] = $line;
         }
         $count++;
     }
     unset($handle, $line);
     //========================================================
     //! Run only the block from currentrow and the blocksize
     //========================================================
     for ($i = 1; $i <= $woocsvImport->options['blocksize']; $i++) {
         $wooProduct = new woocsvImportProduct();
         $wooProduct->header = $woocsvImport->header;
         $realRow = $postData['currentrow'] + 1;
         //===================
         //! We are finished
         //===================
         if ($postData['currentrow'] >= $postData['rows']) {
             ob_get_clean();
             update_option('woocsv-lastrun', array('date' => date("Y-m-d H:i:s"), 'filename' => basename($filename), 'rows' => $postData['rows']));
             delete_option('woocsv-importfile');
             do_action('woocsv_after_import_finished');
             self::dieNice($postData, true);
         }
         // count the rows here else we have a row and than die.
         $woocsvImport->importLog[] = "--> " . __('row', 'woocsv-import') . ":" . $realRow . " / " . (int) $postData['rows'];
         //==================================
         //! We want to skip the first line
         //==================================
         if ($woocsvImport->options['skipfirstline'] == 1 && $postData['currentrow'] == 0) {
             $postData['currentrow']++;
             $woocsvImport->importLog[] = __('Skipping the first row', 'woocsv-import');
             self::dieNice($postData);
         }
         //=========================================
         //! We do not want to skip the first line
         //=========================================
         if ($woocsvImport->options['skipfirstline'] == 0 && $postData['currentrow'] == 0) {
             $wooProduct->rawData = $csvContent[0];
         }
         if ($postData['currentrow'] > 0) {
             $wooProduct->rawData = $csvContent[$postData['currentrow']];
         }
         $postData['currentrow']++;
         //=========================
         //! Lets fill in the data
         //=========================
         do_action('woocsv_before_fill_in_data');
         $wooProduct->fillInData();
         do_action('woocsv_after_fill_in_data');
         //===================
         //! version 2.0.0
         //  lets parse data
         //===================
         $wooProduct->parseData();
         //=======================
         //! let's save the data
         //=======================
         try {
             $id = $wooProduct->save();
         } catch (Exception $e) {
             $id = '';
         }
         //===============================================
         //! lets fill in the memory stuff for debugging
         //===============================================
         $postData['memory'] = round(memory_get_usage() / 1024 / 1024, 2);
     }
     wp_suspend_cache_invalidation(false);
     /* ! 1.2.7 */
     wp_defer_term_counting(false);
     //==========================
     //! version 2.0.0
     //  New die nice function
     //==========================
     self::dieNice($postData);
 }
 /**
  * Display pre-import options
  */
 public function import()
 {
     global $wpdb;
     wp_suspend_cache_invalidation(true);
     echo '<div class="progress">';
     foreach ($this->parsed_data as $key => &$item) {
         $coupon = $this->parser->parse_coupon($item);
         if ($coupon) {
             $this->process_coupon($coupon);
         } else {
             $this->skipped++;
         }
         unset($item, $coupon);
     }
     update_option('woo_sc_is_email_imported_coupons', 'no');
     $this->import_end();
 }
示例#22
0
文件: term.php 项目: wesm87/wp-cli
 /**
  * Generate some terms.
  *
  * ## OPTIONS
  *
  * <taxonomy>
  * : The taxonomy for the generated terms.
  *
  * [--count=<number>]
  * : How many terms to generate. Default: 100
  *
  * [--max_depth=<number>]
  * : Generate child terms down to a certain depth. Default: 1
  *
  * [--format=<format>]
  * : Accepted values: progress, ids. Default: ids.
  *
  * ## EXAMPLES
  *
  *     wp term generate --count=10
  *
  *     # Add meta to every generated term
  *     wp term generate category --format=ids | xargs -0 -d ' ' -I % wp term meta add % foo bar
  */
 public function generate($args, $assoc_args)
 {
     global $wpdb;
     list($taxonomy) = $args;
     $defaults = array('count' => 100, 'max_depth' => 1);
     extract(array_merge($defaults, $assoc_args), EXTR_SKIP);
     if (!taxonomy_exists($taxonomy)) {
         WP_CLI::error(sprintf("'%s' is not a registered taxonomy.", $taxonomy));
     }
     $label = get_taxonomy($taxonomy)->labels->singular_name;
     $slug = sanitize_title_with_dashes($label);
     $hierarchical = get_taxonomy($taxonomy)->hierarchical;
     $format = \WP_CLI\Utils\get_flag_value($assoc_args, 'format', 'progress');
     $notify = false;
     if ('progress' === $format) {
         $notify = \WP_CLI\Utils\make_progress_bar('Generating terms', $count);
     }
     $previous_term_id = 0;
     $current_parent = 0;
     $current_depth = 1;
     $max_id = (int) $wpdb->get_var("SELECT term_taxonomy_id FROM {$wpdb->term_taxonomy} ORDER BY term_taxonomy_id DESC LIMIT 1");
     $suspend_cache_invalidation = wp_suspend_cache_invalidation(true);
     $created = array();
     for ($i = $max_id + 1; $i <= $max_id + $count; $i++) {
         if ($hierarchical) {
             if ($previous_term_id && $this->maybe_make_child() && $current_depth < $max_depth) {
                 $current_parent = $previous_term_id;
                 $current_depth++;
             } else {
                 if ($this->maybe_reset_depth()) {
                     $current_parent = 0;
                     $current_depth = 1;
                 }
             }
         }
         $args = array('parent' => $current_parent, 'slug' => $slug . "-{$i}");
         $name = "{$label} {$i}";
         $term = wp_insert_term($name, $taxonomy, $args);
         if (is_wp_error($term)) {
             WP_CLI::warning($term);
         } else {
             $created[] = $term['term_id'];
             $previous_term_id = $term['term_id'];
             if ('ids' === $format) {
                 echo $term['term_id'];
                 if ($i < $max_id + $count) {
                     echo ' ';
                 }
             }
         }
         if ('progress' === $format) {
             $notify->tick();
         }
     }
     wp_suspend_cache_invalidation($suspend_cache_invalidation);
     clean_term_cache($created, $taxonomy);
     if ('progress' === $format) {
         $notify->finish();
     }
 }
 /**
  * Performs post-import cleanup of files and the cache
  */
 protected function import_end()
 {
     // Re-enable stuff in core
     wp_suspend_cache_invalidation(false);
     wp_cache_flush();
     foreach (get_taxonomies() as $tax) {
         delete_option("{$tax}_children");
         _get_term_hierarchy($tax);
     }
     wp_defer_term_counting(false);
     wp_defer_comment_counting(false);
     /**
      * Complete the import.
      *
      * Fires after the import process has finished. If you need to update
      * your cache or re-enable processing, do so here.
      */
     do_action('import_end');
 }
示例#24
0
 /**
  * The main controller for the actual import stage.
  *
  * @param string $file Path to the XML file for importing
  */
 function import($file)
 {
     add_filter('http_request_timeout', array(&$this, 'bump_request_timeout'));
     $this->import_start($file);
     $this->get_author_mapping();
     wp_suspend_cache_invalidation(true);
     $this->process_posts();
     $this->process_comments();
     if (Blogger_Importer::IMPORT_IMG) {
         $this->process_images();
     }
     $this->process_links();
     wp_suspend_cache_invalidation(false);
     // update incorrect/missing information in the DB
     //$this->backfill_parents();
     //$this->backfill_attachment_urls();
     //$this->remap_featured_images();
     $this->import_end();
 }
示例#25
0
 /**
  * Helper method to crop slider images to the specified sizes.
  *
  * @since 1.0.0
  *
  * @param array $args  Array of args used when cropping the images.
  * @param int $post_id The current post ID.
  */
 public function crop_images($args, $post_id)
 {
     // Gather all available images to crop.
     $slider_data = get_post_meta($post_id, '_sol_slider_data', true);
     $images = !empty($slider_data['slider']) ? $slider_data['slider'] : false;
     $common = Soliloquy_Common::get_instance();
     // Loop through the images and crop them.
     if ($images) {
         // Increase the time limit to account for large image sets and suspend cache invalidations.
         set_time_limit(Soliloquy_Common::get_instance()->get_max_execution_time());
         wp_suspend_cache_invalidation(true);
         foreach ($images as $id => $item) {
             // Get the full image attachment. If it does not return the data we need, skip over it.
             $image = wp_get_attachment_image_src($id, 'full');
             if (!is_array($image)) {
                 // Check for video/HTML slide and possibly use a thumbnail instead.
                 if ((isset($item['type']) && 'video' == $item['type'] || isset($item['type']) && 'html' == $item['type']) && !empty($item['thumb'])) {
                     $image = $item['thumb'];
                 } else {
                     continue;
                 }
             } else {
                 $image = $image[0];
             }
             // Allow image to be filtered to use a different thumbnail than the main image.
             $image = apply_filters('soliloquy_cropped_image', $image, $id, $item, $args, $post_id);
             // Generate the cropped image.
             $cropped_image = $common->resize_image($image, $args['width'], $args['height'], true, $args['position'], $args['quality'], $args['retina'], $slider_data);
             // If there is an error, possibly output error message, otherwise woot!
             if (is_wp_error($cropped_image)) {
                 // If debugging is defined, print out the error.
                 if (defined('SOLILOQUY_CROP_DEBUG') && SOLILOQUY_CROP_DEBUG) {
                     echo '<pre>' . var_export($cropped_image->get_error_message(), true) . '</pre>';
                 }
             }
         }
         // Turn off cache suspension and flush the cache to remove any cache inconsistencies.
         wp_suspend_cache_invalidation(false);
         wp_cache_flush();
     }
 }
 function import_file($file)
 {
     $this->file = $file;
     $this->import_start();
     wp_suspend_cache_invalidation(true);
     $result = $this->process_comments();
     wp_suspend_cache_invalidation(false);
     $this->import_end();
     if (is_wp_error($result)) {
         return $result;
     }
 }
 function import($file)
 {
     $this->import_start($file);
     wp_suspend_cache_invalidation(true);
     // only processing nav menus
     $this->process_menus();
     wp_suspend_cache_invalidation(false);
     $this->import_end();
 }
示例#28
0
 /**
  * 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.
  */
 public function import(array $data, $skip_sleep = false, $import_ignored_functions = false)
 {
     global $wpdb;
     $time_start = microtime(true);
     $num_queries = $wpdb->num_queries;
     $this->logger->info('Starting import. This will take some time…');
     $file_number = 1;
     $num_of_files = count($data);
     do_action('wp_parser_starting_import');
     // Defer term counting for performance
     wp_suspend_cache_invalidation(true);
     wp_defer_term_counting(true);
     wp_defer_comment_counting(true);
     // Remove actions for performance
     remove_action('transition_post_status', '_update_blog_date_on_post_publish', 10);
     remove_action('transition_post_status', '__clear_multi_author_cache', 10);
     delete_option('wp_parser_imported_wp_version');
     delete_option('wp_parser_root_import_dir');
     // Sanity check -- do the required post types exist?
     if (!post_type_exists($this->post_type_class) || !post_type_exists($this->post_type_function) || !post_type_exists($this->post_type_hook)) {
         $this->logger->error(sprintf('Missing post type; check that "%1$s", "%2$s", and "%3$s" are registered.', $this->post_type_class, $this->post_type_function, $this->post_type_hook));
         exit;
     }
     // Sanity check -- do the required taxonomies exist?
     if (!taxonomy_exists($this->taxonomy_file) || !taxonomy_exists($this->taxonomy_since_version) || !taxonomy_exists($this->taxonomy_package)) {
         $this->logger->error(sprintf('Missing taxonomy; check that "%1$s" is registered.', $this->taxonomy_file));
         exit;
     }
     $root = '';
     foreach ($data as $file) {
         $this->logger->info(sprintf('Processing file %1$s of %2$s "%3$s".', number_format_i18n($file_number), number_format_i18n($num_of_files), $file['path']));
         $file_number++;
         $this->import_file($file, $skip_sleep, $import_ignored_functions);
         if (empty($root) && (isset($file['root']) && $file['root'])) {
             $root = $file['root'];
         }
     }
     if (!empty($root)) {
         update_option('wp_parser_root_import_dir', $root);
         $this->logger->info('Updated option wp_parser_root_import_dir: ' . $root);
     }
     $last_import = time();
     $import_date = date_i18n(get_option('date_format'), $last_import);
     $import_time = date_i18n(get_option('time_format'), $last_import);
     update_option('wp_parser_last_import', $last_import);
     $this->logger->info(sprintf('Updated option wp_parser_last_import: %1$s at %2$s.', $import_date, $import_time));
     $wp_version = get_option('wp_parser_imported_wp_version');
     if ($wp_version) {
         $this->logger->info('Updated option wp_parser_imported_wp_version: ' . $wp_version);
     }
     /**
      * Workaround for a WP core bug where hierarchical taxonomy caches are not being cleared
      *
      * https://core.trac.wordpress.org/ticket/14485
      * http://wordpress.stackexchange.com/questions/8357/inserting-terms-in-an-hierarchical-taxonomy
      */
     delete_option("{$this->taxonomy_package}_children");
     delete_option("{$this->taxonomy_since_version}_children");
     /**
      * Action at the end of a complete import
      */
     do_action('wp_parser_ending_import');
     // Start counting again
     wp_defer_term_counting(false);
     wp_suspend_cache_invalidation(false);
     wp_cache_flush();
     wp_defer_comment_counting(false);
     $time_end = microtime(true);
     $time = $time_end - $time_start;
     $this->logger->info('Time: ' . $time);
     $this->logger->info('Queries: ' . ($wpdb->num_queries - $num_queries));
     if (empty($this->errors)) {
         $this->logger->notice('Import complete!');
     } else {
         $this->logger->info('Import complete, but some errors were found:');
         foreach ($this->errors as $error) {
             $this->logger->error($error);
         }
     }
 }
 function import_file($file)
 {
     $this->file = $file;
     $this->import_start();
     $this->get_authors_from_post();
     wp_suspend_cache_invalidation(true);
     $this->get_entries();
     $this->process_categories();
     $this->process_tags();
     $this->process_terms();
     $result = $this->process_posts();
     wp_suspend_cache_invalidation(false);
     $this->backfill_parents();
     $this->backfill_attachment_urls();
     $this->import_end();
     if (is_wp_error($result)) {
         return $result;
     }
 }
 function convert()
 {
     wp_suspend_cache_invalidation(true);
     $this->process_categories();
     $this->process_attributes();
     $this->process_products();
     $this->process_variations();
     wp_suspend_cache_invalidation(false);
 }