本文整理汇总了PHP中set_site_transient函数的典型用法代码示例。如果您正苦于以下问题:PHP set_site_transient函数的具体用法?PHP set_site_transient怎么用?PHP set_site_transient使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了set_site_transient函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get_ep_host
/**
* Retrieve the appropriate EP_HOST
*
* Looks at the defined EP_HOST or a backup global should the defined host failed.
* Priority is given to the EP_HOST constand with the backups only used when needed.
*
* @since 1.6
*
* @global array $ep_backup_host array of backup hosts
*
* @param bool $force Whether to force a new lookup or not
* @param bool $use_only_backups Forces the use of only the backup array, no others
*
* @return string|WP_Error the host to use or an error
*/
public function get_ep_host($force = false, $use_only_backups = false)
{
global $ep_backup_host;
// Delete the transient if we want to force a new good host lookup
if (true === $force) {
delete_site_transient('ep_last_good_host');
}
$last_good_host = get_site_transient('ep_last_good_host');
if ($last_good_host) {
return $last_good_host;
}
// If nothing is defined just return an error
if (!defined('EP_HOST') && !$ep_backup_host) {
return new WP_Error('elasticpress', __('No running host available.', 'elasticpress'));
}
$hosts = array();
if (defined('EP_HOST') && false === $use_only_backups) {
$hosts[] = EP_HOST;
}
// If no backups are defined just return the host
if ($ep_backup_host && is_array($ep_backup_host)) {
$hosts = array_merge($hosts, $ep_backup_host);
}
foreach ($hosts as $host) {
if (true === ep_elasticsearch_alive($host)) {
set_site_transient('ep_last_good_host', $host, apply_filters('ep_last_good_host_timeout', 3600));
return $host;
}
}
return new WP_Error('elasticpress', __('No running host available.', 'elasticpress'));
}
示例2: xu_get_transient
/**
* Get/Set transient.
*
* @param string $key Transient name. Should be 172 (40 on site) characters or less since WordPress will prefix the name.
* @param mixed $value Transient value. Expected to not be SQL-escaped. Can be callable value. Optional.
* @param int $expiration Time until expiration in seconds from now, or 0 for never expires. Default 0.
* @param bool $site Set to true if site transient. Default false.
*
* @return mixed
*/
function xu_get_transient($key, $value = null, $expiration = 0, $site = false)
{
if (!is_string($key)) {
return false;
}
$transient_value = $site ? get_site_transient($key) : get_transient($key);
// Return transient value if it exists or the return value if given value is null.
if ($transient_value || is_null($value)) {
return $transient_value;
}
// Support callable values.
if (is_callable($value)) {
$value = call_user_func($value);
// Return false if null value.
if (is_null($value)) {
return false;
}
}
if ($site) {
set_site_transient($key, $value, $expiration);
} else {
set_transient($key, $value, $expiration);
}
return $value;
}
示例3: instapageApiCall
public function instapageApiCall($service, $data = null, $endpoint = '')
{
if ($service === null) {
$service_parts = parse_url($_SERVER['REQUEST_URI']);
parse_str($url_parts['query'], $service_parts);
if (isset($service_parts['url'])) {
$service = $service_parts['url'];
}
}
$url = self::endpoint . '/ajax/services/' . $endpoint . $service;
$current_ver = self::getInstance()->includes['service']->pluginGet('Version');
$response = wp_remote_post($url, array('method' => 'POST', 'timeout' => 70, 'redirection' => 5, 'httpversion' => '1.0', 'blocking' => true, 'headers' => array(), 'body' => array('service-type' => 'Wordpress', 'service' => $_SERVER['SERVER_NAME'], 'version' => $current_ver, 'user_id' => get_option('instapage.user_id'), 'data' => $data), 'cookies' => array()));
if (is_wp_error($response)) {
$error_message = $response->get_error_message();
if (!empty($error_message)) {
throw new InstapageApiCallException($error_message);
} else {
throw new InstapageApiCallException('500 Internal Server Error');
}
}
$res = json_decode($response['body'], true);
if (!is_array($res) && !is_object($res)) {
throw new InstapageApiCallException('Instapage Services returned empty response.');
}
$data = new stdClass();
foreach ($res as $key => $val) {
$data->{$key} = $val;
}
if ($service == 'update-check') {
set_site_transient('instapage_latest_version', $data, 60 * 60 * 12);
}
return $data;
}
示例4: prli_get_main_message
function prli_get_main_message($message = '', $expiration = 1800)
{
global $prli_update;
// Set the default message
if (empty($message)) {
$message = __("Get started by <a href=\"?page=pretty-link&action=new\">" . "adding a URL</a> that you want to turn into a pretty link.<br/>" . "Come back to see how many times it was clicked.", 'pretty-link');
}
$messages = get_site_transient('_prli_messages');
// if the messages array has expired go back to the mothership
if (!$messages) {
$remote_controller = $prli_update->pro_is_installed_and_authorized() ? 'prlipro' : 'prli';
$message_mothership = "http://prettylinkpro.com/index.php?controller={$remote_controller}&action=json_messages";
if (!class_exists('WP_Http')) {
include_once ABSPATH . WPINC . '/class-http.php';
}
$http = new WP_Http();
$response = $http->request($message_mothership);
if (isset($response) and is_array($response) and isset($response['body']) and !empty($response['body'])) {
$messages = json_decode($response['body']);
} else {
$messages = array($message);
}
set_site_transient("_prli_messages", $messages, $expiration);
}
if (empty($messages) or !$messages or !is_array($messages)) {
return $message;
} else {
return $messages[array_rand($messages)];
}
}
示例5: widget
/**
* @param array $args
* @param array $instance
*/
function widget($args, $instance)
{
extract($args);
$user = esc_attr($instance['user']);
$title = esc_attr($instance['title']);
$number = (int) esc_attr($instance['number']) > 0 ? esc_attr($instance['number']) : 5;
$before_widget = str_replace('class="', 'class="widget_twitter_tweets ', $before_widget);
$title = str_replace('class="', 'class="widget_twitter_tweets ', $before_title) . $title . $after_title;
$title = $before_title . $title . $after_title;
// wp_enqueue_script(
// 'fw-theme-twitter-widget',
// get_template_directory_uri() . '/inc/widgets/twitter/static/js/scripts.js',
// array( 'jquery' ),
// '1.0'
// );
$tweets = get_site_transient('scratch_tweets_' . $user . '_' . $number);
if (empty($tweets)) {
/* @var $connection TwitterOAuth */
$connection = fw_ext_social_twitter_get_connection();
$tweets = $connection->get("https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=" . $user . "&count=" . $number);
set_site_transient('scratch_tweets_' . $user . '_' . $number, $tweets, 12 * HOUR_IN_SECONDS);
}
$view_path = dirname(__FILE__) . '/views/widget.php';
echo fw_render_view($view_path, compact('before_widget', 'title', 'tweets', 'number', 'after_widget'));
}
示例6: recheck
public function recheck()
{
$time_key = $this->slug . '-plugin_updater_api_request_last_checked';
$entity = new WPFront_User_Role_Editor_Entity_Options();
$entity->update_option($time_key, 0);
set_site_transient('update_plugins', null);
}
示例7: queue_old_update
function queue_old_update($transient, $force = false)
{
if (method_exists('FrmUpdate', 'queue_addon_update')) {
global $frm_update;
$plugin = $this;
return $frm_update->queue_addon_update($transient, $plugin, $force);
}
if (!is_object($transient) or empty($transient->checked)) {
return $transient;
}
global $frmpro_is_installed;
if ($frmpro_is_installed) {
$expired = true;
if (!$force) {
$update = get_site_transient($this->pro_last_checked_store);
if ($update) {
$expired = false;
}
}
if (!$update) {
$update = $this->get_current_info($transient->checked[$this->plugin_name], $force, $this->plugin_nicename);
}
if ($update and !empty($update)) {
$update = (object) $update;
$transient->response[$this->plugin_name] = $update;
//only check periodically
if ($expired) {
set_site_transient($this->pro_last_checked_store, $update, $this->pro_check_interval);
}
}
}
return $transient;
}
示例8: rocket_check_update
function rocket_check_update()
{
if (defined('WP_INSTALLING')) {
return false;
}
$plugin_folder = plugin_basename(dirname(WP_ROCKET_FILE));
$plugin_file = basename(WP_ROCKET_FILE);
$version = true;
$plugin_transient = null;
$response = wp_remote_get(WP_ROCKET_WEB_CHECK, array('timeout' => 30));
set_site_transient('update_wprocket', time());
if (!is_a($response, 'WP_Error') && strlen($response['body']) > 32) {
list($version, $url) = explode('|', $response['body']);
if (version_compare($version, WP_ROCKET_VERSION, '<=')) {
return false;
}
$plugin_transient = get_site_transient('update_plugins');
$temp_array = array('slug' => $plugin_folder, 'plugin' => $plugin_folder . '/wp-rocket.php', 'new_version' => $version, 'url' => 'http://wp-rocket.me', 'package' => $url);
} else {
$temp_array = array();
}
if ($plugin_transient) {
$temp_object = (object) $temp_array;
$plugin_transient->response[$plugin_folder . '/' . $plugin_file] = $temp_object;
set_site_transient('update_plugins', $plugin_transient);
} else {
return false;
}
}
示例9: checkForUpdates
public function checkForUpdates()
{
// This errors out when creating Shortcake UIs
if (!is_array($this->extensions)) {
return;
}
foreach ($this->extensions as $extension) {
// Only check for updates every 3 hours
if (!is_multisite()) {
$updateChecker = get_transient(self::UPDATE_CHECKER_TRANSIENT . $extension['slug']);
} else {
$updateChecker = get_site_transient(self::UPDATE_CHECKER_TRANSIENT . $extension['slug']);
}
if (false !== $updateChecker && !self::DEBUG) {
continue;
}
// retrieve our license key from the DB
$licenseKey = get_site_option('sandwich_license_' . $extension['slug']);
if (empty($licenseKey)) {
continue;
}
// setup the updater
$eddUpdater = new PBS_EDD_SL_Plugin_Updater($extension['store_url'], $extension['file'], array('version' => $extension['version'], 'license' => $licenseKey, 'item_name' => $extension['name'], 'author' => $extension['author']));
if (!is_multisite()) {
set_transient(self::UPDATE_CHECKER_TRANSIENT . $extension['slug'], '1', 3 * HOUR_IN_SECONDS);
} else {
set_site_transient(self::UPDATE_CHECKER_TRANSIENT . $extension['slug'], '1', 3 * HOUR_IN_SECONDS);
}
}
}
示例10: beans_updater
/**
* Retrieve product data from Beans REST API.
*
* Data are cached in a 24 hours transients and will be returned if found to avoid long loading time.
*
* @ignore
*/
function beans_updater($value)
{
$data = get_site_transient('beans_updater');
$theme = wp_get_theme('tm-beans');
if (!$theme->exists()) {
return $value;
}
$current_version = $theme->get('Version');
// Query Beans REST API if the transient is expired.
if (empty($data)) {
$args = array('timeout' => 15, 'sslverify' => false);
$response = wp_remote_get('http://www.getbeans.io/rest-api/', $args);
if (is_wp_error($response)) {
return $value;
}
// Retrieve data from the body and decode json format.
$data = json_decode(wp_remote_retrieve_body($response), true);
// Stop here if the is an error.
if (isset($data['error'])) {
// Set temporary transient.
set_site_transient('beans_updater', array('version' => $current_version), 30 * MINUTE_IN_SECONDS);
return $value;
}
set_site_transient('beans_updater', $data, 24 * HOUR_IN_SECONDS);
}
// Return data if Beans is not up to date.
if (version_compare($current_version, beans_get('version', $data), '<')) {
$value->response[$data['path']] = array('slug' => $data['slug'], 'name' => $data['name'], 'url' => $data['changelog_url'], 'package' => $data['download_url'], 'new_version' => $data['version'], 'tested' => $data['tested'], 'requires' => $data['requires']);
return $value;
}
return $value;
}
示例11: __new_feed
/**
* Provided a URL, will return an array representing the feed item for that
* URL. A feed item contains the content, url, simplepie object, and failure
* status for the URL passed. Handles caching of content requests.
*
* @return array
* @author Jared Lang
* */
protected static function __new_feed($url)
{
require_once ABSPATH . '/wp-includes/class-simplepie.php';
$simplepie = null;
$failed = False;
$cache_key = 'feedmanager-' . md5($url);
$content = get_site_transient($cache_key);
if ($content === False) {
$content = @file_get_contents($url);
if ($content === False) {
$failed = True;
$content = null;
error_log('FeedManager failed to fetch data using url of ' . $url);
} else {
set_site_transient($cache_key, $content, self::$cache_length);
}
}
if ($content) {
$simplepie = new SimplePie();
$simplepie->set_raw_data($content);
$simplepie->init();
$simplepie->handle_content_type();
if ($simplepie->error) {
error_log($simplepie->error);
$simplepie = null;
$failed = True;
}
} else {
$failed = True;
}
return array('content' => $content, 'url' => $url, 'simplepie' => $simplepie, 'failed' => $failed);
}
示例12: generate_maths_question
function generate_maths_question()
{
global $aio_wp_security;
//For now we will only do plus, minus, multiplication
$equation_string = '';
$operator_type = array('+', '−', '×');
$operand_display = array('word', 'number');
//let's now generate an equation
$operator = $operator_type[rand(0, 2)];
if ($operator === '×') {
//Don't make the question too hard if multiplication
$first_digit = rand(1, 5);
$second_digit = rand(1, 5);
} else {
$first_digit = rand(1, 20);
$second_digit = rand(1, 20);
}
if ($operand_display[rand(0, 1)] == 'word') {
$first_operand = $this->number_word_mapping($first_digit);
} else {
$first_operand = $first_digit;
}
if ($operand_display[rand(0, 1)] == 'word') {
$second_operand = $this->number_word_mapping($second_digit);
} else {
$second_operand = $second_digit;
}
//Let's caluclate the result and construct the equation string
if ($operator === '+') {
//Addition
$result = $first_digit + $second_digit;
$equation_string .= $first_operand . ' ' . $operator . ' ' . $second_operand . ' = ';
} else {
if ($operator === '−') {
//Subtraction
//If we are going to be negative let's swap operands around
if ($first_digit < $second_digit) {
$equation_string .= $second_operand . ' ' . $operator . ' ' . $first_operand . ' = ';
$result = $second_digit - $first_digit;
} else {
$equation_string .= $first_operand . ' ' . $operator . ' ' . $second_operand . ' = ';
$result = $first_digit - $second_digit;
}
} elseif ($operator === '×') {
//Multiplication
$equation_string .= $first_operand . ' ' . $operator . ' ' . $second_operand . ' = ';
$result = $first_digit * $second_digit;
}
}
//Let's encode correct answer
$captcha_secret_string = $aio_wp_security->configs->get_value('aiowps_captcha_secret_key');
$current_time = time();
$enc_result = base64_encode($current_time . $captcha_secret_string . $result);
$random_str = AIOWPSecurity_Utility::generate_alpha_numeric_random_string(10);
AIOWPSecurity_Utility::is_multisite_install() ? set_site_transient('aiowps_captcha_string_info_' . $random_str, $enc_result, 30 * 60) : set_transient('aiowps_captcha_string_info_' . $random_str, $enc_result, 30 * 60);
$equation_string .= '<input type="hidden" name="aiowps-captcha-string-info" id="aiowps-captcha-string-info" value="' . $random_str . '" />';
$equation_string .= '<input type="hidden" name="aiowps-captcha-temp-string" id="aiowps-captcha-temp-string" value="' . $current_time . '" />';
$equation_string .= '<input type="text" size="2" id="aiowps-captcha-answer" name="aiowps-captcha-answer" value="" />';
return $equation_string;
}
示例13: plugins_api
/**
* Put changelog in plugins_api, return WP.org data as appropriate
*
* @since 2.0.0
*/
public function plugins_api($false, $action, $response)
{
if (!('plugin_information' === $action)) {
return $false;
}
$wp_repo_data = get_site_transient('ghu-' . md5($response->slug . 'php'));
if (!$wp_repo_data) {
$wp_repo_data = wp_remote_get('http://api.wordpress.org/plugins/info/1.0/' . $response->slug . '.php');
set_site_transient('ghu-' . md5($response->slug . 'php'), $wp_repo_data, 12 * HOUR_IN_SECONDS);
}
if (!empty($wp_repo_data['body'])) {
$wp_repo_body = unserialize($wp_repo_data['body']);
if (is_object($wp_repo_body)) {
$response = $wp_repo_body;
}
}
foreach ((array) $this->config as $plugin) {
if ($response->slug === $plugin->repo) {
$response->slug = $plugin->slug;
$response->plugin_name = $plugin->name;
$response->author = $plugin->author;
$response->homepage = $plugin->uri;
$response->version = $plugin->remote_version;
$response->sections = $plugin->sections;
$response->requires = $plugin->requires;
$response->tested = $plugin->tested;
$response->downloaded = $plugin->downloaded;
$response->last_updated = $plugin->last_updated;
$response->rating = $plugin->rating;
$response->num_ratings = $plugin->num_ratings;
//$response->download_link = $plugin->download_link;
}
}
return $response;
}
示例14: wp_credits
/**
* Retrieve the contributor credits.
*
* @global string $wp_version The current WordPress version.
*
* @since 3.2.0
*
* @return array|false A list of all of the contributors, or false on error.
*/
function wp_credits() {
global $wp_version;
$locale = get_locale();
$results = get_site_transient( 'wordpress_credits_' . $locale );
if ( ! is_array( $results )
|| false !== strpos( $wp_version, '-' )
|| ( isset( $results['data']['version'] ) && strpos( $wp_version, $results['data']['version'] ) !== 0 )
) {
$response = wp_remote_get( "http://api.wordpress.org/core/credits/1.1/?version=$wp_version&locale=$locale" );
if ( is_wp_error( $response ) || 200 != wp_remote_retrieve_response_code( $response ) )
return false;
$results = json_decode( wp_remote_retrieve_body( $response ), true );
if ( ! is_array( $results ) )
return false;
set_site_transient( 'wordpress_credits_' . $locale, $results, DAY_IN_SECONDS );
}
return $results;
}
示例15: _get_framework_latest_version
/**
* {@inheritdoc}
* @internal
*/
public function _get_framework_latest_version($force_check)
{
$user_slash_repo = fw()->manifest->get($this->manifest_key);
if (empty($user_slash_repo)) {
return false;
}
if (!preg_match($this->manifest_key_regex, $user_slash_repo)) {
return new WP_Error('fw_ext_update_github_framework_manifest_invalid', __('Framework manifest has invalid "github_update" parameter. Please use "user/repo" format.', 'fw'));
}
$theme_id = preg_replace('[^a-z0-9_]', '_', fw()->theme->manifest->get_id());
$transient_id = 'fw_ext_update_gh_' . $theme_id . '_fw';
// this should be 45 characters or less
if ($force_check) {
delete_site_transient($transient_id);
} else {
$cache = get_site_transient($transient_id);
if ($cache !== false && isset($cache[$user_slash_repo])) {
return $cache[$user_slash_repo];
}
}
$latest_version = $this->fetch_latest_version($user_slash_repo);
if (empty($latest_version)) {
return new WP_Error(sprintf(__('Failed to fetch framework latest version from github "%s".', 'fw'), $user_slash_repo));
}
if (is_wp_error($latest_version)) {
return $latest_version;
}
set_site_transient($transient_id, array($user_slash_repo => $latest_version), $this->transient_expiration);
return $latest_version;
}