当前位置: 首页>>代码示例>>PHP>>正文


PHP get_transient函数代码示例

本文整理汇总了PHP中get_transient函数的典型用法代码示例。如果您正苦于以下问题:PHP get_transient函数的具体用法?PHP get_transient怎么用?PHP get_transient使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了get_transient函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: init

 /**
  * Prevent caching on dynamic pages.
  *
  * @access public
  * @return void
  */
 public function init()
 {
     if (false === ($wc_page_uris = get_transient('woocommerce_cache_excluded_uris'))) {
         if (woocommerce_get_page_id('cart') < 1 || woocommerce_get_page_id('checkout') < 1 || woocommerce_get_page_id('myaccount') < 1) {
             return;
         }
         $wc_page_uris = array();
         $cart_page = get_post(woocommerce_get_page_id('cart'));
         $checkout_page = get_post(woocommerce_get_page_id('checkout'));
         $account_page = get_post(woocommerce_get_page_id('myaccount'));
         $wc_page_uris[] = '/' . $cart_page->post_name;
         $wc_page_uris[] = '/' . $checkout_page->post_name;
         $wc_page_uris[] = '/' . $account_page->post_name;
         $wc_page_uris[] = 'p=' . $cart_page->ID;
         $wc_page_uris[] = 'p=' . $checkout_page->ID;
         $wc_page_uris[] = 'p=' . $account_page->ID;
         set_transient('woocommerce_cache_excluded_uris', $wc_page_uris);
     }
     if (is_array($wc_page_uris)) {
         foreach ($wc_page_uris as $uri) {
             if (strstr($_SERVER['REQUEST_URI'], $uri)) {
                 $this->nocache();
                 break;
             }
         }
     }
 }
开发者ID:rongandat,项目名称:sallumeh,代码行数:33,代码来源:class-wc-cache-helper.php

示例2: genesis_update_check

/**
 * Pings http://api.genesistheme.com/ asking if a new version of this theme is
 * available.
 *
 * If not, it returns false.
 *
 * If so, the external server passes serialized data back to this function,
 * which gets unserialized and returned for use.
 *
 * @since 1.1.0
 *
 * @uses genesis_get_option()
 * @uses PARENT_THEME_VERSION Genesis version string
 *
 * @global string $wp_version WordPress version string
 * @return mixed Unserialized data, or false on failure
 */
function genesis_update_check()
{
    global $wp_version;
    /**	If updates are disabled */
    if (!genesis_get_option('update') || !current_theme_supports('genesis-auto-updates')) {
        return false;
    }
    /** Get time of last update check */
    $genesis_update = get_transient('genesis-update');
    /** If it has expired, do an update check */
    if (!$genesis_update) {
        $url = 'http://api.genesistheme.com/update-themes/';
        $options = apply_filters('genesis_update_remote_post_options', array('body' => array('genesis_version' => PARENT_THEME_VERSION, 'wp_version' => $wp_version, 'php_version' => phpversion(), 'uri' => home_url(), 'user-agent' => "WordPress/{$wp_version};")));
        $response = wp_remote_post($url, $options);
        $genesis_update = wp_remote_retrieve_body($response);
        /** If an error occurred, return FALSE, store for 1 hour */
        if ('error' == $genesis_update || is_wp_error($genesis_update) || !is_serialized($genesis_update)) {
            set_transient('genesis-update', array('new_version' => PARENT_THEME_VERSION), 60 * 60);
            return false;
        }
        /** Else, unserialize */
        $genesis_update = maybe_unserialize($genesis_update);
        /** And store in transient for 24 hours */
        set_transient('genesis-update', $genesis_update, 60 * 60 * 24);
    }
    /** If we're already using the latest version, return false */
    if (version_compare(PARENT_THEME_VERSION, $genesis_update['new_version'], '>=')) {
        return false;
    }
    return $genesis_update;
}
开发者ID:hscale,项目名称:webento,代码行数:48,代码来源:upgrade.php

