Пример #1
0
 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
0
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
0
/**
 * 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
0
/**
 * 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;
    }
}
 /**
  * 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
0
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
0
 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
0
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
0
 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
0
 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
0
 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;
 }
 /**
  * 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
0
 /**
  * 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
0
 /**
  * @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
0
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;
}
Пример #16
0
 function render($args, $instance)
 {
     global $gantry, $comments, $comment;
     ob_start();
     $menu_class = $instance['menu_class'];
     $link_class = $instance['link_class'];
     if ($menu_class != '') {
         $menu_class = ' class="' . $menu_class . '"';
     } else {
         $menu_class = '';
     }
     if ($link_class != '') {
         $link_class = ' class="' . $link_class . '"';
     } else {
         $link_class = '';
     }
     $cache = wp_cache_get('gantry_recentcomments', 'widget');
     if (!is_array($cache)) {
         $cache = array();
     }
     if (isset($cache[$args['widget_id']])) {
         echo $cache[$args['widget_id']];
         return;
     }
     $output = '';
     if (!($number = (int) $instance['number'])) {
         $number = 5;
     } else {
         if ($number < 1) {
             $number = 1;
         }
     }
     if (!($word_limit = (int) $instance['word_limit'])) {
         $word_limit = 8;
     } else {
         if ($word_limit < 1) {
             $word_limit = 1;
         }
     }
     $comments = get_comments(array('number' => $number, 'status' => 'approve'));
     $output .= '<ul' . $menu_class . '>';
     if ($comments) {
         foreach ((array) $comments as $comment) {
             $words = explode(' ', strip_tags($comment->comment_content));
             $comment_text = implode(' ', array_slice($words, 0, $word_limit));
             $avatar = get_avatar($comment->comment_author_email, $size = 32);
             $avatar = str_replace("class='", "class='rt-image ", $avatar);
             $output .= '<li class="gantry_recentcomments">';
             $output .= $avatar;
             $output .= '<a href="' . get_comment_link($comment->comment_ID) . '"' . $link_class . '>' . $comment_text . '...</a>';
             $output .= '<br />By ' . $comment->comment_author;
             $output .= '</li>';
         }
     }
     $output .= '</ul>';
     echo $output;
     $cache[$args['widget_id']] = $output;
     wp_cache_set('gantry_recentcomments', $cache, 'widget');
     echo ob_get_clean();
 }
Пример #17
0
/**
 * Get all page types that exists.
 *
 * @param  bool   $all
 * @param  string $post_type
 * @param  bool   $fake_post_types
 *
 * @return array
 */
function papi_get_all_page_types($all = false, $post_type = null, $fake_post_types = false)
{
    if (empty($post_type)) {
        $post_type = papi_get_post_type();
    }
    $cache_key = papi_cache_key(sprintf('%s_%s', $all, $post_type), $fake_post_types);
    $page_types = wp_cache_get($cache_key);
    $load_once = papi_filter_core_load_one_type_on();
    if (empty($page_types)) {
        $files = papi_get_all_page_type_files();
        foreach ($files as $file) {
            $page_type = papi_get_page_type($file);
            if (is_null($page_type)) {
                continue;
            }
            if ($page_type instanceof Papi_Page_Type === false) {
                continue;
            }
            if (papi()->exists('core.page_type.' . $page_type->post_type[0])) {
                if (!empty($page_types)) {
                    continue;
                }
            } else {
                if (in_array($page_type->post_type[0], $load_once)) {
                    papi()->singleton('core.page_type.' . $page_type->post_type[0], $page_type->get_id());
                }
            }
            if ($fake_post_types) {
                if (isset($page_type->post_type[0]) && !post_type_exists($page_type->post_type[0])) {
                    // Boot page type.
                    $page_type->boot();
                    // Add it to the page types array.
                    $page_types[] = $page_type;
                }
                continue;
            } else {
                if ($page_type instanceof Papi_Option_Type) {
                    continue;
                }
            }
            // Add the page type if the post types is allowed.
            if (!is_null($page_type) && papi_current_user_is_allowed($page_type->capabilities) && ($all || in_array($post_type, $page_type->post_type))) {
                // Boot page type.
                $page_type->boot();
                // Add it to the page types array.
                $page_types[] = $page_type;
            }
        }
        if (is_array($page_types)) {
            usort($page_types, function ($a, $b) {
                return strcmp($a->name, $b->name);
            });
            wp_cache_set($cache_key, $page_types);
        }
    }
    if (!is_array($page_types)) {
        return [];
    }
    return papi_sort_order(array_reverse($page_types));
}
Пример #18
0
 /**
  * @ticket 23326
  */
 public function test_wp_delete_term_should_invalidate_cache()
 {
     global $wpdb;
     $this->set_up_three_posts_and_tags();
     // Prime cache
     $terms = get_terms('post_tag');
     $time1 = wp_cache_get('last_changed', 'terms');
     $num_queries = $wpdb->num_queries;
     // Force last_changed to bump.
     wp_delete_term($terms[0]->term_id, 'post_tag');
     $num_queries = $wpdb->num_queries;
     $this->assertNotEquals($time1, $time2 = wp_cache_get('last_changed', 'terms'));
     // last_changed and num_queries should bump after a term is deleted.
     $terms = get_terms('post_tag');
     $this->assertEquals(2, count($terms));
     $this->assertEquals($time2, wp_cache_get('last_changed', 'terms'));
     $this->assertEquals($num_queries + 1, $wpdb->num_queries);
     $num_queries = $wpdb->num_queries;
     // Again. last_changed and num_queries should remain the same.
     $terms = get_terms('post_tag');
     $this->assertEquals(2, count($terms));
     $this->assertEquals($time2, wp_cache_get('last_changed', 'terms'));
     $this->assertEquals($num_queries, $wpdb->num_queries);
     // @todo Repeat with term insert and update.
 }
