/** * Make API request * * @param string $url * @return string */ function _request($url) { require_once W3TC_INC_DIR . '/functions/http.php'; require_once W3TC_INC_DIR . '/functions/url.php'; $request_url = w3_url_format(W3TC_PAGESPEED_API_URL, array('url' => $url, 'key' => $this->key)); $response = w3_http_get($request_url); if (!is_wp_error($response) && $response['response']['code'] == 200) { return $response['body']; } return false; }
/** * Redirects to URL * * @param string $url * @param array $params * @return string */ function w3_redirect($url = '', $params = array()) { require_once W3TC_INC_DIR . '/functions/url.php'; $url = w3_url_format($url, $params); @header('Location: ' . $url); exit; }
/** * Prime cache * * @param integer $start * @return void */ function prime($start = 0) { $start = (int) $start; /** * Don't start cache prime if queues are still scheduled */ if ($start == 0) { $crons = _get_cron_array(); foreach ($crons as $timestamp => $hooks) { foreach ($hooks as $hook => $keys) { foreach ($keys as $key => $data) { if ($hook == 'w3_pgcache_prime' && count($data['args'])) { return; } } } } } $interval = $this->_config->get_integer('pgcache.prime.interval'); $limit = $this->_config->get_integer('pgcache.prime.limit'); $sitemap = $this->_config->get_string('pgcache.prime.sitemap'); /** * Parse XML sitemap */ $urls = $this->parse_sitemap($sitemap); /** * Queue URLs */ $queue = array_slice($urls, $start, $limit); if (count($urls) > $start + $limit) { wp_schedule_single_event(time() + $interval, 'w3_pgcache_prime', array($start + $limit)); } /** * Make HTTP requests and prime cache */ require_once W3TC_INC_DIR . '/functions/http.php'; foreach ($queue as $url) { $url = w3_url_format($url, array('w3tc_preload' => 1)); w3_http_get($url); } }
/** * Redirects to URL * * @param string $url * @param array $params * @return string */ function w3_redirect($url = '', $params = array()) { $url = w3_url_format($url, $params); @header('Location: ' . $url); exit; }
/** * Make API request * * @param string $url * @return string */ function _request($url) { $request_url = w3_url_format(W3TC_PAGESPEED_API_URL, array('url' => $url, 'key' => $this->key)); $json = w3_http_get($request_url); return $json; }
/** * Redirects to URL * * @param string $url * @param array $params * * @return string */ function w3_redirect_temp($url = '', $params = array()) { w3_require_once(W3TC_INC_DIR . '/functions/url.php'); $url = w3_url_format($url, $params); if (function_exists('do_action')) { do_action('w3_redirect'); } $status_code = 301; $protocol = $_SERVER["SERVER_PROTOCOL"]; if ('HTTP/1.1' === $protocol) { $status_code = 307; } $text = get_status_header_desc($status_code); if (!empty($text)) { $status_header = "{$protocol} {$status_code} {$text}"; @header($status_header, true, $status_code); } @header('Location: ' . $url, true, $status_code); exit; }