示例3: get_photos

 function get_photos($id, $count = 8)
 {
     if (empty($id)) {
         return false;
     }
     $transient_key = md5('favethemes_flickr_cache_' . $id . $count);
     $cached = get_transient($transient_key);
     if (!empty($cached)) {
         return $cached;
     }
     $output = array();
     $rss = 'http://api.flickr.com/services/feeds/photos_public.gne?id=' . $id . '&lang=en-us&format=rss_200';
     $rss = fetch_feed($rss);
     if (is_wp_error($rss)) {
         //check for group feed
         $rss = 'http://api.flickr.com/services/feeds/groups_pool.gne?id=' . $id . '&lang=en-us&format=rss_200';
         $rss = fetch_feed($rss);
     }
     if (!is_wp_error($rss)) {
         $maxitems = $rss->get_item_quantity($count);
         $rss_items = $rss->get_items(0, $maxitems);
         foreach ($rss_items as $item) {
             $temp = array();
             $temp['img_url'] = esc_url($item->get_permalink());
             $temp['title'] = esc_html($item->get_title());
             $content = $item->get_content();
             preg_match_all("/<IMG.+?SRC=[\"']([^\"']+)/si", $content, $sub, PREG_SET_ORDER);
             $photo_url = str_replace("_m.jpg", "_t.jpg", $sub[0][1]);
             $temp['img_src'] = esc_url($photo_url);
             $output[] = $temp;
         }
         set_transient($transient_key, $output, 60 * 60 * 24);
     }
     return $output;
 }
开发者ID:phuthuytinhoc,项目名称:Demo1,代码行数:35,代码来源:magazilla-flickr-photos.php

示例4: check_update

 public static function check_update($plugin_path, $plugin_slug, $plugin_url, $offering, $key, $version, $option)
 {
     $version_info = function_exists('get_site_transient') ? get_site_transient("gforms_userregistration_version") : get_transient("gforms_userregistration_version");
     //making the remote request for version information
     if (!$version_info) {
         //Getting version number
         $version_info = self::get_version_info($offering, $key, $version);
         self::set_version_info($version_info);
     }
     if ($version_info == -1) {
         return $option;
     }
     if (empty($option->response[$plugin_path])) {
         $option->response[$plugin_path] = new stdClass();
     }
     //Empty response means that the key is invalid. Do not queue for upgrade
     if (!$version_info["is_valid_key"] || version_compare($version, $version_info["version"], '>=')) {
         unset($option->response[$plugin_path]);
     } else {
         $option->response[$plugin_path]->url = $plugin_url;
         $option->response[$plugin_path]->slug = $plugin_slug;
         $option->response[$plugin_path]->package = str_replace("{KEY}", $key, $version_info["url"]);
         $option->response[$plugin_path]->new_version = $version_info["version"];
         $option->response[$plugin_path]->id = "0";
     }
     return $option;
 }
开发者ID:vinvinh315,项目名称:maintainwebsolutions.com,代码行数:27,代码来源:plugin-upgrade.php

示例5: moxie_press_endpoint_data

function moxie_press_endpoint_data()
{
    global $wp_query;
    // get query vars
    $json = $wp_query->get('json');
    $name = $wp_query->get('name');
    // use this template redirect only if json is requested
    if ($json != 'true') {
        return;
    }
    // build the query
    $movie_data = array();
    // default args
    $args = array('post_type' => 'movie', 'posts_per_page' => 100);
    if ($name != '') {
        $args['name'] = $name;
    }
    // add name if provided in query
    // check if this particular request is cached, if not, perform the query
    if (false === ($moxie_cached_request = get_transient('moxie_cached_request_' . json_encode($args)))) {
        $moxie_cached_request = new WP_Query($args);
        set_transient('moxie_cached_request_' . json_encode($args), $moxie_cached_request);
    }
    // prepare the object we want to send as response
    if ($moxie_cached_request->have_posts()) {
        while ($moxie_cached_request->have_posts()) {
            $moxie_cached_request->the_post();
            $id = get_the_ID();
            $movie_data[] = array('id' => $id, 'title' => get_the_title(), 'poster_url' => get_post_meta($id, 'moxie_press_poster_url', true), 'rating' => get_post_meta($id, 'moxie_press_rating', true), 'year' => get_post_meta($id, 'moxie_press_year', true), 'short_description' => get_post_meta($id, 'moxie_press_description', true), 'mdbid' => get_post_meta($id, 'moxie_press_mdbid', true));
        }
        wp_reset_postdata();
    }
    // send json data using built-in WP function
    wp_send_json(array('data' => $movie_data));
}
开发者ID:camilodelvasto,项目名称:MoxiePress,代码行数:35,代码来源:json-api.php

