本文整理汇总了PHP中wp_suspend_cache_invalidation函数的典型用法代码示例。如果您正苦于以下问题:PHP wp_suspend_cache_invalidation函数的具体用法?PHP wp_suspend_cache_invalidation怎么用?PHP wp_suspend_cache_invalidation使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wp_suspend_cache_invalidation函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: convert
/**
* Suspend caching and run the converter
*/
function convert()
{
wp_suspend_cache_invalidation(true);
$this->process_jobs();
$this->process_taxonomies();
wp_suspend_cache_invalidation(false);
}
开发者ID:ThemeGit,项目名称:wp-job-manager-jobroller-import,代码行数:10,代码来源:wp-job-manager-jobroller-import.php
示例2: import_stepped
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();
}
示例3: import
/**
* 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);
}
示例4: edit_term_action
/**
* 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: create
/**
* 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: import
/**
* 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();
}
示例7: import
/**
* 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();
}
示例8: import
/**
* 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: dispatch
/**
* 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: import
/**
* 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();
}
示例11: import
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();
}
示例12: wpImportAttachments
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;
}
示例13: import
/**
* 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: die_nicer
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: split_all_shared_terms
/**
* 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);
}