当前位置: 首页>>代码示例>>PHP>>正文


PHP clean_term_cache函数代码示例

本文整理汇总了PHP中clean_term_cache函数的典型用法代码示例。如果您正苦于以下问题:PHP clean_term_cache函数的具体用法?PHP clean_term_cache怎么用?PHP clean_term_cache使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了clean_term_cache函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: 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,");
     }
 }
开发者ID:keesiemeijer,项目名称:term-gen,代码行数:76,代码来源:term-gen-cli.php

示例2: test_term_flushing_cache

 public function test_term_flushing_cache()
 {
     $post_id = $this->factory->post->create();
     $term_id = $this->factory->term->create(['banana', 'post_tag']);
     wp_set_post_terms($post_id, 'banana');
     $first_run = $this->query->query([]);
     $this->assertSame($this->obj->all_post_ids, false);
     clean_term_cache($term_id);
     $second_run = $this->query->query([]);
     $this->assertSame($this->obj->all_post_ids, false);
 }
开发者ID:timeincoss,项目名称:enhanced-post-cache,代码行数:11,代码来源:test-cache.php

示例3: wpSetUpBeforeClass

 public static function wpSetUpBeforeClass($factory)
 {
     global $wpdb;
     register_taxonomy('wptests_tax', 'post');
     // Ensure that there is a term with ID 1.
     if (!get_term(1)) {
         $wpdb->insert($wpdb->terms, array('term_id' => 1));
         $wpdb->insert($wpdb->term_taxonomy, array('term_id' => 1, 'taxonomy' => 'wptests_tax'));
         clean_term_cache(1, 'wptests_tax');
     }
     self::$term_id = self::factory()->term->create(array('taxonomy' => 'wptests_tax'));
 }
开发者ID:atimmer,项目名称:wordpress-develop-mirror,代码行数:12,代码来源:wpTerm.php

示例4: test_cache_should_be_populated_by_successful_fetch

 public function test_cache_should_be_populated_by_successful_fetch()
 {
     global $wpdb;
     $t = self::factory()->term->create(array('taxonomy' => 'wptests_tax'));
     clean_term_cache($t, 'wptests_tax');
     // Prime cache.
     $term_a = get_term($t, 'wptests_tax');
     $num_queries = $wpdb->num_queries;
     // Second call shouldn't require a database query.
     $term_b = get_term($t, 'wptests_tax');
     $this->assertSame($num_queries, $wpdb->num_queries);
     $this->assertEquals($term_a, $term_b);
 }
开发者ID:rclilly,项目名称:wordpress-develop,代码行数:13,代码来源:getTerm.php

示例5: test_should_prime_term_cache

 /**
  * @ticket 14162
  */
 public function test_should_prime_term_cache()
 {
     global $wpdb;
     register_taxonomy('wptests_tax', 'post');
     $t = self::factory()->term->create(array('taxonomy' => 'wptests_tax', 'slug' => 'foo'));
     clean_term_cache($t, 'wptests_tax');
     $num_queries = $wpdb->num_queries;
     $found = get_term_by('slug', 'foo', 'wptests_tax');
     $num_queries++;
     $this->assertTrue($found instanceof WP_Term);
     $this->assertSame($t, $found->term_id);
     $this->assertSame($num_queries, $wpdb->num_queries);
     // Calls to `get_term()` should now hit cache.
     $found2 = get_term($t);
     $this->assertSame($t, $found->term_id);
     $this->assertSame($num_queries, $wpdb->num_queries);
 }
开发者ID:boonebgorges,项目名称:develop.wordpress,代码行数:20,代码来源:getTermBy.php

示例6: wpsc_add_variation_set

/**
 * Add new variation set via AJAX.
 *
 * If the variation set name is the same as an existing variation set,
 * the children variant terms will be added inside that existing set.
 * @since 3.8.8
 */