示例6: cache_in_progress

 function cache_in_progress($reportid)
 {
     global $tzobj;
     $r = intval(substr($reportid, 5));
     /* *** skip the 'users' and take the rest */
     $inprogress = get_transient('amr_users_cache_' . $r);
     if (!$inprogress) {
         $this->log_cache_event('Cache record, but no transient yet? ' . $reportid);
         return false;
     }
     $status = ausers_get_option('amr-users-cache-status');
     //var_dump($status);
     if (isset($status[$reportid]['start']) and !isset($status[$reportid]['end'])) {
         $now = time();
         $diff = $now - $status[$reportid]['start'];
         if ($diff > 60 * 5) {
             $d = date_create(strftime('%c', $status[$reportid]['start']));
             date_timezone_set($d, $tzobj);
             $text = sprintf(__('Report %s started %s ago', 'amr-users'), $reportid, human_time_diff($status[$reportid]['start'], time()));
             $text .= ' ' . __('Something may be wrong - delete cache status, try again, check server logs and/or memory limit', 'amr-users');
             $this->log_cache_event($text);
             $fun = '<a href="http://upload.wikimedia.org/wikipedia/commons/1/12/Apollo13-wehaveaproblem_edit_1.ogg" >' . __('Houston, we have a problem', 'amr-users') . '</a>';
             $text = $fun . '<br/>' . $text;
             amr_users_message($text);
             return false;
         } else {
             return true;
         }
     } else {
         return false;
     }
 }
开发者ID:rdelr011,项目名称:BOLO-Flier-Creator,代码行数:32,代码来源:ameta-cache.php

示例7: fix_in_wpadmin

 function fix_in_wpadmin($config, $force_all_checks = false)
 {
     $exs = new SelfTestExceptions();
     $fix_on_event = false;
     if (w3_is_multisite() && w3_get_blog_id() != 0) {
         if (get_transient('w3tc_config_changes') != ($md5_string = $config->get_md5())) {
             $fix_on_event = true;
             set_transient('w3tc_config_changes', $md5_string, 3600);
         }
     }
     // call plugin-related handlers
     foreach ($this->get_handlers($config) as $h) {
         try {
             $h->fix_on_wpadmin_request($config, $force_all_checks);
             if ($fix_on_event) {
                 $this->fix_on_event($config, 'admin_request');
             }
         } catch (SelfTestExceptions $ex) {
             $exs->push($ex);
         }
     }
     if (count($exs->exceptions()) > 0) {
         throw $exs;
     }
 }
开发者ID:gumbysgoo,项目名称:bestilblomster,代码行数:25,代码来源:AdminEnvironment.php

示例8: purge_transients

 function purge_transients($older_than = '7 days', $safemode = true)
 {
     global $wpdb;
     $older_than_time = strtotime('-' . $older_than);
     if ($older_than_time > time() || $older_than_time < 1) {
         return false;
     }
     $transients = $wpdb->get_col($wpdb->prepare("\n\t\t\t\t\tSELECT REPLACE(option_name, '_transient_timeout_', '') AS transient_name \n\t\t\t\t\tFROM {$wpdb->options} \n\t\t\t\t\tWHERE option_name LIKE '\\_transient\\_timeout\\__%%'\n\t\t\t\t\t\tAND option_value < %s\n\t\t\t", $older_than_time));
     if ($safemode) {
         foreach ($transients as $transient) {
             get_transient($transient);
         }
     } else {
         $options_names = array();
         foreach ($transients as $transient) {
             $options_names[] = '_transient_' . $transient;
             $options_names[] = '_transient_timeout_' . $transient;
         }
         if ($options_names) {
             $options_names = array_map(array($wpdb, 'escape'), $options_names);
             $options_names = "'" . implode("','", $options_names) . "'";
             $result = $wpdb->query("DELETE FROM {$wpdb->options} WHERE option_name IN ({$options_names})");
             if (!$result) {
                 return false;
             }
         }
     }
     return $transients;
 }
