public function run() { if (empty($_POST['key'])) { return new WP_Error('hm_backdrop_no_key', __('No key supplied', 'hm_backdrop')); } $data = WP_Temporary::get('hm_backdrop-' . $_POST['key']); if (empty($data)) { return new WP_Error('hm_backdrop_invalid_key', __('Supplied key was not valid', 'hm_backdrop')); } $result = call_user_func_array($data['callback'], $data['params']); WP_Temporary::delete('hm_backdrop-' . $_POST['key']); if (is_wp_error($result)) { return $result; } return true; }
protected function get_data() { return WP_Temporary::get('hm_backdrop-' . $this->key); }
/** * Check if CloudFlare API user has reached limit. * * If user passed CloudFlare API limits, return false, * otherwise return number of request in current period. * * @since 1.0 * @access public * * @return bool|int Number of made requests or false if reached limit. */ public function can_fetch() { // Check how much requests are already performed in this interval $requests = WP_Temporary::get('purge_cache_for_cloudflare_requests_limit'); if (!$requests) { $requests = 1; } if (1200 > $requests) { return $requests; } else { return false; } }
/** * Schedule task if it's needed. * * @since 1.0 * @access public */ public function maybe_schedule_task() { // Check if this is Backdrop request if (did_action('wp_ajax_nopriv_hm_backdrop_run')) { return; } // Check if queue exists $exists = WP_Temporary::get('simple_email_queue_exist'); if (!$exists) { return; } // Check how much emails are already sent in this interval $sent = WP_Temporary::get('simple_email_queue_sent'); if (!$sent) { $sent = 0; } // If number of sent is smaller than maximum number, schedule task if ($sent < $this->max()) { $task = new \HM\Backdrop\Task(array($this, 'process_queue')); $task->schedule(); } }
/** * Clean expired temporaries from database. * * Search database for all expired temporaries older * that one minute and use methods for retrieval to * delete them. * * Inspired by https://github.com/Seebz/Snippets/tree/master/Wordpress/plugins/purge-transients * * @since 1.0.0 * @access public */ public static function clean() { global $wpdb; /** * Allow short-circuit of cleaning of temporaries. * * Passing a truthy value to the filter * will short-circuit process of cleaning. * * @since 1.0.0 * * @param bool|mixed $pre_value Should cleaning be not done. * Default false to skip it. */ $pre = apply_filters('wp_temporary_clean_pre', false); if (false !== $pre) { return; } // Older than minute, just for case $older_than_time = time() - MINUTE_IN_SECONDS; // Clean single site temporaries $temporaries = $wpdb->get_col($wpdb->prepare("\n\t\t\t\tSELECT REPLACE(option_name, '_temporary_timeout_', '') AS transient_name\n\t\t\t\tFROM {$wpdb->options}\n\t\t\t\tWHERE option_name LIKE '\\_temporary\\_timeout\\__%%'\n\t\t\t\tAND option_value < %s\n\t\t\t\t", $older_than_time)); foreach ($temporaries as $temporary) { WP_Temporary::get($temporary); } // Clean network wide temporaries if (is_multisite()) { $temporaries = $wpdb->get_col($wpdb->prepare("\n\t\t\t\t\tSELECT REPLACE(meta_key, '_site_temporary_timeout_', '') AS temporary_name\n\t\t\t\t\tFROM {$wpdb->sitemeta}\n\t\t\t\t\tWHERE meta_key LIKE '\\_site\\_temporary\\_timeout\\__%%'\n\t\t\t\t\tAND meta_value < %s\n\t\t\t\t\t", $older_than_time)); } else { $temporaries = $wpdb->get_col($wpdb->prepare("\n\t\t\t\t\tSELECT REPLACE(option_name, '_site_temporary_timeout_', '') AS temporary_name\n\t\t\t\t\tFROM {$wpdb->options}\n\t\t\t\t\tWHERE option_name LIKE '\\_site\\_temporary\\_timeout\\__%%'\n\t\t\t\t\tAND option_value < %s\n\t\t\t\t\t", $older_than_time)); } foreach ($temporaries as $temporary) { WP_Temporary::get_site($temporary); } /** * Fires after the cleaning of temporaries has been done. * * @since 1.0.0 */ do_action('wp_temporary_clean_after'); }
/** * Get cache content for name. * * @access public * * @param string $name Name of cache that is searched for. * @return string $cache Value if cache. */ public static function get($name) { return \WP_Temporary::get(self::key($name)); }