本文整理汇总了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();
}