开发者ID:kubens,项目名称:Snippets,代码行数:29,代码来源:purge-transients.php

示例9: get_groupings

 /**
  * Retrive the list of groupings associated with a list id
  *
  * @param  string $list_id     List id for which groupings should be returned
  * @return array  $groups_data Data about the groups
  */
 public function get_groupings($list_id = '')
 {
     global $edd_options;
     if (!empty($edd_options['eddmc_api'])) {
         $grouping_data = get_transient('edd_mailchimp_groupings_' . $list_id);
         if (false === $grouping_data) {
             if (!class_exists('EDD_MailChimp_API')) {
                 require_once EDD_MAILCHIMP_PATH . '/includes/MailChimp.class.php';
             }
             $api = new EDD_MailChimp_API(trim($edd_options['eddmc_api']));
             $grouping_data = $api->call('lists/interest-groupings', array('id' => $list_id));
             set_transient('edd_mailchimp_groupings_' . $list_id, $grouping_data, 24 * 24 * 24);
         }
         $groups_data = array();
         if ($grouping_data && !isset($grouping_data->status)) {
             foreach ($grouping_data as $grouping) {
                 $grouping_id = $grouping->id;
                 $grouping_name = $grouping->name;
                 foreach ($grouping->groups as $groups) {
                     $group_name = $groups->name;
                     $groups_data["{$list_id}|{$grouping_id}|{$group_name}"] = $grouping_name . ' - ' . $group_name;
                 }
             }
         }
     }
     return $groups_data;
 }
开发者ID:EngageWP,项目名称:edd-mail-chimp,代码行数:33,代码来源:class-edd-mailchimp.php

示例10: videopress_get_video_details

/**
 * Get details about a specific video by GUID:
 *
 * @param $guid string
 * @return object
 */
function videopress_get_video_details($guid)
{
    if (!videopress_is_valid_guid($guid)) {
        return new WP_Error('bad-guid-format', __('Invalid Video GUID!', 'jetpack'));
    }
    $version = '1.1';
    $endpoint = sprintf('/videos/%1$s', $guid);
    $query_url = sprintf('https://public-api.wordpress.com/rest/v%1$s%2$s', $version, $endpoint);
    // Look for data in our transient. If nothing, let's make a new query.
    $data_from_cache = get_transient('jetpack_videopress_' . $guid);
    if (false === $data_from_cache) {
        $response = wp_remote_get(esc_url_raw($query_url));
        $data = json_decode(wp_remote_retrieve_body($response));
        // Cache the response for an hour.
        set_transient('jetpack_videopress_' . $guid, $data, HOUR_IN_SECONDS);
    } else {
        $data = $data_from_cache;
    }
    /**
     * Allow functions to modify fetched video details.
     *
     * This filter allows third-party code to modify the return data
     * about a given video.  It may involve swapping some data out or
     * adding new parameters.
     *
     * @since 4.0.0
     *
     * @param object $data The data returned by the WPCOM API. See: https://developer.wordpress.com/docs/api/1.1/get/videos/%24guid/
     * @param string $guid The GUID of the VideoPress video in question.
     */
    return apply_filters('videopress_get_video_details', $data, $guid);
}
开发者ID:automattic,项目名称:jetpack,代码行数:38,代码来源:utility-functions.php

示例11: wpl_instagram_response

/**
 * The API call
 */
