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; }
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; }
/** * 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; }
/** 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; }
/** * 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']; } }
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; } }
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; }
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; }
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; }
/** * 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'); }
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; } }
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; }
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'); }
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; }
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; }
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; }
/** * 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; } }
/** * 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; } }
/** * 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; }
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; }
function widget($args, $instance) { $cache = wp_cache_get('widget_Pending_posts', 'widget'); if (!is_array($cache)) { $cache = array(); } if (isset($cache[$args['widget_id']])) { return $cache[$args['widget_id']]; } ob_start(); extract($args); $title = empty($instance['title']) ? __('Pending Posts', 'Pending_posts_widget') : apply_filters('widget_title', $instance['title']); if (!($number = (int) $instance['number'])) { $number = 10; } else { if ($number < 1) { $number = 1; } else { if ($number > 15) { $number = 15; } } } $queryArgs = array('showposts' => $number, 'what_to_show' => 'posts', 'nopaging' => 0, 'post_status' => 'pending', 'caller_get_posts' => 1, 'order' => 'ASC'); $r = new WP_Query($queryArgs); if ($r->have_posts()) { ?> <?php echo $before_widget; ?> <?php echo $before_title . $title . $after_title; ?> <ul> <?php while ($r->have_posts()) { $r->the_post(); ?> <li><?php if (get_the_title()) { the_title(); } else { the_ID(); } edit_post_link('e', ' (', ')'); ?> </li> <?php } ?> </ul> <?php echo $after_widget; wp_reset_query(); // Restore global post data stomped by the_post(). } $cache[$args['widget_id']] = ob_get_flush(); wp_cache_add('widget_Pending_posts', $cache, 'widget'); }
/** * Retrieves all category IDs. * * @since 2.0.0 * @link http://codex.wordpress.org/Function_Reference/get_all_category_ids * * @return object List of all of the category IDs. */ function get_all_category_ids() { if (!($cat_ids = wp_cache_get('all_category_ids', 'category'))) { $cat_ids = get_terms('category', array('fields' => 'ids', 'get' => 'all')); wp_cache_add('all_category_ids', $cat_ids, 'category'); } return $cat_ids; }
/** * Retrieves all category IDs. * * @since 2.0.0 * @link http://codex.wordpress.org/Function_Reference/get_all_category_ids * * @return object List of all of the category IDs. */ function get_all_category_ids() { if (!($cat_ids = wp_cache_get('all_category_ids', 'category'))) { $cat_ids = get_terms('category', 'fields=ids&get=all'); wp_cache_add('all_category_ids', $cat_ids, 'category'); } return $cat_ids; }
public static function get_instance($term_id, $taxonomy = null) { return false; global $wpdb; $term_id = (int) $term_id; if (!$term_id) { return false; } $_term = wp_cache_get($term_id, 'terms'); // If there isn't a cached version, hit the database. if (!$_term || $taxonomy && $taxonomy !== $_term->taxonomy) { // Grab all matching terms, in case any are shared between taxonomies. $terms = $wpdb->get_results($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 t.term_id = %d", $term_id)); if (!$terms) { return false; } // If a taxonomy was specified, find a match. if ($taxonomy) { foreach ($terms as $match) { if ($taxonomy === $match->taxonomy) { $_term = $match; break; } } // If only one match was found, it's the one we want. } elseif (1 === count($terms)) { $_term = reset($terms); // Otherwise, the term must be shared between taxonomies. } else { // If the term is shared only with invalid taxonomies, return the one valid term. foreach ($terms as $t) { if (!taxonomy_exists($t->taxonomy)) { continue; } // Only hit if we've already identified a term in a valid taxonomy. if ($_term) { return new WP_Error('ambiguous_term_id', __('Term ID is shared between multiple taxonomies'), $term_id); } $_term = $t; } } if (!$_term) { return false; } // Don't return terms from invalid taxonomies. if (!taxonomy_exists($_term->taxonomy)) { return new WP_Error('invalid_taxonomy', __('Invalid taxonomy')); } $_term = sanitize_term($_term, $_term->taxonomy, 'raw'); // Don't cache terms that are shared between taxonomies. if (1 === count($terms)) { wp_cache_add($term_id, $_term, 'terms'); } } $term_obj = new WP_Term($_term); $term_obj->filter($term_obj->filter); return $term_obj; }
/** * {@inheritdoc} */ public function end($key, $group = self::GROUP_DEFAULT) { $key = $this->hash($key); $group = $this->_cleanGroup($group, 'output'); $output = ob_get_contents(); ob_end_clean(); \wp_cache_add($key, $output, $group); echo $output; }
/** * FOLLOWING IS SIMPLY COPIED OUT OF TYPES * TODO make original source reusable and delete copied code */ public function _filterTypesFieldsToViewsDialog($menu) { if (is_admin() || !defined('TYPES_RELPATH')) { return; } wp_enqueue_script('wpcf-js-embedded', TYPES_RELPATH . '/library/toolset/types/embedded/resources/js/basic.js', array('jquery', 'jquery-ui-sortable', 'jquery-ui-draggable', 'jquery-ui-tabs', 'toolset_select2'), WPCF_VERSION); $this->types_js_settings(); $post_type = 'wp-types-group'; $only_active = false; $add_fields = false; $cache_group = 'types_cache_groups'; $cache_key = md5('group::_get_group' . $post_type); $cached_object = wp_cache_get($cache_key, $cache_group); if (false === $cached_object) { $groups = get_posts('numberposts=-1&post_type=' . $post_type . '&post_status=null'); wp_cache_add($cache_key, $groups, $cache_group); } else { $groups = $cached_object; } $_groups = array(); if (!empty($groups)) { foreach ($groups as $k => $group) { $group = wpcf_admin_fields_adjust_group($group, $add_fields); if ($only_active && !$group['is_active']) { continue; } $_groups[$k] = $group; } } $groups = $_groups; $all_post_types = implode(' ', get_post_types(array('public' => true))); $add = array(); if (!empty($groups)) { // $group_id is blank therefore not equal to $group['id'] // use array for item key and CSS class $item_styles = array(); global $post; foreach ($groups as $group_id => $group) { $fields = $this->wpcf_admin_fields_get_fields_by_group($group['id'], 'slug', true, false, true); if (!empty($fields)) { // code from Types used here without breaking the flow // get post types list for every group or apply all $post_types = get_post_meta($group['id'], '_wp_types_group_post_types', true); if ($post_types == 'all') { $post_types = $all_post_types; } $post_types = trim(str_replace(',', ' ', $post_types)); $item_styles[$group['name']] = $post_types; foreach ($fields as $field_id => $field) { $callback = 'wpcfFieldsEditorCallback(\'' . $field['id'] . '\', \'postmeta\', ' . $post->ID . ')'; $menu[$group['name']][stripslashes($field['name'])] = array(stripslashes($field['name']), trim($this->copy_fields_get_shortcode($field), '[]'), $group['name'], $callback); } } } } return $menu; }
public function registerPageTemplate($atts) { $cache_key = 'page_templates-' . md5(get_theme_root() . '/' . get_stylesheet()); $templates = empty(wp_get_theme()->get_page_templates()) ? [] : wp_get_theme()->get_page_templates(); wp_cache_delete($cache_key, 'themes'); $templates = array_merge($templates, $this->templates); wp_cache_add($cache_key, $templates, 'themes', 1800); return $atts; }
static function get($conditions = array(), $limit = null, $active = null) { global $wpdb; $args = func_get_args(); $cache_key = md5(serialize($args)); $cache_category = 'ArloCategories'; if ($cached = wp_cache_get($cache_key, $cache_category)) { return $cached; } $query = "SELECT c.* FROM {$wpdb->prefix}arlo_categories AS c"; $where = array("active = " . $active); foreach ($conditions as $key => $value) { // what to do? switch ($key) { case 'id': if (is_array($value)) { $where[] = "c.c_arlo_id IN (" . implode(',', $value) . ")"; } else { if (!empty($value)) { $where[] = "c.c_arlo_id = {$value}"; $limit = 1; } } break; case 'slug': if (is_array($value)) { $where[] = "c.c_slug IN (" . implode(',', $value) . ")"; } else { if (!empty($value)) { $where[] = "c.c_slug = '{$value}'"; $limit = 1; } } break; case 'parent_id': if (is_array($value)) { $where[] = "c.c_parent_id IN (" . implode(',', $value) . ")"; } else { if (!empty($value)) { $where[] = "c.c_parent_id = {$value}"; } else { $where[] = "c.c_parent_id = 0"; } } continue; break; } } if (!empty($where)) { $query .= ' WHERE ' . implode(' AND ', $where); $query .= ' ORDER BY c_order ASC'; } $result = $limit != 1 ? $wpdb->get_results($query) : $wpdb->get_row($query); wp_cache_add($cache_key, $result, $cache_category, 30); return $result; }
function batcache_clear_url($url) { global $batcache; if (empty($url)) { return false; } $url_key = md5($url); wp_cache_add("{$url_key}_version", 0, $batcache->group); return wp_cache_incr("{$url_key}_version", 1, $batcache->group); }
/** * Add a value to the object cache. * * Errors if a value already exists for the key, which means the value can't * be added. * * ## OPTIONS * * <key> * : Cache key. * * <value> * : Value to add to the key. * * [<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 * * # Add cache. * $ wp cache add my_key my_group my_value 300 * Success: Added object 'my_key' in group 'my_value'. */ public function add($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); if (!wp_cache_add($key, $value, $group, $expiration)) { WP_CLI::error("Could not add object '{$key}' in group '{$group}'. Does it already exist?"); } WP_CLI::success("Added object '{$key}' in group '{$group}'."); }