本文整理汇总了PHP中set_transient函数的典型用法代码示例。如果您正苦于以下问题:PHP set_transient函数的具体用法?PHP set_transient怎么用?PHP set_transient使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了set_transient函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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;
}
示例2: 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;
}
}
}
}
示例3: smart_coupon_activate
/**
* Database changes required for Smart Coupons
*
* Add option 'smart_coupon_email_subject' if not exists
* Enable 'Auto Generation' for Store Credit (discount_type: 'smart_coupon') not having any customer_email
* Disable 'apply_before_tax' for all Store Credit (discount_type: 'smart_coupon')
*/
function smart_coupon_activate()
{
global $wpdb, $blog_id;
if (is_multisite()) {
$blog_ids = $wpdb->get_col("SELECT blog_id FROM {$wpdb->blogs}", 0);
} else {
$blog_ids = array($blog_id);
}
if (!get_option('smart_coupon_email_subject')) {
add_option('smart_coupon_email_subject');
}
foreach ($blog_ids as $blog_id) {
if (file_exists(WP_PLUGIN_DIR . '/woocommerce/woocommerce.php') && is_plugin_active('woocommerce/woocommerce.php')) {
$wpdb_obj = clone $wpdb;
$wpdb->blogid = $blog_id;
$wpdb->set_prefix($wpdb->base_prefix);
$query = "SELECT postmeta.post_id FROM {$wpdb->prefix}postmeta as postmeta WHERE postmeta.meta_key = 'discount_type' AND postmeta.meta_value = 'smart_coupon' AND postmeta.post_id IN\n\t\t\t\t\t(SELECT p.post_id FROM {$wpdb->prefix}postmeta AS p WHERE p.meta_key = 'customer_email' AND p.meta_value = 'a:0:{}') ";
$results = $wpdb->get_col($query);
foreach ($results as $result) {
update_post_meta($result, 'auto_generate_coupon', 'yes');
}
// To disable apply_before_tax option for Gift Certificates / Store Credit.
$post_id_tax_query = "SELECT post_id FROM {$wpdb->prefix}postmeta WHERE meta_key = 'discount_type' AND meta_value = 'smart_coupon'";
$tax_post_ids = $wpdb->get_col($post_id_tax_query);
foreach ($tax_post_ids as $tax_post_id) {
update_post_meta($tax_post_id, 'apply_before_tax', 'no');
}
$wpdb = clone $wpdb_obj;
}
}
if (!is_network_admin() && !isset($_GET['activate-multi'])) {
set_transient('_smart_coupons_activation_redirect', 1, 30);
}
}
示例4: mm_ab_test_inclusion_none
function mm_ab_test_inclusion_none()
{
if (is_admin() && false === get_transient('mm_test', false)) {
$duration = WEEK_IN_SECONDS * 4;
set_transient('mm_test', array('key' => 'none'), $duration);
}
}
示例5: edd_create_protection_files
/**
* Creates blank index.php and .htaccess files
*
* This function runs approximately once per month in order to ensure all folders
* have their necessary protection files
*
* @since 1.1.5
*
* @param bool $force
* @param bool $method
*/
function edd_create_protection_files($force = false, $method = false)
{
if (false === get_transient('edd_check_protection_files') || $force) {
$upload_path = edd_get_upload_dir();
// Make sure the /edd folder is created
wp_mkdir_p($upload_path);
// Top level .htaccess file
$rules = edd_get_htaccess_rules($method);
if (edd_htaccess_exists()) {
$contents = @file_get_contents($upload_path . '/.htaccess');
if ($contents !== $rules || !$contents) {
// Update the .htaccess rules if they don't match
@file_put_contents($upload_path . '/.htaccess', $rules);
}
} elseif (wp_is_writable($upload_path)) {
// Create the file if it doesn't exist
@file_put_contents($upload_path . '/.htaccess', $rules);
}
// Top level blank index.php
if (!file_exists($upload_path . '/index.php') && wp_is_writable($upload_path)) {
@file_put_contents($upload_path . '/index.php', '<?php' . PHP_EOL . '// Silence is golden.');
}
// Now place index.php files in all sub folders
$folders = edd_scan_folders($upload_path);
foreach ($folders as $folder) {
// Create index.php, if it doesn't exist
if (!file_exists($folder . 'index.php') && wp_is_writable($folder)) {
@file_put_contents($folder . 'index.php', '<?php' . PHP_EOL . '// Silence is golden.');
}
}
// Check for the files once per day
set_transient('edd_check_protection_files', true, 3600 * 24);
}
}
示例6: mashsb_install
/**
* Install
*
* Runs on plugin install to populates the settings fields for those plugin
* pages. After successful install, the user is redirected to the MASHSB Welcome
* screen.
*
* @since 2.0
* @global $wpdb
* @global $mashsb_options
* @global $wp_version
* @return void
*/
function mashsb_install()
{
global $wpdb, $mashsb_options, $wp_version;
// Add Upgraded From Option
$current_version = get_option('mashsb_version');
if ($current_version) {
update_option('mashsb_version_upgraded_from', $current_version);
}
// Update the current version
update_option('mashsb_version', MASHSB_VERSION);
// Add plugin installation date and variable for rating div
add_option('mashsb_installDate', date('Y-m-d h:i:s'));
add_option('mashsb_RatingDiv', 'no');
if (!get_option('mashsb_update_notice')) {
add_option('mashsb_update_notice', 'no');
}
/* Setup some default options
* Store our initial social networks in separate option row.
* For easier modification and to prevent some trouble
*/
$networks = array('Facebook', 'Twitter', 'Subscribe');
if (is_plugin_inactive('mashshare-networks/mashshare-networks.php')) {
update_option('mashsb_networks', $networks);
}
// Bail if activating from network, or bulk
if (is_network_admin() || isset($_GET['activate-multi'])) {
return;
}
// Add the transient to redirect / not for multisites
set_transient('_mashsb_activation_redirect', true, 30);
}
示例7: sendWPRCRequestWithRetries
/**
* Send request to the WPRC server only with retries
*
* @param string method
* @param mixed arguments to send
*/
public function sendWPRCRequestWithRetries($method, $args, $timeout = 5)
{
$url = WPRC_SERVER_URL;
$send_result = false;
$failed = 0;
$timer = get_transient('wprc_report_failed_timer');
if ($timer != false && $timer != '' && $timer != null) {
$timer = intval($timer);
} else {
$timer = 0;
}
$timenow = time();
if ($timer - $timenow > 0) {
return false;
}
// discard report
while ($send_result === false && $failed < 2) {
$send_result = $this->sendRequest($method, $url, $args, $timeout);
if ($send_result === false) {
$failed++;
if ($failed < 2) {
usleep(rand(100, 300));
}
// wait 1 to 3 seconds
}
}
if ($send_result === false) {
set_transient('wprc_report_failed_timer', time() + 5 * 60 * 60);
} else {
// reset flags
set_transient('wprc_report_failed_timer', 0);
}
return $send_result;
}
示例8: bbconnect_create_search_post
function bbconnect_create_search_post()
{
// RUN A SECURITY CHECK
if (!wp_verify_nonce($_POST['bbconnect_report_nonce'], 'bbconnect-report-nonce')) {
die('terribly sorry.');
}
global $current_user;
if (!empty($_POST)) {
$post = array('post_content' => serialize($_POST['data']['search']), 'post_title' => $_POST['data']['postTitle'], 'post_status' => 'publish', 'post_type' => 'savedsearch', 'post_author' => $current_user->ID);
$wp_error = wp_insert_post($post, $wp_error);
if (!is_array($wp_error)) {
add_post_meta($wp_error, 'private', $_POST['data']['privateV']);
add_post_meta($wp_error, 'segment', $_POST['data']['segment']);
add_post_meta($wp_error, 'category', $_POST['data']['category']);
if (false === $recently_saved) {
$recently_saved = array();
}
set_transient('bbconnect_' . $current_user->ID . '_last_saved', $wp_error, 3600);
echo '<div class="updated update-nag" style="width:95%; border-left: 4px solid #7ad03a;"><p>Search has been saved as <a href="/post.php?post=' . $wp_error . '&action=edit">savedsearch-' . $wp_error . '</a></p></div>' . "\n";
} else {
echo '<div class="updated"><p>Search has not been saved' . var_dump($wp_error) . '</a></p></div>' . "\n";
}
}
die;
}
示例9: 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;
}
示例10: add_notice
/**
* @see wm_add_notice
*/
public static function add_notice($message, $type = 'info', $title = null, $backtrace = false)
{
$message = rtrim(ucfirst(trim((string) $message)), '.') . '.';
$content = wpautop($title ? "<strong class=\"wm-notice-title\">{$title}</strong><br />{$message}" : $message);
if (false !== $backtrace) {
if (is_array($backtrace)) {
$content .= self::get_backtrace($backtrace);
} else {
if ($stack = array_slice(debug_backtrace(), 2)) {
if (true === $backtrace) {
$content .= "<ol start=\"0\" class=\"wm-notice-backtrace\">";
foreach ($stack as $i => $backtrace) {
$content .= "<li>" . self::get_backtrace($backtrace) . "</li>";
}
$content .= "</ol>";
} else {
if (isset($stack[$backtrace])) {
$content .= self::get_backtrace($stack[$backtrace]);
}
}
}
}
}
self::$notices[] = "<div class=\"wm-notice notice {$type}\">{$content}</div>";
// Cache alerts until they're shown
set_transient('wm_notices', self::$notices);
}
示例11: affiliate_wp_install
function affiliate_wp_install()
{
// Create affiliate caps
$roles = new Affiliate_WP_Capabilities();
$roles->add_caps();
$affiliate_wp_install = new stdClass();
$affiliate_wp_install->affiliates = new Affiliate_WP_DB_Affiliates();
$affiliate_wp_install->affiliate_meta = new Affiliate_WP_Affiliate_Meta_DB();
$affiliate_wp_install->referrals = new Affiliate_WP_Referrals_DB();
$affiliate_wp_install->visits = new Affiliate_WP_Visits_DB();
$affiliate_wp_install->creatives = new Affiliate_WP_Creatives_DB();
$affiliate_wp_install->settings = new Affiliate_WP_Settings();
$affiliate_wp_install->affiliates->create_table();
$affiliate_wp_install->affiliate_meta->create_table();
$affiliate_wp_install->referrals->create_table();
$affiliate_wp_install->visits->create_table();
$affiliate_wp_install->creatives->create_table();
if (!get_option('affwp_is_installed')) {
$affiliate_area = wp_insert_post(array('post_title' => __('Affiliate Area', 'affiliate-wp'), 'post_content' => '[affiliate_area]', 'post_status' => 'publish', 'post_author' => 1, 'post_type' => 'page', 'comment_status' => 'closed'));
$options = $affiliate_wp_install->settings->get_all();
$options['affiliates_page'] = $affiliate_area;
update_option('affwp_settings', $options);
}
update_option('affwp_is_installed', '1');
update_option('affwp_version', AFFILIATEWP_VERSION);
// Clear rewrite rules
flush_rewrite_rules();
// Bail if activating from network, or bulk
if (is_network_admin() || isset($_GET['activate-multi'])) {
return;
}
// Add the transient to redirect
set_transient('_affwp_activation_redirect', true, 30);
}
示例12: 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);
}
示例13: x_demo_content_set_stage_completed
function x_demo_content_set_stage_completed($stage)
{
$transient = get_transient('x_demo_content_stage');
$stages = is_array($transient) ? $transient : array();
$stages[$stage] = true;
set_transient('x_demo_content_stage', $stages);
}
示例14: 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;
}
示例15: cp
/**
* s2Member's PayPal IPN handler (inner processing routine).
*
* @package s2Member\PayPal
* @since 110720
*
* @param array $vars Required. An array of defined variables passed by {@link s2Member\PayPal\c_ws_plugin__s2member_paypal_notify_in::paypal_notify()}.
* @return array|bool The original ``$paypal`` array passed in (extracted) from ``$vars``, or false when conditions do NOT apply.
*/
public static function cp($vars = array())
{
extract($vars, EXTR_OVERWRITE | EXTR_REFS);
// Extract all vars passed in from: ``c_ws_plugin__s2member_paypal_notify_in::paypal_notify()``.
if (!empty($paypal["txn_type"]) && preg_match("/^virtual_terminal\$/i", $paypal["txn_type"])) {
foreach (array_keys(get_defined_vars()) as $__v) {
$__refs[$__v] =& ${$__v};
}
do_action("ws_plugin__s2member_during_paypal_notify_before_virtual_terminal", get_defined_vars());
unset($__refs, $__v);
if (!get_transient($transient_ipn = "s2m_ipn_" . md5("s2member_transient_" . $_paypal_s)) && set_transient($transient_ipn, time(), 31556926 * 10)) {
$paypal["s2member_log"][] = "s2Member `txn_type` identified as ( `virtual_terminal` ).";
$processing = $during = true;
// Yes, we ARE processing this.
$paypal["s2member_log"][] = "The `txn_type` does not require any action on the part of s2Member.";
foreach (array_keys(get_defined_vars()) as $__v) {
$__refs[$__v] =& ${$__v};
}
do_action("ws_plugin__s2member_during_paypal_notify_during_virtual_terminal", get_defined_vars());
unset($__refs, $__v);
} else {
$paypal["s2member_log"][] = "Not processing. Duplicate IPN.";
$paypal["s2member_log"][] = "s2Member `txn_type` identified as ( `virtual_terminal` ).";
$paypal["s2member_log"][] = "Duplicate IPN. Already processed. This IPN will be ignored.";
}
foreach (array_keys(get_defined_vars()) as $__v) {
$__refs[$__v] =& ${$__v};
}
do_action("ws_plugin__s2member_during_paypal_notify_after_virtual_terminal", get_defined_vars());
unset($__refs, $__v);
return apply_filters("c_ws_plugin__s2member_paypal_notify_in_virtual_terminal", $paypal, get_defined_vars());
} else {
return apply_filters("c_ws_plugin__s2member_paypal_notify_in_virtual_terminal", false, get_defined_vars());
}
}