function wpl_instagram_response($userid = null, $count = 6, $columns = 3)
{
    if (intval($userid) === 0) {
        return '<p>No user ID specified.</p>';
    }
    $transient_var = 'biw_' . $userid . '_' . $count;
    if (false === ($items = get_transient($transient_var))) {
        $response = wp_remote_get('https://api.instagram.com/v1/users/' . $userid . '/media/recent/?client_id=' . BIW_CLIENT_ID . '&count=' . esc_attr($count));
        $response_body = json_decode($response['body']);
        //echo '<pre>'; print_r( $response_body ); echo '</pre>';
        if ($response_body->meta->code !== 200) {
            return '<p>Incorrect user ID specified.</p>';
        }
        $items_as_objects = $response_body->data;
        $items = array();
        foreach ($items_as_objects as $item_object) {
            $item['link'] = $item_object->link;
            $item['src'] = $item_object->images->low_resolution->url;
            $items[] = $item;
        }
        set_transient($transient_var, $items, 60 * 60);
    }
    $output = '<ul class="photo-tiles large-block-grid-3 medium-block-grid-6 small-block-grid-3">';
    foreach ($items as $item) {
        $link = $item['link'];
        $image = $item['src'];
        $output .= '<li class="photo-tile"><a href="' . esc_url($link) . '"><img src="' . esc_url($image) . '" /></a></li>';
    }
    $output .= '</ul>';
    return $output;
}
开发者ID:craighays,项目名称:nsfhp,代码行数:34,代码来源:widget-instagram.php

示例12: wplms_update_message

 /**
  * Show Theme changes. Code adapted from W3 Total Cache.
  *
  * @return void
  */
 function wplms_update_message($args)
 {
     $transient_name = 'wplms_upgrade_notice_' . $args['Version'];
     if (false === ($upgrade_notice = get_transient($transient_name))) {
         $response = wp_remote_get('https://s3.amazonaws.com/WPLMS/readme.txt');
         if (!is_wp_error($response) && !empty($response['body'])) {
             // Output Upgrade Notice
             $matches = null;
             $regexp = '~==\\s*Upgrade Notice\\s*==\\s*=\\s*(.*)\\s*=(.*)(=\\s*' . preg_quote(WC_VERSION) . '\\s*=|$)~Uis';
             $upgrade_notice = '';
             if (preg_match($regexp, $response['body'], $matches)) {
                 $version = trim($matches[1]);
                 $notices = (array) preg_split('~[\\r\\n]+~', trim($matches[2]));
                 if (version_compare(WC_VERSION, $version, '<')) {
                     $upgrade_notice .= '<div class="wplms_plugin_upgrade_notice">';
                     foreach ($notices as $index => $line) {
                         $upgrade_notice .= wp_kses_post(preg_replace('~\\[([^\\]]*)\\]\\(([^\\)]*)\\)~', '<a href="${2}">${1}</a>', $line));
                     }
                     $upgrade_notice .= '</div> ';
                 }
             }
             set_transient($transient_name, $upgrade_notice, DAY_IN_SECONDS);
         }
     }
     echo wp_kses_post($upgrade_notice);
 }
开发者ID:emiisor,项目名称:diffhelper,代码行数:31,代码来源:wplms-install.php

示例13: prepare_items

 function prepare_items()
 {
     //First, lets decide how many records per page to show
     $per_page = 20;
     $columns = $this->get_columns();
     $hidden = array();
     $sortable = $this->get_sortable_columns();
     $this->_column_headers = array($columns, $hidden, $sortable);
     //$this->process_bulk_action();
     global $wpdb;
     global $aio_wp_security;
     $logged_in_users = AIOWPSecurity_Utility::is_multisite_install() ? get_site_transient('users_online') : get_transient('users_online');
     if ($logged_in_users !== FALSE) {
         foreach ($logged_in_users as $key => $val) {
             $userdata = get_userdata($val['user_id']);
             $username = $userdata->user_login;
             $val['username'] = $username;
             $logged_in_users[$key] = $val;
         }
     } else {
         $logged_in_users = array();
         //If no transient found set to empty array
     }
     $data = $logged_in_users;
     $current_page = $this->get_pagenum();
     $total_items = count($data);
     $data = array_slice($data, ($current_page - 1) * $per_page, $per_page);
     $this->items = $data;
     $this->set_pagination_args(array('total_items' => $total_items, 'per_page' => $per_page, 'total_pages' => ceil($total_items / $per_page)));
 }