Пример #19
0
 /**
  * @group bp_xprofile_fullname_field_id
  * @group cache
  */
 public function test_bp_xprofile_fullname_field_id_invalidation()
 {
     // Prime the cache
     $id = bp_xprofile_fullname_field_id();
     bp_update_option('bp-xprofile-fullname-field-name', 'foo');
     $this->assertFalse(wp_cache_get('fullname_field_id', 'bp_xprofile'));
 }
Пример #20
0
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;
}
Пример #21
0
 public static function render($slug, $data = array(), $cache = false)
 {
     if (is_string($data)) {
         $data = array('name' => $data);
     }
     $cache = self::_maybe_prevent_caching($slug, $data, $cache);
     $data = wp_parse_args($data, array('name' => '', 'return' => false));
     $return = $data['return'];
     unset($data['return']);
     if ($cache) {
         $cache = self::_get_cache_key($slug, $data);
         if ($cache) {
             $output = wp_cache_get($cache, 'templateparts');
             if (false !== $output) {
                 $output = self::_add_output_html_comments($output, $slug, true);
                 if ($return) {
                     return $output;
                 }
                 echo $output;
                 return;
             }
         }
     }
     $templates = array();
     if (!empty($data['name'])) {
         $templates[] = $slug . '-' . $data['name'] . '.php';
     }
     $templates[] = $slug . '.php';
     $filename = locate_template($templates, false, false);
     if (!$filename) {
         WPStarterTheme\Base\Theme::_doing_it_wrong(__METHOD__, sprintf(__('The template %s does not exist.', 'wp-starter-theme'), $filename));
         return;
     }
     ob_start();
     $require_once = true;
     switch ($slug) {
         case 'header':
             do_action('get_header', $data['name']);
             break;
         case 'footer':
             do_action('get_footer', $data['name']);
             break;
         case 'sidebar':
             do_action('get_sidebar', $data['name']);
             break;
         default:
             do_action('get_template_part_' . $slug, $slug, $data['name']);
             $require_once = false;
     }
     self::_load_template($filename, $data, $require_once);
     $output = ob_get_clean();
     if ($cache) {
         wp_cache_set($cache, $output, 'templateparts', self::CACHE_DURATION);
     }
     $output = self::_add_output_html_comments($output, $slug);
     if ($return) {
         return $output;
     }
     echo $output;
 }
