本文整理汇总了PHP中wp_cache_set函数的典型用法代码示例。如果您正苦于以下问题:PHP wp_cache_set函数的具体用法?PHP wp_cache_set怎么用?PHP wp_cache_set使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wp_cache_set函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: widget
function widget($args, $instance)
{
$cache = wp_cache_get('widget_nice_opening_hours', 'widget');
if (!is_array($cache)) {
$cache = array();
}
if (!isset($args['widget_id'])) {
$args['widget_id'] = $this->id;
}
if (isset($cache[$args['widget_id']])) {
echo $cache[$args['widget_id']];
return;
}
ob_start();
$settings = array_fill_keys($this->settings, '');
extract($args, EXTR_SKIP);
$instance = wp_parse_args($instance, $settings);
extract($instance, EXTR_SKIP);
echo $before_widget;
if ($title != '') {
echo $before_title . apply_filters('widget_title', $title, $instance, $this->id_base) . $after_title;
}
// get times and do the magic!
echo nice_opening_hours();
echo $after_widget;
$cache[$args['widget_id']] = ob_get_flush();
wp_cache_set('widget_nice_opening_hours', $cache, 'widget');
}
示例2: 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;
}
示例3: 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;
}
示例4: 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;
}
示例5: widget
function widget($args, $instance)
{
$cache = wp_cache_get($this->className, 'widget');
if (!is_array($cache)) {
$cache = array();
}
if (!isset($args['widget_id'])) {
$args['widget_id'] = null;
}
if (isset($cache[$args['widget_id']])) {
echo $cache[$args['widget_id']];
return;
}
ob_start();
extract($args, EXTR_SKIP);
$title = apply_filters('widget_title', $instance['title'], $instance, $this->id_base);
echo $before_widget;
if ($title) {
echo $before_title, $title, $after_title;
}
if (isset($instance['list'])) {
echo ciGetPracticeAreasTitlesList($instance['maxPracticeAreas']);
} else {
echo ciGetPracticeAreasHTML($instance['maxPracticeAreas'], 0, $instance['maxCharLength']);
}
echo $after_widget;
$cache[$args['widget_id']] = ob_get_flush();
wp_cache_set($this->className, $cache, 'widget');
}
示例6: 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;
}
示例7: acf_get_value
function acf_get_value($post_id, $field)
{
// try cache
$found = false;
$cache = wp_cache_get("load_value/post_id={$post_id}/name={$field['name']}", 'acf', false, $found);
if ($found) {
return $cache;
}
// load value
$value = acf_get_metadata($post_id, $field['name']);
// if value was duplicated, it may now be a serialized string!
$value = maybe_unserialize($value);
// no value? try default_value
if ($value === null && isset($field['default_value'])) {
$value = $field['default_value'];
}
// filter for 3rd party customization
$value = apply_filters("acf/load_value", $value, $post_id, $field);
$value = apply_filters("acf/load_value/type={$field['type']}", $value, $post_id, $field);
$value = apply_filters("acf/load_value/name={$field['name']}", $value, $post_id, $field);
$value = apply_filters("acf/load_value/key={$field['key']}", $value, $post_id, $field);
//update cache
wp_cache_set("load_value/post_id={$post_id}/name={$field['name']}", $value, 'acf');
// return
return $value;
}
示例8: testGetPostNavFromCache
function testGetPostNavFromCache()
{
wp_cache_set('navigation-1', array('test' => 2), 'comicpress');
$post_2 = (object) array('ID' => 2);
wp_insert_post((array) $post_2);
$this->assertEquals(array('test' => $post_2), $this->nav->get_post_nav((object) array('ID' => 1)));
}
示例9: hsinsider_get_lead_art
function hsinsider_get_lead_art($post = null)
{
if (empty($post)) {
global $post;
}
if (has_post_thumbnail()) {
$featured_id = get_post_thumbnail_id($post->ID);
$the_query = wp_cache_get($featured_id . '_attachment');
if ($the_query == false) {
/**
* Query for the Featured Image Caption
*/
$args = array('p' => $featured_id, 'post_type' => 'attachment');
$the_query = new WP_Query($args);
// Set the cache to expire the data after 300 seconds
wp_cache_set($featured_id . '_attachment', $the_query, '', 300);
}
if ($the_query->have_posts()) {
while ($the_query->have_posts()) {
$the_query->the_post();
$featured_caption = get_the_excerpt();
}
}
wp_reset_postdata();
$featured_url = wp_get_attachment_url($featured_id);
$featured_html = '<figure><img src="' . esc_url($featured_url) . '" class="attachment-post-thumbnail size-post-thumbnail wp-post-image img-responsive"/><figcaption class="wp-caption-text">' . esc_html($featured_caption) . '</figcaption></figure>';
echo $featured_html;
}
}
示例10: widget
public function widget($args, $instance)
{
$cache = wp_cache_get('widget_willow_recent_posts', 'widget');
if (!is_array($cache)) {
$cache = array();
}
if (!isset($args['widget_id'])) {
$args['widget_id'] = $this->id;
}
if (isset($cache[$args['widget_id']])) {
echo $cache[$args['widget_id']];
return;
}
$title = apply_filters('widget_title', $instance['title']);
if (empty($instance['number']) || !($number = absint($instance['number']))) {
$number = 5;
}
$show_date = isset($instance['show_date']) ? $instance['show_date'] : false;
global $wp_query;
$temp = $wp_query;
$wp_query = new WP_Query(array('post_type' => 'post', 'posts_per_page' => $number, 'ignore_sticky_posts' => 1));
ob_start();
echo $args['before_widget'];
echo !empty($title) ? $args['before_title'] . $title . $args['after_title'] : '';
include locate_template('loop-widget-posts.php');
echo $args['after_widget'];
$cache[$args['widget_id']] = ob_get_flush();
$wp_query = $temp;
wp_reset_postdata();
wp_cache_set('widget_willow_recent_posts', $cache, 'widget');
}
示例11: wpjam_get_post_thumbnail_uri
function wpjam_get_post_thumbnail_uri($post = null)
{
$post = get_post($post);
if (!$post) {
return false;
}
$post_id = $post->ID;
$post_thumbnail_uri = wp_cache_get($post_id, 'post_thumbnail_uri');
if ($post_thumbnail_uri === false) {
if (has_post_thumbnail($post_id)) {
$post_thumbnail_uri = wp_get_attachment_url(get_post_meta($post_id, '_thumbnail_id', true));
} elseif ($post_thumbnail_uri = apply_filters('wpjam_pre_post_thumbnail_uri', false, $post)) {
// do nothing
} elseif ($first_img = get_post_first_image(do_shortcode($post->post_content))) {
$pre = apply_filters('pre_qiniu_remote', false, $first_img);
$img_type = strtolower(pathinfo($first_img, PATHINFO_EXTENSION));
if ($pre == false && wpjam_qiniutek_get_setting('remote') && get_option('permalink_structure') && strpos($first_img, LOCAL_HOST) === false && strpos($first_img, CDN_HOST) === false) {
$img_type = $img_type == 'png' ? $img_type : 'jpg';
$first_img = CDN_HOST . '/qiniu/' . $post_id . '/image/' . md5($first_img) . '.' . $img_type;
}
$post_thumbnail_uri = $first_img;
} elseif ($post_thumbnail_uri = apply_filters('wpjam_post_thumbnail_uri', false, $post)) {
//do nothing
} else {
$post_thumbnail_uri = wpjam_get_default_thumbnail_uri();
}
wp_cache_set($post_id, $post_thumbnail_uri, 'post_thumbnail_uri', 6000);
}
return $post_thumbnail_uri;
}
示例12: ap_find_mentioned_users
function ap_find_mentioned_users($content)
{
global $wpdb;
// Find all mentions in content.
preg_match_all('/(?:[\\s.]|^)@(\\w+)/', $content, $matches);
if (is_array($matches) && count($matches) > 0 && !empty($matches[0])) {
$user_logins = array();
// Remove duplicates.
$unique_logins = array_unique($matches[0]);
foreach ($unique_logins as $user_login) {
$user_logins[] = sanitize_title_for_query(sanitize_user(wp_unslash($user_login), true));
}
if (count($user_logins) == 0) {
return false;
}
$user_logins_s = "'" . implode("','", $user_logins) . "'";
$key = md5($user_logins_s);
$cache = wp_cache_get($key, 'ap_user_ids');
if (false !== $cache) {
return $cache;
}
$query = $wpdb->prepare("SELECT id, user_login FROM {$wpdb->users} WHERE user_login IN ({$user_logins_s})");
$result = $wpdb->get_results($query);
wp_cache_set($key, $result, 'ap_user_ids');
return $result;
}
return false;
}
示例13: get_tags_from_current_posts
/**
* Get tags from current post views
*
* @return boolean
*/
public static function get_tags_from_current_posts()
{
if (is_array(self::$posts) && count(self::$posts) > 0) {
// Generate SQL from post id
$postlist = implode("', '", self::$posts);
// Generate key cache
$key = md5(maybe_serialize($postlist));
$results = array();
// Get cache if exist
$cache = wp_cache_get('generate_keywords', 'simpletags');
if ($cache === false) {
foreach (self::$posts as $object_id) {
// Get terms
$terms = get_object_term_cache($object_id, 'post_tag');
if (false === $terms) {
$terms = wp_get_object_terms($object_id, 'post_tag');
}
if ($terms != false) {
$results = array_merge($results, $terms);
}
}
$cache[$key] = $results;
wp_cache_set('generate_keywords', $cache, 'simpletags');
} else {
if (isset($cache[$key])) {
return $cache[$key];
}
}
return $results;
}
return array();
}
示例14: update_translation_batch
public static function update_translation_batch($batch_name = false, $tp_id = false)
{
global $wpdb;
$batch_name = $batch_name ? $batch_name : ((bool) $tp_id === false || $tp_id === 'local' ? self::get_generic_batch_name() : TranslationProxy_Basket::get_basket_name());
if (!$batch_name) {
return null;
}
$cache_key = md5($batch_name);
$cache_group = 'update_translation_batch';
$cache_found = false;
$batch_id = wp_cache_get($cache_key, $cache_group, false, $cache_found);
if ($cache_found && $batch_id) {
return $batch_id;
}
$batch_id_sql = "SELECT id FROM {$wpdb->prefix}icl_translation_batches WHERE batch_name=%s";
$batch_id_prepared = $wpdb->prepare($batch_id_sql, array($batch_name));
$batch_id = $wpdb->get_var($batch_id_prepared);
if (!$batch_id) {
$data = array('batch_name' => $batch_name, 'last_update' => date('Y-m-d H:i:s'));
if ($tp_id) {
if ($tp_id === 'local') {
$tp_id = 0;
}
$data['tp_id'] = $tp_id;
}
$wpdb->insert($wpdb->prefix . 'icl_translation_batches', $data);
$batch_id = $wpdb->insert_id;
wp_cache_set($cache_key, $batch_id, $cache_group);
}
return $batch_id;
}
示例15: refresh
/**
* Reads the options from options table
*
* @since 1.0.0
*/
public function refresh()
{
$option_key = $this->option_key();
$settings = MS_Factory::get_option($option_key);
MS_Factory::populate_model($this, $settings);
wp_cache_set($option_key, $this, 'MS_Model_Option');
}