Merge pull request #10299 from shivapoudel/shortcode-tag

Introduce function to check shortcode tag
This commit is contained in:
Mike Jolley 2016-02-09 11:05:55 +00:00
commit 1a976fba44
1 changed files with 15 additions and 5 deletions

View File

@ -86,7 +86,7 @@ if ( ! function_exists( 'is_cart' ) ) {
* @return bool
*/
function is_cart() {
return is_page( wc_get_page_id( 'cart' ) ) || defined( 'WOOCOMMERCE_CART' ) || ( ! empty( $post ) && strstr( $post->post_content, '[woocommerce_cart' ) );
return is_page( wc_get_page_id( 'cart' ) ) || defined( 'WOOCOMMERCE_CART' ) || wc_post_content_has_shortcode( 'woocommerce_cart' );
}
}
@ -97,8 +97,7 @@ if ( ! function_exists( 'is_checkout' ) ) {
* @return bool
*/
function is_checkout() {
global $post;
return is_page( wc_get_page_id( 'checkout' ) ) || ( ! empty( $post ) && strstr( $post->post_content, '[woocommerce_checkout' ) ) || apply_filters( 'woocommerce_is_checkout', false );
return is_page( wc_get_page_id( 'checkout' ) ) || wc_post_content_has_shortcode( 'woocommerce_checkout' ) || apply_filters( 'woocommerce_is_checkout', false );
}
}
@ -154,7 +153,7 @@ if ( ! function_exists( 'is_account_page' ) ) {
* @return bool
*/
function is_account_page() {
return is_page( wc_get_page_id( 'myaccount' ) ) || ( ! empty( $post ) && strstr( $post->post_content, '[woocommerce_my_account' ) ) || apply_filters( 'woocommerce_is_account_page', false );
return is_page( wc_get_page_id( 'myaccount' ) ) || wc_post_content_has_shortcode( 'woocommerce_my_account' ) || apply_filters( 'woocommerce_is_account_page', false );
}
}
@ -352,7 +351,6 @@ function wc_is_webhook_valid_topic( $topic ) {
return false;
}
/**
* Simple check for validating a URL, it must start with http:// or https://.
* and pass FILTER_VALIDATE_URL validation.
@ -393,3 +391,15 @@ function wc_site_is_https() {
function wc_checkout_is_https() {
return wc_site_is_https() || 'yes' === get_option( 'woocommerce_force_ssl_checkout' ) || class_exists( 'WordPressHTTPS' ) || strstr( wc_get_page_permalink( 'checkout' ), 'https:' );
}
/**
* Checks whether the content passed contains a specific short code.
*
* @param string $tag Shortcode tag to check.
* @return bool
*/
function wc_post_content_has_shortcode( $tag = '' ) {
global $post;
return is_a( $post, 'WP_Post' ) && has_shortcode( $post->post_content, $tag );
}