本文整理汇总了PHP中wp_cache_add函数的典型用法代码示例。如果您正苦于以下问题:PHP wp_cache_add函数的具体用法?PHP wp_cache_add怎么用?PHP wp_cache_add使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wp_cache_add函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:trishasalas,项目名称:rgy,代码行数:25,代码来源:batcache.php
示例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;
}
开发者ID:gopinathshiva,项目名称:wordpress-vip-plugins,代码行数:29,代码来源:recent-comments.php
示例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;
}
开发者ID:ricardo93borges,项目名称:mdt-upload,代码行数:41,代码来源:getImages.php
示例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;
}
开发者ID:kolipu,项目名称:EventCalendar3,代码行数:31,代码来源:eventcalendar3.php
示例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'];
}
}
开发者ID:jaredwilli,项目名称:3.0basics,代码行数:66,代码来源:widgets.php
示例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;
}
}
开发者ID:kinhdon2011,项目名称:nexthemes-plugins,代码行数:29,代码来源:class-staticblocks.php
示例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;
}
开发者ID:AkimBolushbek,项目名称:wordpress-soc-2007,代码行数:35,代码来源:themes.wordpress.net.php
示例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;
}
开发者ID:boltogriz,项目名称:blog-cook,代码行数:34,代码来源:functions.php
示例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;
}
开发者ID:snitchashor,项目名称:wp-united,代码行数:32,代码来源:comments.php
示例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');
}
开发者ID:vadia007,项目名称:acoustics,代码行数:32,代码来源:image.php
示例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;
}
}
开发者ID:ryan2407,项目名称:Vision,代码行数:26,代码来源:powerpress-playlist.php
示例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;
}
开发者ID:adamplabarge,项目名称:bermstyle,代码行数:28,代码来源:wfConfig.php
示例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');
}
开发者ID:azeemgolive,项目名称:thefunkidsgame,代码行数:25,代码来源:widget-page-content.php
示例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;
}
开发者ID:danielcoats,项目名称:schoolpress,代码行数:29,代码来源:functions.bb-topics.php
示例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;
}
开发者ID:kosir,项目名称:thatcamp-org,代码行数:35,代码来源:custom_field_model.php
示例16: generate_data
function generate_data()
{
global $wpdb, $bwp_gxs, $post;
$sql_where = apply_filters('bwp_gxs_post_where', '', 'page');
$latest_post_query = '
SELECT * FROM ' . $wpdb->posts . " wposts\n\t\t\t\tWHERE wposts.post_status = 'publish' AND wposts.post_type = 'page' {$sql_where}" . '
ORDER BY wposts.post_modified DESC';
$latest_posts = $this->get_results($latest_post_query);
if (!isset($latest_posts) || 0 == sizeof($latest_posts)) {
return false;
}
$data = array();
for ($i = 0; $i < sizeof($latest_posts); $i++) {
$post = $latest_posts[$i];
$data = $this->init_data($data);
wp_cache_add($post->ID, $post, 'posts');
$data['location'] = get_permalink();
$data['lastmod'] = $this->format_lastmod(strtotime($post->post_modified));
$data['freq'] = $this->cal_frequency($post);
$data['priority'] = $this->cal_priority($post, $data['freq']);
$this->data[] = $data;
}
// Probably save some memory ;)
unset($latest_posts);
// Always return true if we can get here, otherwise you're stuck at the SQL cycling limit
return true;
}
开发者ID:rconnelly,项目名称:vacationware,代码行数:27,代码来源:page.php
示例17: get_bookmark
/**
* Retrieve Bookmark data based on ID
*
* @since 2.1.0
* @uses $wpdb Database Object
*
* @param int $bookmark_id
* @param string $output Optional. Either OBJECT, ARRAY_N, or ARRAY_A constant
* @param string $filter Optional, default is 'raw'.
* @return array|object Type returned depends on $output value.
*/
function get_bookmark($bookmark, $output = OBJECT, $filter = 'raw')
{
global $wpdb;
if (empty($bookmark)) {
if (isset($GLOBALS['link'])) {
$_bookmark =& $GLOBALS['link'];
} else {
$_bookmark = null;
}
} elseif (is_object($bookmark)) {
wp_cache_add($bookmark->link_id, $bookmark, 'bookmark');
$_bookmark = $bookmark;
} else {
if (isset($GLOBALS['link']) && $GLOBALS['link']->link_id == $bookmark) {
$_bookmark =& $GLOBALS['link'];
} elseif (!($_bookmark = wp_cache_get($bookmark, 'bookmark'))) {
$_bookmark = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->links} WHERE link_id = %d LIMIT 1", $bookmark));
$_bookmark->link_category = array_unique(wp_get_object_terms($_bookmark->link_id, 'link_category', 'fields=ids'));
wp_cache_add($_bookmark->link_id, $_bookmark, 'bookmark');
}
}
$_bookmark = sanitize_bookmark($_bookmark, $filter);
if ($output == OBJECT) {
return $_bookmark;
} elseif ($output == ARRAY_A) {
return get_object_vars($_bookmark);
} elseif ($output == ARRAY_N) {
return array_values(get_object_vars($_bookmark));
} else {
return $_bookmark;
}
}
开发者ID:papayalabs,项目名称:htdocs,代码行数:43,代码来源:bookmark.php
示例18: 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;
}
}
开发者ID:akirk,项目名称:GlotPress,代码行数:37,代码来源:meta.php
示例19: get_object_term
/**
* Wrap wp_get_object_terms to cache it and return only one object
* inspired by the function get_the_terms
*
* @since 1.2
*
* @param int $object_id post_id or term_id
* @param string $taxonomy Polylang taxonomy depending if we are looking for a post ( or term ) language ( or translation )
* @return bool|object the term associated to the object in the requested taxonomy if exists, false otherwise
*/
public function get_object_term($object_id, $taxonomy)
{
if (empty($object_id)) {
return false;
}
$object_id = (int) $object_id;
$term = get_object_term_cache($object_id, $taxonomy);
if (false === $term) {
// query language and translations at the same time
$taxonomies = array($this->tax_language, $this->tax_translations);
// query terms
foreach (wp_get_object_terms($object_id, $taxonomies) as $t) {
$terms[$t->taxonomy] = $t;
if ($t->taxonomy == $taxonomy) {
$term = $t;
}
}
// store it the way WP wants it
// set an empty cache if no term found in the taxonomy
foreach ($taxonomies as $tax) {
wp_cache_add($object_id, empty($terms[$tax]) ? array() : array($terms[$tax]), $tax . '_relationships');
}
} else {
$term = reset($term);
}
return empty($term) ? false : $term;
}
开发者ID:spielhoelle,项目名称:amnesty,代码行数:37,代码来源:translated-object.php
示例20: widget
function widget($args, $instance)
{
global $wpdb, $comments, $comment;
extract($args, EXTR_SKIP);
$title = apply_filters('widget_title', empty($instance['title']) ? __('My Recent Comments', 'my_framework') : $instance['title']);
if (!($number = (int) $instance['number'])) {
$number = 5;
} else {
if ($number < 1) {
$number = 1;
} else {
if ($number > 15) {
$number = 15;
}
}
}
$comment_len = 100;
if (!($comments = wp_cache_get('recent_comments', 'widget'))) {
$comments = $wpdb->get_results("SELECT * FROM {$wpdb->comments} WHERE comment_approved = '1' and comment_type not in ('pingback','trackback') ORDER BY comment_date_gmt DESC LIMIT 15");
wp_cache_add('recent_comments', $comments, 'widget');
}
$comments = array_slice((array) $comments, 0, $number);
?>
<?php
echo $before_widget;
?>
<?php
if ($title) {
echo $before_title . $title . $after_title;
}
?>
<ul id="recentcomments"><?php
if ($comments) {
foreach ((array) $comments as $comment) {
?>
<li class="recentcomments">
<?php
echo strip_tags(substr(apply_filters('get_comment_text', $comment->comment_content), 0, $comment_len));
if (strlen($comment->comment_content) > $comment_len) {
echo '...';
}
?>
<br />
<?php
echo __('by', 'my_framework') . ' ' . sprintf(_x('%1$s on %2$s', 'widgets'), get_comment_author_link(), '<a href="' . esc_url(get_comment_link($comment->comment_ID)) . '">' . get_the_title($comment->comment_post_ID) . '</a>');
?>
</li>
<?php
}
}
?>
</ul>
<?php
echo $after_widget;
}
开发者ID:sangikumar,项目名称:IP,代码行数:59,代码来源:my-comment-widget.php
注:本文中的wp_cache_add函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论