} $date_archive_permalink = $this->get_non_cached_date_archive_permalink(); return $date_archive_permalink; } /** * Determine whether this is the homepage and shows posts. * * @return bool Whether or not the current page is the homepage that displays posts. */ public function is_home_posts_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); if ( ! $wp_query->is_home() ) { return false; } /* * Whether the static page's `Homepage` option is actually not set to a page. * Otherwise WordPress proceeds to handle the homepage as a `Your latest posts` page. */ if ( (int) \get_option( 'page_on_front' ) === 0 ) { return true; } return \get_option( 'show_on_front' ) === 'posts'; } /** * Determine whether this is the static frontpage. * * @return bool Whether or not the current page is a static frontpage. */ public function is_home_static_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); if ( ! $wp_query->is_front_page() ) { return false; } if ( \get_option( 'show_on_front' ) !== 'page' ) { return false; } return $wp_query->is_page( \get_option( 'page_on_front' ) ); } /** * Determine whether this is the static posts page. * * @return bool Whether or not the current page is a static posts page. */ public function is_static_posts_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); $queried_object = $wp_query->get_queried_object(); return ( $wp_query->is_posts_page && \is_a( $queried_object, WP_Post::class ) && $queried_object->post_type === 'page' ); } /** * Determine whether this is the statically set posts page, when it's not the frontpage. * * @return bool Whether or not it's a non-frontpage, statically set posts page. */ public function is_posts_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); if ( ! $wp_query->is_home() ) { return false; } return \get_option( 'show_on_front' ) === 'page'; } /** * Determine whether this is a post type archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is a post type archive. */ public function is_post_type_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_post_type_archive(); } /** * Determine whether this is a term archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is a term archive. */ public function is_term_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_tax || $wp_query->is_tag || $wp_query->is_category; } /** * Determine whether this is an attachment page. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is an attachment page. */ public function is_attachment() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_attachment; } /** * Determine whether this is an author archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is an author archive. */ public function is_author_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_author(); } /** * Determine whether this is an date archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is an date archive. */ public function is_date_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_date(); } /** * Determine whether this is a search result. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is a search result. */ public function is_search_result() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_search(); } /** * Determine whether this is a 404 page. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is a 404 page. */ public function is_404() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_404(); } /** * Checks if the current page is the post format archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether or not the current page is the post format archive. */ public function is_post_format_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_tax( 'post_format' ); } /** * Determine whether this page is an taxonomy archive page for multiple terms (url: /term-1,term2/). * * @return bool Whether or not the current page is an archive page for multiple terms. */ public function is_multiple_terms_page() { if ( ! $this->is_term_archive() ) { return false; } return $this->count_queried_terms() > 1; } /** * Checks whether the current page is paged. * * @codeCoverageIgnore This method only calls a WordPress function. * * @return bool Whether the current page is paged. */ public function is_paged() { return \is_paged(); } /** * Checks if the current page is the front page. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether or not the current page is the front page. */ public function is_front_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_front_page(); } /** * Retrieves the current admin page. * * @codeCoverageIgnore It only wraps a global WordPress variable. * * @return string The current page. */ public function get_current_admin_page() { global $pagenow; return $pagenow; } /** * Check if the current opened page is a Yoast SEO page. * * @return bool True when current page is a yoast seo plugin page. */ public function is_yoast_seo_page() { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information. if ( isset( $_GET['page'] ) && \is_string( $_GET['page'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Reason: We are not processing form information, We are only using the variable in the strpos function. $current_page = \wp_unslash( $_GET['page'] ); return \strpos( $current_page, 'wpseo_' ) === 0; } return false; } /** * Returns the current Yoast SEO page. * (E.g. the `page` query variable in the URL). * * @return string The current Yoast SEO page. */ public function get_current_yoast_seo_page() { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information. if ( isset( $_GET['page'] ) && \is_string( $_GET['page'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information. return \sanitize_text_field( \wp_unslash( $_GET['page'] ) ); } return ''; } /** * Checks if the current global post is the privacy policy page. * * @return bool current global post is set as privacy page */ public function current_post_is_privacy_policy() { global $post; if ( ! isset( $post->ID ) ) { return false; } return \intval( $post->ID ) === \intval( \get_option( 'wp_page_for_privacy_policy', false ) ); } /** * Returns the permalink of the currently opened date archive. * * @return string The permalink of the currently opened date archive. */ protected function get_non_cached_date_archive_permalink() { $date_archive_permalink = ''; $wp_query = $this->wp_query_wrapper->get_main_query(); if ( $wp_query->is_day() ) { $date_archive_permalink = \get_day_link( $wp_query->get( 'year' ), $wp_query->get( 'monthnum' ), $wp_query->get( 'day' ) ); } if ( $wp_query->is_month() ) { $date_archive_permalink = \get_month_link( $wp_query->get( 'year' ), $wp_query->get( 'monthnum' ) ); } if ( $wp_query->is_year() ) { $date_archive_permalink = \get_year_link( $wp_query->get( 'year' ) ); } return $date_archive_permalink; } /** * Counts the total amount of queried terms. * * @codeCoverageIgnore This relies too much on WordPress dependencies. * * @return int The amoumt of queried terms. */ protected function count_queried_terms() { $wp_query = $this->wp_query_wrapper->get_main_query(); $term = $wp_query->get_queried_object(); $queried_terms = $wp_query->tax_query->queried_terms; if ( \is_null( $term ) || empty( $queried_terms[ $term->taxonomy ]['terms'] ) ) { return 0; } return \count( $queried_terms[ $term->taxonomy ]['terms'] ); } } } $date_archive_permalink = $this->get_non_cached_date_archive_permalink(); return $date_archive_permalink; } /** * Determine whether this is the homepage and shows posts. * * @return bool Whether or not the current page is the homepage that displays posts. */ public function is_home_posts_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); if ( ! $wp_query->is_home() ) { return false; } /* * Whether the static page's `Homepage` option is actually not set to a page. * Otherwise WordPress proceeds to handle the homepage as a `Your latest posts` page. */ if ( (int) \get_option( 'page_on_front' ) === 0 ) { return true; } return \get_option( 'show_on_front' ) === 'posts'; } /** * Determine whether this is the static frontpage. * * @return bool Whether or not the current page is a static frontpage. */ public function is_home_static_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); if ( ! $wp_query->is_front_page() ) { return false; } if ( \get_option( 'show_on_front' ) !== 'page' ) { return false; } return $wp_query->is_page( \get_option( 'page_on_front' ) ); } /** * Determine whether this is the static posts page. * * @return bool Whether or not the current page is a static posts page. */ public function is_static_posts_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); $queried_object = $wp_query->get_queried_object(); return ( $wp_query->is_posts_page && \is_a( $queried_object, WP_Post::class ) && $queried_object->post_type === 'page' ); } /** * Determine whether this is the statically set posts page, when it's not the frontpage. * * @return bool Whether or not it's a non-frontpage, statically set posts page. */ public function is_posts_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); if ( ! $wp_query->is_home() ) { return false; } return \get_option( 'show_on_front' ) === 'page'; } /** * Determine whether this is a post type archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is a post type archive. */ public function is_post_type_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_post_type_archive(); } /** * Determine whether this is a term archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is a term archive. */ public function is_term_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_tax || $wp_query->is_tag || $wp_query->is_category; } /** * Determine whether this is an attachment page. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is an attachment page. */ public function is_attachment() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_attachment; } /** * Determine whether this is an author archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is an author archive. */ public function is_author_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_author(); } /** * Determine whether this is an date archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is an date archive. */ public function is_date_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_date(); } /** * Determine whether this is a search result. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is a search result. */ public function is_search_result() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_search(); } /** * Determine whether this is a 404 page. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is a 404 page. */ public function is_404() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_404(); } /** * Checks if the current page is the post format archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether or not the current page is the post format archive. */ public function is_post_format_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_tax( 'post_format' ); } /** * Determine whether this page is an taxonomy archive page for multiple terms (url: /term-1,term2/). * * @return bool Whether or not the current page is an archive page for multiple terms. */ public function is_multiple_terms_page() { if ( ! $this->is_term_archive() ) { return false; } return $this->count_queried_terms() > 1; } /** * Checks whether the current page is paged. * * @codeCoverageIgnore This method only calls a WordPress function. * * @return bool Whether the current page is paged. */ public function is_paged() { return \is_paged(); } /** * Checks if the current page is the front page. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether or not the current page is the front page. */ public function is_front_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_front_page(); } /** * Retrieves the current admin page. * * @codeCoverageIgnore It only wraps a global WordPress variable. * * @return string The current page. */ public function get_current_admin_page() { global $pagenow; return $pagenow; } /** * Check if the current opened page is a Yoast SEO page. * * @return bool True when current page is a yoast seo plugin page. */ public function is_yoast_seo_page() { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information. if ( isset( $_GET['page'] ) && \is_string( $_GET['page'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Reason: We are not processing form information, We are only using the variable in the strpos function. $current_page = \wp_unslash( $_GET['page'] ); return \strpos( $current_page, 'wpseo_' ) === 0; } return false; } /** * Returns the current Yoast SEO page. * (E.g. the `page` query variable in the URL). * * @return string The current Yoast SEO page. */ public function get_current_yoast_seo_page() { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information. if ( isset( $_GET['page'] ) && \is_string( $_GET['page'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information. return \sanitize_text_field( \wp_unslash( $_GET['page'] ) ); } return ''; } /** * Checks if the current global post is the privacy policy page. * * @return bool current global post is set as privacy page */ public function current_post_is_privacy_policy() { global $post; if ( ! isset( $post->ID ) ) { return false; } return \intval( $post->ID ) === \intval( \get_option( 'wp_page_for_privacy_policy', false ) ); } /** * Returns the permalink of the currently opened date archive. * * @return string The permalink of the currently opened date archive. */ protected function get_non_cached_date_archive_permalink() { $date_archive_permalink = ''; $wp_query = $this->wp_query_wrapper->get_main_query(); if ( $wp_query->is_day() ) { $date_archive_permalink = \get_day_link( $wp_query->get( 'year' ), $wp_query->get( 'monthnum' ), $wp_query->get( 'day' ) ); } if ( $wp_query->is_month() ) { $date_archive_permalink = \get_month_link( $wp_query->get( 'year' ), $wp_query->get( 'monthnum' ) ); } if ( $wp_query->is_year() ) { $date_archive_permalink = \get_year_link( $wp_query->get( 'year' ) ); } return $date_archive_permalink; } /** * Counts the total amount of queried terms. * * @codeCoverageIgnore This relies too much on WordPress dependencies. * * @return int The amoumt of queried terms. */ protected function count_queried_terms() { $wp_query = $this->wp_query_wrapper->get_main_query(); $term = $wp_query->get_queried_object(); $queried_terms = $wp_query->tax_query->queried_terms; if ( \is_null( $term ) || empty( $queried_terms[ $term->taxonomy ]['terms'] ) ) { return 0; } return \count( $queried_terms[ $term->taxonomy ]['terms'] ); } } } $date_archive_permalink = $this->get_non_cached_date_archive_permalink(); return $date_archive_permalink; } /** * Determine whether this is the homepage and shows posts. * * @return bool Whether or not the current page is the homepage that displays posts. */ public function is_home_posts_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); if ( ! $wp_query->is_home() ) { return false; } /* * Whether the static page's `Homepage` option is actually not set to a page. * Otherwise WordPress proceeds to handle the homepage as a `Your latest posts` page. */ if ( (int) \get_option( 'page_on_front' ) === 0 ) { return true; } return \get_option( 'show_on_front' ) === 'posts'; } /** * Determine whether this is the static frontpage. * * @return bool Whether or not the current page is a static frontpage. */ public function is_home_static_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); if ( ! $wp_query->is_front_page() ) { return false; } if ( \get_option( 'show_on_front' ) !== 'page' ) { return false; } return $wp_query->is_page( \get_option( 'page_on_front' ) ); } /** * Determine whether this is the static posts page. * * @return bool Whether or not the current page is a static posts page. */ public function is_static_posts_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); $queried_object = $wp_query->get_queried_object(); return ( $wp_query->is_posts_page && \is_a( $queried_object, WP_Post::class ) && $queried_object->post_type === 'page' ); } /** * Determine whether this is the statically set posts page, when it's not the frontpage. * * @return bool Whether or not it's a non-frontpage, statically set posts page. */ public function is_posts_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); if ( ! $wp_query->is_home() ) { return false; } return \get_option( 'show_on_front' ) === 'page'; } /** * Determine whether this is a post type archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is a post type archive. */ public function is_post_type_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_post_type_archive(); } /** * Determine whether this is a term archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is a term archive. */ public function is_term_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_tax || $wp_query->is_tag || $wp_query->is_category; } /** * Determine whether this is an attachment page. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is an attachment page. */ public function is_attachment() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_attachment; } /** * Determine whether this is an author archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is an author archive. */ public function is_author_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_author(); } /** * Determine whether this is an date archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is an date archive. */ public function is_date_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_date(); } /** * Determine whether this is a search result. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is a search result. */ public function is_search_result() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_search(); } /** * Determine whether this is a 404 page. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is a 404 page. */ public function is_404() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_404(); } /** * Checks if the current page is the post format archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether or not the current page is the post format archive. */ public function is_post_format_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_tax( 'post_format' ); } /** * Determine whether this page is an taxonomy archive page for multiple terms (url: /term-1,term2/). * * @return bool Whether or not the current page is an archive page for multiple terms. */ public function is_multiple_terms_page() { if ( ! $this->is_term_archive() ) { return false; } return $this->count_queried_terms() > 1; } /** * Checks whether the current page is paged. * * @codeCoverageIgnore This method only calls a WordPress function. * * @return bool Whether the current page is paged. */ public function is_paged() { return \is_paged(); } /** * Checks if the current page is the front page. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether or not the current page is the front page. */ public function is_front_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_front_page(); } /** * Retrieves the current admin page. * * @codeCoverageIgnore It only wraps a global WordPress variable. * * @return string The current page. */ public function get_current_admin_page() { global $pagenow; return $pagenow; } /** * Check if the current opened page is a Yoast SEO page. * * @return bool True when current page is a yoast seo plugin page. */ public function is_yoast_seo_page() { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information. if ( isset( $_GET['page'] ) && \is_string( $_GET['page'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Reason: We are not processing form information, We are only using the variable in the strpos function. $current_page = \wp_unslash( $_GET['page'] ); return \strpos( $current_page, 'wpseo_' ) === 0; } return false; } /** * Returns the current Yoast SEO page. * (E.g. the `page` query variable in the URL). * * @return string The current Yoast SEO page. */ public function get_current_yoast_seo_page() { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information. if ( isset( $_GET['page'] ) && \is_string( $_GET['page'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information. return \sanitize_text_field( \wp_unslash( $_GET['page'] ) ); } return ''; } /** * Checks if the current global post is the privacy policy page. * * @return bool current global post is set as privacy page */ public function current_post_is_privacy_policy() { global $post; if ( ! isset( $post->ID ) ) { return false; } return \intval( $post->ID ) === \intval( \get_option( 'wp_page_for_privacy_policy', false ) ); } /** * Returns the permalink of the currently opened date archive. * * @return string The permalink of the currently opened date archive. */ protected function get_non_cached_date_archive_permalink() { $date_archive_permalink = ''; $wp_query = $this->wp_query_wrapper->get_main_query(); if ( $wp_query->is_day() ) { $date_archive_permalink = \get_day_link( $wp_query->get( 'year' ), $wp_query->get( 'monthnum' ), $wp_query->get( 'day' ) ); } if ( $wp_query->is_month() ) { $date_archive_permalink = \get_month_link( $wp_query->get( 'year' ), $wp_query->get( 'monthnum' ) ); } if ( $wp_query->is_year() ) { $date_archive_permalink = \get_year_link( $wp_query->get( 'year' ) ); } return $date_archive_permalink; } /** * Counts the total amount of queried terms. * * @codeCoverageIgnore This relies too much on WordPress dependencies. * * @return int The amoumt of queried terms. */ protected function count_queried_terms() { $wp_query = $this->wp_query_wrapper->get_main_query(); $term = $wp_query->get_queried_object(); $queried_terms = $wp_query->tax_query->queried_terms; if ( \is_null( $term ) || empty( $queried_terms[ $term->taxonomy ]['terms'] ) ) { return 0; } return \count( $queried_terms[ $term->taxonomy ]['terms'] ); } } } $date_archive_permalink = $this->get_non_cached_date_archive_permalink(); return $date_archive_permalink; } /** * Determine whether this is the homepage and shows posts. * * @return bool Whether or not the current page is the homepage that displays posts. */ public function is_home_posts_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); if ( ! $wp_query->is_home() ) { return false; } /* * Whether the static page's `Homepage` option is actually not set to a page. * Otherwise WordPress proceeds to handle the homepage as a `Your latest posts` page. */ if ( (int) \get_option( 'page_on_front' ) === 0 ) { return true; } return \get_option( 'show_on_front' ) === 'posts'; } /** * Determine whether this is the static frontpage. * * @return bool Whether or not the current page is a static frontpage. */ public function is_home_static_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); if ( ! $wp_query->is_front_page() ) { return false; } if ( \get_option( 'show_on_front' ) !== 'page' ) { return false; } return $wp_query->is_page( \get_option( 'page_on_front' ) ); } /** * Determine whether this is the static posts page. * * @return bool Whether or not the current page is a static posts page. */ public function is_static_posts_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); $queried_object = $wp_query->get_queried_object(); return ( $wp_query->is_posts_page && \is_a( $queried_object, WP_Post::class ) && $queried_object->post_type === 'page' ); } /** * Determine whether this is the statically set posts page, when it's not the frontpage. * * @return bool Whether or not it's a non-frontpage, statically set posts page. */ public function is_posts_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); if ( ! $wp_query->is_home() ) { return false; } return \get_option( 'show_on_front' ) === 'page'; } /** * Determine whether this is a post type archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is a post type archive. */ public function is_post_type_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_post_type_archive(); } /** * Determine whether this is a term archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is a term archive. */ public function is_term_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_tax || $wp_query->is_tag || $wp_query->is_category; } /** * Determine whether this is an attachment page. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is an attachment page. */ public function is_attachment() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_attachment; } /** * Determine whether this is an author archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is an author archive. */ public function is_author_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_author(); } /** * Determine whether this is an date archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is an date archive. */ public function is_date_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_date(); } /** * Determine whether this is a search result. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is a search result. */ public function is_search_result() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_search(); } /** * Determine whether this is a 404 page. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is a 404 page. */ public function is_404() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_404(); } /** * Checks if the current page is the post format archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether or not the current page is the post format archive. */ public function is_post_format_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_tax( 'post_format' ); } /** * Determine whether this page is an taxonomy archive page for multiple terms (url: /term-1,term2/). * * @return bool Whether or not the current page is an archive page for multiple terms. */ public function is_multiple_terms_page() { if ( ! $this->is_term_archive() ) { return false; } return $this->count_queried_terms() > 1; } /** * Checks whether the current page is paged. * * @codeCoverageIgnore This method only calls a WordPress function. * * @return bool Whether the current page is paged. */ public function is_paged() { return \is_paged(); } /** * Checks if the current page is the front page. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether or not the current page is the front page. */ public function is_front_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_front_page(); } /** * Retrieves the current admin page. * * @codeCoverageIgnore It only wraps a global WordPress variable. * * @return string The current page. */ public function get_current_admin_page() { global $pagenow; return $pagenow; } /** * Check if the current opened page is a Yoast SEO page. * * @return bool True when current page is a yoast seo plugin page. */ public function is_yoast_seo_page() { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information. if ( isset( $_GET['page'] ) && \is_string( $_GET['page'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Reason: We are not processing form information, We are only using the variable in the strpos function. $current_page = \wp_unslash( $_GET['page'] ); return \strpos( $current_page, 'wpseo_' ) === 0; } return false; } /** * Returns the current Yoast SEO page. * (E.g. the `page` query variable in the URL). * * @return string The current Yoast SEO page. */ public function get_current_yoast_seo_page() { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information. if ( isset( $_GET['page'] ) && \is_string( $_GET['page'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information. return \sanitize_text_field( \wp_unslash( $_GET['page'] ) ); } return ''; } /** * Checks if the current global post is the privacy policy page. * * @return bool current global post is set as privacy page */ public function current_post_is_privacy_policy() { global $post; if ( ! isset( $post->ID ) ) { return false; } return \intval( $post->ID ) === \intval( \get_option( 'wp_page_for_privacy_policy', false ) ); } /** * Returns the permalink of the currently opened date archive. * * @return string The permalink of the currently opened date archive. */ protected function get_non_cached_date_archive_permalink() { $date_archive_permalink = ''; $wp_query = $this->wp_query_wrapper->get_main_query(); if ( $wp_query->is_day() ) { $date_archive_permalink = \get_day_link( $wp_query->get( 'year' ), $wp_query->get( 'monthnum' ), $wp_query->get( 'day' ) ); } if ( $wp_query->is_month() ) { $date_archive_permalink = \get_month_link( $wp_query->get( 'year' ), $wp_query->get( 'monthnum' ) ); } if ( $wp_query->is_year() ) { $date_archive_permalink = \get_year_link( $wp_query->get( 'year' ) ); } return $date_archive_permalink; } /** * Counts the total amount of queried terms. * * @codeCoverageIgnore This relies too much on WordPress dependencies. * * @return int The amoumt of queried terms. */ protected function count_queried_terms() { $wp_query = $this->wp_query_wrapper->get_main_query(); $term = $wp_query->get_queried_object(); $queried_terms = $wp_query->tax_query->queried_terms; if ( \is_null( $term ) || empty( $queried_terms[ $term->taxonomy ]['terms'] ) ) { return 0; } return \count( $queried_terms[ $term->taxonomy ]['terms'] ); } } } $date_archive_permalink = $this->get_non_cached_date_archive_permalink(); return $date_archive_permalink; } /** * Determine whether this is the homepage and shows posts. * * @return bool Whether or not the current page is the homepage that displays posts. */ public function is_home_posts_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); if ( ! $wp_query->is_home() ) { return false; } /* * Whether the static page's `Homepage` option is actually not set to a page. * Otherwise WordPress proceeds to handle the homepage as a `Your latest posts` page. */ if ( (int) \get_option( 'page_on_front' ) === 0 ) { return true; } return \get_option( 'show_on_front' ) === 'posts'; } /** * Determine whether this is the static frontpage. * * @return bool Whether or not the current page is a static frontpage. */ public function is_home_static_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); if ( ! $wp_query->is_front_page() ) { return false; } if ( \get_option( 'show_on_front' ) !== 'page' ) { return false; } return $wp_query->is_page( \get_option( 'page_on_front' ) ); } /** * Determine whether this is the static posts page. * * @return bool Whether or not the current page is a static posts page. */ public function is_static_posts_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); $queried_object = $wp_query->get_queried_object(); return ( $wp_query->is_posts_page && \is_a( $queried_object, WP_Post::class ) && $queried_object->post_type === 'page' ); } /** * Determine whether this is the statically set posts page, when it's not the frontpage. * * @return bool Whether or not it's a non-frontpage, statically set posts page. */ public function is_posts_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); if ( ! $wp_query->is_home() ) { return false; } return \get_option( 'show_on_front' ) === 'page'; } /** * Determine whether this is a post type archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is a post type archive. */ public function is_post_type_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_post_type_archive(); } /** * Determine whether this is a term archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is a term archive. */ public function is_term_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_tax || $wp_query->is_tag || $wp_query->is_category; } /** * Determine whether this is an attachment page. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is an attachment page. */ public function is_attachment() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_attachment; } /** * Determine whether this is an author archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is an author archive. */ public function is_author_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_author(); } /** * Determine whether this is an date archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is an date archive. */ public function is_date_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_date(); } /** * Determine whether this is a search result. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is a search result. */ public function is_search_result() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_search(); } /** * Determine whether this is a 404 page. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is a 404 page. */ public function is_404() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_404(); } /** * Checks if the current page is the post format archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether or not the current page is the post format archive. */ public function is_post_format_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_tax( 'post_format' ); } /** * Determine whether this page is an taxonomy archive page for multiple terms (url: /term-1,term2/). * * @return bool Whether or not the current page is an archive page for multiple terms. */ public function is_multiple_terms_page() { if ( ! $this->is_term_archive() ) { return false; } return $this->count_queried_terms() > 1; } /** * Checks whether the current page is paged. * * @codeCoverageIgnore This method only calls a WordPress function. * * @return bool Whether the current page is paged. */ public function is_paged() { return \is_paged(); } /** * Checks if the current page is the front page. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether or not the current page is the front page. */ public function is_front_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_front_page(); } /** * Retrieves the current admin page. * * @codeCoverageIgnore It only wraps a global WordPress variable. * * @return string The current page. */ public function get_current_admin_page() { global $pagenow; return $pagenow; } /** * Check if the current opened page is a Yoast SEO page. * * @return bool True when current page is a yoast seo plugin page. */ public function is_yoast_seo_page() { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information. if ( isset( $_GET['page'] ) && \is_string( $_GET['page'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Reason: We are not processing form information, We are only using the variable in the strpos function. $current_page = \wp_unslash( $_GET['page'] ); return \strpos( $current_page, 'wpseo_' ) === 0; } return false; } /** * Returns the current Yoast SEO page. * (E.g. the `page` query variable in the URL). * * @return string The current Yoast SEO page. */ public function get_current_yoast_seo_page() { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information. if ( isset( $_GET['page'] ) && \is_string( $_GET['page'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information. return \sanitize_text_field( \wp_unslash( $_GET['page'] ) ); } return ''; } /** * Checks if the current global post is the privacy policy page. * * @return bool current global post is set as privacy page */ public function current_post_is_privacy_policy() { global $post; if ( ! isset( $post->ID ) ) { return false; } return \intval( $post->ID ) === \intval( \get_option( 'wp_page_for_privacy_policy', false ) ); } /** * Returns the permalink of the currently opened date archive. * * @return string The permalink of the currently opened date archive. */ protected function get_non_cached_date_archive_permalink() { $date_archive_permalink = ''; $wp_query = $this->wp_query_wrapper->get_main_query(); if ( $wp_query->is_day() ) { $date_archive_permalink = \get_day_link( $wp_query->get( 'year' ), $wp_query->get( 'monthnum' ), $wp_query->get( 'day' ) ); } if ( $wp_query->is_month() ) { $date_archive_permalink = \get_month_link( $wp_query->get( 'year' ), $wp_query->get( 'monthnum' ) ); } if ( $wp_query->is_year() ) { $date_archive_permalink = \get_year_link( $wp_query->get( 'year' ) ); } return $date_archive_permalink; } /** * Counts the total amount of queried terms. * * @codeCoverageIgnore This relies too much on WordPress dependencies. * * @return int The amoumt of queried terms. */ protected function count_queried_terms() { $wp_query = $this->wp_query_wrapper->get_main_query(); $term = $wp_query->get_queried_object(); $queried_terms = $wp_query->tax_query->queried_terms; if ( \is_null( $term ) || empty( $queried_terms[ $term->taxonomy ]['terms'] ) ) { return 0; } return \count( $queried_terms[ $term->taxonomy ]['terms'] ); } } } $date_archive_permalink = $this->get_non_cached_date_archive_permalink(); return $date_archive_permalink; } /** * Determine whether this is the homepage and shows posts. * * @return bool Whether or not the current page is the homepage that displays posts. */ public function is_home_posts_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); if ( ! $wp_query->is_home() ) { return false; } /* * Whether the static page's `Homepage` option is actually not set to a page. * Otherwise WordPress proceeds to handle the homepage as a `Your latest posts` page. */ if ( (int) \get_option( 'page_on_front' ) === 0 ) { return true; } return \get_option( 'show_on_front' ) === 'posts'; } /** * Determine whether this is the static frontpage. * * @return bool Whether or not the current page is a static frontpage. */ public function is_home_static_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); if ( ! $wp_query->is_front_page() ) { return false; } if ( \get_option( 'show_on_front' ) !== 'page' ) { return false; } return $wp_query->is_page( \get_option( 'page_on_front' ) ); } /** * Determine whether this is the static posts page. * * @return bool Whether or not the current page is a static posts page. */ public function is_static_posts_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); $queried_object = $wp_query->get_queried_object(); return ( $wp_query->is_posts_page && \is_a( $queried_object, WP_Post::class ) && $queried_object->post_type === 'page' ); } /** * Determine whether this is the statically set posts page, when it's not the frontpage. * * @return bool Whether or not it's a non-frontpage, statically set posts page. */ public function is_posts_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); if ( ! $wp_query->is_home() ) { return false; } return \get_option( 'show_on_front' ) === 'page'; } /** * Determine whether this is a post type archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is a post type archive. */ public function is_post_type_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_post_type_archive(); } /** * Determine whether this is a term archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is a term archive. */ public function is_term_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_tax || $wp_query->is_tag || $wp_query->is_category; } /** * Determine whether this is an attachment page. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is an attachment page. */ public function is_attachment() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_attachment; } /** * Determine whether this is an author archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is an author archive. */ public function is_author_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_author(); } /** * Determine whether this is an date archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is an date archive. */ public function is_date_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_date(); } /** * Determine whether this is a search result. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is a search result. */ public function is_search_result() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_search(); } /** * Determine whether this is a 404 page. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is a 404 page. */ public function is_404() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_404(); } /** * Checks if the current page is the post format archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether or not the current page is the post format archive. */ public function is_post_format_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_tax( 'post_format' ); } /** * Determine whether this page is an taxonomy archive page for multiple terms (url: /term-1,term2/). * * @return bool Whether or not the current page is an archive page for multiple terms. */ public function is_multiple_terms_page() { if ( ! $this->is_term_archive() ) { return false; } return $this->count_queried_terms() > 1; } /** * Checks whether the current page is paged. * * @codeCoverageIgnore This method only calls a WordPress function. * * @return bool Whether the current page is paged. */ public function is_paged() { return \is_paged(); } /** * Checks if the current page is the front page. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether or not the current page is the front page. */ public function is_front_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_front_page(); } /** * Retrieves the current admin page. * * @codeCoverageIgnore It only wraps a global WordPress variable. * * @return string The current page. */ public function get_current_admin_page() { global $pagenow; return $pagenow; } /** * Check if the current opened page is a Yoast SEO page. * * @return bool True when current page is a yoast seo plugin page. */ public function is_yoast_seo_page() { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information. if ( isset( $_GET['page'] ) && \is_string( $_GET['page'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Reason: We are not processing form information, We are only using the variable in the strpos function. $current_page = \wp_unslash( $_GET['page'] ); return \strpos( $current_page, 'wpseo_' ) === 0; } return false; } /** * Returns the current Yoast SEO page. * (E.g. the `page` query variable in the URL). * * @return string The current Yoast SEO page. */ public function get_current_yoast_seo_page() { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information. if ( isset( $_GET['page'] ) && \is_string( $_GET['page'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information. return \sanitize_text_field( \wp_unslash( $_GET['page'] ) ); } return ''; } /** * Checks if the current global post is the privacy policy page. * * @return bool current global post is set as privacy page */ public function current_post_is_privacy_policy() { global $post; if ( ! isset( $post->ID ) ) { return false; } return \intval( $post->ID ) === \intval( \get_option( 'wp_page_for_privacy_policy', false ) ); } /** * Returns the permalink of the currently opened date archive. * * @return string The permalink of the currently opened date archive. */ protected function get_non_cached_date_archive_permalink() { $date_archive_permalink = ''; $wp_query = $this->wp_query_wrapper->get_main_query(); if ( $wp_query->is_day() ) { $date_archive_permalink = \get_day_link( $wp_query->get( 'year' ), $wp_query->get( 'monthnum' ), $wp_query->get( 'day' ) ); } if ( $wp_query->is_month() ) { $date_archive_permalink = \get_month_link( $wp_query->get( 'year' ), $wp_query->get( 'monthnum' ) ); } if ( $wp_query->is_year() ) { $date_archive_permalink = \get_year_link( $wp_query->get( 'year' ) ); } return $date_archive_permalink; } /** * Counts the total amount of queried terms. * * @codeCoverageIgnore This relies too much on WordPress dependencies. * * @return int The amoumt of queried terms. */ protected function count_queried_terms() { $wp_query = $this->wp_query_wrapper->get_main_query(); $term = $wp_query->get_queried_object(); $queried_terms = $wp_query->tax_query->queried_terms; if ( \is_null( $term ) || empty( $queried_terms[ $term->taxonomy ]['terms'] ) ) { return 0; } return \count( $queried_terms[ $term->taxonomy ]['terms'] ); } } } $date_archive_permalink = $this->get_non_cached_date_archive_permalink(); return $date_archive_permalink; } /** * Determine whether this is the homepage and shows posts. * * @return bool Whether or not the current page is the homepage that displays posts. */ public function is_home_posts_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); if ( ! $wp_query->is_home() ) { return false; } /* * Whether the static page's `Homepage` option is actually not set to a page. * Otherwise WordPress proceeds to handle the homepage as a `Your latest posts` page. */ if ( (int) \get_option( 'page_on_front' ) === 0 ) { return true; } return \get_option( 'show_on_front' ) === 'posts'; } /** * Determine whether this is the static frontpage. * * @return bool Whether or not the current page is a static frontpage. */ public function is_home_static_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); if ( ! $wp_query->is_front_page() ) { return false; } if ( \get_option( 'show_on_front' ) !== 'page' ) { return false; } return $wp_query->is_page( \get_option( 'page_on_front' ) ); } /** * Determine whether this is the static posts page. * * @return bool Whether or not the current page is a static posts page. */ public function is_static_posts_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); $queried_object = $wp_query->get_queried_object(); return ( $wp_query->is_posts_page && \is_a( $queried_object, WP_Post::class ) && $queried_object->post_type === 'page' ); } /** * Determine whether this is the statically set posts page, when it's not the frontpage. * * @return bool Whether or not it's a non-frontpage, statically set posts page. */ public function is_posts_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); if ( ! $wp_query->is_home() ) { return false; } return \get_option( 'show_on_front' ) === 'page'; } /** * Determine whether this is a post type archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is a post type archive. */ public function is_post_type_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_post_type_archive(); } /** * Determine whether this is a term archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is a term archive. */ public function is_term_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_tax || $wp_query->is_tag || $wp_query->is_category; } /** * Determine whether this is an attachment page. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is an attachment page. */ public function is_attachment() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_attachment; } /** * Determine whether this is an author archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is an author archive. */ public function is_author_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_author(); } /** * Determine whether this is an date archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is an date archive. */ public function is_date_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_date(); } /** * Determine whether this is a search result. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is a search result. */ public function is_search_result() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_search(); } /** * Determine whether this is a 404 page. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is a 404 page. */ public function is_404() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_404(); } /** * Checks if the current page is the post format archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether or not the current page is the post format archive. */ public function is_post_format_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_tax( 'post_format' ); } /** * Determine whether this page is an taxonomy archive page for multiple terms (url: /term-1,term2/). * * @return bool Whether or not the current page is an archive page for multiple terms. */ public function is_multiple_terms_page() { if ( ! $this->is_term_archive() ) { return false; } return $this->count_queried_terms() > 1; } /** * Checks whether the current page is paged. * * @codeCoverageIgnore This method only calls a WordPress function. * * @return bool Whether the current page is paged. */ public function is_paged() { return \is_paged(); } /** * Checks if the current page is the front page. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether or not the current page is the front page. */ public function is_front_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_front_page(); } /** * Retrieves the current admin page. * * @codeCoverageIgnore It only wraps a global WordPress variable. * * @return string The current page. */ public function get_current_admin_page() { global $pagenow; return $pagenow; } /** * Check if the current opened page is a Yoast SEO page. * * @return bool True when current page is a yoast seo plugin page. */ public function is_yoast_seo_page() { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information. if ( isset( $_GET['page'] ) && \is_string( $_GET['page'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Reason: We are not processing form information, We are only using the variable in the strpos function. $current_page = \wp_unslash( $_GET['page'] ); return \strpos( $current_page, 'wpseo_' ) === 0; } return false; } /** * Returns the current Yoast SEO page. * (E.g. the `page` query variable in the URL). * * @return string The current Yoast SEO page. */ public function get_current_yoast_seo_page() { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information. if ( isset( $_GET['page'] ) && \is_string( $_GET['page'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information. return \sanitize_text_field( \wp_unslash( $_GET['page'] ) ); } return ''; } /** * Checks if the current global post is the privacy policy page. * * @return bool current global post is set as privacy page */ public function current_post_is_privacy_policy() { global $post; if ( ! isset( $post->ID ) ) { return false; } return \intval( $post->ID ) === \intval( \get_option( 'wp_page_for_privacy_policy', false ) ); } /** * Returns the permalink of the currently opened date archive. * * @return string The permalink of the currently opened date archive. */ protected function get_non_cached_date_archive_permalink() { $date_archive_permalink = ''; $wp_query = $this->wp_query_wrapper->get_main_query(); if ( $wp_query->is_day() ) { $date_archive_permalink = \get_day_link( $wp_query->get( 'year' ), $wp_query->get( 'monthnum' ), $wp_query->get( 'day' ) ); } if ( $wp_query->is_month() ) { $date_archive_permalink = \get_month_link( $wp_query->get( 'year' ), $wp_query->get( 'monthnum' ) ); } if ( $wp_query->is_year() ) { $date_archive_permalink = \get_year_link( $wp_query->get( 'year' ) ); } return $date_archive_permalink; } /** * Counts the total amount of queried terms. * * @codeCoverageIgnore This relies too much on WordPress dependencies. * * @return int The amoumt of queried terms. */ protected function count_queried_terms() { $wp_query = $this->wp_query_wrapper->get_main_query(); $term = $wp_query->get_queried_object(); $queried_terms = $wp_query->tax_query->queried_terms; if ( \is_null( $term ) || empty( $queried_terms[ $term->taxonomy ]['terms'] ) ) { return 0; } return \count( $queried_terms[ $term->taxonomy ]['terms'] ); } } } $date_archive_permalink = $this->get_non_cached_date_archive_permalink(); return $date_archive_permalink; } /** * Determine whether this is the homepage and shows posts. * * @return bool Whether or not the current page is the homepage that displays posts. */ public function is_home_posts_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); if ( ! $wp_query->is_home() ) { return false; } /* * Whether the static page's `Homepage` option is actually not set to a page. * Otherwise WordPress proceeds to handle the homepage as a `Your latest posts` page. */ if ( (int) \get_option( 'page_on_front' ) === 0 ) { return true; } return \get_option( 'show_on_front' ) === 'posts'; } /** * Determine whether this is the static frontpage. * * @return bool Whether or not the current page is a static frontpage. */ public function is_home_static_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); if ( ! $wp_query->is_front_page() ) { return false; } if ( \get_option( 'show_on_front' ) !== 'page' ) { return false; } return $wp_query->is_page( \get_option( 'page_on_front' ) ); } /** * Determine whether this is the static posts page. * * @return bool Whether or not the current page is a static posts page. */ public function is_static_posts_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); $queried_object = $wp_query->get_queried_object(); return ( $wp_query->is_posts_page && \is_a( $queried_object, WP_Post::class ) && $queried_object->post_type === 'page' ); } /** * Determine whether this is the statically set posts page, when it's not the frontpage. * * @return bool Whether or not it's a non-frontpage, statically set posts page. */ public function is_posts_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); if ( ! $wp_query->is_home() ) { return false; } return \get_option( 'show_on_front' ) === 'page'; } /** * Determine whether this is a post type archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is a post type archive. */ public function is_post_type_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_post_type_archive(); } /** * Determine whether this is a term archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is a term archive. */ public function is_term_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_tax || $wp_query->is_tag || $wp_query->is_category; } /** * Determine whether this is an attachment page. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is an attachment page. */ public function is_attachment() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_attachment; } /** * Determine whether this is an author archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is an author archive. */ public function is_author_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_author(); } /** * Determine whether this is an date archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is an date archive. */ public function is_date_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_date(); } /** * Determine whether this is a search result. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is a search result. */ public function is_search_result() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_search(); } /** * Determine whether this is a 404 page. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is a 404 page. */ public function is_404() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_404(); } /** * Checks if the current page is the post format archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether or not the current page is the post format archive. */ public function is_post_format_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_tax( 'post_format' ); } /** * Determine whether this page is an taxonomy archive page for multiple terms (url: /term-1,term2/). * * @return bool Whether or not the current page is an archive page for multiple terms. */ public function is_multiple_terms_page() { if ( ! $this->is_term_archive() ) { return false; } return $this->count_queried_terms() > 1; } /** * Checks whether the current page is paged. * * @codeCoverageIgnore This method only calls a WordPress function. * * @return bool Whether the current page is paged. */ public function is_paged() { return \is_paged(); } /** * Checks if the current page is the front page. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether or not the current page is the front page. */ public function is_front_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_front_page(); } /** * Retrieves the current admin page. * * @codeCoverageIgnore It only wraps a global WordPress variable. * * @return string The current page. */ public function get_current_admin_page() { global $pagenow; return $pagenow; } /** * Check if the current opened page is a Yoast SEO page. * * @return bool True when current page is a yoast seo plugin page. */ public function is_yoast_seo_page() { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information. if ( isset( $_GET['page'] ) && \is_string( $_GET['page'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Reason: We are not processing form information, We are only using the variable in the strpos function. $current_page = \wp_unslash( $_GET['page'] ); return \strpos( $current_page, 'wpseo_' ) === 0; } return false; } /** * Returns the current Yoast SEO page. * (E.g. the `page` query variable in the URL). * * @return string The current Yoast SEO page. */ public function get_current_yoast_seo_page() { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information. if ( isset( $_GET['page'] ) && \is_string( $_GET['page'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information. return \sanitize_text_field( \wp_unslash( $_GET['page'] ) ); } return ''; } /** * Checks if the current global post is the privacy policy page. * * @return bool current global post is set as privacy page */ public function current_post_is_privacy_policy() { global $post; if ( ! isset( $post->ID ) ) { return false; } return \intval( $post->ID ) === \intval( \get_option( 'wp_page_for_privacy_policy', false ) ); } /** * Returns the permalink of the currently opened date archive. * * @return string The permalink of the currently opened date archive. */ protected function get_non_cached_date_archive_permalink() { $date_archive_permalink = ''; $wp_query = $this->wp_query_wrapper->get_main_query(); if ( $wp_query->is_day() ) { $date_archive_permalink = \get_day_link( $wp_query->get( 'year' ), $wp_query->get( 'monthnum' ), $wp_query->get( 'day' ) ); } if ( $wp_query->is_month() ) { $date_archive_permalink = \get_month_link( $wp_query->get( 'year' ), $wp_query->get( 'monthnum' ) ); } if ( $wp_query->is_year() ) { $date_archive_permalink = \get_year_link( $wp_query->get( 'year' ) ); } return $date_archive_permalink; } /** * Counts the total amount of queried terms. * * @codeCoverageIgnore This relies too much on WordPress dependencies. * * @return int The amoumt of queried terms. */ protected function count_queried_terms() { $wp_query = $this->wp_query_wrapper->get_main_query(); $term = $wp_query->get_queried_object(); $queried_terms = $wp_query->tax_query->queried_terms; if ( \is_null( $term ) || empty( $queried_terms[ $term->taxonomy ]['terms'] ) ) { return 0; } return \count( $queried_terms[ $term->taxonomy ]['terms'] ); } } } $date_archive_permalink = $this->get_non_cached_date_archive_permalink(); return $date_archive_permalink; } /** * Determine whether this is the homepage and shows posts. * * @return bool Whether or not the current page is the homepage that displays posts. */ public function is_home_posts_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); if ( ! $wp_query->is_home() ) { return false; } /* * Whether the static page's `Homepage` option is actually not set to a page. * Otherwise WordPress proceeds to handle the homepage as a `Your latest posts` page. */ if ( (int) \get_option( 'page_on_front' ) === 0 ) { return true; } return \get_option( 'show_on_front' ) === 'posts'; } /** * Determine whether this is the static frontpage. * * @return bool Whether or not the current page is a static frontpage. */ public function is_home_static_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); if ( ! $wp_query->is_front_page() ) { return false; } if ( \get_option( 'show_on_front' ) !== 'page' ) { return false; } return $wp_query->is_page( \get_option( 'page_on_front' ) ); } /** * Determine whether this is the static posts page. * * @return bool Whether or not the current page is a static posts page. */ public function is_static_posts_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); $queried_object = $wp_query->get_queried_object(); return ( $wp_query->is_posts_page && \is_a( $queried_object, WP_Post::class ) && $queried_object->post_type === 'page' ); } /** * Determine whether this is the statically set posts page, when it's not the frontpage. * * @return bool Whether or not it's a non-frontpage, statically set posts page. */ public function is_posts_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); if ( ! $wp_query->is_home() ) { return false; } return \get_option( 'show_on_front' ) === 'page'; } /** * Determine whether this is a post type archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is a post type archive. */ public function is_post_type_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_post_type_archive(); } /** * Determine whether this is a term archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is a term archive. */ public function is_term_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_tax || $wp_query->is_tag || $wp_query->is_category; } /** * Determine whether this is an attachment page. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is an attachment page. */ public function is_attachment() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_attachment; } /** * Determine whether this is an author archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is an author archive. */ public function is_author_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_author(); } /** * Determine whether this is an date archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is an date archive. */ public function is_date_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_date(); } /** * Determine whether this is a search result. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is a search result. */ public function is_search_result() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_search(); } /** * Determine whether this is a 404 page. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is a 404 page. */ public function is_404() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_404(); } /** * Checks if the current page is the post format archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether or not the current page is the post format archive. */ public function is_post_format_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_tax( 'post_format' ); } /** * Determine whether this page is an taxonomy archive page for multiple terms (url: /term-1,term2/). * * @return bool Whether or not the current page is an archive page for multiple terms. */ public function is_multiple_terms_page() { if ( ! $this->is_term_archive() ) { return false; } return $this->count_queried_terms() > 1; } /** * Checks whether the current page is paged. * * @codeCoverageIgnore This method only calls a WordPress function. * * @return bool Whether the current page is paged. */ public function is_paged() { return \is_paged(); } /** * Checks if the current page is the front page. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether or not the current page is the front page. */ public function is_front_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_front_page(); } /** * Retrieves the current admin page. * * @codeCoverageIgnore It only wraps a global WordPress variable. * * @return string The current page. */ public function get_current_admin_page() { global $pagenow; return $pagenow; } /** * Check if the current opened page is a Yoast SEO page. * * @return bool True when current page is a yoast seo plugin page. */ public function is_yoast_seo_page() { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information. if ( isset( $_GET['page'] ) && \is_string( $_GET['page'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Reason: We are not processing form information, We are only using the variable in the strpos function. $current_page = \wp_unslash( $_GET['page'] ); return \strpos( $current_page, 'wpseo_' ) === 0; } return false; } /** * Returns the current Yoast SEO page. * (E.g. the `page` query variable in the URL). * * @return string The current Yoast SEO page. */ public function get_current_yoast_seo_page() { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information. if ( isset( $_GET['page'] ) && \is_string( $_GET['page'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information. return \sanitize_text_field( \wp_unslash( $_GET['page'] ) ); } return ''; } /** * Checks if the current global post is the privacy policy page. * * @return bool current global post is set as privacy page */ public function current_post_is_privacy_policy() { global $post; if ( ! isset( $post->ID ) ) { return false; } return \intval( $post->ID ) === \intval( \get_option( 'wp_page_for_privacy_policy', false ) ); } /** * Returns the permalink of the currently opened date archive. * * @return string The permalink of the currently opened date archive. */ protected function get_non_cached_date_archive_permalink() { $date_archive_permalink = ''; $wp_query = $this->wp_query_wrapper->get_main_query(); if ( $wp_query->is_day() ) { $date_archive_permalink = \get_day_link( $wp_query->get( 'year' ), $wp_query->get( 'monthnum' ), $wp_query->get( 'day' ) ); } if ( $wp_query->is_month() ) { $date_archive_permalink = \get_month_link( $wp_query->get( 'year' ), $wp_query->get( 'monthnum' ) ); } if ( $wp_query->is_year() ) { $date_archive_permalink = \get_year_link( $wp_query->get( 'year' ) ); } return $date_archive_permalink; } /** * Counts the total amount of queried terms. * * @codeCoverageIgnore This relies too much on WordPress dependencies. * * @return int The amoumt of queried terms. */ protected function count_queried_terms() { $wp_query = $this->wp_query_wrapper->get_main_query(); $term = $wp_query->get_queried_object(); $queried_terms = $wp_query->tax_query->queried_terms; if ( \is_null( $term ) || empty( $queried_terms[ $term->taxonomy ]['terms'] ) ) { return 0; } return \count( $queried_terms[ $term->taxonomy ]['terms'] ); } } } $date_archive_permalink = $this->get_non_cached_date_archive_permalink(); return $date_archive_permalink; } /** * Determine whether this is the homepage and shows posts. * * @return bool Whether or not the current page is the homepage that displays posts. */ public function is_home_posts_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); if ( ! $wp_query->is_home() ) { return false; } /* * Whether the static page's `Homepage` option is actually not set to a page. * Otherwise WordPress proceeds to handle the homepage as a `Your latest posts` page. */ if ( (int) \get_option( 'page_on_front' ) === 0 ) { return true; } return \get_option( 'show_on_front' ) === 'posts'; } /** * Determine whether this is the static frontpage. * * @return bool Whether or not the current page is a static frontpage. */ public function is_home_static_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); if ( ! $wp_query->is_front_page() ) { return false; } if ( \get_option( 'show_on_front' ) !== 'page' ) { return false; } return $wp_query->is_page( \get_option( 'page_on_front' ) ); } /** * Determine whether this is the static posts page. * * @return bool Whether or not the current page is a static posts page. */ public function is_static_posts_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); $queried_object = $wp_query->get_queried_object(); return ( $wp_query->is_posts_page && \is_a( $queried_object, WP_Post::class ) && $queried_object->post_type === 'page' ); } /** * Determine whether this is the statically set posts page, when it's not the frontpage. * * @return bool Whether or not it's a non-frontpage, statically set posts page. */ public function is_posts_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); if ( ! $wp_query->is_home() ) { return false; } return \get_option( 'show_on_front' ) === 'page'; } /** * Determine whether this is a post type archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is a post type archive. */ public function is_post_type_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_post_type_archive(); } /** * Determine whether this is a term archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is a term archive. */ public function is_term_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_tax || $wp_query->is_tag || $wp_query->is_category; } /** * Determine whether this is an attachment page. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is an attachment page. */ public function is_attachment() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_attachment; } /** * Determine whether this is an author archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is an author archive. */ public function is_author_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_author(); } /** * Determine whether this is an date archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is an date archive. */ public function is_date_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_date(); } /** * Determine whether this is a search result. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is a search result. */ public function is_search_result() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_search(); } /** * Determine whether this is a 404 page. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is a 404 page. */ public function is_404() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_404(); } /** * Checks if the current page is the post format archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether or not the current page is the post format archive. */ public function is_post_format_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_tax( 'post_format' ); } /** * Determine whether this page is an taxonomy archive page for multiple terms (url: /term-1,term2/). * * @return bool Whether or not the current page is an archive page for multiple terms. */ public function is_multiple_terms_page() { if ( ! $this->is_term_archive() ) { return false; } return $this->count_queried_terms() > 1; } /** * Checks whether the current page is paged. * * @codeCoverageIgnore This method only calls a WordPress function. * * @return bool Whether the current page is paged. */ public function is_paged() { return \is_paged(); } /** * Checks if the current page is the front page. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether or not the current page is the front page. */ public function is_front_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_front_page(); } /** * Retrieves the current admin page. * * @codeCoverageIgnore It only wraps a global WordPress variable. * * @return string The current page. */ public function get_current_admin_page() { global $pagenow; return $pagenow; } /** * Check if the current opened page is a Yoast SEO page. * * @return bool True when current page is a yoast seo plugin page. */ public function is_yoast_seo_page() { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information. if ( isset( $_GET['page'] ) && \is_string( $_GET['page'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Reason: We are not processing form information, We are only using the variable in the strpos function. $current_page = \wp_unslash( $_GET['page'] ); return \strpos( $current_page, 'wpseo_' ) === 0; } return false; } /** * Returns the current Yoast SEO page. * (E.g. the `page` query variable in the URL). * * @return string The current Yoast SEO page. */ public function get_current_yoast_seo_page() { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information. if ( isset( $_GET['page'] ) && \is_string( $_GET['page'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information. return \sanitize_text_field( \wp_unslash( $_GET['page'] ) ); } return ''; } /** * Checks if the current global post is the privacy policy page. * * @return bool current global post is set as privacy page */ public function current_post_is_privacy_policy() { global $post; if ( ! isset( $post->ID ) ) { return false; } return \intval( $post->ID ) === \intval( \get_option( 'wp_page_for_privacy_policy', false ) ); } /** * Returns the permalink of the currently opened date archive. * * @return string The permalink of the currently opened date archive. */ protected function get_non_cached_date_archive_permalink() { $date_archive_permalink = ''; $wp_query = $this->wp_query_wrapper->get_main_query(); if ( $wp_query->is_day() ) { $date_archive_permalink = \get_day_link( $wp_query->get( 'year' ), $wp_query->get( 'monthnum' ), $wp_query->get( 'day' ) ); } if ( $wp_query->is_month() ) { $date_archive_permalink = \get_month_link( $wp_query->get( 'year' ), $wp_query->get( 'monthnum' ) ); } if ( $wp_query->is_year() ) { $date_archive_permalink = \get_year_link( $wp_query->get( 'year' ) ); } return $date_archive_permalink; } /** * Counts the total amount of queried terms. * * @codeCoverageIgnore This relies too much on WordPress dependencies. * * @return int The amoumt of queried terms. */ protected function count_queried_terms() { $wp_query = $this->wp_query_wrapper->get_main_query(); $term = $wp_query->get_queried_object(); $queried_terms = $wp_query->tax_query->queried_terms; if ( \is_null( $term ) || empty( $queried_terms[ $term->taxonomy ]['terms'] ) ) { return 0; } return \count( $queried_terms[ $term->taxonomy ]['terms'] ); } } } $date_archive_permalink = $this->get_non_cached_date_archive_permalink(); return $date_archive_permalink; } /** * Determine whether this is the homepage and shows posts. * * @return bool Whether or not the current page is the homepage that displays posts. */ public function is_home_posts_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); if ( ! $wp_query->is_home() ) { return false; } /* * Whether the static page's `Homepage` option is actually not set to a page. * Otherwise WordPress proceeds to handle the homepage as a `Your latest posts` page. */ if ( (int) \get_option( 'page_on_front' ) === 0 ) { return true; } return \get_option( 'show_on_front' ) === 'posts'; } /** * Determine whether this is the static frontpage. * * @return bool Whether or not the current page is a static frontpage. */ public function is_home_static_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); if ( ! $wp_query->is_front_page() ) { return false; } if ( \get_option( 'show_on_front' ) !== 'page' ) { return false; } return $wp_query->is_page( \get_option( 'page_on_front' ) ); } /** * Determine whether this is the static posts page. * * @return bool Whether or not the current page is a static posts page. */ public function is_static_posts_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); $queried_object = $wp_query->get_queried_object(); return ( $wp_query->is_posts_page && \is_a( $queried_object, WP_Post::class ) && $queried_object->post_type === 'page' ); } /** * Determine whether this is the statically set posts page, when it's not the frontpage. * * @return bool Whether or not it's a non-frontpage, statically set posts page. */ public function is_posts_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); if ( ! $wp_query->is_home() ) { return false; } return \get_option( 'show_on_front' ) === 'page'; } /** * Determine whether this is a post type archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is a post type archive. */ public function is_post_type_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_post_type_archive(); } /** * Determine whether this is a term archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is a term archive. */ public function is_term_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_tax || $wp_query->is_tag || $wp_query->is_category; } /** * Determine whether this is an attachment page. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is an attachment page. */ public function is_attachment() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_attachment; } /** * Determine whether this is an author archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is an author archive. */ public function is_author_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_author(); } /** * Determine whether this is an date archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is an date archive. */ public function is_date_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_date(); } /** * Determine whether this is a search result. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is a search result. */ public function is_search_result() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_search(); } /** * Determine whether this is a 404 page. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is a 404 page. */ public function is_404() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_404(); } /** * Checks if the current page is the post format archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether or not the current page is the post format archive. */ public function is_post_format_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_tax( 'post_format' ); } /** * Determine whether this page is an taxonomy archive page for multiple terms (url: /term-1,term2/). * * @return bool Whether or not the current page is an archive page for multiple terms. */ public function is_multiple_terms_page() { if ( ! $this->is_term_archive() ) { return false; } return $this->count_queried_terms() > 1; } /** * Checks whether the current page is paged. * * @codeCoverageIgnore This method only calls a WordPress function. * * @return bool Whether the current page is paged. */ public function is_paged() { return \is_paged(); } /** * Checks if the current page is the front page. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether or not the current page is the front page. */ public function is_front_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_front_page(); } /** * Retrieves the current admin page. * * @codeCoverageIgnore It only wraps a global WordPress variable. * * @return string The current page. */ public function get_current_admin_page() { global $pagenow; return $pagenow; } /** * Check if the current opened page is a Yoast SEO page. * * @return bool True when current page is a yoast seo plugin page. */ public function is_yoast_seo_page() { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information. if ( isset( $_GET['page'] ) && \is_string( $_GET['page'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Reason: We are not processing form information, We are only using the variable in the strpos function. $current_page = \wp_unslash( $_GET['page'] ); return \strpos( $current_page, 'wpseo_' ) === 0; } return false; } /** * Returns the current Yoast SEO page. * (E.g. the `page` query variable in the URL). * * @return string The current Yoast SEO page. */ public function get_current_yoast_seo_page() { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information. if ( isset( $_GET['page'] ) && \is_string( $_GET['page'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information. return \sanitize_text_field( \wp_unslash( $_GET['page'] ) ); } return ''; } /** * Checks if the current global post is the privacy policy page. * * @return bool current global post is set as privacy page */ public function current_post_is_privacy_policy() { global $post; if ( ! isset( $post->ID ) ) { return false; } return \intval( $post->ID ) === \intval( \get_option( 'wp_page_for_privacy_policy', false ) ); } /** * Returns the permalink of the currently opened date archive. * * @return string The permalink of the currently opened date archive. */ protected function get_non_cached_date_archive_permalink() { $date_archive_permalink = ''; $wp_query = $this->wp_query_wrapper->get_main_query(); if ( $wp_query->is_day() ) { $date_archive_permalink = \get_day_link( $wp_query->get( 'year' ), $wp_query->get( 'monthnum' ), $wp_query->get( 'day' ) ); } if ( $wp_query->is_month() ) { $date_archive_permalink = \get_month_link( $wp_query->get( 'year' ), $wp_query->get( 'monthnum' ) ); } if ( $wp_query->is_year() ) { $date_archive_permalink = \get_year_link( $wp_query->get( 'year' ) ); } return $date_archive_permalink; } /** * Counts the total amount of queried terms. * * @codeCoverageIgnore This relies too much on WordPress dependencies. * * @return int The amoumt of queried terms. */ protected function count_queried_terms() { $wp_query = $this->wp_query_wrapper->get_main_query(); $term = $wp_query->get_queried_object(); $queried_terms = $wp_query->tax_query->queried_terms; if ( \is_null( $term ) || empty( $queried_terms[ $term->taxonomy ]['terms'] ) ) { return 0; } return \count( $queried_terms[ $term->taxonomy ]['terms'] ); } } } $date_archive_permalink = $this->get_non_cached_date_archive_permalink(); return $date_archive_permalink; } /** * Determine whether this is the homepage and shows posts. * * @return bool Whether or not the current page is the homepage that displays posts. */ public function is_home_posts_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); if ( ! $wp_query->is_home() ) { return false; } /* * Whether the static page's `Homepage` option is actually not set to a page. * Otherwise WordPress proceeds to handle the homepage as a `Your latest posts` page. */ if ( (int) \get_option( 'page_on_front' ) === 0 ) { return true; } return \get_option( 'show_on_front' ) === 'posts'; } /** * Determine whether this is the static frontpage. * * @return bool Whether or not the current page is a static frontpage. */ public function is_home_static_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); if ( ! $wp_query->is_front_page() ) { return false; } if ( \get_option( 'show_on_front' ) !== 'page' ) { return false; } return $wp_query->is_page( \get_option( 'page_on_front' ) ); } /** * Determine whether this is the static posts page. * * @return bool Whether or not the current page is a static posts page. */ public function is_static_posts_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); $queried_object = $wp_query->get_queried_object(); return ( $wp_query->is_posts_page && \is_a( $queried_object, WP_Post::class ) && $queried_object->post_type === 'page' ); } /** * Determine whether this is the statically set posts page, when it's not the frontpage. * * @return bool Whether or not it's a non-frontpage, statically set posts page. */ public function is_posts_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); if ( ! $wp_query->is_home() ) { return false; } return \get_option( 'show_on_front' ) === 'page'; } /** * Determine whether this is a post type archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is a post type archive. */ public function is_post_type_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_post_type_archive(); } /** * Determine whether this is a term archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is a term archive. */ public function is_term_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_tax || $wp_query->is_tag || $wp_query->is_category; } /** * Determine whether this is an attachment page. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is an attachment page. */ public function is_attachment() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_attachment; } /** * Determine whether this is an author archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is an author archive. */ public function is_author_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_author(); } /** * Determine whether this is an date archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is an date archive. */ public function is_date_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_date(); } /** * Determine whether this is a search result. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is a search result. */ public function is_search_result() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_search(); } /** * Determine whether this is a 404 page. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is a 404 page. */ public function is_404() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_404(); } /** * Checks if the current page is the post format archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether or not the current page is the post format archive. */ public function is_post_format_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_tax( 'post_format' ); } /** * Determine whether this page is an taxonomy archive page for multiple terms (url: /term-1,term2/). * * @return bool Whether or not the current page is an archive page for multiple terms. */ public function is_multiple_terms_page() { if ( ! $this->is_term_archive() ) { return false; } return $this->count_queried_terms() > 1; } /** * Checks whether the current page is paged. * * @codeCoverageIgnore This method only calls a WordPress function. * * @return bool Whether the current page is paged. */ public function is_paged() { return \is_paged(); } /** * Checks if the current page is the front page. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether or not the current page is the front page. */ public function is_front_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_front_page(); } /** * Retrieves the current admin page. * * @codeCoverageIgnore It only wraps a global WordPress variable. * * @return string The current page. */ public function get_current_admin_page() { global $pagenow; return $pagenow; } /** * Check if the current opened page is a Yoast SEO page. * * @return bool True when current page is a yoast seo plugin page. */ public function is_yoast_seo_page() { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information. if ( isset( $_GET['page'] ) && \is_string( $_GET['page'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Reason: We are not processing form information, We are only using the variable in the strpos function. $current_page = \wp_unslash( $_GET['page'] ); return \strpos( $current_page, 'wpseo_' ) === 0; } return false; } /** * Returns the current Yoast SEO page. * (E.g. the `page` query variable in the URL). * * @return string The current Yoast SEO page. */ public function get_current_yoast_seo_page() { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information. if ( isset( $_GET['page'] ) && \is_string( $_GET['page'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information. return \sanitize_text_field( \wp_unslash( $_GET['page'] ) ); } return ''; } /** * Checks if the current global post is the privacy policy page. * * @return bool current global post is set as privacy page */ public function current_post_is_privacy_policy() { global $post; if ( ! isset( $post->ID ) ) { return false; } return \intval( $post->ID ) === \intval( \get_option( 'wp_page_for_privacy_policy', false ) ); } /** * Returns the permalink of the currently opened date archive. * * @return string The permalink of the currently opened date archive. */ protected function get_non_cached_date_archive_permalink() { $date_archive_permalink = ''; $wp_query = $this->wp_query_wrapper->get_main_query(); if ( $wp_query->is_day() ) { $date_archive_permalink = \get_day_link( $wp_query->get( 'year' ), $wp_query->get( 'monthnum' ), $wp_query->get( 'day' ) ); } if ( $wp_query->is_month() ) { $date_archive_permalink = \get_month_link( $wp_query->get( 'year' ), $wp_query->get( 'monthnum' ) ); } if ( $wp_query->is_year() ) { $date_archive_permalink = \get_year_link( $wp_query->get( 'year' ) ); } return $date_archive_permalink; } /** * Counts the total amount of queried terms. * * @codeCoverageIgnore This relies too much on WordPress dependencies. * * @return int The amoumt of queried terms. */ protected function count_queried_terms() { $wp_query = $this->wp_query_wrapper->get_main_query(); $term = $wp_query->get_queried_object(); $queried_terms = $wp_query->tax_query->queried_terms; if ( \is_null( $term ) || empty( $queried_terms[ $term->taxonomy ]['terms'] ) ) { return 0; } return \count( $queried_terms[ $term->taxonomy ]['terms'] ); } } } $date_archive_permalink = $this->get_non_cached_date_archive_permalink(); return $date_archive_permalink; } /** * Determine whether this is the homepage and shows posts. * * @return bool Whether or not the current page is the homepage that displays posts. */ public function is_home_posts_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); if ( ! $wp_query->is_home() ) { return false; } /* * Whether the static page's `Homepage` option is actually not set to a page. * Otherwise WordPress proceeds to handle the homepage as a `Your latest posts` page. */ if ( (int) \get_option( 'page_on_front' ) === 0 ) { return true; } return \get_option( 'show_on_front' ) === 'posts'; } /** * Determine whether this is the static frontpage. * * @return bool Whether or not the current page is a static frontpage. */ public function is_home_static_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); if ( ! $wp_query->is_front_page() ) { return false; } if ( \get_option( 'show_on_front' ) !== 'page' ) { return false; } return $wp_query->is_page( \get_option( 'page_on_front' ) ); } /** * Determine whether this is the static posts page. * * @return bool Whether or not the current page is a static posts page. */ public function is_static_posts_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); $queried_object = $wp_query->get_queried_object(); return ( $wp_query->is_posts_page && \is_a( $queried_object, WP_Post::class ) && $queried_object->post_type === 'page' ); } /** * Determine whether this is the statically set posts page, when it's not the frontpage. * * @return bool Whether or not it's a non-frontpage, statically set posts page. */ public function is_posts_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); if ( ! $wp_query->is_home() ) { return false; } return \get_option( 'show_on_front' ) === 'page'; } /** * Determine whether this is a post type archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is a post type archive. */ public function is_post_type_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_post_type_archive(); } /** * Determine whether this is a term archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is a term archive. */ public function is_term_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_tax || $wp_query->is_tag || $wp_query->is_category; } /** * Determine whether this is an attachment page. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is an attachment page. */ public function is_attachment() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_attachment; } /** * Determine whether this is an author archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is an author archive. */ public function is_author_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_author(); } /** * Determine whether this is an date archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is an date archive. */ public function is_date_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_date(); } /** * Determine whether this is a search result. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is a search result. */ public function is_search_result() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_search(); } /** * Determine whether this is a 404 page. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is a 404 page. */ public function is_404() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_404(); } /** * Checks if the current page is the post format archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether or not the current page is the post format archive. */ public function is_post_format_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_tax( 'post_format' ); } /** * Determine whether this page is an taxonomy archive page for multiple terms (url: /term-1,term2/). * * @return bool Whether or not the current page is an archive page for multiple terms. */ public function is_multiple_terms_page() { if ( ! $this->is_term_archive() ) { return false; } return $this->count_queried_terms() > 1; } /** * Checks whether the current page is paged. * * @codeCoverageIgnore This method only calls a WordPress function. * * @return bool Whether the current page is paged. */ public function is_paged() { return \is_paged(); } /** * Checks if the current page is the front page. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether or not the current page is the front page. */ public function is_front_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_front_page(); } /** * Retrieves the current admin page. * * @codeCoverageIgnore It only wraps a global WordPress variable. * * @return string The current page. */ public function get_current_admin_page() { global $pagenow; return $pagenow; } /** * Check if the current opened page is a Yoast SEO page. * * @return bool True when current page is a yoast seo plugin page. */ public function is_yoast_seo_page() { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information. if ( isset( $_GET['page'] ) && \is_string( $_GET['page'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Reason: We are not processing form information, We are only using the variable in the strpos function. $current_page = \wp_unslash( $_GET['page'] ); return \strpos( $current_page, 'wpseo_' ) === 0; } return false; } /** * Returns the current Yoast SEO page. * (E.g. the `page` query variable in the URL). * * @return string The current Yoast SEO page. */ public function get_current_yoast_seo_page() { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information. if ( isset( $_GET['page'] ) && \is_string( $_GET['page'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information. return \sanitize_text_field( \wp_unslash( $_GET['page'] ) ); } return ''; } /** * Checks if the current global post is the privacy policy page. * * @return bool current global post is set as privacy page */ public function current_post_is_privacy_policy() { global $post; if ( ! isset( $post->ID ) ) { return false; } return \intval( $post->ID ) === \intval( \get_option( 'wp_page_for_privacy_policy', false ) ); } /** * Returns the permalink of the currently opened date archive. * * @return string The permalink of the currently opened date archive. */ protected function get_non_cached_date_archive_permalink() { $date_archive_permalink = ''; $wp_query = $this->wp_query_wrapper->get_main_query(); if ( $wp_query->is_day() ) { $date_archive_permalink = \get_day_link( $wp_query->get( 'year' ), $wp_query->get( 'monthnum' ), $wp_query->get( 'day' ) ); } if ( $wp_query->is_month() ) { $date_archive_permalink = \get_month_link( $wp_query->get( 'year' ), $wp_query->get( 'monthnum' ) ); } if ( $wp_query->is_year() ) { $date_archive_permalink = \get_year_link( $wp_query->get( 'year' ) ); } return $date_archive_permalink; } /** * Counts the total amount of queried terms. * * @codeCoverageIgnore This relies too much on WordPress dependencies. * * @return int The amoumt of queried terms. */ protected function count_queried_terms() { $wp_query = $this->wp_query_wrapper->get_main_query(); $term = $wp_query->get_queried_object(); $queried_terms = $wp_query->tax_query->queried_terms; if ( \is_null( $term ) || empty( $queried_terms[ $term->taxonomy ]['terms'] ) ) { return 0; } return \count( $queried_terms[ $term->taxonomy ]['terms'] ); } } } $date_archive_permalink = $this->get_non_cached_date_archive_permalink(); return $date_archive_permalink; } /** * Determine whether this is the homepage and shows posts. * * @return bool Whether or not the current page is the homepage that displays posts. */ public function is_home_posts_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); if ( ! $wp_query->is_home() ) { return false; } /* * Whether the static page's `Homepage` option is actually not set to a page. * Otherwise WordPress proceeds to handle the homepage as a `Your latest posts` page. */ if ( (int) \get_option( 'page_on_front' ) === 0 ) { return true; } return \get_option( 'show_on_front' ) === 'posts'; } /** * Determine whether this is the static frontpage. * * @return bool Whether or not the current page is a static frontpage. */ public function is_home_static_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); if ( ! $wp_query->is_front_page() ) { return false; } if ( \get_option( 'show_on_front' ) !== 'page' ) { return false; } return $wp_query->is_page( \get_option( 'page_on_front' ) ); } /** * Determine whether this is the static posts page. * * @return bool Whether or not the current page is a static posts page. */ public function is_static_posts_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); $queried_object = $wp_query->get_queried_object(); return ( $wp_query->is_posts_page && \is_a( $queried_object, WP_Post::class ) && $queried_object->post_type === 'page' ); } /** * Determine whether this is the statically set posts page, when it's not the frontpage. * * @return bool Whether or not it's a non-frontpage, statically set posts page. */ public function is_posts_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); if ( ! $wp_query->is_home() ) { return false; } return \get_option( 'show_on_front' ) === 'page'; } /** * Determine whether this is a post type archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is a post type archive. */ public function is_post_type_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_post_type_archive(); } /** * Determine whether this is a term archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is a term archive. */ public function is_term_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_tax || $wp_query->is_tag || $wp_query->is_category; } /** * Determine whether this is an attachment page. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is an attachment page. */ public function is_attachment() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_attachment; } /** * Determine whether this is an author archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is an author archive. */ public function is_author_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_author(); } /** * Determine whether this is an date archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is an date archive. */ public function is_date_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_date(); } /** * Determine whether this is a search result. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is a search result. */ public function is_search_result() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_search(); } /** * Determine whether this is a 404 page. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is a 404 page. */ public function is_404() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_404(); } /** * Checks if the current page is the post format archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether or not the current page is the post format archive. */ public function is_post_format_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_tax( 'post_format' ); } /** * Determine whether this page is an taxonomy archive page for multiple terms (url: /term-1,term2/). * * @return bool Whether or not the current page is an archive page for multiple terms. */ public function is_multiple_terms_page() { if ( ! $this->is_term_archive() ) { return false; } return $this->count_queried_terms() > 1; } /** * Checks whether the current page is paged. * * @codeCoverageIgnore This method only calls a WordPress function. * * @return bool Whether the current page is paged. */ public function is_paged() { return \is_paged(); } /** * Checks if the current page is the front page. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether or not the current page is the front page. */ public function is_front_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_front_page(); } /** * Retrieves the current admin page. * * @codeCoverageIgnore It only wraps a global WordPress variable. * * @return string The current page. */ public function get_current_admin_page() { global $pagenow; return $pagenow; } /** * Check if the current opened page is a Yoast SEO page. * * @return bool True when current page is a yoast seo plugin page. */ public function is_yoast_seo_page() { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information. if ( isset( $_GET['page'] ) && \is_string( $_GET['page'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Reason: We are not processing form information, We are only using the variable in the strpos function. $current_page = \wp_unslash( $_GET['page'] ); return \strpos( $current_page, 'wpseo_' ) === 0; } return false; } /** * Returns the current Yoast SEO page. * (E.g. the `page` query variable in the URL). * * @return string The current Yoast SEO page. */ public function get_current_yoast_seo_page() { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information. if ( isset( $_GET['page'] ) && \is_string( $_GET['page'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information. return \sanitize_text_field( \wp_unslash( $_GET['page'] ) ); } return ''; } /** * Checks if the current global post is the privacy policy page. * * @return bool current global post is set as privacy page */ public function current_post_is_privacy_policy() { global $post; if ( ! isset( $post->ID ) ) { return false; } return \intval( $post->ID ) === \intval( \get_option( 'wp_page_for_privacy_policy', false ) ); } /** * Returns the permalink of the currently opened date archive. * * @return string The permalink of the currently opened date archive. */ protected function get_non_cached_date_archive_permalink() { $date_archive_permalink = ''; $wp_query = $this->wp_query_wrapper->get_main_query(); if ( $wp_query->is_day() ) { $date_archive_permalink = \get_day_link( $wp_query->get( 'year' ), $wp_query->get( 'monthnum' ), $wp_query->get( 'day' ) ); } if ( $wp_query->is_month() ) { $date_archive_permalink = \get_month_link( $wp_query->get( 'year' ), $wp_query->get( 'monthnum' ) ); } if ( $wp_query->is_year() ) { $date_archive_permalink = \get_year_link( $wp_query->get( 'year' ) ); } return $date_archive_permalink; } /** * Counts the total amount of queried terms. * * @codeCoverageIgnore This relies too much on WordPress dependencies. * * @return int The amoumt of queried terms. */ protected function count_queried_terms() { $wp_query = $this->wp_query_wrapper->get_main_query(); $term = $wp_query->get_queried_object(); $queried_terms = $wp_query->tax_query->queried_terms; if ( \is_null( $term ) || empty( $queried_terms[ $term->taxonomy ]['terms'] ) ) { return 0; } return \count( $queried_terms[ $term->taxonomy ]['terms'] ); } } } $date_archive_permalink = $this->get_non_cached_date_archive_permalink(); return $date_archive_permalink; } /** * Determine whether this is the homepage and shows posts. * * @return bool Whether or not the current page is the homepage that displays posts. */ public function is_home_posts_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); if ( ! $wp_query->is_home() ) { return false; } /* * Whether the static page's `Homepage` option is actually not set to a page. * Otherwise WordPress proceeds to handle the homepage as a `Your latest posts` page. */ if ( (int) \get_option( 'page_on_front' ) === 0 ) { return true; } return \get_option( 'show_on_front' ) === 'posts'; } /** * Determine whether this is the static frontpage. * * @return bool Whether or not the current page is a static frontpage. */ public function is_home_static_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); if ( ! $wp_query->is_front_page() ) { return false; } if ( \get_option( 'show_on_front' ) !== 'page' ) { return false; } return $wp_query->is_page( \get_option( 'page_on_front' ) ); } /** * Determine whether this is the static posts page. * * @return bool Whether or not the current page is a static posts page. */ public function is_static_posts_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); $queried_object = $wp_query->get_queried_object(); return ( $wp_query->is_posts_page && \is_a( $queried_object, WP_Post::class ) && $queried_object->post_type === 'page' ); } /** * Determine whether this is the statically set posts page, when it's not the frontpage. * * @return bool Whether or not it's a non-frontpage, statically set posts page. */ public function is_posts_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); if ( ! $wp_query->is_home() ) { return false; } return \get_option( 'show_on_front' ) === 'page'; } /** * Determine whether this is a post type archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is a post type archive. */ public function is_post_type_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_post_type_archive(); } /** * Determine whether this is a term archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is a term archive. */ public function is_term_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_tax || $wp_query->is_tag || $wp_query->is_category; } /** * Determine whether this is an attachment page. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is an attachment page. */ public function is_attachment() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_attachment; } /** * Determine whether this is an author archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is an author archive. */ public function is_author_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_author(); } /** * Determine whether this is an date archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is an date archive. */ public function is_date_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_date(); } /** * Determine whether this is a search result. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is a search result. */ public function is_search_result() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_search(); } /** * Determine whether this is a 404 page. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is a 404 page. */ public function is_404() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_404(); } /** * Checks if the current page is the post format archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether or not the current page is the post format archive. */ public function is_post_format_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_tax( 'post_format' ); } /** * Determine whether this page is an taxonomy archive page for multiple terms (url: /term-1,term2/). * * @return bool Whether or not the current page is an archive page for multiple terms. */ public function is_multiple_terms_page() { if ( ! $this->is_term_archive() ) { return false; } return $this->count_queried_terms() > 1; } /** * Checks whether the current page is paged. * * @codeCoverageIgnore This method only calls a WordPress function. * * @return bool Whether the current page is paged. */ public function is_paged() { return \is_paged(); } /** * Checks if the current page is the front page. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether or not the current page is the front page. */ public function is_front_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_front_page(); } /** * Retrieves the current admin page. * * @codeCoverageIgnore It only wraps a global WordPress variable. * * @return string The current page. */ public function get_current_admin_page() { global $pagenow; return $pagenow; } /** * Check if the current opened page is a Yoast SEO page. * * @return bool True when current page is a yoast seo plugin page. */ public function is_yoast_seo_page() { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information. if ( isset( $_GET['page'] ) && \is_string( $_GET['page'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Reason: We are not processing form information, We are only using the variable in the strpos function. $current_page = \wp_unslash( $_GET['page'] ); return \strpos( $current_page, 'wpseo_' ) === 0; } return false; } /** * Returns the current Yoast SEO page. * (E.g. the `page` query variable in the URL). * * @return string The current Yoast SEO page. */ public function get_current_yoast_seo_page() { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information. if ( isset( $_GET['page'] ) && \is_string( $_GET['page'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information. return \sanitize_text_field( \wp_unslash( $_GET['page'] ) ); } return ''; } /** * Checks if the current global post is the privacy policy page. * * @return bool current global post is set as privacy page */ public function current_post_is_privacy_policy() { global $post; if ( ! isset( $post->ID ) ) { return false; } return \intval( $post->ID ) === \intval( \get_option( 'wp_page_for_privacy_policy', false ) ); } /** * Returns the permalink of the currently opened date archive. * * @return string The permalink of the currently opened date archive. */ protected function get_non_cached_date_archive_permalink() { $date_archive_permalink = ''; $wp_query = $this->wp_query_wrapper->get_main_query(); if ( $wp_query->is_day() ) { $date_archive_permalink = \get_day_link( $wp_query->get( 'year' ), $wp_query->get( 'monthnum' ), $wp_query->get( 'day' ) ); } if ( $wp_query->is_month() ) { $date_archive_permalink = \get_month_link( $wp_query->get( 'year' ), $wp_query->get( 'monthnum' ) ); } if ( $wp_query->is_year() ) { $date_archive_permalink = \get_year_link( $wp_query->get( 'year' ) ); } return $date_archive_permalink; } /** * Counts the total amount of queried terms. * * @codeCoverageIgnore This relies too much on WordPress dependencies. * * @return int The amoumt of queried terms. */ protected function count_queried_terms() { $wp_query = $this->wp_query_wrapper->get_main_query(); $term = $wp_query->get_queried_object(); $queried_terms = $wp_query->tax_query->queried_terms; if ( \is_null( $term ) || empty( $queried_terms[ $term->taxonomy ]['terms'] ) ) { return 0; } return \count( $queried_terms[ $term->taxonomy ]['terms'] ); } } } $date_archive_permalink = $this->get_non_cached_date_archive_permalink(); return $date_archive_permalink; } /** * Determine whether this is the homepage and shows posts. * * @return bool Whether or not the current page is the homepage that displays posts. */ public function is_home_posts_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); if ( ! $wp_query->is_home() ) { return false; } /* * Whether the static page's `Homepage` option is actually not set to a page. * Otherwise WordPress proceeds to handle the homepage as a `Your latest posts` page. */ if ( (int) \get_option( 'page_on_front' ) === 0 ) { return true; } return \get_option( 'show_on_front' ) === 'posts'; } /** * Determine whether this is the static frontpage. * * @return bool Whether or not the current page is a static frontpage. */ public function is_home_static_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); if ( ! $wp_query->is_front_page() ) { return false; } if ( \get_option( 'show_on_front' ) !== 'page' ) { return false; } return $wp_query->is_page( \get_option( 'page_on_front' ) ); } /** * Determine whether this is the static posts page. * * @return bool Whether or not the current page is a static posts page. */ public function is_static_posts_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); $queried_object = $wp_query->get_queried_object(); return ( $wp_query->is_posts_page && \is_a( $queried_object, WP_Post::class ) && $queried_object->post_type === 'page' ); } /** * Determine whether this is the statically set posts page, when it's not the frontpage. * * @return bool Whether or not it's a non-frontpage, statically set posts page. */ public function is_posts_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); if ( ! $wp_query->is_home() ) { return false; } return \get_option( 'show_on_front' ) === 'page'; } /** * Determine whether this is a post type archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is a post type archive. */ public function is_post_type_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_post_type_archive(); } /** * Determine whether this is a term archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is a term archive. */ public function is_term_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_tax || $wp_query->is_tag || $wp_query->is_category; } /** * Determine whether this is an attachment page. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is an attachment page. */ public function is_attachment() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_attachment; } /** * Determine whether this is an author archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is an author archive. */ public function is_author_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_author(); } /** * Determine whether this is an date archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is an date archive. */ public function is_date_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_date(); } /** * Determine whether this is a search result. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is a search result. */ public function is_search_result() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_search(); } /** * Determine whether this is a 404 page. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is a 404 page. */ public function is_404() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_404(); } /** * Checks if the current page is the post format archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether or not the current page is the post format archive. */ public function is_post_format_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_tax( 'post_format' ); } /** * Determine whether this page is an taxonomy archive page for multiple terms (url: /term-1,term2/). * * @return bool Whether or not the current page is an archive page for multiple terms. */ public function is_multiple_terms_page() { if ( ! $this->is_term_archive() ) { return false; } return $this->count_queried_terms() > 1; } /** * Checks whether the current page is paged. * * @codeCoverageIgnore This method only calls a WordPress function. * * @return bool Whether the current page is paged. */ public function is_paged() { return \is_paged(); } /** * Checks if the current page is the front page. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether or not the current page is the front page. */ public function is_front_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_front_page(); } /** * Retrieves the current admin page. * * @codeCoverageIgnore It only wraps a global WordPress variable. * * @return string The current page. */ public function get_current_admin_page() { global $pagenow; return $pagenow; } /** * Check if the current opened page is a Yoast SEO page. * * @return bool True when current page is a yoast seo plugin page. */ public function is_yoast_seo_page() { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information. if ( isset( $_GET['page'] ) && \is_string( $_GET['page'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Reason: We are not processing form information, We are only using the variable in the strpos function. $current_page = \wp_unslash( $_GET['page'] ); return \strpos( $current_page, 'wpseo_' ) === 0; } return false; } /** * Returns the current Yoast SEO page. * (E.g. the `page` query variable in the URL). * * @return string The current Yoast SEO page. */ public function get_current_yoast_seo_page() { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information. if ( isset( $_GET['page'] ) && \is_string( $_GET['page'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information. return \sanitize_text_field( \wp_unslash( $_GET['page'] ) ); } return ''; } /** * Checks if the current global post is the privacy policy page. * * @return bool current global post is set as privacy page */ public function current_post_is_privacy_policy() { global $post; if ( ! isset( $post->ID ) ) { return false; } return \intval( $post->ID ) === \intval( \get_option( 'wp_page_for_privacy_policy', false ) ); } /** * Returns the permalink of the currently opened date archive. * * @return string The permalink of the currently opened date archive. */ protected function get_non_cached_date_archive_permalink() { $date_archive_permalink = ''; $wp_query = $this->wp_query_wrapper->get_main_query(); if ( $wp_query->is_day() ) { $date_archive_permalink = \get_day_link( $wp_query->get( 'year' ), $wp_query->get( 'monthnum' ), $wp_query->get( 'day' ) ); } if ( $wp_query->is_month() ) { $date_archive_permalink = \get_month_link( $wp_query->get( 'year' ), $wp_query->get( 'monthnum' ) ); } if ( $wp_query->is_year() ) { $date_archive_permalink = \get_year_link( $wp_query->get( 'year' ) ); } return $date_archive_permalink; } /** * Counts the total amount of queried terms. * * @codeCoverageIgnore This relies too much on WordPress dependencies. * * @return int The amoumt of queried terms. */ protected function count_queried_terms() { $wp_query = $this->wp_query_wrapper->get_main_query(); $term = $wp_query->get_queried_object(); $queried_terms = $wp_query->tax_query->queried_terms; if ( \is_null( $term ) || empty( $queried_terms[ $term->taxonomy ]['terms'] ) ) { return 0; } return \count( $queried_terms[ $term->taxonomy ]['terms'] ); } } } $date_archive_permalink = $this->get_non_cached_date_archive_permalink(); return $date_archive_permalink; } /** * Determine whether this is the homepage and shows posts. * * @return bool Whether or not the current page is the homepage that displays posts. */ public function is_home_posts_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); if ( ! $wp_query->is_home() ) { return false; } /* * Whether the static page's `Homepage` option is actually not set to a page. * Otherwise WordPress proceeds to handle the homepage as a `Your latest posts` page. */ if ( (int) \get_option( 'page_on_front' ) === 0 ) { return true; } return \get_option( 'show_on_front' ) === 'posts'; } /** * Determine whether this is the static frontpage. * * @return bool Whether or not the current page is a static frontpage. */ public function is_home_static_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); if ( ! $wp_query->is_front_page() ) { return false; } if ( \get_option( 'show_on_front' ) !== 'page' ) { return false; } return $wp_query->is_page( \get_option( 'page_on_front' ) ); } /** * Determine whether this is the static posts page. * * @return bool Whether or not the current page is a static posts page. */ public function is_static_posts_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); $queried_object = $wp_query->get_queried_object(); return ( $wp_query->is_posts_page && \is_a( $queried_object, WP_Post::class ) && $queried_object->post_type === 'page' ); } /** * Determine whether this is the statically set posts page, when it's not the frontpage. * * @return bool Whether or not it's a non-frontpage, statically set posts page. */ public function is_posts_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); if ( ! $wp_query->is_home() ) { return false; } return \get_option( 'show_on_front' ) === 'page'; } /** * Determine whether this is a post type archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is a post type archive. */ public function is_post_type_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_post_type_archive(); } /** * Determine whether this is a term archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is a term archive. */ public function is_term_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_tax || $wp_query->is_tag || $wp_query->is_category; } /** * Determine whether this is an attachment page. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is an attachment page. */ public function is_attachment() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_attachment; } /** * Determine whether this is an author archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is an author archive. */ public function is_author_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_author(); } /** * Determine whether this is an date archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is an date archive. */ public function is_date_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_date(); } /** * Determine whether this is a search result. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is a search result. */ public function is_search_result() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_search(); } /** * Determine whether this is a 404 page. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is a 404 page. */ public function is_404() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_404(); } /** * Checks if the current page is the post format archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether or not the current page is the post format archive. */ public function is_post_format_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_tax( 'post_format' ); } /** * Determine whether this page is an taxonomy archive page for multiple terms (url: /term-1,term2/). * * @return bool Whether or not the current page is an archive page for multiple terms. */ public function is_multiple_terms_page() { if ( ! $this->is_term_archive() ) { return false; } return $this->count_queried_terms() > 1; } /** * Checks whether the current page is paged. * * @codeCoverageIgnore This method only calls a WordPress function. * * @return bool Whether the current page is paged. */ public function is_paged() { return \is_paged(); } /** * Checks if the current page is the front page. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether or not the current page is the front page. */ public function is_front_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_front_page(); } /** * Retrieves the current admin page. * * @codeCoverageIgnore It only wraps a global WordPress variable. * * @return string The current page. */ public function get_current_admin_page() { global $pagenow; return $pagenow; } /** * Check if the current opened page is a Yoast SEO page. * * @return bool True when current page is a yoast seo plugin page. */ public function is_yoast_seo_page() { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information. if ( isset( $_GET['page'] ) && \is_string( $_GET['page'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Reason: We are not processing form information, We are only using the variable in the strpos function. $current_page = \wp_unslash( $_GET['page'] ); return \strpos( $current_page, 'wpseo_' ) === 0; } return false; } /** * Returns the current Yoast SEO page. * (E.g. the `page` query variable in the URL). * * @return string The current Yoast SEO page. */ public function get_current_yoast_seo_page() { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information. if ( isset( $_GET['page'] ) && \is_string( $_GET['page'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information. return \sanitize_text_field( \wp_unslash( $_GET['page'] ) ); } return ''; } /** * Checks if the current global post is the privacy policy page. * * @return bool current global post is set as privacy page */ public function current_post_is_privacy_policy() { global $post; if ( ! isset( $post->ID ) ) { return false; } return \intval( $post->ID ) === \intval( \get_option( 'wp_page_for_privacy_policy', false ) ); } /** * Returns the permalink of the currently opened date archive. * * @return string The permalink of the currently opened date archive. */ protected function get_non_cached_date_archive_permalink() { $date_archive_permalink = ''; $wp_query = $this->wp_query_wrapper->get_main_query(); if ( $wp_query->is_day() ) { $date_archive_permalink = \get_day_link( $wp_query->get( 'year' ), $wp_query->get( 'monthnum' ), $wp_query->get( 'day' ) ); } if ( $wp_query->is_month() ) { $date_archive_permalink = \get_month_link( $wp_query->get( 'year' ), $wp_query->get( 'monthnum' ) ); } if ( $wp_query->is_year() ) { $date_archive_permalink = \get_year_link( $wp_query->get( 'year' ) ); } return $date_archive_permalink; } /** * Counts the total amount of queried terms. * * @codeCoverageIgnore This relies too much on WordPress dependencies. * * @return int The amoumt of queried terms. */ protected function count_queried_terms() { $wp_query = $this->wp_query_wrapper->get_main_query(); $term = $wp_query->get_queried_object(); $queried_terms = $wp_query->tax_query->queried_terms; if ( \is_null( $term ) || empty( $queried_terms[ $term->taxonomy ]['terms'] ) ) { return 0; } return \count( $queried_terms[ $term->taxonomy ]['terms'] ); } } } $date_archive_permalink = $this->get_non_cached_date_archive_permalink(); return $date_archive_permalink; } /** * Determine whether this is the homepage and shows posts. * * @return bool Whether or not the current page is the homepage that displays posts. */ public function is_home_posts_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); if ( ! $wp_query->is_home() ) { return false; } /* * Whether the static page's `Homepage` option is actually not set to a page. * Otherwise WordPress proceeds to handle the homepage as a `Your latest posts` page. */ if ( (int) \get_option( 'page_on_front' ) === 0 ) { return true; } return \get_option( 'show_on_front' ) === 'posts'; } /** * Determine whether this is the static frontpage. * * @return bool Whether or not the current page is a static frontpage. */ public function is_home_static_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); if ( ! $wp_query->is_front_page() ) { return false; } if ( \get_option( 'show_on_front' ) !== 'page' ) { return false; } return $wp_query->is_page( \get_option( 'page_on_front' ) ); } /** * Determine whether this is the static posts page. * * @return bool Whether or not the current page is a static posts page. */ public function is_static_posts_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); $queried_object = $wp_query->get_queried_object(); return ( $wp_query->is_posts_page && \is_a( $queried_object, WP_Post::class ) && $queried_object->post_type === 'page' ); } /** * Determine whether this is the statically set posts page, when it's not the frontpage. * * @return bool Whether or not it's a non-frontpage, statically set posts page. */ public function is_posts_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); if ( ! $wp_query->is_home() ) { return false; } return \get_option( 'show_on_front' ) === 'page'; } /** * Determine whether this is a post type archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is a post type archive. */ public function is_post_type_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_post_type_archive(); } /** * Determine whether this is a term archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is a term archive. */ public function is_term_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_tax || $wp_query->is_tag || $wp_query->is_category; } /** * Determine whether this is an attachment page. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is an attachment page. */ public function is_attachment() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_attachment; } /** * Determine whether this is an author archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is an author archive. */ public function is_author_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_author(); } /** * Determine whether this is an date archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is an date archive. */ public function is_date_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_date(); } /** * Determine whether this is a search result. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is a search result. */ public function is_search_result() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_search(); } /** * Determine whether this is a 404 page. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is a 404 page. */ public function is_404() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_404(); } /** * Checks if the current page is the post format archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether or not the current page is the post format archive. */ public function is_post_format_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_tax( 'post_format' ); } /** * Determine whether this page is an taxonomy archive page for multiple terms (url: /term-1,term2/). * * @return bool Whether or not the current page is an archive page for multiple terms. */ public function is_multiple_terms_page() { if ( ! $this->is_term_archive() ) { return false; } return $this->count_queried_terms() > 1; } /** * Checks whether the current page is paged. * * @codeCoverageIgnore This method only calls a WordPress function. * * @return bool Whether the current page is paged. */ public function is_paged() { return \is_paged(); } /** * Checks if the current page is the front page. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether or not the current page is the front page. */ public function is_front_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_front_page(); } /** * Retrieves the current admin page. * * @codeCoverageIgnore It only wraps a global WordPress variable. * * @return string The current page. */ public function get_current_admin_page() { global $pagenow; return $pagenow; } /** * Check if the current opened page is a Yoast SEO page. * * @return bool True when current page is a yoast seo plugin page. */ public function is_yoast_seo_page() { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information. if ( isset( $_GET['page'] ) && \is_string( $_GET['page'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Reason: We are not processing form information, We are only using the variable in the strpos function. $current_page = \wp_unslash( $_GET['page'] ); return \strpos( $current_page, 'wpseo_' ) === 0; } return false; } /** * Returns the current Yoast SEO page. * (E.g. the `page` query variable in the URL). * * @return string The current Yoast SEO page. */ public function get_current_yoast_seo_page() { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information. if ( isset( $_GET['page'] ) && \is_string( $_GET['page'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information. return \sanitize_text_field( \wp_unslash( $_GET['page'] ) ); } return ''; } /** * Checks if the current global post is the privacy policy page. * * @return bool current global post is set as privacy page */ public function current_post_is_privacy_policy() { global $post; if ( ! isset( $post->ID ) ) { return false; } return \intval( $post->ID ) === \intval( \get_option( 'wp_page_for_privacy_policy', false ) ); } /** * Returns the permalink of the currently opened date archive. * * @return string The permalink of the currently opened date archive. */ protected function get_non_cached_date_archive_permalink() { $date_archive_permalink = ''; $wp_query = $this->wp_query_wrapper->get_main_query(); if ( $wp_query->is_day() ) { $date_archive_permalink = \get_day_link( $wp_query->get( 'year' ), $wp_query->get( 'monthnum' ), $wp_query->get( 'day' ) ); } if ( $wp_query->is_month() ) { $date_archive_permalink = \get_month_link( $wp_query->get( 'year' ), $wp_query->get( 'monthnum' ) ); } if ( $wp_query->is_year() ) { $date_archive_permalink = \get_year_link( $wp_query->get( 'year' ) ); } return $date_archive_permalink; } /** * Counts the total amount of queried terms. * * @codeCoverageIgnore This relies too much on WordPress dependencies. * * @return int The amoumt of queried terms. */ protected function count_queried_terms() { $wp_query = $this->wp_query_wrapper->get_main_query(); $term = $wp_query->get_queried_object(); $queried_terms = $wp_query->tax_query->queried_terms; if ( \is_null( $term ) || empty( $queried_terms[ $term->taxonomy ]['terms'] ) ) { return 0; } return \count( $queried_terms[ $term->taxonomy ]['terms'] ); } } } $date_archive_permalink = $this->get_non_cached_date_archive_permalink(); return $date_archive_permalink; } /** * Determine whether this is the homepage and shows posts. * * @return bool Whether or not the current page is the homepage that displays posts. */ public function is_home_posts_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); if ( ! $wp_query->is_home() ) { return false; } /* * Whether the static page's `Homepage` option is actually not set to a page. * Otherwise WordPress proceeds to handle the homepage as a `Your latest posts` page. */ if ( (int) \get_option( 'page_on_front' ) === 0 ) { return true; } return \get_option( 'show_on_front' ) === 'posts'; } /** * Determine whether this is the static frontpage. * * @return bool Whether or not the current page is a static frontpage. */ public function is_home_static_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); if ( ! $wp_query->is_front_page() ) { return false; } if ( \get_option( 'show_on_front' ) !== 'page' ) { return false; } return $wp_query->is_page( \get_option( 'page_on_front' ) ); } /** * Determine whether this is the static posts page. * * @return bool Whether or not the current page is a static posts page. */ public function is_static_posts_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); $queried_object = $wp_query->get_queried_object(); return ( $wp_query->is_posts_page && \is_a( $queried_object, WP_Post::class ) && $queried_object->post_type === 'page' ); } /** * Determine whether this is the statically set posts page, when it's not the frontpage. * * @return bool Whether or not it's a non-frontpage, statically set posts page. */ public function is_posts_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); if ( ! $wp_query->is_home() ) { return false; } return \get_option( 'show_on_front' ) === 'page'; } /** * Determine whether this is a post type archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is a post type archive. */ public function is_post_type_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_post_type_archive(); } /** * Determine whether this is a term archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is a term archive. */ public function is_term_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_tax || $wp_query->is_tag || $wp_query->is_category; } /** * Determine whether this is an attachment page. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is an attachment page. */ public function is_attachment() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_attachment; } /** * Determine whether this is an author archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is an author archive. */ public function is_author_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_author(); } /** * Determine whether this is an date archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is an date archive. */ public function is_date_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_date(); } /** * Determine whether this is a search result. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is a search result. */ public function is_search_result() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_search(); } /** * Determine whether this is a 404 page. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is a 404 page. */ public function is_404() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_404(); } /** * Checks if the current page is the post format archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether or not the current page is the post format archive. */ public function is_post_format_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_tax( 'post_format' ); } /** * Determine whether this page is an taxonomy archive page for multiple terms (url: /term-1,term2/). * * @return bool Whether or not the current page is an archive page for multiple terms. */ public function is_multiple_terms_page() { if ( ! $this->is_term_archive() ) { return false; } return $this->count_queried_terms() > 1; } /** * Checks whether the current page is paged. * * @codeCoverageIgnore This method only calls a WordPress function. * * @return bool Whether the current page is paged. */ public function is_paged() { return \is_paged(); } /** * Checks if the current page is the front page. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether or not the current page is the front page. */ public function is_front_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_front_page(); } /** * Retrieves the current admin page. * * @codeCoverageIgnore It only wraps a global WordPress variable. * * @return string The current page. */ public function get_current_admin_page() { global $pagenow; return $pagenow; } /** * Check if the current opened page is a Yoast SEO page. * * @return bool True when current page is a yoast seo plugin page. */ public function is_yoast_seo_page() { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information. if ( isset( $_GET['page'] ) && \is_string( $_GET['page'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Reason: We are not processing form information, We are only using the variable in the strpos function. $current_page = \wp_unslash( $_GET['page'] ); return \strpos( $current_page, 'wpseo_' ) === 0; } return false; } /** * Returns the current Yoast SEO page. * (E.g. the `page` query variable in the URL). * * @return string The current Yoast SEO page. */ public function get_current_yoast_seo_page() { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information. if ( isset( $_GET['page'] ) && \is_string( $_GET['page'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information. return \sanitize_text_field( \wp_unslash( $_GET['page'] ) ); } return ''; } /** * Checks if the current global post is the privacy policy page. * * @return bool current global post is set as privacy page */ public function current_post_is_privacy_policy() { global $post; if ( ! isset( $post->ID ) ) { return false; } return \intval( $post->ID ) === \intval( \get_option( 'wp_page_for_privacy_policy', false ) ); } /** * Returns the permalink of the currently opened date archive. * * @return string The permalink of the currently opened date archive. */ protected function get_non_cached_date_archive_permalink() { $date_archive_permalink = ''; $wp_query = $this->wp_query_wrapper->get_main_query(); if ( $wp_query->is_day() ) { $date_archive_permalink = \get_day_link( $wp_query->get( 'year' ), $wp_query->get( 'monthnum' ), $wp_query->get( 'day' ) ); } if ( $wp_query->is_month() ) { $date_archive_permalink = \get_month_link( $wp_query->get( 'year' ), $wp_query->get( 'monthnum' ) ); } if ( $wp_query->is_year() ) { $date_archive_permalink = \get_year_link( $wp_query->get( 'year' ) ); } return $date_archive_permalink; } /** * Counts the total amount of queried terms. * * @codeCoverageIgnore This relies too much on WordPress dependencies. * * @return int The amoumt of queried terms. */ protected function count_queried_terms() { $wp_query = $this->wp_query_wrapper->get_main_query(); $term = $wp_query->get_queried_object(); $queried_terms = $wp_query->tax_query->queried_terms; if ( \is_null( $term ) || empty( $queried_terms[ $term->taxonomy ]['terms'] ) ) { return 0; } return \count( $queried_terms[ $term->taxonomy ]['terms'] ); } } } $date_archive_permalink = $this->get_non_cached_date_archive_permalink(); return $date_archive_permalink; } /** * Determine whether this is the homepage and shows posts. * * @return bool Whether or not the current page is the homepage that displays posts. */ public function is_home_posts_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); if ( ! $wp_query->is_home() ) { return false; } /* * Whether the static page's `Homepage` option is actually not set to a page. * Otherwise WordPress proceeds to handle the homepage as a `Your latest posts` page. */ if ( (int) \get_option( 'page_on_front' ) === 0 ) { return true; } return \get_option( 'show_on_front' ) === 'posts'; } /** * Determine whether this is the static frontpage. * * @return bool Whether or not the current page is a static frontpage. */ public function is_home_static_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); if ( ! $wp_query->is_front_page() ) { return false; } if ( \get_option( 'show_on_front' ) !== 'page' ) { return false; } return $wp_query->is_page( \get_option( 'page_on_front' ) ); } /** * Determine whether this is the static posts page. * * @return bool Whether or not the current page is a static posts page. */ public function is_static_posts_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); $queried_object = $wp_query->get_queried_object(); return ( $wp_query->is_posts_page && \is_a( $queried_object, WP_Post::class ) && $queried_object->post_type === 'page' ); } /** * Determine whether this is the statically set posts page, when it's not the frontpage. * * @return bool Whether or not it's a non-frontpage, statically set posts page. */ public function is_posts_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); if ( ! $wp_query->is_home() ) { return false; } return \get_option( 'show_on_front' ) === 'page'; } /** * Determine whether this is a post type archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is a post type archive. */ public function is_post_type_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_post_type_archive(); } /** * Determine whether this is a term archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is a term archive. */ public function is_term_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_tax || $wp_query->is_tag || $wp_query->is_category; } /** * Determine whether this is an attachment page. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is an attachment page. */ public function is_attachment() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_attachment; } /** * Determine whether this is an author archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is an author archive. */ public function is_author_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_author(); } /** * Determine whether this is an date archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is an date archive. */ public function is_date_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_date(); } /** * Determine whether this is a search result. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is a search result. */ public function is_search_result() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_search(); } /** * Determine whether this is a 404 page. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is a 404 page. */ public function is_404() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_404(); } /** * Checks if the current page is the post format archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether or not the current page is the post format archive. */ public function is_post_format_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_tax( 'post_format' ); } /** * Determine whether this page is an taxonomy archive page for multiple terms (url: /term-1,term2/). * * @return bool Whether or not the current page is an archive page for multiple terms. */ public function is_multiple_terms_page() { if ( ! $this->is_term_archive() ) { return false; } return $this->count_queried_terms() > 1; } /** * Checks whether the current page is paged. * * @codeCoverageIgnore This method only calls a WordPress function. * * @return bool Whether the current page is paged. */ public function is_paged() { return \is_paged(); } /** * Checks if the current page is the front page. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether or not the current page is the front page. */ public function is_front_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_front_page(); } /** * Retrieves the current admin page. * * @codeCoverageIgnore It only wraps a global WordPress variable. * * @return string The current page. */ public function get_current_admin_page() { global $pagenow; return $pagenow; } /** * Check if the current opened page is a Yoast SEO page. * * @return bool True when current page is a yoast seo plugin page. */ public function is_yoast_seo_page() { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information. if ( isset( $_GET['page'] ) && \is_string( $_GET['page'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Reason: We are not processing form information, We are only using the variable in the strpos function. $current_page = \wp_unslash( $_GET['page'] ); return \strpos( $current_page, 'wpseo_' ) === 0; } return false; } /** * Returns the current Yoast SEO page. * (E.g. the `page` query variable in the URL). * * @return string The current Yoast SEO page. */ public function get_current_yoast_seo_page() { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information. if ( isset( $_GET['page'] ) && \is_string( $_GET['page'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information. return \sanitize_text_field( \wp_unslash( $_GET['page'] ) ); } return ''; } /** * Checks if the current global post is the privacy policy page. * * @return bool current global post is set as privacy page */ public function current_post_is_privacy_policy() { global $post; if ( ! isset( $post->ID ) ) { return false; } return \intval( $post->ID ) === \intval( \get_option( 'wp_page_for_privacy_policy', false ) ); } /** * Returns the permalink of the currently opened date archive. * * @return string The permalink of the currently opened date archive. */ protected function get_non_cached_date_archive_permalink() { $date_archive_permalink = ''; $wp_query = $this->wp_query_wrapper->get_main_query(); if ( $wp_query->is_day() ) { $date_archive_permalink = \get_day_link( $wp_query->get( 'year' ), $wp_query->get( 'monthnum' ), $wp_query->get( 'day' ) ); } if ( $wp_query->is_month() ) { $date_archive_permalink = \get_month_link( $wp_query->get( 'year' ), $wp_query->get( 'monthnum' ) ); } if ( $wp_query->is_year() ) { $date_archive_permalink = \get_year_link( $wp_query->get( 'year' ) ); } return $date_archive_permalink; } /** * Counts the total amount of queried terms. * * @codeCoverageIgnore This relies too much on WordPress dependencies. * * @return int The amoumt of queried terms. */ protected function count_queried_terms() { $wp_query = $this->wp_query_wrapper->get_main_query(); $term = $wp_query->get_queried_object(); $queried_terms = $wp_query->tax_query->queried_terms; if ( \is_null( $term ) || empty( $queried_terms[ $term->taxonomy ]['terms'] ) ) { return 0; } return \count( $queried_terms[ $term->taxonomy ]['terms'] ); } } } $date_archive_permalink = $this->get_non_cached_date_archive_permalink(); return $date_archive_permalink; } /** * Determine whether this is the homepage and shows posts. * * @return bool Whether or not the current page is the homepage that displays posts. */ public function is_home_posts_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); if ( ! $wp_query->is_home() ) { return false; } /* * Whether the static page's `Homepage` option is actually not set to a page. * Otherwise WordPress proceeds to handle the homepage as a `Your latest posts` page. */ if ( (int) \get_option( 'page_on_front' ) === 0 ) { return true; } return \get_option( 'show_on_front' ) === 'posts'; } /** * Determine whether this is the static frontpage. * * @return bool Whether or not the current page is a static frontpage. */ public function is_home_static_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); if ( ! $wp_query->is_front_page() ) { return false; } if ( \get_option( 'show_on_front' ) !== 'page' ) { return false; } return $wp_query->is_page( \get_option( 'page_on_front' ) ); } /** * Determine whether this is the static posts page. * * @return bool Whether or not the current page is a static posts page. */ public function is_static_posts_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); $queried_object = $wp_query->get_queried_object(); return ( $wp_query->is_posts_page && \is_a( $queried_object, WP_Post::class ) && $queried_object->post_type === 'page' ); } /** * Determine whether this is the statically set posts page, when it's not the frontpage. * * @return bool Whether or not it's a non-frontpage, statically set posts page. */ public function is_posts_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); if ( ! $wp_query->is_home() ) { return false; } return \get_option( 'show_on_front' ) === 'page'; } /** * Determine whether this is a post type archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is a post type archive. */ public function is_post_type_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_post_type_archive(); } /** * Determine whether this is a term archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is a term archive. */ public function is_term_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_tax || $wp_query->is_tag || $wp_query->is_category; } /** * Determine whether this is an attachment page. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is an attachment page. */ public function is_attachment() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_attachment; } /** * Determine whether this is an author archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is an author archive. */ public function is_author_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_author(); } /** * Determine whether this is an date archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is an date archive. */ public function is_date_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_date(); } /** * Determine whether this is a search result. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is a search result. */ public function is_search_result() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_search(); } /** * Determine whether this is a 404 page. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is a 404 page. */ public function is_404() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_404(); } /** * Checks if the current page is the post format archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether or not the current page is the post format archive. */ public function is_post_format_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_tax( 'post_format' ); } /** * Determine whether this page is an taxonomy archive page for multiple terms (url: /term-1,term2/). * * @return bool Whether or not the current page is an archive page for multiple terms. */ public function is_multiple_terms_page() { if ( ! $this->is_term_archive() ) { return false; } return $this->count_queried_terms() > 1; } /** * Checks whether the current page is paged. * * @codeCoverageIgnore This method only calls a WordPress function. * * @return bool Whether the current page is paged. */ public function is_paged() { return \is_paged(); } /** * Checks if the current page is the front page. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether or not the current page is the front page. */ public function is_front_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_front_page(); } /** * Retrieves the current admin page. * * @codeCoverageIgnore It only wraps a global WordPress variable. * * @return string The current page. */ public function get_current_admin_page() { global $pagenow; return $pagenow; } /** * Check if the current opened page is a Yoast SEO page. * * @return bool True when current page is a yoast seo plugin page. */ public function is_yoast_seo_page() { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information. if ( isset( $_GET['page'] ) && \is_string( $_GET['page'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Reason: We are not processing form information, We are only using the variable in the strpos function. $current_page = \wp_unslash( $_GET['page'] ); return \strpos( $current_page, 'wpseo_' ) === 0; } return false; } /** * Returns the current Yoast SEO page. * (E.g. the `page` query variable in the URL). * * @return string The current Yoast SEO page. */ public function get_current_yoast_seo_page() { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information. if ( isset( $_GET['page'] ) && \is_string( $_GET['page'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information. return \sanitize_text_field( \wp_unslash( $_GET['page'] ) ); } return ''; } /** * Checks if the current global post is the privacy policy page. * * @return bool current global post is set as privacy page */ public function current_post_is_privacy_policy() { global $post; if ( ! isset( $post->ID ) ) { return false; } return \intval( $post->ID ) === \intval( \get_option( 'wp_page_for_privacy_policy', false ) ); } /** * Returns the permalink of the currently opened date archive. * * @return string The permalink of the currently opened date archive. */ protected function get_non_cached_date_archive_permalink() { $date_archive_permalink = ''; $wp_query = $this->wp_query_wrapper->get_main_query(); if ( $wp_query->is_day() ) { $date_archive_permalink = \get_day_link( $wp_query->get( 'year' ), $wp_query->get( 'monthnum' ), $wp_query->get( 'day' ) ); } if ( $wp_query->is_month() ) { $date_archive_permalink = \get_month_link( $wp_query->get( 'year' ), $wp_query->get( 'monthnum' ) ); } if ( $wp_query->is_year() ) { $date_archive_permalink = \get_year_link( $wp_query->get( 'year' ) ); } return $date_archive_permalink; } /** * Counts the total amount of queried terms. * * @codeCoverageIgnore This relies too much on WordPress dependencies. * * @return int The amoumt of queried terms. */ protected function count_queried_terms() { $wp_query = $this->wp_query_wrapper->get_main_query(); $term = $wp_query->get_queried_object(); $queried_terms = $wp_query->tax_query->queried_terms; if ( \is_null( $term ) || empty( $queried_terms[ $term->taxonomy ]['terms'] ) ) { return 0; } return \count( $queried_terms[ $term->taxonomy ]['terms'] ); } } } $date_archive_permalink = $this->get_non_cached_date_archive_permalink(); return $date_archive_permalink; } /** * Determine whether this is the homepage and shows posts. * * @return bool Whether or not the current page is the homepage that displays posts. */ public function is_home_posts_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); if ( ! $wp_query->is_home() ) { return false; } /* * Whether the static page's `Homepage` option is actually not set to a page. * Otherwise WordPress proceeds to handle the homepage as a `Your latest posts` page. */ if ( (int) \get_option( 'page_on_front' ) === 0 ) { return true; } return \get_option( 'show_on_front' ) === 'posts'; } /** * Determine whether this is the static frontpage. * * @return bool Whether or not the current page is a static frontpage. */ public function is_home_static_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); if ( ! $wp_query->is_front_page() ) { return false; } if ( \get_option( 'show_on_front' ) !== 'page' ) { return false; } return $wp_query->is_page( \get_option( 'page_on_front' ) ); } /** * Determine whether this is the static posts page. * * @return bool Whether or not the current page is a static posts page. */ public function is_static_posts_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); $queried_object = $wp_query->get_queried_object(); return ( $wp_query->is_posts_page && \is_a( $queried_object, WP_Post::class ) && $queried_object->post_type === 'page' ); } /** * Determine whether this is the statically set posts page, when it's not the frontpage. * * @return bool Whether or not it's a non-frontpage, statically set posts page. */ public function is_posts_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); if ( ! $wp_query->is_home() ) { return false; } return \get_option( 'show_on_front' ) === 'page'; } /** * Determine whether this is a post type archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is a post type archive. */ public function is_post_type_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_post_type_archive(); } /** * Determine whether this is a term archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is a term archive. */ public function is_term_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_tax || $wp_query->is_tag || $wp_query->is_category; } /** * Determine whether this is an attachment page. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is an attachment page. */ public function is_attachment() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_attachment; } /** * Determine whether this is an author archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is an author archive. */ public function is_author_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_author(); } /** * Determine whether this is an date archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is an date archive. */ public function is_date_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_date(); } /** * Determine whether this is a search result. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is a search result. */ public function is_search_result() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_search(); } /** * Determine whether this is a 404 page. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is a 404 page. */ public function is_404() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_404(); } /** * Checks if the current page is the post format archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether or not the current page is the post format archive. */ public function is_post_format_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_tax( 'post_format' ); } /** * Determine whether this page is an taxonomy archive page for multiple terms (url: /term-1,term2/). * * @return bool Whether or not the current page is an archive page for multiple terms. */ public function is_multiple_terms_page() { if ( ! $this->is_term_archive() ) { return false; } return $this->count_queried_terms() > 1; } /** * Checks whether the current page is paged. * * @codeCoverageIgnore This method only calls a WordPress function. * * @return bool Whether the current page is paged. */ public function is_paged() { return \is_paged(); } /** * Checks if the current page is the front page. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether or not the current page is the front page. */ public function is_front_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_front_page(); } /** * Retrieves the current admin page. * * @codeCoverageIgnore It only wraps a global WordPress variable. * * @return string The current page. */ public function get_current_admin_page() { global $pagenow; return $pagenow; } /** * Check if the current opened page is a Yoast SEO page. * * @return bool True when current page is a yoast seo plugin page. */ public function is_yoast_seo_page() { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information. if ( isset( $_GET['page'] ) && \is_string( $_GET['page'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Reason: We are not processing form information, We are only using the variable in the strpos function. $current_page = \wp_unslash( $_GET['page'] ); return \strpos( $current_page, 'wpseo_' ) === 0; } return false; } /** * Returns the current Yoast SEO page. * (E.g. the `page` query variable in the URL). * * @return string The current Yoast SEO page. */ public function get_current_yoast_seo_page() { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information. if ( isset( $_GET['page'] ) && \is_string( $_GET['page'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information. return \sanitize_text_field( \wp_unslash( $_GET['page'] ) ); } return ''; } /** * Checks if the current global post is the privacy policy page. * * @return bool current global post is set as privacy page */ public function current_post_is_privacy_policy() { global $post; if ( ! isset( $post->ID ) ) { return false; } return \intval( $post->ID ) === \intval( \get_option( 'wp_page_for_privacy_policy', false ) ); } /** * Returns the permalink of the currently opened date archive. * * @return string The permalink of the currently opened date archive. */ protected function get_non_cached_date_archive_permalink() { $date_archive_permalink = ''; $wp_query = $this->wp_query_wrapper->get_main_query(); if ( $wp_query->is_day() ) { $date_archive_permalink = \get_day_link( $wp_query->get( 'year' ), $wp_query->get( 'monthnum' ), $wp_query->get( 'day' ) ); } if ( $wp_query->is_month() ) { $date_archive_permalink = \get_month_link( $wp_query->get( 'year' ), $wp_query->get( 'monthnum' ) ); } if ( $wp_query->is_year() ) { $date_archive_permalink = \get_year_link( $wp_query->get( 'year' ) ); } return $date_archive_permalink; } /** * Counts the total amount of queried terms. * * @codeCoverageIgnore This relies too much on WordPress dependencies. * * @return int The amoumt of queried terms. */ protected function count_queried_terms() { $wp_query = $this->wp_query_wrapper->get_main_query(); $term = $wp_query->get_queried_object(); $queried_terms = $wp_query->tax_query->queried_terms; if ( \is_null( $term ) || empty( $queried_terms[ $term->taxonomy ]['terms'] ) ) { return 0; } return \count( $queried_terms[ $term->taxonomy ]['terms'] ); } } } $date_archive_permalink = $this->get_non_cached_date_archive_permalink(); return $date_archive_permalink; } /** * Determine whether this is the homepage and shows posts. * * @return bool Whether or not the current page is the homepage that displays posts. */ public function is_home_posts_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); if ( ! $wp_query->is_home() ) { return false; } /* * Whether the static page's `Homepage` option is actually not set to a page. * Otherwise WordPress proceeds to handle the homepage as a `Your latest posts` page. */ if ( (int) \get_option( 'page_on_front' ) === 0 ) { return true; } return \get_option( 'show_on_front' ) === 'posts'; } /** * Determine whether this is the static frontpage. * * @return bool Whether or not the current page is a static frontpage. */ public function is_home_static_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); if ( ! $wp_query->is_front_page() ) { return false; } if ( \get_option( 'show_on_front' ) !== 'page' ) { return false; } return $wp_query->is_page( \get_option( 'page_on_front' ) ); } /** * Determine whether this is the static posts page. * * @return bool Whether or not the current page is a static posts page. */ public function is_static_posts_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); $queried_object = $wp_query->get_queried_object(); return ( $wp_query->is_posts_page && \is_a( $queried_object, WP_Post::class ) && $queried_object->post_type === 'page' ); } /** * Determine whether this is the statically set posts page, when it's not the frontpage. * * @return bool Whether or not it's a non-frontpage, statically set posts page. */ public function is_posts_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); if ( ! $wp_query->is_home() ) { return false; } return \get_option( 'show_on_front' ) === 'page'; } /** * Determine whether this is a post type archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is a post type archive. */ public function is_post_type_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_post_type_archive(); } /** * Determine whether this is a term archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is a term archive. */ public function is_term_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_tax || $wp_query->is_tag || $wp_query->is_category; } /** * Determine whether this is an attachment page. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is an attachment page. */ public function is_attachment() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_attachment; } /** * Determine whether this is an author archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is an author archive. */ public function is_author_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_author(); } /** * Determine whether this is an date archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is an date archive. */ public function is_date_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_date(); } /** * Determine whether this is a search result. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is a search result. */ public function is_search_result() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_search(); } /** * Determine whether this is a 404 page. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is a 404 page. */ public function is_404() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_404(); } /** * Checks if the current page is the post format archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether or not the current page is the post format archive. */ public function is_post_format_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_tax( 'post_format' ); } /** * Determine whether this page is an taxonomy archive page for multiple terms (url: /term-1,term2/). * * @return bool Whether or not the current page is an archive page for multiple terms. */ public function is_multiple_terms_page() { if ( ! $this->is_term_archive() ) { return false; } return $this->count_queried_terms() > 1; } /** * Checks whether the current page is paged. * * @codeCoverageIgnore This method only calls a WordPress function. * * @return bool Whether the current page is paged. */ public function is_paged() { return \is_paged(); } /** * Checks if the current page is the front page. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether or not the current page is the front page. */ public function is_front_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_front_page(); } /** * Retrieves the current admin page. * * @codeCoverageIgnore It only wraps a global WordPress variable. * * @return string The current page. */ public function get_current_admin_page() { global $pagenow; return $pagenow; } /** * Check if the current opened page is a Yoast SEO page. * * @return bool True when current page is a yoast seo plugin page. */ public function is_yoast_seo_page() { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information. if ( isset( $_GET['page'] ) && \is_string( $_GET['page'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Reason: We are not processing form information, We are only using the variable in the strpos function. $current_page = \wp_unslash( $_GET['page'] ); return \strpos( $current_page, 'wpseo_' ) === 0; } return false; } /** * Returns the current Yoast SEO page. * (E.g. the `page` query variable in the URL). * * @return string The current Yoast SEO page. */ public function get_current_yoast_seo_page() { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information. if ( isset( $_GET['page'] ) && \is_string( $_GET['page'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information. return \sanitize_text_field( \wp_unslash( $_GET['page'] ) ); } return ''; } /** * Checks if the current global post is the privacy policy page. * * @return bool current global post is set as privacy page */ public function current_post_is_privacy_policy() { global $post; if ( ! isset( $post->ID ) ) { return false; } return \intval( $post->ID ) === \intval( \get_option( 'wp_page_for_privacy_policy', false ) ); } /** * Returns the permalink of the currently opened date archive. * * @return string The permalink of the currently opened date archive. */ protected function get_non_cached_date_archive_permalink() { $date_archive_permalink = ''; $wp_query = $this->wp_query_wrapper->get_main_query(); if ( $wp_query->is_day() ) { $date_archive_permalink = \get_day_link( $wp_query->get( 'year' ), $wp_query->get( 'monthnum' ), $wp_query->get( 'day' ) ); } if ( $wp_query->is_month() ) { $date_archive_permalink = \get_month_link( $wp_query->get( 'year' ), $wp_query->get( 'monthnum' ) ); } if ( $wp_query->is_year() ) { $date_archive_permalink = \get_year_link( $wp_query->get( 'year' ) ); } return $date_archive_permalink; } /** * Counts the total amount of queried terms. * * @codeCoverageIgnore This relies too much on WordPress dependencies. * * @return int The amoumt of queried terms. */ protected function count_queried_terms() { $wp_query = $this->wp_query_wrapper->get_main_query(); $term = $wp_query->get_queried_object(); $queried_terms = $wp_query->tax_query->queried_terms; if ( \is_null( $term ) || empty( $queried_terms[ $term->taxonomy ]['terms'] ) ) { return 0; } return \count( $queried_terms[ $term->taxonomy ]['terms'] ); } } } $date_archive_permalink = $this->get_non_cached_date_archive_permalink(); return $date_archive_permalink; } /** * Determine whether this is the homepage and shows posts. * * @return bool Whether or not the current page is the homepage that displays posts. */ public function is_home_posts_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); if ( ! $wp_query->is_home() ) { return false; } /* * Whether the static page's `Homepage` option is actually not set to a page. * Otherwise WordPress proceeds to handle the homepage as a `Your latest posts` page. */ if ( (int) \get_option( 'page_on_front' ) === 0 ) { return true; } return \get_option( 'show_on_front' ) === 'posts'; } /** * Determine whether this is the static frontpage. * * @return bool Whether or not the current page is a static frontpage. */ public function is_home_static_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); if ( ! $wp_query->is_front_page() ) { return false; } if ( \get_option( 'show_on_front' ) !== 'page' ) { return false; } return $wp_query->is_page( \get_option( 'page_on_front' ) ); } /** * Determine whether this is the static posts page. * * @return bool Whether or not the current page is a static posts page. */ public function is_static_posts_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); $queried_object = $wp_query->get_queried_object(); return ( $wp_query->is_posts_page && \is_a( $queried_object, WP_Post::class ) && $queried_object->post_type === 'page' ); } /** * Determine whether this is the statically set posts page, when it's not the frontpage. * * @return bool Whether or not it's a non-frontpage, statically set posts page. */ public function is_posts_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); if ( ! $wp_query->is_home() ) { return false; } return \get_option( 'show_on_front' ) === 'page'; } /** * Determine whether this is a post type archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is a post type archive. */ public function is_post_type_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_post_type_archive(); } /** * Determine whether this is a term archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is a term archive. */ public function is_term_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_tax || $wp_query->is_tag || $wp_query->is_category; } /** * Determine whether this is an attachment page. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is an attachment page. */ public function is_attachment() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_attachment; } /** * Determine whether this is an author archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is an author archive. */ public function is_author_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_author(); } /** * Determine whether this is an date archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is an date archive. */ public function is_date_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_date(); } /** * Determine whether this is a search result. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is a search result. */ public function is_search_result() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_search(); } /** * Determine whether this is a 404 page. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is a 404 page. */ public function is_404() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_404(); } /** * Checks if the current page is the post format archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether or not the current page is the post format archive. */ public function is_post_format_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_tax( 'post_format' ); } /** * Determine whether this page is an taxonomy archive page for multiple terms (url: /term-1,term2/). * * @return bool Whether or not the current page is an archive page for multiple terms. */ public function is_multiple_terms_page() { if ( ! $this->is_term_archive() ) { return false; } return $this->count_queried_terms() > 1; } /** * Checks whether the current page is paged. * * @codeCoverageIgnore This method only calls a WordPress function. * * @return bool Whether the current page is paged. */ public function is_paged() { return \is_paged(); } /** * Checks if the current page is the front page. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether or not the current page is the front page. */ public function is_front_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_front_page(); } /** * Retrieves the current admin page. * * @codeCoverageIgnore It only wraps a global WordPress variable. * * @return string The current page. */ public function get_current_admin_page() { global $pagenow; return $pagenow; } /** * Check if the current opened page is a Yoast SEO page. * * @return bool True when current page is a yoast seo plugin page. */ public function is_yoast_seo_page() { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information. if ( isset( $_GET['page'] ) && \is_string( $_GET['page'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Reason: We are not processing form information, We are only using the variable in the strpos function. $current_page = \wp_unslash( $_GET['page'] ); return \strpos( $current_page, 'wpseo_' ) === 0; } return false; } /** * Returns the current Yoast SEO page. * (E.g. the `page` query variable in the URL). * * @return string The current Yoast SEO page. */ public function get_current_yoast_seo_page() { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information. if ( isset( $_GET['page'] ) && \is_string( $_GET['page'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information. return \sanitize_text_field( \wp_unslash( $_GET['page'] ) ); } return ''; } /** * Checks if the current global post is the privacy policy page. * * @return bool current global post is set as privacy page */ public function current_post_is_privacy_policy() { global $post; if ( ! isset( $post->ID ) ) { return false; } return \intval( $post->ID ) === \intval( \get_option( 'wp_page_for_privacy_policy', false ) ); } /** * Returns the permalink of the currently opened date archive. * * @return string The permalink of the currently opened date archive. */ protected function get_non_cached_date_archive_permalink() { $date_archive_permalink = ''; $wp_query = $this->wp_query_wrapper->get_main_query(); if ( $wp_query->is_day() ) { $date_archive_permalink = \get_day_link( $wp_query->get( 'year' ), $wp_query->get( 'monthnum' ), $wp_query->get( 'day' ) ); } if ( $wp_query->is_month() ) { $date_archive_permalink = \get_month_link( $wp_query->get( 'year' ), $wp_query->get( 'monthnum' ) ); } if ( $wp_query->is_year() ) { $date_archive_permalink = \get_year_link( $wp_query->get( 'year' ) ); } return $date_archive_permalink; } /** * Counts the total amount of queried terms. * * @codeCoverageIgnore This relies too much on WordPress dependencies. * * @return int The amoumt of queried terms. */ protected function count_queried_terms() { $wp_query = $this->wp_query_wrapper->get_main_query(); $term = $wp_query->get_queried_object(); $queried_terms = $wp_query->tax_query->queried_terms; if ( \is_null( $term ) || empty( $queried_terms[ $term->taxonomy ]['terms'] ) ) { return 0; } return \count( $queried_terms[ $term->taxonomy ]['terms'] ); } } } $date_archive_permalink = $this->get_non_cached_date_archive_permalink(); return $date_archive_permalink; } /** * Determine whether this is the homepage and shows posts. * * @return bool Whether or not the current page is the homepage that displays posts. */ public function is_home_posts_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); if ( ! $wp_query->is_home() ) { return false; } /* * Whether the static page's `Homepage` option is actually not set to a page. * Otherwise WordPress proceeds to handle the homepage as a `Your latest posts` page. */ if ( (int) \get_option( 'page_on_front' ) === 0 ) { return true; } return \get_option( 'show_on_front' ) === 'posts'; } /** * Determine whether this is the static frontpage. * * @return bool Whether or not the current page is a static frontpage. */ public function is_home_static_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); if ( ! $wp_query->is_front_page() ) { return false; } if ( \get_option( 'show_on_front' ) !== 'page' ) { return false; } return $wp_query->is_page( \get_option( 'page_on_front' ) ); } /** * Determine whether this is the static posts page. * * @return bool Whether or not the current page is a static posts page. */ public function is_static_posts_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); $queried_object = $wp_query->get_queried_object(); return ( $wp_query->is_posts_page && \is_a( $queried_object, WP_Post::class ) && $queried_object->post_type === 'page' ); } /** * Determine whether this is the statically set posts page, when it's not the frontpage. * * @return bool Whether or not it's a non-frontpage, statically set posts page. */ public function is_posts_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); if ( ! $wp_query->is_home() ) { return false; } return \get_option( 'show_on_front' ) === 'page'; } /** * Determine whether this is a post type archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is a post type archive. */ public function is_post_type_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_post_type_archive(); } /** * Determine whether this is a term archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is a term archive. */ public function is_term_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_tax || $wp_query->is_tag || $wp_query->is_category; } /** * Determine whether this is an attachment page. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is an attachment page. */ public function is_attachment() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_attachment; } /** * Determine whether this is an author archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is an author archive. */ public function is_author_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_author(); } /** * Determine whether this is an date archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is an date archive. */ public function is_date_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_date(); } /** * Determine whether this is a search result. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is a search result. */ public function is_search_result() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_search(); } /** * Determine whether this is a 404 page. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether nor not the current page is a 404 page. */ public function is_404() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_404(); } /** * Checks if the current page is the post format archive. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether or not the current page is the post format archive. */ public function is_post_format_archive() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_tax( 'post_format' ); } /** * Determine whether this page is an taxonomy archive page for multiple terms (url: /term-1,term2/). * * @return bool Whether or not the current page is an archive page for multiple terms. */ public function is_multiple_terms_page() { if ( ! $this->is_term_archive() ) { return false; } return $this->count_queried_terms() > 1; } /** * Checks whether the current page is paged. * * @codeCoverageIgnore This method only calls a WordPress function. * * @return bool Whether the current page is paged. */ public function is_paged() { return \is_paged(); } /** * Checks if the current page is the front page. * * @codeCoverageIgnore It wraps WordPress functionality. * * @return bool Whether or not the current page is the front page. */ public function is_front_page() { $wp_query = $this->wp_query_wrapper->get_main_query(); return $wp_query->is_front_page(); } /** * Retrieves the current admin page. * * @codeCoverageIgnore It only wraps a global WordPress variable. * * @return string The current page. */ public function get_current_admin_page() { global $pagenow; return $pagenow; } /** * Check if the current opened page is a Yoast SEO page. * * @return bool True when current page is a yoast seo plugin page. */ public function is_yoast_seo_page() { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information. if ( isset( $_GET['page'] ) && \is_string( $_GET['page'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Reason: We are not processing form information, We are only using the variable in the strpos function. $current_page = \wp_unslash( $_GET['page'] ); return \strpos( $current_page, 'wpseo_' ) === 0; } return false; } /** * Returns the current Yoast SEO page. * (E.g. the `page` query variable in the URL). * * @return string The current Yoast SEO page. */ public function get_current_yoast_seo_page() { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information. if ( isset( $_GET['page'] ) && \is_string( $_GET['page'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information. return \sanitize_text_field( \wp_unslash( $_GET['page'] ) ); } return ''; } /** * Checks if the current global post is the privacy policy page. * * @return bool current global post is set as privacy page */ public function current_post_is_privacy_policy() { global $post; if ( ! isset( $post->ID ) ) { return false; } return \intval( $post->ID ) === \intval( \get_option( 'wp_page_for_privacy_policy', false ) ); } /** * Returns the permalink of the currently opened date archive. * * @return string The permalink of the currently opened date archive. */ protected function get_non_cached_date_archive_permalink() { $date_archive_permalink = ''; $wp_query = $this->wp_query_wrapper->get_main_query(); if ( $wp_query->is_day() ) { $date_archive_permalink = \get_day_link( $wp_query->get( 'year' ), $wp_query->get( 'monthnum' ), $wp_query->get( 'day' ) ); } if ( $wp_query->is_month() ) { $date_archive_permalink = \get_month_link( $wp_query->get( 'year' ), $wp_query->get( 'monthnum' ) ); } if ( $wp_query->is_year() ) { $date_archive_permalink = \get_year_link( $wp_query->get( 'year' ) ); } return $date_archive_permalink; } /** * Counts the total amount of queried terms. * * @codeCoverageIgnore This relies too much on WordPress dependencies. * * @return int The amoumt of queried terms. */ protected function count_queried_terms() { $wp_query = $this->wp_query_wrapper->get_main_query(); $term = $wp_query->get_queried_object(); $queried_terms = $wp_query->tax_query->queried_terms; if ( \is_null( $term ) || empty( $queried_terms[ $term->taxonomy ]['terms'] ) ) { return 0; } return \count( $queried_terms[ $term->taxonomy ]['terms'] ); } }
Fatal error: Uncaught Error: Class "Yoast\WP\SEO\Helpers\Current_Page_Helper" not found in /htdocs/wp-content/plugins/wordpress-seo/src/generated/container.php:3082 Stack trace: #0 /htdocs/wp-content/plugins/wordpress-seo/src/generated/container.php(5289): Yoast\WP\SEO\Generated\Cached_Container->getCurrentPageHelperService() #1 /htdocs/wp-content/plugins/wordpress-seo/vendor_prefixed/symfony/dependency-injection/Container.php(271): Yoast\WP\SEO\Generated\Cached_Container->getIndexableRepositoryService() #2 /htdocs/wp-content/plugins/wordpress-seo/src/surfaces/classes-surface.php(38): YoastSEO_Vendor\Symfony\Component\DependencyInjection\Container->get('Yoast\\WP\\SEO\\Re...') #3 /htdocs/wp-content/plugins/wordpress-seo/inc/class-wpseo-admin-bar-menu.php(132): Yoast\WP\SEO\Surfaces\Classes_Surface->get('Yoast\\WP\\SEO\\Re...') #4 /htdocs/wp-content/plugins/wordpress-seo/inc/wpseo-non-ajax-functions.php(20): WPSEO_Admin_Bar_Menu->__construct() #5 /htdocs/wp-includes/class-wp-hook.php(324): wpseo_initialize_admin_bar('') #6 /htdocs/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters(NULL, Array) #7 /htdocs/wp-includes/plugin.php(517): WP_Hook->do_action(Array) #8 /htdocs/wp-settings.php(726): do_action('wp_loaded') #9 /htdocs/wp-config.php(102): require_once('/htdocs/wp-sett...') #10 /htdocs/wp-load.php(50): require_once('/htdocs/wp-conf...') #11 /htdocs/wp-blog-header.php(13): require_once('/htdocs/wp-load...') #12 /htdocs/index.php(17): require('/htdocs/wp-blog...') #13 {main} thrown in /htdocs/wp-content/plugins/wordpress-seo/src/generated/container.php on line 3082