コード例 #1
0
 protected function handleCustomActions()
 {
     if (!isset($_GET['custom_action'], $_GET['nonce'], $_GET['post'])) {
         return;
     }
     $_sNonce = AmazonAutoLinks_WPUtility::getTransient('AAL_Nonce_' . $_GET['nonce']);
     if (false === $_sNonce) {
         add_action('admin_notices', array($this, 'replyToNotifyNonceFailed'));
         return;
     }
     AmazonAutoLinks_WPUtility::deleteTransient('AAL_Nonce_' . $_GET['nonce']);
     // Currently only the status toggle is supported.
     if ('toggle_status' === $_GET['custom_action'] && $_GET['post']) {
         $_aUnitIDs = get_post_meta($_GET['post'], 'unit_ids', true);
         // if this field is empty, the post must be the wrong post type.
         if (empty($_aUnitIDs)) {
             return;
         }
         $_bIsEnabled = get_post_meta($_GET['post'], 'status', true);
         update_post_meta($_GET['post'], 'status', !$_bIsEnabled);
     }
 }
コード例 #2
0
 /**
  * A wrapper method for the get_transient() function.
  * 
  * This method does retrieves the transient with the given transient key. In addition, it checks if it is an array; otherwise, it makes it an array.
  * 
  * @access          public
  * @since           2.0.0
  * @since           3       Changed to use a custom database.
  * @remark          The scope is public as the event method uses it.
  */
 public function getCache($sTransientKey)
 {
     if ($this->bUseCacheTable) {
         $_oCacheTable = new AmazonAutoLinks_DatabaseTable_request_cache(AmazonAutoLinks_Registry::$aDatabaseTables['request_cache']);
         $_aData = $_oCacheTable->getCache($sTransientKey);
         $vData = $_aData['data'];
     } else {
         $vData = AmazonAutoLinks_WPUtility::getTransient($sTransientKey);
     }
     // if it's false, no transient is stored. Otherwise, some values are in there.
     if (in_array($vData, array(false, ''), true)) {
         return false;
     }
     // If it's array, okay.
     if (is_array($vData)) {
         return $vData;
     }
     // Maybe it's encoded
     if (is_string($vData) && is_serialized($vData)) {
         return unserialize($vData);
     }
     // Maybe it's an object. In that case, convert it to an associative array.
     if (is_object($vData)) {
         return get_object_vars($vData);
     }
     // It's an unknown type, then cast array.
     return (array) $vData;
 }
コード例 #3
0
 /**
  * A callback for the accessSiteAtShutDown() method.
  * 
  * @since            1.0.0
  */
 public static function _replyToAccessSite()
 {
     // Retrieve the plugin scheduled tasks array.
     $_sTransientName = md5(get_class());
     $_aTasks = AmazonAutoLinks_WPUtility::getTransient($_sTransientName);
     $_aTasks = $_aTasks ? $_aTasks : array();
     $_nNow = microtime(true);
     // Check the excessive background call protection interval
     if (!self::$_fIgnoreLock) {
         $_nCalled = isset($_aTasks['called']) ? $_aTasks['called'] : 0;
         if ($_nCalled + self::$_iLockBackgroundCallInterval > $_nNow) {
             return;
             // if it's called within 10 seconds from the last time of calling this method, do nothing to avoid excessive calls.
         }
     }
     // Renew the called time.
     $_aFlagKeys = array('called' => $_nNow);
     // set a locked key so it prevents duplicated function calls due to too many calls caused by simultaneous accesses.
     AmazonAutoLinks_WPUtility::setTransient($_sTransientName, $_aFlagKeys + $_aTasks, self::getAllowedMaxExecutionTime());
     // Compose a GET query array
     $_aGet = self::$_aGet;
     if (defined('WP_DEBUG')) {
         $_aGet['debug'] = WP_DEBUG;
     }
     unset($_aGet[0]);
     // Load the site in the background.
     wp_remote_get(site_url('?' . http_build_query($_aGet)), array('timeout' => 0.1, 'sslverify' => false, 'cookies' => $_aFlagKeys + array($_sTransientName => true)));
 }
コード例 #4
0
 /**
  * Loads the data.
  */
 public function load()
 {
     // If this returns an empty value, SimplePie will fetch the feed.
     if (0 == $this->iLifetime) {
         return null;
     }
     // the stored cache data
     return AmazonAutoLinks_WPUtility::getTransient($this->sTransientName);
 }