Yoast\WP\SEO\Memoizers
Meta_Tags_Context_Memoizer::for_current_page
Gets the meta tags context for the current page. This function is memoized so every call will return the same result.
Метод класса: Meta_Tags_Context_Memoizer{}
Хуков нет.
Возвращает
Meta_Tags_Context. The meta tags context.
Использование
$Meta_Tags_Context_Memoizer = new Meta_Tags_Context_Memoizer(); $Meta_Tags_Context_Memoizer->for_current_page();
Код Meta_Tags_Context_Memoizer::for_current_page() Meta Tags Context Memoizer::for current page Yoast 26.3
public function for_current_page() {
if ( ! isset( $this->cache['current_page'] ) ) {
// First reset the query to ensure we actually have the current page.
global $wp_query, $post;
$old_wp_query = $wp_query;
$old_post = $post;
// phpcs:ignore WordPress.WP.DiscouragedFunctions.wp_reset_query_wp_reset_query -- Reason: The recommended function, wp_reset_postdata, doesn't reset wp_query.
\wp_reset_query();
$indexable = $this->repository->for_current_page();
$page_type = $this->current_page->get_page_type();
if ( $page_type === 'Fallback' ) {
// Do not cache the context if it's a fallback page.
// The likely cause for this is that this function was called before the query was loaded.
$context = $this->get( $indexable, $page_type );
// Restore the previous query.
// phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited -- Reason: we have to restore the query.
$GLOBALS['wp_query'] = $old_wp_query;
// phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited -- Reason: we have to restore the post.
$GLOBALS['post'] = $old_post;
return $context;
}
$this->cache['current_page'] = $this->get( $indexable, $page_type );
// Restore the previous query.
// phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited -- Reason: we have to restore the query.
$GLOBALS['wp_query'] = $old_wp_query;
// phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited -- Reason: we have to restore the post.
$GLOBALS['post'] = $old_post;
}
return $this->cache['current_page'];
}