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; }
* * @package Purge_Cache_for_CloudFlare * @subpackage Unistall */ /* Exit if accessed directly or not in unistall */ if (!defined('ABSPATH') || !defined('WP_UNINSTALL_PLUGIN')) { exit; } // Load dependencies require __DIR__ . '/vendor/autoload.php'; /* * Remove options on uninstallation of plugin. * * @since 1.0 */ delete_option('purge_cache_for_cloudflare_api_key'); delete_option('purge_cache_for_cloudflare_api_email_address'); delete_option('purge_cache_for_cloudflare_urls'); /* * Clean expired temporaries on uninstallation of plugin. * * @since 1.0 */ WP_Temporary::clean(); /* * Delete temporaries on uninstallation of plugin. * * @since 1.0 */ WP_Temporary::delete('purge_cache_for_cloudflare_requests_limit');
protected function get_data() { return WP_Temporary::get('hm_backdrop-' . $this->key); }
/** * Make CloudFlare API request. * * @since 1.0 * @access public * * @param string $endpoint Endpoint of CloudFlare API URL. * @param array $args Request arguments. * @return WP_Error|array $response The response or WP_Error on failure. */ public function request($endpoint, $args) { // Have we passed limit $requests = $this->can_fetch(); if (!$requests) { return new WP_Error('purge-cache-for-cloudflare-requests-limit', __('Requests limit passed.', 'purge-cache-for-cloudflare'), 429); } // Save new number of requests in this interval WP_Temporary::update('purge_cache_for_cloudflare_requests_limit', $requests + 1, 15 * MINUTE_IN_SECONDS); $defaults = array('headers' => array('X-Auth-Email' => $this->email, 'X-Auth-Key' => $this->api_key, 'Content-Type' => 'application/json')); $r = wp_parse_args($args, $defaults); $response = wp_remote_request($this->base_endpoint . $endpoint, $r); return $response; }
/** * 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'); }
/** * Delete cache content for name. * * @access public * * @param string $string Name of cache that is deleted. * @return bool True if deletion is successful, false otherwise. */ public static function delete($name) { return \WP_Temporary::delete(self::key($name)); }