本文整理汇总了PHP中wp_cache_get函数的典型用法代码示例。如果您正苦于以下问题:PHP wp_cache_get函数的具体用法?PHP wp_cache_get怎么用?PHP wp_cache_get使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wp_cache_get函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get_data_by
static function get_data_by($field, $value)
{
if ('id' == $field) {
if (!is_numeric($value)) {
return false;
}
$value = intval($value);
if ($value < 1) {
return false;
}
} else {
$value = trim($value);
}
if (!$value) {
return false;
}
switch ($field) {
case 'id':
$custom_field_id = $value;
$db_field = 'id';
break;
default:
return false;
}
if (false !== $custom_field_id) {
if ($custom_field = wp_cache_get($custom_field_id, 'yop_poll_custom_field')) {
return $custom_field;
}
}
if (!($custom_field = $GLOBALS['wpdb']->get_row($GLOBALS['wpdb']->prepare("SELECT\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t*\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t FROM\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t{$GLOBALS['wpdb']->yop_poll_custom_fields}\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t WHERE\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t{$db_field} = %s", $value)))) {
return false;
}
wp_cache_add($custom_field->ID, $custom_field, 'yop_poll_custom_field');
return $custom_field;
}
示例2: wpjam_topic_get_weixin_user
function wpjam_topic_get_weixin_user($openid = '')
{
if ($openid == '') {
if (!wpjam_topic_get_openid()) {
return false;
}
$current_user_id = get_current_user_id();
$wpjam_weixin_user = get_transient('wpjam_weixin_user_' . $current_user_id);
if ($wpjam_weixin_user === false) {
$wpjam_weixin_user = wpjam_topic_remote_request('http://jam.wpweixin.com/api/get_user.json');
if (is_wp_error($wpjam_weixin_user)) {
return $wpjam_weixin_user;
}
set_transient('wpjam_weixin_user_' . $current_user_id, $wpjam_weixin_user, DAY_IN_SECONDS * 15);
// 15天检查一次
}
} else {
$wpjam_weixin_user = wp_cache_get($openid, 'wpjam_weixin_user');
// if($wpjam_weixin_user === false){
$wpjam_weixin_user = wpjam_topic_remote_request('http://jam.wpweixin.com/api/get_user.json?openid=' . $openid);
// if(is_wp_error($wpjam_weixin_user)){
// return $wpjam_weixin_user;
// }
// wp_cache_set($openid, $wpjam_weixin_user, 'wpjam_weixin_user', HOUR_IN_SECONDS);
// }
}
return $wpjam_weixin_user;
}
示例3: ap_opt
/**
* To retrive AnsPress option
* @param string $key Name of option to retrive,
* Keep it blank to get all options of AnsPress
* @param string $value Enter value to update existing option
* @return string
* @since 0.1
*/
function ap_opt($key = false, $value = null)
{
$settings = wp_cache_get('ap_opt', 'options');
if ($settings === false) {
$settings = get_option('anspress_opt');
if (!$settings) {
$settings = array();
}
$settings = $settings + ap_default_options();
wp_cache_set('ap_opt', $settings, 'options');
}
if (!is_null($value)) {
$settings[$key] = $value;
update_option('anspress_opt', $settings);
// clear cache if option updated
wp_cache_delete('ap_opt', 'options');
return;
}
if (false === $key) {
return $settings;
}
if (isset($settings[$key])) {
return $settings[$key];
} else {
return NULL;
}
return false;
}
示例4: gp_get_meta
/**
* Retrieves and returns a meta value from the database
*
* @param string $object_type The object type.
* @param int $object_id ID of the object metadata is for.
* @param string|null $meta_key Optional. Metadata key. Default null.
*
* @return mixed|false Metadata or false.
*/
function gp_get_meta($object_type, $object_id, $meta_key = null)
{
global $wpdb;
$meta_key = gp_sanitize_meta_key($meta_key);
if (!$object_type) {
return false;
}
if (!is_numeric($object_id) || empty($object_id)) {
return false;
}
$object_id = (int) $object_id;
$object_meta = wp_cache_get($object_id, $object_type);
if (false === $object_meta) {
$db_object_meta = $wpdb->get_results($wpdb->prepare("SELECT `meta_key`, `meta_value` FROM `{$wpdb->gp_meta}` WHERE `object_type` = %s AND `object_id` = %d", $object_type, $object_id));
$object_meta = array();
foreach ($db_object_meta as $meta) {
$object_meta[$meta->meta_key] = maybe_unserialize($meta->meta_value);
}
wp_cache_add($object_id, $object_meta, $object_type);
}
if ($meta_key && isset($object_meta[$meta_key])) {
return $object_meta[$meta_key];
} elseif (!$meta_key) {
return $object_meta;
} else {
return false;
}
}
示例5: test_save_term_meta
/**
* Test behavior when using the term meta fields.
*/
public function test_save_term_meta()
{
$term_option = new Fieldmanager_Textfield(array('name' => 'term_option'));
// check normal save and fetch behavior
$text = rand_str();
$this->save_values($term_option, $this->term, $text);
$data = fm_get_term_meta($this->term->term_id, $this->term->taxonomy, 'term_option', true);
$this->assertEquals($text, $data);
$data = fm_get_term_meta($this->term->term_id, $this->term->taxonomy, 'term_option', false);
$this->assertEquals(array($text), $data);
// check update and fetch
$text_updated = rand_str();
$this->save_values($term_option, $this->term, $text_updated);
$data = fm_get_term_meta($this->term->term_id, $this->term->taxonomy, 'term_option', true);
$this->assertEquals($text_updated, $data);
$this->assertInternalType('int', Fieldmanager_Util_Term_Meta()->get_term_meta_post_id($this->term->term_id, $this->term->taxonomy));
$cache_key = Fieldmanager_Util_Term_Meta()->get_term_meta_post_id_cache_key($this->term->term_id, $this->term->taxonomy);
$this->assertNotEquals(false, wp_cache_get($cache_key));
fm_delete_term_meta($this->term->term_id, $this->term->taxonomy, 'term_option');
// post id not cached right after removal of only meta value, which results in deletion of the post
$this->assertEquals(false, wp_cache_get($cache_key));
// checking that the post id is reported as false when it doesn't exist now
$this->assertEquals(false, Fieldmanager_Util_Term_Meta()->get_term_meta_post_id($this->term->term_id, $this->term->taxonomy));
// checking that the post id is cached now to return false since it doesn't exist
$this->assertNotEquals(false, wp_cache_get($cache_key));
}
示例6: get_field
function get_field($field_name, $post_id = false)
{
global $post, $acf;
if (!$post_id) {
$post_id = $post->ID;
} elseif ($post_id == "options") {
$post_id = 999999999;
}
// return cache
$cache = wp_cache_get('acf_get_field_' . $post_id . '_' . $field_name);
if ($cache) {
return $cache;
}
// default
$value = "";
// get value
$field_key = get_post_meta($post_id, '_' . $field_name, true);
if ($field_key != "") {
// we can load the field properly!
$field = $acf->get_acf_field($field_key);
$value = $acf->get_value_for_api($post_id, $field);
} else {
// just load the text version
$value = get_post_meta($post_id, $field_name, true);
}
// no value?
if ($value == "") {
$value = false;
}
// update cache
wp_cache_set('acf_get_field_' . $post_id . '_' . $field_name, $value);
return $value;
}
示例7: update
function update($new_instance, $old_instance)
{
$instance = $old_instance;
$instance['title'] = strip_tags($new_instance['title']);
$instance['number'] = (int) $new_instance['number'];
$instance['minnum'] = (int) $new_instance['minnum'];
$instance['maxnum'] = (int) $new_instance['maxnum'];
$instance['unit'] = $new_instance['unit'];
$instance['smallest'] = $new_instance['smallest'];
$instance['largest'] = $new_instance['largest'];
$instance['mincolor'] = strip_tags($new_instance['mincolor']);
$instance['maxcolor'] = strip_tags($new_instance['maxcolor']);
$instance['format'] = $new_instance['format'];
$instance['orderby'] = $new_instance['orderby'];
$instance['order'] = $new_instance['order'];
$instance['showcount'] = $new_instance['showcount'];
$instance['showcats'] = $new_instance['showcats'];
$instance['showtags'] = $new_instance['showtags'];
$instance['empty'] = $new_instance['empty'];
$this->flush_widget_cache();
$alloptions = wp_cache_get('alloptions', 'options');
if (isset($alloptions['widget_tw'])) {
delete_option('widget_tw');
}
return $instance;
}
示例8: get_galleries
function get_galleries($ids = array())
{
$galleries = wp_cache_get('galleries', THEME_NAME);
if (!$galleries) {
$options = array('post_type' => 'property_gallery', 'post_status' => 'publish', 'post__in' => $ids, 'posts_per_page' => PHP_INT_MAX);
$galleries = get_posts($options);
foreach ($galleries as &$gallery) {
$_content = $gallery->post_content;
$gallery_images_ids = array();
$featured_image = null;
preg_match('/\\[gallery ids="(.*?)"\\]/', $_content, $matches);
$gallery->images = array();
$gallery->featured_image = null;
if (!empty($matches[1])) {
$gallery_images_ids = explode(',', $matches[1]);
$featured_image = wp_get_attachment_image_src($gallery_images_ids[0], 'properties-gallery-normal');
$_gallery = array();
foreach ($gallery_images_ids as $id) {
$image = wp_get_attachment_image_src($id, 'properties-gallery-normal');
$_gallery[] = $image;
}
$gallery->images = $_gallery;
$gallery->featured_image = $featured_image;
}
}
// Save galleries if there is a permanent cache installed
wp_cache_set('galleries', $galleries, THEME_NAME);
}
return $galleries;
}
示例9: get_terms_in_found_set
function get_terms_in_found_set()
{
if (isset($this->terms_in_found_set)) {
return $this->terms_in_found_set;
}
$matching_post_ids = $this->facets->get_matching_post_ids();
// if there aren't any matching post ids, we don't need to query
if (!$matching_post_ids) {
return array();
}
//end if
$cache_key = md5(serialize($matching_post_ids));
if (!($this->terms_in_found_set = wp_cache_get($cache_key, 'scrib-facet-post-author'))) {
global $wpdb;
$terms = $wpdb->get_results('SELECT post_author , COUNT(*) AS hits FROM ' . $wpdb->posts . ' WHERE ID IN (' . implode(',', $matching_post_ids) . ') GROUP BY post_author LIMIT 1000 /* generated in Facet_Post_Author::get_terms_in_found_set() */');
$this->terms_in_found_set = array();
foreach ($terms as $term) {
$userdata = get_userdata($term->post_author);
if (empty($userdata->display_name)) {
continue;
}
$this->terms_in_found_set[] = (object) array('facet' => $this->name, 'slug' => $userdata->user_nicename, 'name' => $userdata->display_name, 'description' => $userdata->user_description, 'term_id' => $term->post_author, 'count' => $term->hits);
}
wp_cache_set($cache_key, $this->terms_in_found_set, 'scrib-facet-post-author', $this->ttl);
}
return $this->terms_in_found_set;
}
示例10: get_locale
public function get_locale($code)
{
global $wpdb;
$all_locales = null;
if (is_null($code)) {
return false;
}
$found = false;
$locale = wp_cache_get('get_locale' . $code, '', false, $found);
if ($found) {
return $locale;
}
$all_locales_data = $wpdb->get_results("SELECT code, locale FROM {$wpdb->prefix}icl_locale_map");
foreach ($all_locales_data as $locales_data) {
$all_locales[$locales_data->code] = $locales_data->locale;
}
$locale = isset($all_locales[$code]) ? $all_locales[$code] : false;
if ($locale === false) {
$this_locale_data = $wpdb->get_row($wpdb->prepare("SELECT code, default_locale FROM {$wpdb->prefix}icl_languages WHERE code = %s", $code));
if ($this_locale_data) {
$locale = $this_locale_data->default_locale;
}
}
wp_cache_set('get_locale' . $code, $locale);
return $locale;
}
示例11: GalleryGallery
function GalleryGallery($data = array())
{
global $wpdb;
$this->plugin_name = basename(dirname(dirname(__FILE__)));
$this->table = $wpdb->prefix . strtolower($this->pre) . "_" . $this->controller;
if (is_admin()) {
$this->check_table($this->model);
}
if (!empty($data)) {
foreach ($data as $dkey => $dval) {
$this->{$dkey} = stripslashes_deep($dval);
switch ($dkey) {
case 'id':
$slidescountquery = "SELECT COUNT(`id`) FROM `" . $wpdb->prefix . strtolower($this->pre) . "_galleriesslides` WHERE `gallery_id` = '" . $dval . "'";
$query_hash = md5($slidescountquery);
if ($oc_slidescount = wp_cache_get($query_hash, 'slideshowgallery')) {
$this->slidescount = $oc_slidescount;
} else {
$this->slidescount = $wpdb->get_var($slidescountquery);
wp_cache_set($query_hash, $this->slidescount, 'slideshowgallery', 0);
}
break;
}
}
}
return true;
}
示例12: set_dfi_meta_key
/**
* Mostly the same as `get_metadata()` makes sure any postthumbnail function gets checked at
* the deepest level possible.
*
* @see /wp-includes/meta.php get_metadata()
*
* @param null $null
* @param int $object_id ID of the object metadata is for
* @param string $meta_key Optional. Metadata key. If not specified, retrieve all metadata for
* the specified object.
* @param bool $single Optional, default is false. If true, return only the first value of the
* specified meta_key. This parameter has no effect if meta_key is not specified.
* @return string|array Single metadata value, or array of values
*/
function set_dfi_meta_key($null = null, $object_id, $meta_key, $single)
{
// only affect thumbnails on the frontend, do allow ajax calls
if (is_admin() && (!defined('DOING_AJAX') || !DOING_AJAX) || '_thumbnail_id' != $meta_key) {
return $null;
}
$meta_type = 'post';
$meta_cache = wp_cache_get($object_id, $meta_type . '_meta');
if (!$meta_cache) {
$meta_cache = update_meta_cache($meta_type, array($object_id));
$meta_cache = $meta_cache[$object_id];
}
if (!$meta_key) {
return $meta_cache;
}
if (isset($meta_cache[$meta_key])) {
if ($single) {
return maybe_unserialize($meta_cache[$meta_key][0]);
} else {
return array_map('maybe_unserialize', $meta_cache[$meta_key]);
}
}
if ($single) {
// allow to set an other ID see the readme.txt for details
return apply_filters('dfi_thumbnail_id', get_option('dfi_image_id'), $object_id);
} else {
return array();
}
}
示例13: getMonthly
/**
* Return monthly
*
* @link
* https://core.trac.wordpress.org/browser/tags/4.2.2/src/wp-includes/general-template.php#L1335
* @return string
*/
public static function getMonthly($limit = self::LIMIT)
{
global $wpdb, $wp_locale;
$last_changed = wp_cache_get('last_changed', 'posts');
if (!$last_changed) {
$last_changed = microtime();
wp_cache_set('last_changed', $last_changed, 'posts');
}
$query = "SELECT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, count(ID) as total\n\t\t\tFROM {$wpdb->posts}\n\t\t\tWHERE post_type = 'post' AND post_status = 'publish'\n\t\t\tGROUP BY YEAR(post_date), MONTH(post_date)\n\t\t\tORDER BY post_date DESC ";
if ($limit) {
$query .= " LIMIT {$limit}";
}
$key = md5($query);
$key = "wp_get_archives:{$key}:{$last_changed}";
if (!($results = wp_cache_get($key, 'posts'))) {
$results = $wpdb->get_results($query);
wp_cache_set($key, $results, 'posts');
}
$archives = [];
foreach ($results as $result) {
$url = get_month_link($result->year, $result->month);
/* translators: 1: month name, 2: 4-digit year */
$text = sprintf(__('%1$s %2$d'), $wp_locale->get_month($result->month), $result->year);
$archives[] = new Archive($text, $url, $result->total);
}
return $archives;
}
示例14: test_bp_messages_delete_metadata_cache_on_thread_delete
/**
* @group bp_messages_delete_meta
* @group messages_delete_thread
*/
public function test_bp_messages_delete_metadata_cache_on_thread_delete()
{
$this->old_current_user = get_current_user_id();
$u1 = $this->factory->user->create();
$u2 = $this->factory->user->create();
// create the thread
$t1 = $this->factory->message->create(array('sender_id' => $u1, 'recipients' => array($u2), 'subject' => 'Oy'));
// create a reply
$this->factory->message->create(array('thread_id' => $t1, 'sender_id' => $u2, 'recipients' => array($u1), 'content' => 'Yo'));
// add message meta
list($m1, $m2) = $this->get_message_ids($t1);
bp_messages_update_meta($m1, 'yolo', 'gah');
bp_messages_update_meta($m2, 'yolo', 'bah');
// prime message meta cache
bp_messages_get_meta($m1, 'yolo');
bp_messages_get_meta($m2, 'yolo');
// delete thread
// to outright delete a thread, both recipients must delete it
$this->set_current_user($u1);
messages_delete_thread($t1);
$this->set_current_user($u2);
messages_delete_thread($t1);
// assert empty meta cache
$this->assertEmpty(wp_cache_get($m1, 'message_meta'));
$this->assertEmpty(wp_cache_get($m2, 'message_meta'));
// cleanup
$this->set_current_user($this->old_current_user);
}
示例15: cached_result
function cached_result($cache_key, $cache_group, $fn = null)
{
if (is_null($fn)) {
$fn = $cache_group;
$cache_group = '';
$namespaced = [];
}
if ($cache_group) {
$namespaced = wp_cache_get($cache_group, 'cache_namespaces');
if ($namespaced === false) {
wp_cache_set($cache_group, $namespaced = [], CACHE_NAMESPACES);
}
}
if (!is_preview() && in_array($cache_key, $namespaced) && ($result = wp_cache_get($cache_key, $cache_group))) {
return $result;
}
$result = call_user_func($fn);
if (!is_preview()) {
wp_cache_set($cache_key, $result, $cache_group);
if ($cache_group) {
wp_cache_set($cache_group, $namespaced + [$cache_key], CACHE_NAMESPACES);
}
}
return $result;
}