From d7493b0b8af395648b48e86764fa6f8a5172f86e Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Wed, 12 Feb 2014 12:18:36 +0000 Subject: [PATCH] is_wc_endpoint_url Closes #4731 --- includes/class-wc-query.php | 8 ++++++++ includes/wc-conditional-functions.php | 24 ++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/includes/class-wc-query.php b/includes/class-wc-query.php index eece62fe6b7..99f4ea5ea3c 100644 --- a/includes/class-wc-query.php +++ b/includes/class-wc-query.php @@ -115,6 +115,14 @@ class WC_Query { return $vars; } + /** + * Get query vars + * @return array() + */ + public function get_query_vars() { + return $this->query_vars; + } + /** * Parse the request and look for query vars - endpoints may not be supported */ diff --git a/includes/wc-conditional-functions.php b/includes/wc-conditional-functions.php index 228edb53933..bcc8e665640 100644 --- a/includes/wc-conditional-functions.php +++ b/includes/wc-conditional-functions.php @@ -130,6 +130,30 @@ if ( ! function_exists( 'is_checkout_pay_page' ) ) { } } +if ( ! function_exists( 'is_wc_endpoint_url' ) ) { + + /** + * is_wc_endpoint_url - Check if an endpoint is showing + * + * @access public + * @param string $endpoint + * @return bool + */ + function is_wc_endpoint_url( $endpoint ) { + global $wp; + + $wc_endpoints = WC()->query->get_query_vars(); + + if ( ! isset( $wc_endpoints[ $endpoint ] ) ) { + return false; + } else { + $endpoint_var = $wc_endpoints[ $endpoint ]; + } + + return isset( $wp->query_vars[ $endpoint_var ] ) ? true : false; + } +} + if ( ! function_exists( 'is_account_page' ) ) { /**