Пример #22
0
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_gateway_data()
 {
     if (!($this->gateway_data = wp_cache_get($this->log_id, 'wpsc_checkout_form_gateway_data'))) {
         $map = array('firstname' => 'first_name', 'lastname' => 'last_name', 'address' => 'street', 'city' => 'city', 'state' => 'state', 'country' => 'country', 'postcode' => 'zip', 'phone' => 'phone');
         foreach (array('shipping', 'billing') as $type) {
             $data_key = "{$type}_address";
             $this->gateway_data[$data_key] = array();
             foreach ($map as $key => $new_key) {
                 $key = $type . $key;
                 if (isset($this->data[$key])) {
                     $value = $this->data[$key];
                     if ($new_key == 'state' && is_numeric($value)) {
                         $value = wpsc_get_state_by_id($value, 'code');
                     }
                     $this->gateway_data[$data_key][$new_key] = $value;
                 }
             }
             $name = isset($this->gateway_data[$data_key]['first_name']) ? $this->gateway_data[$data_key]['first_name'] . ' ' : '';
             $name .= isset($this->gateway_data[$data_key]['last_name']) ? $this->gateway_data[$data_key]['last_name'] : '';
             $this->gateway_data[$data_key]['name'] = trim($name);
         }
         wp_cache_set($this->log_id, $this->gateway_data, 'wpsc_checkout_form_gateway_data');
     }
     return apply_filters('wpsc_checkout_form_gateway_data', $this->gateway_data, $this->log_id);
 }
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;
}
Пример #25
0
 function get_comment_changes()
 {
     global $spec_comment_log, $current_user;
     $user_roles = $current_user->roles;
     $role = array_shift($user_roles);
     $action_id = 0;
     if (isset($_POST['action_id'])) {
         $action_id = absint($_POST['action_id']);
     }
     $time = '';
     if (isset($_POST['time'])) {
         $time = $_POST['time'];
     }
     $post_id = $_POST['post_id'];
     // Get the details from cache
     $cachekey = 'icit_spec_discus_' . $post_id . '_' . $action_id . '_' . $role;
     $encoded_json = wp_cache_get($cachekey, 'spec_discussion');
     if (empty($encoded_json)) {
         $encoded_json = $this->grab_changedcomments_json($spec_comment_log, $post_id, $time, $action_id);
         // The details weren't in cache lets add it now.
         wp_cache_set($cachekey, $encoded_json, 'spec_discussion', 20);
     }
     echo $encoded_json;
     die;
 }
Пример #26
0
 function filter_woocommerce_ajax_params($woocommerce_params)
 {
     global $sitepress, $post;
     $value = array();
     $value = $woocommerce_params;
     if ($sitepress->get_current_language() !== $sitepress->get_default_language()) {
         $value['ajax_url'] = add_query_arg('lang', ICL_LANGUAGE_CODE, $woocommerce_params['ajax_url']);
         $value['checkout_url'] = add_query_arg('action', 'woocommerce-checkout', $value['ajax_url']);
     }
     if (!isset($post->ID)) {
         return $value;
     }
     $ch_pages = wp_cache_get('ch_pages', 'wcml_ch_pages');
     if (empty($ch_pages)) {
         $ch_pages = array('checkout_page_id' => get_option('woocommerce_checkout_page_id'), 'pay_page_id' => get_option('woocommerce_pay_page_id'), 'cart_page_id' => get_option('woocommerce_cart_page_id'));
         $ch_pages['translated_checkout_page_id'] = apply_filters('translate_object_id', $ch_pages['checkout_page_id'], 'page', false);
         $ch_pages['translated_pay_page_id'] = apply_filters('translate_object_id', $ch_pages['pay_page_id'], 'page', false);
         $ch_pages['translated_cart_page_id'] = apply_filters('translate_object_id', $ch_pages['cart_page_id'], 'page', false);
     }
     wp_cache_set('ch_pages', $ch_pages, 'wcml_ch_pages');
     if ($ch_pages['translated_cart_page_id'] == $post->ID) {
         $value['is_cart'] = 1;
         $value['cart_url'] = get_permalink($ch_pages['translated_cart_page_id']);
     } else {
         if ($ch_pages['translated_checkout_page_id'] == $post->ID || $ch_pages['checkout_page_id'] == $post->ID) {
             $value['is_checkout'] = 1;
             $_SESSION['wpml_globalcart_language'] = $sitepress->get_current_language();
         } else {
             if ($ch_pages['translated_pay_page_id'] == $post->ID) {
                 $value['is_pay_page'] = 1;
             }
         }
     }
     return $value;
 }
