本文整理匯總了PHP中WPSEO_Utils::get_sitemap_cache_key方法的典型用法代碼示例。如果您正苦於以下問題:PHP WPSEO_Utils::get_sitemap_cache_key方法的具體用法?PHP WPSEO_Utils::get_sitemap_cache_key怎麽用?PHP WPSEO_Utils::get_sitemap_cache_key使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類WPSEO_Utils
的用法示例。
在下文中一共展示了WPSEO_Utils::get_sitemap_cache_key方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: redirect
/**
* Hijack requests for potential sitemaps and XSL files.
*
* @param \WP_Query $query Main query instance.
*/
function redirect($query)
{
if (!$query->is_main_query()) {
return;
}
$xsl = get_query_var('xsl');
if (!empty($xsl)) {
$this->xsl_output($xsl);
$this->sitemap_close();
}
$type = get_query_var('sitemap');
if (empty($type)) {
return;
}
$this->set_n(get_query_var('sitemap_n'));
/**
* Filter: 'wpseo_enable_xml_sitemap_transient_caching' - Allow disabling the transient cache
*
* @api bool $unsigned Enable cache or not, defaults to true
*/
$caching = apply_filters('wpseo_enable_xml_sitemap_transient_caching', true);
if ($caching) {
do_action('wpseo_sitemap_stylesheet_cache_' . $type, $this);
$sitemap_cache_key = WPSEO_Utils::get_sitemap_cache_key($type, $this->n);
$this->sitemap = get_transient($sitemap_cache_key);
}
if (!$this->sitemap || '' == $this->sitemap) {
$this->build_sitemap($type);
// 404 for invalid or empty sitemaps.
if ($this->bad_sitemap) {
$GLOBALS['wp_query']->set_404();
status_header(404);
return;
}
if ($caching) {
/**
* We need to set a timeout, otherwise the transient is loaded every request!
*
* See: https://codex.wordpress.org/Function_Reference/set_transient
* NB: transients that never expire are autoloaded, whereas transients with an expiration time
* are not autoloaded. Consider this when adding transients that may not be needed on every
* page, and thus do not need to be autoloaded, impacting page performance.
*/
set_transient($sitemap_cache_key, $this->sitemap, DAY_IN_SECONDS);
}
} else {
$this->transient = true;
}
$this->output();
$this->sitemap_close();
}