| 1 |
<?php |
| 2 |
|
| 3 |
// If this file is called directly, abort. |
| 4 |
if ( ! defined( 'WPINC' ) ) { |
| 5 |
die; |
| 6 |
} |
| 7 |
|
| 8 |
|
| 9 |
/** |
| 10 |
* List of regex to exclude woowommerce URL |
| 11 |
* |
| 12 |
* @param array $url_exclude |
| 13 |
* @return array |
| 14 |
*/ |
| 15 |
function wplng_exclude_woocommerce_url( $url_exclude ) { |
| 16 |
|
| 17 |
/** |
| 18 |
* Return if WooCommerce look not load |
| 19 |
*/ |
| 20 |
|
| 21 |
if ( ! function_exists( 'is_woocommerce' ) ) { |
| 22 |
return $url_exclude; |
| 23 |
} |
| 24 |
|
| 25 |
/** |
| 26 |
* List woocommerce URL and slug |
| 27 |
*/ |
| 28 |
|
| 29 |
$url_woocommerce = array(); |
| 30 |
|
| 31 |
// Get WooCommerce Cart URL |
| 32 |
if ( function_exists( 'wc_get_cart_url' ) ) { |
| 33 |
$url_woocommerce[] = wc_get_cart_url(); |
| 34 |
} |
| 35 |
|
| 36 |
// Get WooCommerce Checkout URL |
| 37 |
if ( function_exists( 'wc_get_checkout_url' ) ) { |
| 38 |
$url_woocommerce[] = wc_get_checkout_url(); |
| 39 |
} |
| 40 |
|
| 41 |
// Get WooCommerce My Account Page |
| 42 |
if ( function_exists( 'wc_get_page_permalink' ) ) { |
| 43 |
$url_woocommerce[] = wc_get_page_permalink( 'myaccount' ); |
| 44 |
} |
| 45 |
|
| 46 |
// Get Woocommerce permalink option |
| 47 |
$option_links = get_option( 'woocommerce_permalinks' ); |
| 48 |
|
| 49 |
// Get WooCommerce product base slug |
| 50 |
if ( isset( $option_links['product_base'] ) ) { |
| 51 |
$url_woocommerce[] = '/' . $option_links['product_base'] . '/'; |
| 52 |
} |
| 53 |
|
| 54 |
// Get WooCommerce product category slug |
| 55 |
if ( isset( $option_links['category_base'] ) ) { |
| 56 |
$url_woocommerce[] = '/' . $option_links['category_base'] . '/'; |
| 57 |
} |
| 58 |
|
| 59 |
// Get WooCommerce product tag slug |
| 60 |
if ( isset( $option_links['tag_base'] ) ) { |
| 61 |
$url_woocommerce[] = '/' . $option_links['tag_base'] . '/'; |
| 62 |
} |
| 63 |
|
| 64 |
/** |
| 65 |
* Check, sanitize and transform URL to REGEX |
| 66 |
*/ |
| 67 |
|
| 68 |
$regex_woocommerce = array(); |
| 69 |
|
| 70 |
foreach ( $url_woocommerce as $key => $url ) { |
| 71 |
|
| 72 |
// URL : Check, sanitize and make relative |
| 73 |
|
| 74 |
if ( ! is_string( $url ) || '' === $url ) { |
| 75 |
continue; |
| 76 |
} |
| 77 |
|
| 78 |
$url = sanitize_url( $url ); |
| 79 |
$url = wp_make_link_relative( $url ); |
| 80 |
|
| 81 |
// Transform the URL to Regex |
| 82 |
|
| 83 |
$regex = preg_quote( $url ); |
| 84 |
|
| 85 |
if ( '' === $regex ) { |
| 86 |
continue; |
| 87 |
} |
| 88 |
|
| 89 |
$regex = '#^' . $regex . '(.*)#'; |
| 90 |
|
| 91 |
$regex_woocommerce[] = $regex; |
| 92 |
|
| 93 |
} |
| 94 |
|
| 95 |
return array_merge( $url_exclude, $regex_woocommerce ); |
| 96 |
} |
| 97 |
|