function wpsc_add_variation_set()
{
    $new_variation_set = $_POST['variation_set'];
    $variants = preg_split('/\\s*,\\s*/', $_POST['variants']);
    $parent_term_exists = term_exists($new_variation_set, 'wpsc-variation');
    // only use an existing parent ID if the term is not a child term
    if ($parent_term_exists) {
        $parent_term = get_term($parent_term_exists['term_id'], 'wpsc-variation');
        if ($parent_term->parent == '0') {
            $variation_set_id = $parent_term_exists['term_id'];
        }
    }
    if (empty($variation_set_id)) {
        $results = wp_insert_term($new_variation_set, 'wpsc-variation');
        if (is_wp_error($results)) {
            die('-1');
        }
        $variation_set_id = $results['term_id'];
    }
    $inserted_variants = array();
    if (!empty($variation_set_id)) {
        foreach ($variants as $variant) {
            $results = wp_insert_term($variant, 'wpsc-variation', array('parent' => $variation_set_id));
            if (is_wp_error($results)) {
                die('-1');
            }
            $inserted_variants[] = $results['term_id'];
        }
        require_once 'includes/walker-variation-checklist.php';
        /* --- DIRTY HACK START --- */
        /*
        There's a bug with term cache in WordPress core. See http://core.trac.wordpress.org/ticket/14485.
        The next 3 lines will delete children term cache for wpsc-variation.
        Without this hack, the new child variations won't be displayed on "Variations" page and
        also won't be displayed in wp_terms_checklist() call below.
        */
        clean_term_cache($variation_set_id, 'wpsc-variation');
        delete_option('wpsc-variation_children');
        wp_cache_set('last_changed', 1, 'terms');
        _get_term_hierarchy('wpsc-variation');
        /* --- DIRTY HACK END --- */
        wp_terms_checklist((int) $_POST['post_id'], array('taxonomy' => 'wpsc-variation', 'descendants_and_self' => $variation_set_id, 'walker' => new WPSC_Walker_Variation_Checklist($inserted_variants), 'checked_ontop' => false));
    }
    exit;
}
开发者ID:rmccue,项目名称:WP-e-Commerce,代码行数:52,代码来源:ajax-and-init.php

示例7: testTaxonomyAll

 public function testTaxonomyAll()
 {
     include_once 'samples/Team.php';
     include_once 'samples/Person.php';
     $faker = FakerFactory::create();
     $samples = 5;
     $termIds = [];
     register_taxonomy(Team::getTaxonomy(), Team::getPostTypes());
     for ($i = 0; $i < $samples; $i++) {
         $t = self::factory()->term->create(['taxonomy' => Team::getTaxonomy()]);
         clean_term_cache($t, Team::getTaxonomy());
         //$termIds[] = wp_insert_term( $faker->word, Team::getTaxonomy() );
     }
     $teams = Team::all();
     $this->assertCount($samples, $teams);
     foreach ($teams as $term) {
         $this->assertInstanceOf(Team::class, $term);
     }
 }
开发者ID:alpineio,项目名称:atlas,代码行数:19,代码来源:TaxonomyTest.php

示例8: admin_init

 /**
  * Handle storyline sorting.
  * 
  * @hook admin_init
  * @uses WebcomicAdmin::notify()
  */
 public function admin_init()
 {
     global $wpdb;
     if (isset($_POST['webcomic_action']) and 'term_sort' === $_POST['webcomic_action'] and wp_verify_nonce($_POST['webcomic_term_sort'], 'webcomic_term_sort')) {
         if (isset($_POST['webcomic_cancel_sort'])) {
             wp_redirect(add_query_arg(array('taxonomy' => $_POST['webcomic_taxonomy'], 'post_type' => $_POST['webcomic_collection']), admin_url('edit-tags.php')));
             die;
         } else {
             $terms = $count = array();
             parse_str($_POST['webcomic_terms'], $terms);
             foreach ($terms['term'] as $k => $v) {
                 $count[$v] = empty($count[$v]) ? 1 : $count[$v] + 1;
                 $wpdb->update($wpdb->terms, array('term_group' => $count[$v]), array('term_id' => $k));
                 $wpdb->update($wpdb->term_taxonomy, array('parent' => 'null' === $v ? 0 : $v), array('term_id' => $k, 'taxonomy' => $_POST['webcomic_taxonomy']));
             }
             clean_term_cache(array_keys($terms['term']), $_POST['webcomic_taxonomy']);
             WebcomicAdmin::notify('<b>' . __('Order updated.', 'webcomic') . '</b>');
         }
     }
 }
