From fcb7aaab0ea092d7b8a55c0be09c8ce32a2e7cc3 Mon Sep 17 00:00:00 2001 From: jweston491 Date: Mon, 23 Sep 2024 14:44:10 -0700 Subject: [PATCH] fix: Ensure `check_url_match` function is defined only once I'm using Bluehost, and the Bluehost plugin relies on this package as a dependency. When registering a new user in our app's frontend, we get this error: ``` PHP Fatal error: Cannot redeclare NewfoldLabs\WP\Module\ECommerce\check_url_match() (previously declared in /mysitepath/public_html/wp-content/plugins/bluehost-wordpress-plugin/vendor/newfold-labs/wp-module-ecommerce/includes/ECommerce.php:699) in /mysitepath/public_html/wp-content/plugins/bluehost-wordpress-plugin/vendor/newfold-labs/wp-module-ecommerce/includes/ECommerce.php on line 699 ``` So this PR aims to fix that. --- includes/ECommerce.php | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/includes/ECommerce.php b/includes/ECommerce.php index cf02bb71..be9df240 100644 --- a/includes/ECommerce.php +++ b/includes/ECommerce.php @@ -712,21 +712,23 @@ public function show_store_setup() { $brand = $this->container->plugin()->id; - /** - * Verifies if the url is matching with the regex - * - * @param string $brand_name id of the brand - * - * @param string $site_url siteurl - */ - function check_url_match( $brand_name, $site_url ) { - switch ( $brand_name ) { - case 'bluehost': - return ! preg_match( '/\b\w+(\.\w+)*\.mybluehost\.me\b/', $site_url ); - case 'hostgator': - return ! preg_match( '/\b\w+(\.\w+)*\.temporary\.site\b/', $site_url ); - default: - return true; + if ( ! function_exists( __NAMESPACE__ . '\check_url_match' ) ) { + /** + * Verifies if the url is matching with the regex + * + * @param string $brand_name id of the brand + * + * @param string $site_url siteurl + */ + function check_url_match( $brand_name, $site_url ) { + switch ( $brand_name ) { + case 'bluehost': + return ! preg_match( '/\b\w+(\.\w+)*\.mybluehost\.me\b/', $site_url ); + case 'hostgator': + return ! preg_match( '/\b\w+(\.\w+)*\.temporary\.site\b/', $site_url ); + default: + return true; + } } } if ( check_url_match( $brand, $site_url ) ) {