public function __construct() { // Objects $this->oBase64 = new FetchTweets_Base64(); // For transient (cache) renewal events add_action('fetch_tweets_action_transient_renewal', array($this, '_replyToRenewTransients')); // For transient (cache) formatting events - adds oEmbed elements. add_action('fetch_tweets_action_transient_add_oembed_elements', array($this, '_replyToAddOEmbedElements')); // For SimplePie cache renewal events add_action('fetch_tweets_action_simplepie_renew_cache', array($this, '_replyToRenewSimplePieCaches')); // This must be called after the above action hooks are added. if ('intense' == $GLOBALS['oFetchTweets_Option']->aOptions['cache_settings']['caching_mode']) { new FetchTweets_Cron(apply_filters('fetch_tweets_filter_plugin_cron_actions', array('fetch_tweets_action_transient_renewal', 'fetch_tweets_action_transient_add_oembed_elements', 'fetch_tweets_action_simplepie_renew_cache'))); } else { if (FetchTweets_Cron::isBackground()) { exit; } } // Redirects if (isset($_GET['fetch_tweets_link']) && $_GET['fetch_tweets_link']) { $_oRedirect = new FetchTweets_Redirects(); $_oRedirect->go($_GET['fetch_tweets_link']); // will exit there. } // Draw the cached image. if (isset($_GET['fetch_tweets_image']) && $_GET['fetch_tweets_image'] && is_user_logged_in()) { $_oImageLoader = new FetchTweets_ImageHandler('FTWS'); $_oImageLoader->draw($_GET['fetch_tweets_image']); exit; } // For the activation hook add_action('fetch_tweets_action_setup_transients', array($this, '_replyToSetUpTransients')); }
public function _replyToUpdateCacheItems() { if (null !== self::$_bUpdateCacheCalled) { return; } self::$_bUpdateCacheCalled = true; if (empty($this->arrExpiredTransientsRequestURIs)) { return; } // Perform multi-dimensional array_unique() // @deprecated As of v2.3.5 the request URI is set to the key, so it is already unique by default. // $this->arrExpiredTransientsRequestURIs = array_map( "unserialize", array_unique( array_map( "serialize", $this->arrExpiredTransientsRequestURIs ) ) ); $_iScheduled = 0; foreach ($this->arrExpiredTransientsRequestURIs as $_aExpiredCacheRequest) { /* the structure of $_aExpiredCacheRequest = array( 'URI' => the API request URI 'key' => the array key that holds the result. e.g. for search results, the 'statuses' key holds the fetched tweets. 'rate_limit_status_key' => the array holding the representation of the rate limit status dimensional key. */ // Check if the URI key holds a valid url. if (!filter_var($_aExpiredCacheRequest['URI'], FILTER_VALIDATE_URL)) { continue; } // Schedules the action to run in the background with WP Cron. // If already scheduled, skip. $_aArgs = array($_aExpiredCacheRequest); if (wp_next_scheduled('fetch_tweets_action_transient_renewal', $_aArgs)) { continue; } wp_schedule_single_event(time(), 'fetch_tweets_action_transient_renewal', $_aArgs); $_iScheduled++; } if (!$_iScheduled) { return; } // Call the background process. if ('intense' == $this->oOption->aOptions['cache_settings']['caching_mode']) { FetchTweets_Cron::see(); return; } wp_remote_get(site_url("/wp-cron.php"), array('timeout' => 0.01, 'sslverify' => false)); }
/** * Accesses the site in the background at the end of the script execution. * * This is used to trigger cron events in the background and sets a static flag so that it ensures it is done only once per page load. * * @since 1.0.0 */ public static function see($aGet = array(), $fIgnoreLock = false) { if (isset($_GET['doing_wp_cron'])) { return; } // WP Cron if (isset($GLOBALS['pagenow']) && $GLOBALS['pagenow'] == 'admin-ajax.php') { return; } // WP Heart-beat API // Ensures the task is done only once in a page load. static $_bIsCalled; if ($_bIsCalled) { return; } $_bIsCalled = true; // Store the static properties. self::$_fIgnoreLock = $fIgnoreLock ? $fIgnoreLock : self::$_fIgnoreLock; self::$_aGet = (array) $aGet + self::$_aGet; $_sSelfClassName = get_class(); if (did_action('shutdown')) { self::_replyToAccessSite(); return; // important as what the action has performed does not mean the action never will be fired again. } add_action('shutdown', "{$_sSelfClassName}::_replyToAccessSite", 999); // do not pass self::_replyToAccessSite. }