开发者ID:ecerta,项目名称:webcomic,代码行数:26,代码来源:taxonomy.php

示例9: wc_set_term_order

/**
 * Set the sort order of a term.
 *
 * @param int $term_id
 * @param int $index
 * @param string $taxonomy
 * @param bool $recursive (default: false)
 * @return int
 */
function wc_set_term_order($term_id, $index, $taxonomy, $recursive = false)
{
    $term_id = (int) $term_id;
    $index = (int) $index;
    // Meta name
    if (taxonomy_is_product_attribute($taxonomy)) {
        $meta_name = 'order_' . esc_attr($taxonomy);
    } else {
        $meta_name = 'order';
    }
    update_woocommerce_term_meta($term_id, $meta_name, $index);
    if (!$recursive) {
        return $index;
    }
    $children = get_terms($taxonomy, "parent={$term_id}&menu_order=ASC&hide_empty=0");
    foreach ($children as $term) {
        $index++;
        $index = wc_set_term_order($term->term_id, $index, $taxonomy, true);
    }
    clean_term_cache($term_id, $taxonomy);
    return $index;
}
开发者ID:Korkey128k,项目名称:woocommerce,代码行数:31,代码来源:wc-term-functions.php

示例10: update_terms_relationship_cache

 /**
  * @param int|array $terms_ids
  * @param $taxonomy
  */
 public function update_terms_relationship_cache($terms_ids, $taxonomy)
 {
     remove_filter('get_terms_args', array($this, 'get_terms_args_filter'));
     remove_filter('terms_clauses', array($this, 'terms_clauses'), 10);
     remove_filter('list_terms_exclusions', array($this, 'exclude_other_terms'), 1);
     clean_term_cache($terms_ids, $taxonomy);
     add_filter('get_terms_args', array($this, 'get_terms_args_filter'));
     // filters terms by language
     add_filter('terms_clauses', array($this, 'terms_clauses'), 10, 4);
     add_filter('list_terms_exclusions', array($this, 'exclude_other_terms'), 1, 2);
 }
开发者ID:pablomarsan,项目名称:iftheme-docs,代码行数:15,代码来源:sitepress.class.php

示例11: wp_update_term_count

function wp_update_term_count( $terms, $taxonomy ) {
	global $wpdb;

	if ( empty($terms) )
		return false;

	if ( !is_array($terms) )
		$terms = array($terms);

	$terms = array_map('intval', $terms);

	$taxonomy = get_taxonomy($taxonomy);
	if ( !empty($taxonomy->update_count_callback) ) {
		call_user_func($taxonomy->update_count_callback, $terms);
	} else {
		// Default count updater
		foreach ($terms as $term) {
			$count = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->term_relationships WHERE term_taxonomy_id = '$term'");
			$wpdb->query("UPDATE $wpdb->term_taxonomy SET count = '$count' WHERE term_taxonomy_id = '$term'");
		}

	}

	clean_term_cache($terms);

	return true;
}
开发者ID:staylor,项目名称:develop.svn.wordpress.org,代码行数:27,代码来源:taxonomy.php