开发者ID:bobz0r75,项目名称:budref,代码行数:30,代码来源:wp-security-list-logged-in-users.php

示例14: al_product_adder_admin_notices_styles

/**
 * Plugin compatibility checker
 *
 * Here current theme is checked for compatibility with WP PRODUCT ADDER.
 *
 * @version		1.1.2
 * @package		ecommerce-product-catalog/functions
 * @author 		Norbert Dreszer
 */
function al_product_adder_admin_notices_styles()
{
    if (current_user_can('activate_plugins')) {
        if (!is_advanced_mode_forced()) {
            $template = get_option('template');
            $integration_type = get_integration_type();
            if (!empty($_GET['hide_al_product_adder_support_check'])) {
                update_option('product_adder_theme_support_check', $template);
                return;
            }
            if (get_option('product_adder_theme_support_check') !== $template && current_user_can('delete_others_products')) {
                product_adder_theme_check_notice();
            }
        }
        if (is_ic_catalog_admin_page()) {
            $product_count = ic_products_count();
            if ($product_count > 5) {
                if (false === get_transient('implecode_hide_plugin_review_info')) {
                    implecode_plugin_review_notice();
                    set_transient('implecode_hide_plugin_translation_info', 1, WEEK_IN_SECONDS);
                } else {
                    if (false === get_transient('implecode_hide_plugin_translation_info') && !is_english_catalog_active()) {
                        implecode_plugin_translation_notice();
                    }
                }
            } else {
                if (false === get_transient('implecode_hide_plugin_review_info')) {
                    set_transient('implecode_hide_plugin_review_info', 1, WEEK_IN_SECONDS);
                }
            }
        }
    }
}
开发者ID:nanookYs,项目名称:orientreizen,代码行数:42,代码来源:theme-product_adder_support.php

示例15: fetch_feed

 function fetch_feed($username, $slice = 8)
 {
     $barcelona_remote_url = esc_url('http://instagram.com/' . trim(strtolower($username)));
     $barcelona_transient_key = 'barcelona_instagram_feed_' . sanitize_title_with_dashes($username);
     $slice = absint($slice);
     if (false === ($barcelona_result_data = get_transient($barcelona_transient_key))) {
         $barcelona_remote = wp_remote_get($barcelona_remote_url);
         if (is_wp_error($barcelona_remote) || 200 != wp_remote_retrieve_response_code($barcelona_remote)) {
             return new WP_Error('not-connected', esc_html__('Unable to communicate with Instagram.', 'barcelona'));
         }
         preg_match('#window\\.\\_sharedData\\s\\=\\s(.*?)\\;\\<\\/script\\>#', $barcelona_remote['body'], $barcelona_match);
         if (!empty($barcelona_match)) {
             $barcelona_data = json_decode(end($barcelona_match), true);
             if (is_array($barcelona_data) && isset($barcelona_data['entry_data']['ProfilePage'][0]['user']['media']['nodes'])) {
                 $barcelona_result_data = $barcelona_data['entry_data']['ProfilePage'][0]['user']['media']['nodes'];
             }
         }
         if (is_array($barcelona_result_data)) {
             set_transient($barcelona_transient_key, $barcelona_result_data, 60 * 60 * 2);
         }
     }
     if (empty($barcelona_result_data)) {
         return new WP_Error('no-images', esc_html__('Instagram did not return any images.', 'barcelona'));
     }
     return array_slice($barcelona_result_data, 0, $slice);
 }
开发者ID:yalmaa,项目名称:little-magazine,代码行数:26,代码来源:barcelona-instagram-feed.php


注:本文中的get_transient函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。