本文整理汇总了PHP中wp_cache_add函数的典型用法代码示例。如果您正苦于以下问题:PHP wp_cache_add函数的具体用法?PHP wp_cache_add怎么用?PHP wp_cache_add使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wp_cache_add函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: batcache_clear_url
function batcache_clear_url($url)
{
global $batcache, $wp_object_cache;
if (empty($url)) {
return false;
}
if (0 === strpos($url, 'https://')) {
$url = str_replace('https://', 'http://', $url);
}
if (0 !== strpos($url, 'http://')) {
$url = 'http://' . $url;
}
$url_key = md5($url);
wp_cache_add("{$url_key}_version", 0, $batcache->group);
$retval = wp_cache_incr("{$url_key}_version", 1, $batcache->group);
$batcache_no_remote_group_key = array_search($batcache->group, (array) $wp_object_cache->no_remote_groups);
if (false !== $batcache_no_remote_group_key) {
// The *_version key needs to be replicated remotely, otherwise invalidation won't work.
// The race condition here should be acceptable.
unset($wp_object_cache->no_remote_groups[$batcache_no_remote_group_key]);
$retval = wp_cache_set("{$url_key}_version", $retval, $batcache->group);
$wp_object_cache->no_remote_groups[$batcache_no_remote_group_key] = $batcache->group;
}
return $retval;
}
示例2: get_most_recent_comments
function get_most_recent_comments($args = null)
{
global $most_recent_comments_args;
// You can pass any of these arguments as well as any argument supported by get_comments()
$defaults = array('passworded_posts' => false, 'showpings' => false, 'post_types' => array('post', 'page'), 'post_statuses' => array('publish', 'static'), 'number' => 5, 'status' => 'approve');
$most_recent_comments_args = wp_parse_args($args, $defaults);
// Create the cache key
$key = md5(serialize($most_recent_comments_args));
$last_changed = wp_cache_get('last_changed', 'comment');
if (!$last_changed) {
$last_changed = time();
wp_cache_set('last_changed', $last_changed, 'comment');
}
$cache_key = "most_recent_comments:{$key}:{$last_changed}";
// Check to see if we already have results for this request
if ($cache = wp_cache_get($cache_key, 'comment')) {
return $cache;
}
// Modify the get_comments() SQL query
add_filter('comments_clauses', '_mrc_modify_comments_clauses');
// Get the comments
// The custom arguments will be ignored by get_comments()
$comments = get_comments($most_recent_comments_args);
// Remove the get_comments() SQL query filter
remove_filter('comments_clauses', '_mrc_modify_comments_clauses');
// Cache these results
wp_cache_add($cache_key, $comments, 'comment');
return $comments;
}
示例3: update_meta_cache_byID
/**
* Update the metadata cache for the specified objects.
*
* @since 2.9.0
* @uses $wpdb WordPress database object for queries.
*
* @param string $meta_type Type of object metadata is for (e.g., comment, post, or user)
* @param int|array $object_ids array or comma delimited list of object IDs to update cache for
* @return mixed Metadata cache for the specified objects, or false on failure.
*/
function update_meta_cache_byID($post_ID, $meta_type = 'attachment')
{
if (empty($post_ID)) {
return false;
}
global $wpdb;
$cache_key = $meta_type . '_meta';
$cache = array();
// Get meta info
$meta_list = $wpdb->get_results($wpdb->prepare("select p.id,p.guid from wp_posts p inner join (select max(id) as id from wp_posts where post_parent = {$post_ID} and post_type = 'attachment') a on (p.id = a.id)", $meta_type), ARRAY_A);
if (!empty($meta_list)) {
foreach ($meta_list as $metarow) {
$mpid = intval($post_ID);
$mkey = $cache_key;
$mval = $metarow['guid'];
// Force subkeys to be array type:
if (!isset($cache[$mpid]) || !is_array($cache[$mpid])) {
$cache[$mpid] = array();
}
if (!isset($cache[$mpid][$mkey]) || !is_array($cache[$mpid][$mkey])) {
$cache[$mpid][$mkey] = array();
}
// Add a value to the current pid/key:
$cache[$mpid][$mkey][] = $mval;
}
}
if (isset($cache[$post_ID])) {
wp_cache_add($post_ID, $cache[$post_ID], $cache_key);
}
return $cache;
}
示例4: ec3_filter_the_posts
/** Read the schedule table for the posts, and add an ec3_schedule array
* to each post. */
function ec3_filter_the_posts($posts)
{
if ('array' != gettype($posts) || 0 == count($posts)) {
return $posts;
}
$post_ids = array();
// Can't use foreach, because it gets *copies* (in PHP<5)
for ($i = 0; $i < count($posts); $i++) {
$post_ids[] = intval($posts[$i]->ID);
$posts[$i]->ec3_schedule = array();
}
global $ec3, $wpdb;
$sql = "SELECT *,IF(end>='{$ec3->today}',1,0) AS active\n FROM {$ec3->schedule}\n WHERE post_id IN (" . implode(',', $post_ids) . ")\n ORDER BY start";
$key = md5($sql);
$schedule = wp_cache_get($key, 'ec3');
if ($schedule === FALSE) {
$schedule = $wpdb->get_results($sql);
wp_cache_add($key, $schedule, 'ec3');
}
// Flip $post_ids so that it maps post ID to position in the $posts array.
$post_ids = array_flip($post_ids);
if ($post_ids && $schedule) {
foreach ($schedule as $s) {
$i = $post_ids[$s->post_id];
$posts[$i]->ec3_schedule[] = $s;
}
}
return $posts;
}
示例5: bb_popularPosts
/**
* Calculate the posts with the most comments from the last 6 months
*
* @param array args previously specified arguments
* @param int postCount the number of posts to display
*/
function bb_popularPosts($args = array(), $displayComments = TRUE, $interval = '')
{
global $wpdb;
$postCount = 5;
$request = 'SELECT * FROM ' . $wpdb->posts . ' WHERE ';
if ($interval != '') {
$request .= 'post_date>DATE_SUB(NOW(), ' . $interval . ') ';
}
$request .= 'post_status="publish" AND comment_count > 0 ORDER BY comment_count DESC LIMIT 0, ' . $postCount;
$posts = $wpdb->get_results($request);
if (count($posts) >= 1) {
$defaults = array('title' => __('Popular Posts', BB_BASE));
$args = bb_defaultArgs($args, $defaults);
foreach ($posts as $post) {
wp_cache_add($post->ID, $post, 'posts');
$popularPosts[] = array('title' => stripslashes($post->post_title), 'url' => get_permalink($post->ID), 'comment_count' => $post->comment_count);
}
echo $args['before_widget'] . $args['before_title'] . $args['title'] . $args['after_title'];
?>
<div class="widgetInternalWrapper">
<ol class="popularPosts postsList">
<?php
foreach ($popularPosts as $post) {
if ($listClass == 'odd') {
$listClass = 'even';
} else {
$listClass = 'odd';
}
?>
<li class="<?php
echo $listClass;
?>
">
<a href="<?php
echo $post['url'];
?>
"><?php
echo $post['title'];
?>
</a>
<?php
if ($displayComments) {
?>
<span class="commentsCount">(<?php
echo $post['comment_count'] . ' ' . __('comments', BB_BASE);
?>
)</span>
<?php
}
?>
</li>
<?php
}
?>
</ol>
</div>
<?php
echo $args['after_widget'];
}
}
示例6: getSticBlockContent
public static function getSticBlockContent($id = false, $return = false)
{
if (!$id) {
return;
}
$output = false;
$output = wp_cache_get($id, 'nth_get_staticBlock');
if (!$output) {
$blocks = get_posts(array('include' => $id, 'post_type' => 'nth_stblock', 'posts_per_page' => 1));
$output = '';
foreach ($blocks as $post) {
setup_postdata($post);
$output = do_shortcode($post->post_content);
$shortcodes_custom_css = get_post_meta($post->ID, '_wpb_shortcodes_custom_css', true);
if (!empty($shortcodes_custom_css)) {
$output .= '<style type="text/css" data-type="vc_shortcodes-custom-css">';
$output .= $shortcodes_custom_css;
$output .= '</style>';
}
}
wp_reset_postdata();
wp_cache_add($id, $output, 'nth_get_staticBlock');
}
if ($return) {
return $output;
} else {
echo $output;
}
}
示例7: wpupdate_themeswordpressnet_search
function wpupdate_themeswordpressnet_search($args)
{
$url = wpupdate_themeswordpressnet_searchCreate($args['info']);
$url = 'http://themes.wordpress.net/?' . $url . '&submit=Show';
if ($args['info']['page'] > 1) {
$url .= '&paged=' . $args['info']['page'];
}
$results = wp_cache_get('wpupdate_searchThemesThemesWordpressNet_' . md5($url), 'wpupdate');
if (!$results) {
$results = array('results' => array(), 'pages' => 0);
$snoopy = new Snoopy();
$snoopy->fetch($url);
preg_match_all('#<a href="(.*?)" rel="bookmark" title="(.*?)"><img src=".*/snapshots/(\\d+?)-thumb.jpg"#i', $snoopy->results, $mat1);
if (!$mat1) {
return $args;
}
for ($i = 0; $i < count($mat1[1]); $i++) {
$id = $mat1[3][$i];
$results['results'][] = array('name' => $mat1[2][$i], 'url' => $mat1[1][$i], 'id' => $id, 'download' => 'http://themes.wordpress.net/download.php?theme=' . $id, 'snapshot' => array('thumb' => 'http://s.themes.wordpress.net/snapshots/' . $id . '-thumb.jpg', 'medium' => 'http://s.themes.wordpress.net/snapshots/' . $id . '-medium.jpg', 'big' => 'http://s.themes.wordpress.net/snapshots/' . $id . '-big.jpg'), 'testrun' => 'http://themes.wordpress.net/testrun/?wptheme=' . $id);
}
//Check the number of pages, If this isnt the last page, change it.
if (preg_match('#title="Last »">(\\d+)</a>#', $snoopy->results, $pages)) {
$results['pages'] = (int) $pages[1];
}
wp_cache_add('wpupdate_searchThemesThemesWordpressNet_' . md5($url), $results, 'wpupdate', 21600);
}
//end if ( ! $results )
//Merge Result set
$args['results'] = array_merge($args['results'], $results['results']);
//Check if theres more pages than set
if ($results['pages'] > $args['info']['pages']) {
$args['info']['pages'] = $results['pages'];
}
return $args;
}
示例8: get_recent_comments
function get_recent_comments($args)
{
global $wpdb, $comments, $comment;
extract($args, EXTR_SKIP);
$themePath = get_bloginfo('template_url');
$imageLink = '<h2>Популярные записи</h2>';
$options = get_option('widget_recent_comments');
$title = empty($options['title']) ? __($imageLink) : apply_filters('widget_title', $options['title']);
if (!($number = (int) $options['number'])) {
$number = 5;
} else {
if ($number < 1) {
$number = 1;
} else {
if ($number > 15) {
$number = 15;
}
}
}
if (!($comments = wp_cache_get('recent_comments', 'widget'))) {
$comments = $wpdb->get_results("SELECT * FROM {$wpdb->comments} WHERE comment_approved = '1' ORDER BY comment_date_gmt DESC LIMIT {$number}");
wp_cache_add('recent_comments', $comments, 'widget');
}
echo $before_widget;
echo $before_title . $title . $after_title;
echo '<ul id="recentcomments">';
if ($comments) {
foreach ((array) $comments as $comment) {
echo '<li class="recentcomments">' . sprintf(__('%2$s'), get_comment_author_link(), '<a href="' . get_comment_link($comment->comment_ID) . '">' . get_the_title($comment->comment_post_ID) . '</a>') . '</li>';
}
}
echo '</ul>';
echo $after_widget;
}
示例9: get
public function get($query, $comments, $count = false, $prefetch = false)
{
global $wpuDebug;
if (!$this->can_handle_request($query, $prefetch) || $this->doingQuery) {
return $comments;
}
// this must be set before set_current_query as we sometimes
// need to pull from WP
$this->doingQuery = true;
$this->set_current_query($query, $comments, $count, $prefetch);
$this->create_request_signature();
$sig = $this->currentQuery['signature'];
if (!isset($this->queries[$sig])) {
$wpuDebug->add('New XPost query created for query ' . $sig);
$this->queries[$sig] = new WPU_XPost_Query($this->idOffset);
} else {
$wpuDebug->add('Re-using XPost query from store for query ' . $sig);
}
$result = $this->queries[$sig]->get_result($this->currentQuery);
$newLinks = array();
foreach ($this->links as $linkGroup => $links) {
$newLinks[$linkGroup] = array_merge($links, $this->queries[$sig]->links[$linkGroup]);
}
$this->links = $newLinks;
$this->doingQuery = false;
if (!empty($this->primeCacheKey)) {
$last_changed = wp_cache_get('last_changed', 'comment');
$cache_key = "get_comments:{$this->primeCacheKey}:{$last_changed}";
wp_cache_add($cache_key, $result, 'comment');
}
return $result;
}
示例10: flagImage
/**
* Constructor
*
* @param object $gallery The flagGallery object representing the gallery containing this image
* @return void
*/
function flagImage($gallery)
{
//This must be an object
$gallery = (object) $gallery;
// Build up the object
foreach ($gallery as $key => $value) {
$this->{$key} = $value;
}
// Finish initialisation
$this->name = $gallery->name;
$this->path = $gallery->path;
$this->title = $gallery->title;
$this->previewpic = $gallery->previewpic;
$this->galleryid = $gallery->galleryid;
$this->alttext = $gallery->alttext;
$this->description = $gallery->description;
// set urls and paths
$this->imageURL = get_option('siteurl') . '/' . $this->path . '/' . $this->filename;
$this->webimageURL = get_option('siteurl') . '/' . $this->path . '/webview/' . $this->filename;
$this->thumbURL = get_option('siteurl') . '/' . $this->path . '/thumbs/thumbs_' . $this->filename;
$this->imagePath = WINABSPATH . $this->path . '/' . $this->filename;
$this->webimagePath = WINABSPATH . $this->path . '/webview/' . $this->filename;
$this->thumbPath = WINABSPATH . $this->path . '/thumbs/thumbs_' . $this->filename;
$this->meta_data = unserialize($this->meta_data);
wp_cache_add($this->pid, $this, 'flag_image');
}
示例11: powerpress_get_term_by_ttid
function powerpress_get_term_by_ttid($ttid, $output = OBJECT, $filter = 'raw')
{
global $wpdb;
$value = intval($ttid);
$field = 'tt.term_taxonomy_id';
$term = $wpdb->get_row($wpdb->prepare("SELECT t.*, tt.* FROM {$wpdb->terms} AS t INNER JOIN {$wpdb->term_taxonomy} AS tt ON t.term_id = tt.term_id WHERE {$field} = %s LIMIT 1", $value));
if (!$term) {
return false;
}
$taxonomy = $term->taxonomy;
wp_cache_add($term->term_id, $term, $taxonomy);
/** This filter is documented in wp-includes/taxonomy.php */
$term = apply_filters('get_term', $term, $taxonomy);
/** This filter is documented in wp-includes/taxonomy.php */
$term = apply_filters("get_{$taxonomy}", $term, $taxonomy);
$term = sanitize_term($term, $taxonomy, $filter);
if ($output == OBJECT) {
return $term;
} elseif ($output == ARRAY_A) {
return get_object_vars($term);
} elseif ($output == ARRAY_N) {
return array_values(get_object_vars($term));
} else {
return $term;
}
}
示例12: loadAllOptions
public static function loadAllOptions()
{
global $wpdb;
$options = wp_cache_get('alloptions', 'wordfence');
if (!$options) {
$table = self::table();
self::updateTableExists();
$suppress = $wpdb->suppress_errors();
if (!($rawOptions = $wpdb->get_results("SELECT name, val FROM {$table} WHERE autoload = 'yes'"))) {
$rawOptions = $wpdb->get_results("SELECT name, val FROM {$table}");
}
$wpdb->suppress_errors($suppress);
$options = array();
foreach ((array) $rawOptions as $o) {
if (in_array($o->name, self::$serializedOptions)) {
$val = maybe_unserialize($o->val);
if ($val) {
$options[$o->name] = $val;
}
} else {
$options[$o->name] = $o->val;
}
}
wp_cache_add_non_persistent_groups('wordfence');
wp_cache_add('alloptions', $options, 'wordfence');
}
return $options;
}
示例13: widget
function widget($args, $instance)
{
$cache = wp_cache_get('widget_page_content', 'widget');
if (!is_array($cache)) {
$cache = array();
}
if (isset($cache[$args['widget_id']])) {
echo $cache[$args['widget_id']];
return;
}
ob_start();
extract($args);
$title = apply_filters('widget_title', empty($instance['title']) ? '' : $instance['title']);
echo $before_widget;
if ($title) {
echo $before_title . $title . $after_title;
}
global $post;
$content = apply_filters('the_content', $post->post_content);
$content = str_replace(']]>', ']]>', $content);
echo $content;
echo $after_widget;
$cache[$args['widget_id']] = ob_get_flush();
wp_cache_add('widget_recent_posts', $cache, 'widget');
}
示例14: get_topic
function get_topic($id, $cache = true)
{
global $bbdb;
if (!is_numeric($id)) {
list($slug, $sql) = bb_get_sql_from_slug('topic', $id);
$id = wp_cache_get($slug, 'bb_topic_slug');
}
// not else
if (is_numeric($id)) {
$id = (int) $id;
$sql = "topic_id = {$id}";
}
if (0 === $id || !$sql) {
return false;
}
// &= not =&
$cache &= 'AND topic_status = 0' == ($where = apply_filters('get_topic_where', 'AND topic_status = 0'));
if (($cache || !$where) && is_numeric($id) && false !== ($topic = wp_cache_get($id, 'bb_topic'))) {
return $topic;
}
// $where is NOT bbdb:prepared
$topic = $bbdb->get_row("SELECT * FROM {$bbdb->topics} WHERE {$sql} {$where}");
$topic = bb_append_meta($topic, 'topic');
if ($cache) {
wp_cache_set($topic->topic_id, $topic, 'bb_topic');
wp_cache_add($topic->topic_slug, $topic->topic_id, 'bb_topic_slug');
}
return $topic;
}
示例15: 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;
}