示例12: reorder_term

 /**
  * Save new term order in database.
  *
  * @param  string   $taxonomy      Taxonomy name.
  * @param  object   $term          Term object.
  * @param  int      $custom_order  Taxonomy name.
  * @param  int|bool $new_parent_id ID of new parent element.
  * @return int|bool
  */
 private function reorder_term($taxonomy, $term, $custom_order, $new_parent_id = false)
 {
     global $wpdb;
     // new data
     $data = array('custom_order' => $custom_order);
     // update parent ID
     if ($new_parent_id !== false && $term->parent != $new_parent_id) {
         $data['parent'] = $new_parent_id;
     }
     $ret = $wpdb->update($wpdb->term_taxonomy, $data, array('term_taxonomy_id' => $term->term_taxonomy_id));
     clean_term_cache($term->term_id, $taxonomy);
     return $ret;
 }
开发者ID:SirDingus,项目名称:andyducett,代码行数:22,代码来源:class-i-order-terms.php

示例13: wp_update_term_count_now

/**
 * Perform term count update immediately.
 *
 * @since 2.5.0
 *
 * @param array $terms The term_taxonomy_id of terms to update.
 * @param string $taxonomy The context of the term.
 * @return bool Always true when complete.
 */
function wp_update_term_count_now( $terms, $taxonomy ) {
	global $wpdb;

	$terms = array_map('intval', $terms);

	$taxonomy = get_taxonomy($taxonomy);
	if ( !empty($taxonomy->update_count_callback) ) {
		call_user_func($taxonomy->update_count_callback, $terms, $taxonomy);
	} else {
		$object_types = (array) $taxonomy->object_type;
		foreach ( $object_types as &$object_type ) {
			if ( 0 === strpos( $object_type, 'attachment:' ) )
				list( $object_type ) = explode( ':', $object_type );
		}

		if ( $object_types == array_filter( $object_types, 'post_type_exists' ) ) {
			// Only post types are attached to this taxonomy
			_update_post_term_count( $terms, $taxonomy );
		} else {
			// Default count updater
			_update_generic_term_count( $terms, $taxonomy );
		}
	}

	clean_term_cache($terms, '', false);

	return true;
}
开发者ID:pauEscarcia,项目名称:AIMM,代码行数:37,代码来源:TAXONOMY.PHP

示例14: documentate_set_term_order

/**
 * Set the sort order of a term
 *
 * @param int $term_id
 * @param int $index
 * @param string $taxonomy
 * @param bool $recursive (default: false)
 * @return int
 */
function documentate_set_term_order($term_id, $index, $taxonomy, $recursive = false)
{
    $term_id = (int) $term_id;
    $index = (int) $index;
    update_term_meta($term_id, 'order', $index);
    if (!$recursive) {
        return $index;
    }
    $children = get_terms($taxonomy, "parent={$term_id}&menu_order=ASC&hide_empty=0");
    foreach ($children as $term) {
        $index++;
        $index = documentate_set_term_order($term->term_id, $index, $taxonomy, true);
    }
    clean_term_cache($term_id, $taxonomy);
    return $index;
}
开发者ID:helgatheviking,项目名称:Documentate,代码行数:25,代码来源:docu-term-functions.php

示例15: portfolio_set_term_order

 public function portfolio_set_term_order($term_id, $index, $taxonomy, $recursive = false)
 {
     $term_id = (int) $term_id;
     $index = (int) $index;
     $meta_name = 'order';
     $this->update_a3_portfolio_category_meta($term_id, $meta_name, $index);
     if (!$recursive) {
         return $index;
     }
     $children = get_terms($taxonomy, "parent={$term_id}&menu_order=ASC&hide_empty=0");
     foreach ($children as $term) {
         $index++;
         $index = $this->portfolio_set_term_order($term->term_id, $index, $taxonomy, true);
     }
     clean_term_cache($term_id, $taxonomy);
     return $index;
 }
开发者ID:manhhung86it,项目名称:builder-site,代码行数:17,代码来源:a3-portfolio-cat.php


注:本文中的clean_term_cache函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。