Пример #27
0
 public function query()
 {
     global $wpdb;
     $read_unread = '';
     if ($this->args['unread'] && $this->args['read']) {
         $read_unread .= "apmeta_type = 'notification' OR apmeta_type = 'unread_notification'";
     } elseif ($this->args['read']) {
         $read_unread .= "apmeta_type = 'notification'";
     } else {
         $read_unread .= "apmeta_type = 'unread_notification'";
     }
     $query = $wpdb->prepare("SELECT SQL_CALC_FOUND_ROWS apmeta_id as id, apmeta_userid as user_id, apmeta_actionid as affected_user_id, apmeta_param as type, apmeta_value as args, apmeta_type as is_unread, apmeta_date as date FROM " . $wpdb->prefix . "ap_meta WHERE (" . $read_unread . ") AND apmeta_actionid = %d ORDER BY CASE apmeta_type WHEN 'unread_notification' THEN 1 ELSE -1 END DESC, apmeta_date DESC LIMIT %d,%d", $this->args['user_id'], $this->offset, $this->per_page);
     $this->cache_key = md5($query);
     $result = wp_cache_get($this->cache_key, 'ap');
     $this->total_count = wp_cache_get($this->cache_key . '_count', 'ap');
     if ($result === false) {
         $result = $wpdb->get_results($query);
         wp_cache_set($this->cache_key, $result, 'ap');
         $this->total_count = $wpdb->get_var(apply_filters('ap_notification_found_rows', "SELECT FOUND_ROWS()", $this));
         wp_cache_set($this->cache_key . '_count', $this->total_count, 'ap');
     }
     $this->notifications = $result;
     $this->total_pages = ceil($this->total_count / $this->per_page);
     $this->count = count($result);
 }
