本文整理汇总了PHP中wp_cache_replace函数的典型用法代码示例。如果您正苦于以下问题:PHP wp_cache_replace函数的具体用法?PHP wp_cache_replace怎么用?PHP wp_cache_replace使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wp_cache_replace函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: meta_reset
public static function meta_reset()
{
global $pagenow;
self::$reset_meta = apply_filters('piklist_reset_meta_admin_pages', self::$reset_meta);
if (in_array($pagenow, self::$reset_meta)) {
foreach (self::$reset_meta as $page => $data) {
if (isset($_REQUEST[$data['id']])) {
wp_cache_replace($_REQUEST[$data['id']], false, $data['group']);
break;
}
}
}
}
示例2: filter_object_item
function filter_object_item($terms, $object_ids, $taxonomies)
{
global $current_user;
switch ($taxonomies) {
case '\'category\'':
// Gets the current Post Categories Cache
$_categories = wp_cache_get($object_ids, 'category_relationships');
if (is_array($_categories)) {
foreach ($_categories as $id => $cat) {
if (!capa_protect::user_can_access($id, $current_user, 'category')) {
unset($_categories[$id]);
}
}
wp_cache_replace($object_ids, $_categories, 'category_relationships');
}
break;
}
return $terms;
}
示例3: update_var
function update_var($field = null)
{
$options = array();
$flag = true;
if ($field == null) {
$options['cf_registered_sidebars'] = $this->cf_registered_sidebars;
$options['sidebars_fields'] = $this->sidebars_fields;
$options['cf_registered_fields'] = $this->cf_registered_fields;
} else {
if (empty($this->options)) {
$this->options = wp_cache_get('cf_options-' . $this->post_type, FLAG_CACHE);
}
$options = $this->options;
if (!isset($options[$field]) || isset($options[$field]) && $options[$field] !== $this->{$field}) {
$options[$field] = $this->{$field};
} else {
$flag = false;
}
}
if ($flag == true) {
update_option('cf_options-' . $this->post_type, $options);
wp_cache_replace('cf_options-' . $this->post_type, $options, FLAG_CACHE, 3600);
}
}
示例4: thePosts
//.........这里部分代码省略.........
* Fix the Cholesterol typo oops in early versions
*/
if ($postDOM->recipeVersion < '3') {
$postDOM->fixTimes("preptime");
$postDOM->fixTimes("cooktime");
$postDOM->fixTimes("duration");
$postDOM->setParentValueByClassName("cholestrol", $this->settings->lblCholesterol, "Cholestrol");
}
$data = new stdClass();
/**
* Get the ratings from the comment meta table if we use the EasyRecipe comment method
* Other rating methods are handled in EasyRecipePlusDocument->applyStyle()
* hasRatings is left unset for Self Rating
*/
if ($this->ratingMethod == 'EasyRecipe') {
$q = "SELECT COUNT(*) AS count, SUM(meta_value) AS sum FROM {$wpdb->comments} JOIN {$wpdb->commentmeta} ON {$wpdb->commentmeta}.comment_id = {$wpdb->comments}.comment_ID ";
$q .= "WHERE comment_approved = 1 AND meta_key = 'ERRating' AND comment_post_ID = {$post->ID} AND meta_value > 0";
$ratings = $wpdb->get_row($q);
if ((int) $ratings->count > 0) {
$data->ratingCount = $ratings->count;
$data->ratingValue = number_format($ratings->sum / $ratings->count, 1);
$data->ratingPC = $data->ratingValue * 100 / 5;
$data->hasRating = true;
} else {
$data->hasRating = false;
}
} else {
if ($this->ratingMethod == 'Disabled') {
$data->hasRating = false;
}
}
switch ($this->settings->saveButton) {
case 'Ziplist':
$data->saveButtonJS = self::ZIPLISTJS;
$data->saveButton = sprintf(self::ZIPLISTBUTTON, $this->settings->ziplistPartnerKey, urlencode(get_permalink($post->ID)), $this->settings->lblSave);
$data->hasSave = true;
break;
case 'BigOven':
$data->saveButtonJS = '';
$data->saveButton = sprintf(self::BIGOVENBUTTON, self::$EasyRecipePlusUrl);
$data->hasSave = true;
break;
}
$this->settings->getLabels($data);
$data->hasLinkback = $this->settings->allowLink;
$data->displayPrint = $this->settings->displayPrint;
$data->style = $this->styleName;
$data->title = $post->post_title;
$data->blogname = get_option("blogname");
// TODO - do all this stuff at initialise time?
$data->siteURL = $this->homeURL;
/**
* If the site isn't using permalinks then just pass the print stuff as a qurerystring param
*/
if ($wp_rewrite->using_permalinks()) {
$data->sitePrintURL = $data->siteURL;
} else {
$data->sitePrintURL = $data->siteURL . "?";
}
$data->postID = $post->ID;
$data->recipeurl = get_permalink($post->ID);
$data->convertFractions = $this->settings->convertFractions;
if ($this->styleName[0] == '_') {
$styleName = substr($this->styleName, 1);
$templateFile = $this->settings->customTemplates . "/styles/{$styleName}/style.html";
} else {
$templateFile = self::$EasyRecipePlusDir . "/styles/{$this->styleName}/style.html";
}
$template = new EasyRecipePlusTemplate($templateFile);
$data->isLoggedIn = is_user_logged_in();
/**
* Apply styles to the recipe data and return the content with recipes replace by a shortcode and also each recipe's HTML
* Also keep a copy so we don't have to reformat in the case where the theme asks for the same post again
*
* This didn't work! Some themes don't call the_content() (esp for excerpts) so we can't rely on hooking into that to supply the formatted html
* We need to do it right here - it seems that the_posts is the only reliable place to replace the base recipe HTML with the formatted recipe HTML
*/
/**
* Replace the original content with the one that has the easyrecipe(s) nicely formatted and marked up
* Also keep a copy so we don't have to reformat in the case where the theme asks for the same post again
*/
$this->postContent[$post->ID] = $post->post_content = $postDOM->applyStyle($template, $data);
/**
* If we haven't already done so, hook into the_content filter to stop wpauto() messing with recipe HTML
*/
if (empty($shortcode_tags['easyrecipe'])) {
add_filter('the_content', array($this, 'theContent'), 0);
add_shortcode('easyrecipe', array($this, 'replaceRecipeShortcode'));
}
/**
* Some themes do a get_post() again instead of using the posts as modified by plugins
* So make sure our modified post is in cache so the get_post() picks up the modified version not the original
* Need to do both add and replace since add doesn't replace and replace doesn't add and we can't be sure if the cache key exists at this point
*/
wp_cache_add($post->ID, $post, 'posts');
wp_cache_replace($post->ID, $post, 'posts');
$newPosts[] = $post;
}
return $newPosts;
}
示例5: test_wp_cache_replace
public function test_wp_cache_replace()
{
$key = 'my-key';
$val1 = 'first-val';
$val2 = 'second-val';
$fake_key = 'my-fake-key';
// Save the first value to cache and verify
wp_cache_set($key, $val1);
$this->assertEquals($val1, wp_cache_get($key));
// Replace the value and verify
wp_cache_replace($key, $val2);
$this->assertEquals($val2, wp_cache_get($key));
// Non-existant key should fail
$this->assertFalse(wp_cache_replace($fake_key, $val1));
// Make sure $fake_key is not stored
$this->assertFalse(wp_cache_get($fake_key));
}
示例6: replace
/**
* Replace a value in the object cache, if the value already exists.
*
* Errors if the value can't be replaced.
*
* ## OPTIONS
*
* <key>
* : Cache key.
*
* <value>
* : Value to replace.
*
* [<group>]
* : Method for grouping data within the cache which allows the same key to be used across groups.
*
* [<expiration>]
* : Define how long to keep the value, in seconds. `0` means as long as possible.
* ---
* default: 0
* ---
*
* ## EXAMPLES
*
* # Replace cache.
* $ wp cache replace my_key new_value my_group
* Success: Replaced object 'my_key' in group 'my_group'.
*/
public function replace($args, $assoc_args)
{
list($key, $value) = $args;
$group = \WP_CLI\Utils\get_flag_value($args, 2, '');
$expiration = \WP_CLI\Utils\get_flag_value($args, 3, 0);
$result = wp_cache_replace($key, $value, $group, $expiration);
if (false === $result) {
WP_CLI::error("Could not replace object '{$key}' in group '{$group}'. Does it already exist?");
}
WP_CLI::success("Replaced object '{$key}' in group '{$group}'.");
}
示例7: xu_update_option
/**
* Update or add option value to hidden post type.
*
* @param string $name Option name.
* @param mixed $value Option value.
*
* @return mixed Returns false on failure.
*/
function xu_update_option($name, $value)
{
$name = xu_get_option_name($name);
if (empty($name)) {
return false;
}
$old = xu_get_option($name);
if ($old === $value) {
return false;
}
if ($old === false) {
return xu_add_option($name, $value);
}
if (!($post_id = xu_get_option_post_id($name))) {
return $default;
}
if (!update_post_meta($post_id, 'option_value', $value)) {
return false;
}
wp_cache_replace($name, $value, 'xu_large_option');
return true;
}
示例8: apply_filters
function &get_category(&$category, $output = OBJECT) {
global $wpdb;
if ( empty($category) )
return null;
if ( is_object($category) ) {
wp_cache_add($category->cat_ID, $category, 'category');
$_category = $category;
} else {
if ( ! $_category = wp_cache_get($category, 'category') ) {
$_category = $wpdb->get_row("SELECT * FROM $wpdb->categories WHERE cat_ID = '$category' LIMIT 1");
wp_cache_add($category, $_category, 'category');
}
}
$_category = apply_filters('get_category', $_category);
if ( !isset($_category->fullpath) ) {
$_category = set_category_path($_category);
wp_cache_replace($_category->cat_ID, $_category, 'category');
}
if ( $output == OBJECT ) {
return $_category;
} elseif ( $output == ARRAY_A ) {
return get_object_vars($_category);
} elseif ( $output == ARRAY_N ) {
return array_values(get_object_vars($_category));
} else {
return $_category;
}
}
示例9: replace
/**
* Replace an existing value in the object cache.
*
* @uses wp_cache_replace
*
* @param array $args Function arguments.
* @param array $assoc_args Function arguments with parameter key.
* @return void
*/
public function replace($args, $assoc_args)
{
if (count($assoc_args) + count($args) < 2) {
WP_CLI::line('usage: wp cache replace <key> <value> [group] [expiration]');
exit;
}
list($key, $value) = $args;
$group = isset($args[2]) ? $args[2] : '';
$expiration = isset($args[3]) ? $args[3] : 0;
$result = wp_cache_replace($key, $value, $group, $expiration);
if (false === $result) {
WP_CLI::error("Could not replace object '{$key}' in group '{$group}'. Does it already exist?");
exit;
}
WP_CLI::success("Replaced object '{$key}' in group '{$group}'.");
}
示例10: get_body_class
/**
* get_body_class()
*
* @param int $post_id
* @param $query
* @return int $is_parent
*/
function get_body_class($post_id, $query)
{
$var = false;
$post_id = (int) $post_id;
$post = wp_cache_get($post_id, 'posts');
if ($post !== false) {
if (isset($post->is_parent)) {
$var = $post->is_parent;
$this->cache_hits++;
} else {
$var = (int) self::$wpdb->get_var($query);
$post->is_parent = $var;
wp_cache_replace($post->ID, $post, 'posts');
}
}
return $var;
}
示例11: wp_cache_get
$r = wp_cache_get('key', 'test-group');
$rf = wp_cache_get('key', 'test-group', true);
echo "wp_cache_add > wp_cache_get force: " . bool_to_str($r == $rf);
echo "wp_cache_add > wp_cache_get: " . bool_to_str($r == 'value');
$r = wp_cache_get('integer', 'test-group');
$rf = wp_cache_get('integer', 'test-group', true);
echo "wp_cache_add exist > wp_cache_get force: " . bool_to_str($r == $rf);
echo "wp_cache_add exist > wp_cache_get: " . bool_to_str($r == -1);
// test wp_cache_delete
wp_cache_delete('key', 'test-group');
wp_cache_delete('integer', 'test-group');
$false = wp_cache_get('key', 'test-group');
$falsef = wp_cache_get('integer', 'test-group', true);
echo "wp_cache_delete > wp_cache_get force:" . bool_to_str($falsef === $false);
echo "wp_cache_delete > wp_cache_get: " . bool_to_str($false === false);
// test wp_cache_replace
$false = wp_cache_replace('key', 'value', 'test-group');
wp_cache_set('key', 'value', 'test-group');
$true = wp_cache_replace('key', 'value', 'test-group');
echo "wp_cache_replace: " . bool_to_str($true === true);
echo "wp_cache_replace no exist: " . bool_to_str($false == false);
$r = wp_cache_get('key', 'test-group');
$rf = wp_cache_get('key', 'test-group', true);
echo "wp_cache_replace > wp_cache_get force: " . bool_to_str($r == $rf);
echo "wp_cache_replace > wp_cache_get: " . bool_to_str($r == 'value');
// test wp_cache_set
wp_cache_set('a', 'b', 'test-group');
$r = wp_cache_get('a', 'test-group');
$rf = wp_cache_get('a', 'test-group', true);
echo "wp_cache_set > wp_cache_get force: " . bool_to_str($r == $rf);
echo "wp_cache_set > wp_cache_get: " . bool_to_str($r == 'b');
示例12: getHtmlId
/**
* Get HTML Unique ID for each action box
*/
function getHtmlId()
{
//this to have unique ID attribute of the main containing div in case there is more
//than 1 of the same action box. Cache key is composed of $_htmlUniqueId prefix and
//ID of the action box.
$actionBoxId = $this->getId();
$htmlUniqueId = wp_cache_get($this->_html_UniqueId . $actionBoxId);
if (false === $htmlUniqueId) {
//this is the first
$htmlUniqueId = 1;
wp_cache_set($this->_html_UniqueId . $actionBoxId, $htmlUniqueId);
} else {
//another box is already displayed
$htmlUniqueId++;
wp_cache_replace($this->_html_UniqueId . $actionBoxId, $htmlUniqueId);
}
return $actionBoxId . $htmlUniqueId;
}
示例13: thePosts
//.........这里部分代码省略.........
/**
* Make sure we haven't already formatted this post. This can happen in preview mode where WP replaces the post_content
* of the parent with the autosave content which we've already processed.
* If this is the case, save the formatted code and mark this post as having been processed
* TODO - are there implications for the object cache for themes that re-read posts?
*/
if ($postDOM->isFormatted) {
$this->postContent[$post->ID] = $post->post_content;
$newPosts[] = $post;
continue;
}
/**
* Fix possibly broken times in older posts
* Fix the Cholesterol typo oops in early versions
*/
if ($postDOM->recipeVersion < '3') {
$postDOM->fixTimes("preptime");
$postDOM->fixTimes("cooktime");
$postDOM->fixTimes("duration");
$postDOM->setParentValueByClassName("cholestrol", $this->settings->lblCholesterol, "Cholestrol");
}
$data = new stdClass();
/**
* Get the ratings from the comment meta table if we use the EasyRecipe comment method
* Other rating methods are handled in EasyRecipeDocument->applyStyle()
* hasRatings is left unset for Self Rating
*/
if ($this->ratingMethod == 'EasyRecipe') {
$q = "SELECT COUNT(*) AS count, SUM(meta_value) AS sum FROM {$wpdb->comments} JOIN {$wpdb->commentmeta} ON {$wpdb->commentmeta}.comment_id = {$wpdb->comments}.comment_ID ";
$q .= "WHERE comment_approved = 1 AND meta_key = 'ERRating' AND comment_post_ID = {$post->ID} AND meta_value > 0";
$ratings = $wpdb->get_row($q);
if ((int) $ratings->count > 0) {
$data->ratingCount = $ratings->count;
$data->ratingValue = number_format($ratings->sum / $ratings->count, 1);
$data->ratingPC = $data->ratingValue * 100 / 5;
$data->hasRating = true;
} else {
$data->hasRating = false;
}
} else {
if ($this->ratingMethod == 'Disabled') {
$data->hasRating = false;
}
}
$this->settings->getLabels($data);
$data->hasLinkback = $this->settings->allowLink;
$data->displayPrint = $this->settings->displayPrint;
$data->style = $this->styleName;
$data->title = $post->post_title;
$data->blogname = get_option("blogname");
// TODO - do all this stuff at initialise time?
$data->siteURL = $this->homeURL;
/**
* If the site isn't using permalinks then just pass the print stuff as a qurerystring param
*/
if ($wp_rewrite->using_permalinks()) {
$data->sitePrintURL = $data->siteURL;
} else {
$data->sitePrintURL = $data->siteURL . "?";
}
$data->postID = $post->ID;
$data->recipeurl = get_permalink($post->ID);
$data->convertFractions = $this->settings->convertFractions;
if ($this->styleName[0] == '_') {
$styleName = substr($this->styleName, 1);
$templateFile = $this->settings->customTemplates . "/styles/{$styleName}/style.html";
} else {
$templateFile = self::$EasyRecipeDir . "/styles/{$this->styleName}/style.html";
}
$template = new EasyRecipeTemplate($templateFile);
/**
* Apply styles to the recipe data and return the content with recipes replace by a shortcode and also each recipe's HTML
* Also keep a copy so we don't have to reformat in the case where the theme asks for the same post again
*
* This didn't work! Some themes don't call the_content() (esp for excerpts) so we can't rely on hooking into that to supply the formatted html
* We need to do it right here - it seems that the_posts is the only reliable place to replace the base recipe HTML with the formatted recipe HTML
*/
/**
* Replace the original content with the one that has the easyrecipe(s) nicely formatted and marked up
* Also keep a copy so we don't have to reformat in the case where the theme asks for the same post again
*/
$this->postContent[$post->ID] = $post->post_content = $postDOM->applyStyle($template, $data);
/**
* If we haven't already done so, hook into the_content filter to stop wpauto() messing with recipe HTML
*/
if (empty($shortcode_tags['easyrecipe'])) {
add_filter('the_content', array($this, 'theContent'), 0);
add_shortcode('easyrecipe', array($this, 'replaceRecipeShortcode'));
}
/**
* Some themes do a get_post() again instead of using the posts as modified by plugins
* So make sure our modified post is in cache so the get_post() picks up the modified version not the original
* Need to do both add and replace since add doesn't replace and replace doesn't add and we can't be sure if the cache key exists at this point
*/
wp_cache_add($post->ID, $post, 'posts');
wp_cache_replace($post->ID, $post, 'posts');
$newPosts[] = $post;
}
return $newPosts;
}
示例14: replace
/**
* Replace an existing value in the object cache.
*
* @synopsis <key> <value> [<group>] [<expiration>]
*/
public function replace($args, $assoc_args)
{
list($key, $value) = $args;
$group = isset($args[2]) ? $args[2] : '';
$expiration = isset($args[3]) ? $args[3] : 0;
$result = wp_cache_replace($key, $value, $group, $expiration);
if (false === $result) {
WP_CLI::error("Could not replace object '{$key}' in group '{$group}'. Does it already exist?");
}
WP_CLI::success("Replaced object '{$key}' in group '{$group}'.");
}
示例15: cache_get
private function cache_get($key, $cache_time)
{
$t = wp_cache_get($key, 'dymoloader1.0');
if ($t !== false && isset($t['data'])) {
// check soft expire
if ($t['softexpire'] < time()) {
// update cache with new soft expire time
$t['softexpire'] = time() + ($cache_time - 5 * MINUTE_IN_SECONDS);
wp_cache_replace($key, $t, 'dymoloader1.0', $cache_time);
}
return json_decode(gzuncompress($t['data']), true);
} else {
return NULL;
}
}