Пример #28
0
function jetpack_instagram_handler($matches, $atts, $url)
{
    global $content_width;
    static $did_script;
    // keep a copy of the passed-in URL since it's modified below
    $passed_url = $url;
    $max_width = 698;
    $min_width = 320;
    if (is_feed()) {
        $media_url = sprintf('http://instagr.am/p/%s/media/?size=l', $matches[2]);
        return sprintf('<a href="%s" title="%s"><img src="%s" alt="Instagram Photo" /></a>', esc_url($url), esc_attr__('View on Instagram', 'jetpack'), esc_url($media_url));
    }
    $atts = shortcode_atts(array('width' => isset($content_width) ? $content_width : $max_width, 'hidecaption' => false), $atts);
    $atts['width'] = absint($atts['width']);
    if ($atts['width'] > $max_width || $min_width > $atts['width']) {
        $atts['width'] = $max_width;
    }
    // remove the modal param from the URL
    $url = remove_query_arg('modal', $url);
    // force .com instead of .am for https support
    $url = str_replace('instagr.am', 'instagram.com', $url);
    // The oembed endpoint expects HTTP, but HTTP requests 301 to HTTPS
    $instagram_http_url = str_replace('https://', 'http://', $url);
    $instagram_https_url = str_replace('http://', 'https://', $url);
    $url_args = array('url' => $instagram_http_url, 'maxwidth' => $atts['width']);
    if ($atts['hidecaption']) {
        $url_args['hidecaption'] = 'true';
    }
    $url = esc_url_raw(add_query_arg($url_args, 'https://api.instagram.com/oembed/'));
    // Don't use object caching here by default, but give themes ability to turn it on.
    $response_body_use_cache = apply_filters('instagram_cache_oembed_api_response_body', false, $matches, $atts, $passed_url);
    $response_body = false;
    if ($response_body_use_cache) {
        $cache_key = 'oembed_response_body_' . md5($url);
        $response_body = wp_cache_get($cache_key, 'instagram_embeds');
    }
    if (!$response_body) {
        // Not using cache (default case) or cache miss
        $instagram_response = wp_remote_get($url, array('redirection' => 0));
        if (is_wp_error($instagram_response) || 200 != $instagram_response['response']['code'] || empty($instagram_response['body'])) {
            return "<!-- instagram error: invalid oratv resource -->";
        }
        $response_body = json_decode($instagram_response['body']);
        if ($response_body_use_cache) {
            // if caching it is short-lived since this is a "Cache-Control: no-cache" resource
            wp_cache_set($cache_key, $response_body, 'instagram_embeds', HOUR_IN_SECONDS + mt_rand(0, HOUR_IN_SECONDS));
        }
    }
    if (!empty($response_body->html)) {
        if (!$did_script) {
            $did_script = true;
            add_action('wp_footer', 'jetpack_instagram_add_script');
        }
        // there's a script in the response, which we strip on purpose since it's added above
        $ig_embed = preg_replace('@<(script)[^>]*?>.*?</\\1>@si', '', $response_body->html);
    } else {
        $ig_embed = jetpack_instagram_iframe_embed($instagram_https_url, $atts);
    }
    return $ig_embed;
}
Пример #29
0
 function get_terms_in_found_set()
 {
     if (isset($this->facets->_matching_tax_facets[$this->name]) && is_array($this->facets->_matching_tax_facets[$this->name])) {
         return $this->facets->_matching_tax_facets[$this->name];
     }
     $matching_post_ids = $this->facets->get_matching_post_ids();
     // if there aren't any matching post ids, we don't need to query
     if (!is_array($matching_post_ids) || !count($matching_post_ids)) {
         return array();
     }
     //end if
     scriblio()->timer('facet_taxonomy::get_terms_in_found_set');
     $timer_notes = 'from cache';
     $cache_key = md5(serialize($matching_post_ids)) . $this->version;
     if (!($this->facets->_matching_tax_facets = wp_cache_get($cache_key . (scriblio()->cachebuster ? 'CACHEBUSTER' : ''), 'scrib-facet-taxonomy'))) {
         $timer_notes = 'from query';
         global $wpdb;
         $facets_query = "SELECT b.term_id, c.term_taxonomy_id, b.slug, b.name, a.taxonomy, a.description, COUNT(c.term_taxonomy_id) AS `count`\n\t\t\t\tFROM {$wpdb->term_relationships} c\n\t\t\t\tINNER JOIN {$wpdb->term_taxonomy} a ON a.term_taxonomy_id = c.term_taxonomy_id\n\t\t\t\tINNER JOIN {$wpdb->terms} b ON a.term_id = b.term_id\n\t\t\t\tWHERE c.object_id IN (" . implode(',', $matching_post_ids) . ")\n\t\t\t\tGROUP BY c.term_taxonomy_id ORDER BY count DESC LIMIT 2000\n\t\t\t\t/* generated in Facet_Taxonomy::get_terms_in_found_set() */";
         $terms = $wpdb->get_results($facets_query);
         scriblio()->timer('facet_taxonomy::get_terms_in_found_set::scriblio_facet_taxonomy_terms');
         $terms = apply_filters('scriblio_facet_taxonomy_terms', $terms);
         scriblio()->timer('facet_taxonomy::get_terms_in_found_set::scriblio_facet_taxonomy_terms', count($terms) . ' terms');
         $this->facets->_matching_tax_facets = array();
         foreach ($terms as $term) {
             $this->facets->_matching_tax_facets[$this->facets->_tax_to_facet[$term->taxonomy]][] = (object) array('facet' => $this->facets->_tax_to_facet[$term->taxonomy], 'slug' => $term->slug, 'name' => $term->name, 'count' => $term->count, 'description' => $term->description, 'term_id' => $term->term_id, 'term_taxonomy_id' => $term->term_taxonomy_id);
         }
         wp_cache_set($cache_key, $this->facets->_matching_tax_facets, 'scrib-facet-taxonomy', $this->ttl);
     }
     scriblio()->timer('facet_taxonomy::get_terms_in_found_set', $timer_notes);
     if (!isset($this->facets->_matching_tax_facets[$this->name]) || !is_array($this->facets->_matching_tax_facets[$this->name])) {
         return array();
     } else {
         return $this->facets->_matching_tax_facets[$this->name];
     }
 }
 function widget()
 {
     // Check if obj exists in cache
     $users = wp_cache_get('active_users');
     if ($users == false) {
         // Generate the query
         $users = get_users(array('role' => 'student'));
         // Cache the results
         wp_cache_set('active_users', $users, '', 300);
     }
     //$users = get_users( array( 'role' => 'student' ) );
     $users_for_counts = array();
     foreach ($users as $user) {
         $users_for_counts[] = $user->ID;
     }
     // Check if obj exists in cache
     $counts = wp_cache_get('user_count');
     if ($counts == false) {
         // Generate the obj
         $counts = count_many_users_posts($users_for_counts);
         // Cache the results
         wp_cache_set('user_count', $counts, '', 300);
     }
     arsort($counts);
     $counts = array_slice($counts, 0, 5, true);
     echo 'There are currently <strong>' . intval(count($users)) . '</strong> students with HS Insider accounts.';
     echo '<p><strong>Most-active students:</strong></p><ul>';
     foreach ($counts as $user_id => $count) {
         echo '<li><a href="' . esc_url(get_author_posts_url($user_id)) . '" target=_blank>' . esc_html(get_the_author_meta('display_name', $user_id)) . '</a>: (<strong>' . intval($count) . '</strong>)</li>';
     }
     echo '</ul>';
 }