From 1b6daa2c35af62d1487a2cad695cfd4bac619058 Mon Sep 17 00:00:00 2001 From: Oli Date: Wed, 11 Dec 2019 18:56:51 -0700 Subject: [PATCH 1/9] Update class-functions Adding more hosting providers to get_hosting_provider() function to be able to identify managed WordPress hosts. --- packages/sync/src/class-functions.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/packages/sync/src/class-functions.php b/packages/sync/src/class-functions.php index dc45c5c8c6414..fc7b6a83eb3da 100644 --- a/packages/sync/src/class-functions.php +++ b/packages/sync/src/class-functions.php @@ -167,6 +167,15 @@ public static function get_hosting_provider() { if ( defined( 'MM_BASE_DIR' ) ) { return 'bh'; } + if ( defined( 'PAGELYBIN' ) ) { + return 'pagely'; + } + if ( defined( 'KINSTAMU_VERSION' ) ) { + return 'kinsta'; + } + if ( defined( 'FLYWHEEL_CONFIG_DIR' ) ) { + return 'flywheel'; + } if ( defined( 'IS_PRESSABLE' ) ) { return 'pressable'; } From 505170daf8e1afe2f84b2213cdea2780c6341d4d Mon Sep 17 00:00:00 2001 From: Oli Date: Thu, 12 Dec 2019 16:44:46 -0700 Subject: [PATCH 2/9] Update class-functions.php Update get_hosting_provider() function to use an array of hosting provider constants to check the hosting provider --- packages/sync/src/class-functions.php | 31 ++++++++++++--------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/packages/sync/src/class-functions.php b/packages/sync/src/class-functions.php index fc7b6a83eb3da..011b0ed30df31 100644 --- a/packages/sync/src/class-functions.php +++ b/packages/sync/src/class-functions.php @@ -161,24 +161,21 @@ public static function get_post_type_features() { * @return string Hosting provider. */ public static function get_hosting_provider() { - if ( defined( 'GD_SYSTEM_PLUGIN_DIR' ) || class_exists( '\\WPaaS\\Plugin' ) ) { - return 'gd-managed-wp'; - } - if ( defined( 'MM_BASE_DIR' ) ) { - return 'bh'; - } - if ( defined( 'PAGELYBIN' ) ) { - return 'pagely'; - } - if ( defined( 'KINSTAMU_VERSION' ) ) { - return 'kinsta'; - } - if ( defined( 'FLYWHEEL_CONFIG_DIR' ) ) { - return 'flywheel'; - } - if ( defined( 'IS_PRESSABLE' ) ) { - return 'pressable'; + $hosting_provider_constants = array( + 'GD_SYSTEM_PLUGIN_DIR' => 'gd-managed-wp', + 'MM_BASE_DIR' => 'bh', + 'PAGELYBIN' => 'pagely', + 'KINSTAMU_VERSION' => 'kinsta', + 'FLYWHEEL_CONFIG_DIR' => 'flywheel', + 'IS_PRESSABLE' => 'pressable', + ); + + foreach ( $hosting_provider_constants as $constant => $constant_value ) { + if ( defined( $constant ) ) { + return $constant_value; + } } + if ( function_exists( 'is_wpe' ) || function_exists( 'is_wpe_snapshot' ) ) { return 'wpe'; } From 0b829863f0edd3fe721e84ae84167541e52401d8 Mon Sep 17 00:00:00 2001 From: Oli Date: Fri, 13 Dec 2019 14:45:19 -0700 Subject: [PATCH 3/9] Update class-functions.php Adding in secondary check for class_exists for gd-managed-wp --- packages/sync/src/class-functions.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/sync/src/class-functions.php b/packages/sync/src/class-functions.php index 011b0ed30df31..497982526c09c 100644 --- a/packages/sync/src/class-functions.php +++ b/packages/sync/src/class-functions.php @@ -175,7 +175,9 @@ public static function get_hosting_provider() { return $constant_value; } } - + if ( class_exists( '\\WPaaS\\Plugin' ) ) { + return 'gd-managed-wp'; + } if ( function_exists( 'is_wpe' ) || function_exists( 'is_wpe_snapshot' ) ) { return 'wpe'; } From a47b413b164e64509bf980b13e87d1a51cd64cf9 Mon Sep 17 00:00:00 2001 From: Oli Date: Fri, 13 Dec 2019 15:03:16 -0700 Subject: [PATCH 4/9] Update class-functions.php Update variable name when returning the constant value to $hosting_provider --- packages/sync/src/class-functions.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/sync/src/class-functions.php b/packages/sync/src/class-functions.php index 497982526c09c..8254df4211c79 100644 --- a/packages/sync/src/class-functions.php +++ b/packages/sync/src/class-functions.php @@ -170,9 +170,9 @@ public static function get_hosting_provider() { 'IS_PRESSABLE' => 'pressable', ); - foreach ( $hosting_provider_constants as $constant => $constant_value ) { + foreach ( $hosting_provider_constants as $constant => $hosting_provider ) { if ( defined( $constant ) ) { - return $constant_value; + return $hosting_provider; } } if ( class_exists( '\\WPaaS\\Plugin' ) ) { From cce2bae0a4077e1108fdcf58e80096aa1e26d525 Mon Sep 17 00:00:00 2001 From: Oli Date: Tue, 17 Dec 2019 09:17:06 -0700 Subject: [PATCH 5/9] Update hosting provider check for managed WP and adding tests Update checking for managed WP hosts and adding tests for get_hosting_provider() function check. --- packages/sync/src/class-functions.php | 52 +++++++++++-------- .../test_class.jetpack-sync-callables.php | 44 ++++++++++++++++ 2 files changed, 73 insertions(+), 23 deletions(-) diff --git a/packages/sync/src/class-functions.php b/packages/sync/src/class-functions.php index 8254df4211c79..6542efe669817 100644 --- a/packages/sync/src/class-functions.php +++ b/packages/sync/src/class-functions.php @@ -161,30 +161,36 @@ public static function get_post_type_features() { * @return string Hosting provider. */ public static function get_hosting_provider() { - $hosting_provider_constants = array( - 'GD_SYSTEM_PLUGIN_DIR' => 'gd-managed-wp', - 'MM_BASE_DIR' => 'bh', - 'PAGELYBIN' => 'pagely', - 'KINSTAMU_VERSION' => 'kinsta', - 'FLYWHEEL_CONFIG_DIR' => 'flywheel', - 'IS_PRESSABLE' => 'pressable', - ); - - foreach ( $hosting_provider_constants as $constant => $hosting_provider ) { - if ( defined( $constant ) ) { - return $hosting_provider; - } - } - if ( class_exists( '\\WPaaS\\Plugin' ) ) { - return 'gd-managed-wp'; + $hosting_provider = 'unknown'; + + switch ( true ) { + case ( Constants::is_defined( 'GD_SYSTEM_PLUGIN_DIR' ) || class_exists( '\\WPaaS\\Plugin' ) ): + $hosting_provider = 'gd-managed-wp'; + break; + case ( Constants::is_defined( 'MM_BASE_DIR' ) ): + $hosting_provider = 'bh'; + break; + case ( Constants::is_defined( 'PAGELYBIN' ) ): + $hosting_provider = 'pagely'; + break; + case ( Constants::is_defined( 'KINSTAMU_VERSION' ) ): + $hosting_provider = 'kinsta'; + break; + case ( Constants::is_defined( 'FLYWHEEL_CONFIG_DIR' ) ): + $hosting_provider = 'flywheel'; + break; + case ( Constants::is_defined( 'IS_PRESSABLE' ) ): + $hosting_provider = 'pressable'; + break; + case ( function_exists( 'is_wpe' ) || function_exists( 'is_wpe_snapshot' ) ): + $hosting_provider = 'wpe'; + break; + case ( Constants::is_defined( 'VIP_GO_ENV' ) && false !== Constants::get_constant( 'VIP_GO_ENV' ) ): + $hosting_provider = 'vip-go'; + break; } - if ( function_exists( 'is_wpe' ) || function_exists( 'is_wpe_snapshot' ) ) { - return 'wpe'; - } - if ( defined( 'VIP_GO_ENV' ) && false !== VIP_GO_ENV ) { - return 'vip-go'; - } - return 'unknown'; + + return $hosting_provider; } /** diff --git a/tests/php/sync/test_class.jetpack-sync-callables.php b/tests/php/sync/test_class.jetpack-sync-callables.php index d0787281ca8b0..5395b62fc9ff3 100644 --- a/tests/php/sync/test_class.jetpack-sync-callables.php +++ b/tests/php/sync/test_class.jetpack-sync-callables.php @@ -1053,6 +1053,50 @@ public function test_sync_callable_recursive_gets_checksum() { $this->assertTrue( ! empty( $synced_value ), 'We couldn\'t synced a value!' ); } + /** + * Test get_hosting_provider() callable to ensure that known hosts have the + * right hosting provider returned. + * + * @return void + */ + public function test_get_hosting_provider_callable() { + Constants::set_constant( 'GD_SYSTEM_PLUGIN_DIR', 'set' ); + if ( Constants::is_defined( 'GD_SYSTEM_PLUGIN_DIR' ) || class_exists( '\\WPaaS\\Plugin' ) ) { + $this->assertEquals( Functions::get_hosting_provider(), 'gd-managed-wp' ); + Constants::clear_constants(); + } + Constants::set_constant( 'MM_BASE_DIR', 'set' ); + if ( Constants::is_defined( 'MM_BASE_DIR' ) ) { + $this->assertEquals( Functions::get_hosting_provider(), 'bh' ); + Constants::clear_constants(); + } + Constants::set_constant( 'PAGELYBIN', 'set' ); + if ( Constants::is_defined( 'PAGELYBIN' ) ) { + $this->assertEquals( Functions::get_hosting_provider(), 'pagely' ); + Constants::clear_constants(); + } + Constants::set_constant( 'KINSTAMU_VERSION', 'set' ); + if ( Constants::is_defined( 'KINSTAMU_VERSION' ) ) { + $this->assertEquals( Functions::get_hosting_provider(), 'kinsta' ); + Constants::clear_constants(); + } + Constants::set_constant( 'FLYWHEEL_CONFIG_DIR', 'set' ); + if ( Constants::is_defined( 'FLYWHEEL_CONFIG_DIR' ) ) { + $this->assertEquals( Functions::get_hosting_provider(), 'flywheel' ); + Constants::clear_constants(); + } + Constants::set_constant( 'IS_PRESSABLE', 'set' ); + if ( Constants::is_defined( 'IS_PRESSABLE' ) ) { + $this->assertEquals( Functions::get_hosting_provider(), 'pressable' ); + Constants::clear_constants(); + } + Constants::set_constant( 'VIP_GO_ENV', 'set' ); + if ( Constants::is_defined( 'VIP_GO_ENV' ) && false !== Constants::get_constant( 'VIP_GO_ENV' ) ) { + $this->assertEquals( Functions::get_hosting_provider(), 'vip-go' ); + Constants::clear_constants(); + } + } + } function jetpack_recursive_banana() { From 80f1e5b89c81e62218dfb21c956f7d58b00e184c Mon Sep 17 00:00:00 2001 From: Oli Date: Thu, 19 Dec 2019 13:30:12 -0700 Subject: [PATCH 6/9] Update class-functions.php Splitting out hosting provider detection in to detection by specific types in separate functions which are now called by the main get_hosting_provider() function --- packages/sync/src/class-functions.php | 64 +++++++++++++++++++++++++-- 1 file changed, 60 insertions(+), 4 deletions(-) diff --git a/packages/sync/src/class-functions.php b/packages/sync/src/class-functions.php index 6542efe669817..42fc52bddfc90 100644 --- a/packages/sync/src/class-functions.php +++ b/packages/sync/src/class-functions.php @@ -163,8 +163,33 @@ public static function get_post_type_features() { public static function get_hosting_provider() { $hosting_provider = 'unknown'; + $hosting_provider_detection_methods = array( + 'get_hosting_provider_by_known_constant', + 'get_hosting_provider_by_known_class', + 'get_hosting_provider_by_known_function', + ); + + $functions = new Functions(); + foreach ( $hosting_provider_detection_methods as $method ) { + $hosting_provider = call_user_func( array( $functions, $method ) ); + if ( false !== $hosting_provider ) { + return $hosting_provider; + } + } + + return $hosting_provider; + } + + /** + * Return a hosting provider using a set of known constants. + * + * @return mixed A host identifier string or false. + */ + public static function get_hosting_provider_by_known_constant() { + $hosting_provider = false; + switch ( true ) { - case ( Constants::is_defined( 'GD_SYSTEM_PLUGIN_DIR' ) || class_exists( '\\WPaaS\\Plugin' ) ): + case ( Constants::is_defined( 'GD_SYSTEM_PLUGIN_DIR' ) ): $hosting_provider = 'gd-managed-wp'; break; case ( Constants::is_defined( 'MM_BASE_DIR' ) ): @@ -182,9 +207,6 @@ public static function get_hosting_provider() { case ( Constants::is_defined( 'IS_PRESSABLE' ) ): $hosting_provider = 'pressable'; break; - case ( function_exists( 'is_wpe' ) || function_exists( 'is_wpe_snapshot' ) ): - $hosting_provider = 'wpe'; - break; case ( Constants::is_defined( 'VIP_GO_ENV' ) && false !== Constants::get_constant( 'VIP_GO_ENV' ) ): $hosting_provider = 'vip-go'; break; @@ -193,6 +215,40 @@ public static function get_hosting_provider() { return $hosting_provider; } + /** + * Return a hosting provider using a set of known classes. + * + * @return mixed A host identifier string or false. + */ + public static function get_hosting_provider_by_known_class() { + $hosting_provider = false; + + switch ( true ) { + case ( class_exists( '\\WPaaS\\Plugin' ) ): + $hosting_provider = 'gd-managed-wp'; + break; + } + + return $hosting_provider; + } + + /** + * Return a hosting provider using a set of known functions. + * + * @return mixed A host identifier string or false. + */ + public static function get_hosting_provider_by_known_function() { + $hosting_provider = false; + + switch ( true ) { + case ( function_exists( 'is_wpe' ) || function_exists( 'is_wpe_snapshot' ) ): + $hosting_provider = 'wpe'; + break; + } + + return $hosting_provider; + } + /** * Return array of allowed REST API post types. * From 317edad1900cdedce425e7326f911ef2139af357 Mon Sep 17 00:00:00 2001 From: Oli Date: Fri, 20 Dec 2019 12:19:09 -0700 Subject: [PATCH 7/9] Update Tests for get_hosting_provider Updating class functions to be non static and adding test for get_hosting_provider() for each method of getting a hosting provider --- packages/sync/src/class-functions.php | 6 +- .../test_class.jetpack-sync-callables.php | 63 +++++++++---------- 2 files changed, 32 insertions(+), 37 deletions(-) diff --git a/packages/sync/src/class-functions.php b/packages/sync/src/class-functions.php index 42fc52bddfc90..40783381d2659 100644 --- a/packages/sync/src/class-functions.php +++ b/packages/sync/src/class-functions.php @@ -185,7 +185,7 @@ public static function get_hosting_provider() { * * @return mixed A host identifier string or false. */ - public static function get_hosting_provider_by_known_constant() { + public function get_hosting_provider_by_known_constant() { $hosting_provider = false; switch ( true ) { @@ -220,7 +220,7 @@ public static function get_hosting_provider_by_known_constant() { * * @return mixed A host identifier string or false. */ - public static function get_hosting_provider_by_known_class() { + public function get_hosting_provider_by_known_class() { $hosting_provider = false; switch ( true ) { @@ -237,7 +237,7 @@ public static function get_hosting_provider_by_known_class() { * * @return mixed A host identifier string or false. */ - public static function get_hosting_provider_by_known_function() { + public function get_hosting_provider_by_known_function() { $hosting_provider = false; switch ( true ) { diff --git a/tests/php/sync/test_class.jetpack-sync-callables.php b/tests/php/sync/test_class.jetpack-sync-callables.php index 5395b62fc9ff3..35e7c20b5f15d 100644 --- a/tests/php/sync/test_class.jetpack-sync-callables.php +++ b/tests/php/sync/test_class.jetpack-sync-callables.php @@ -1060,45 +1060,40 @@ public function test_sync_callable_recursive_gets_checksum() { * @return void */ public function test_get_hosting_provider_callable() { + // Get hosting provider by known constant. + $functions = new Functions(); Constants::set_constant( 'GD_SYSTEM_PLUGIN_DIR', 'set' ); - if ( Constants::is_defined( 'GD_SYSTEM_PLUGIN_DIR' ) || class_exists( '\\WPaaS\\Plugin' ) ) { - $this->assertEquals( Functions::get_hosting_provider(), 'gd-managed-wp' ); - Constants::clear_constants(); - } - Constants::set_constant( 'MM_BASE_DIR', 'set' ); - if ( Constants::is_defined( 'MM_BASE_DIR' ) ) { - $this->assertEquals( Functions::get_hosting_provider(), 'bh' ); - Constants::clear_constants(); - } - Constants::set_constant( 'PAGELYBIN', 'set' ); - if ( Constants::is_defined( 'PAGELYBIN' ) ) { - $this->assertEquals( Functions::get_hosting_provider(), 'pagely' ); - Constants::clear_constants(); - } - Constants::set_constant( 'KINSTAMU_VERSION', 'set' ); - if ( Constants::is_defined( 'KINSTAMU_VERSION' ) ) { - $this->assertEquals( Functions::get_hosting_provider(), 'kinsta' ); - Constants::clear_constants(); - } - Constants::set_constant( 'FLYWHEEL_CONFIG_DIR', 'set' ); - if ( Constants::is_defined( 'FLYWHEEL_CONFIG_DIR' ) ) { - $this->assertEquals( Functions::get_hosting_provider(), 'flywheel' ); - Constants::clear_constants(); - } - Constants::set_constant( 'IS_PRESSABLE', 'set' ); - if ( Constants::is_defined( 'IS_PRESSABLE' ) ) { - $this->assertEquals( Functions::get_hosting_provider(), 'pressable' ); - Constants::clear_constants(); - } - Constants::set_constant( 'VIP_GO_ENV', 'set' ); - if ( Constants::is_defined( 'VIP_GO_ENV' ) && false !== Constants::get_constant( 'VIP_GO_ENV' ) ) { - $this->assertEquals( Functions::get_hosting_provider(), 'vip-go' ); - Constants::clear_constants(); - } + $this->assertEquals( $functions->get_hosting_provider_by_known_constant(), 'gd-managed-wp' ); + Constants::clear_constants(); + + Constants::set_constant( 'UNKNOWN', 'set' ); + $this->assertFalse( $functions->get_hosting_provider_by_known_constant() ); + Constants::clear_constants(); + + // Get hosting provider by known class. + $this->assertFalse( $functions->get_hosting_provider_by_known_class() ); + + $class_mock = $this->getMockBuilder( '\\WPaaS\\Plugin' ) + ->getMock(); // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable + + $this->assertEquals( $functions->get_hosting_provider_by_known_class(), 'gd-managed-wp' ); + + // Get hosting provider by known function. + $this->assertEquals( $functions->get_hosting_provider_by_known_function(), 'wpe' ); + } } +/** + * Used for test_get_hosting_provider_callable() + * + * @return boolean + */ +function is_wpe() { + return true; +} + function jetpack_recursive_banana() { $banana = new StdClass; $banana->arr = array(); From eea525c57f838ee06b199d12554e58dfcce827b6 Mon Sep 17 00:00:00 2001 From: Oli Date: Fri, 20 Dec 2019 13:53:40 -0700 Subject: [PATCH 8/9] Update unit tests and fix get_hosting_provider() return Updating the unit tests for get_hosting_provider() to be separate tests for each method that function calls and a test for unknown hosting providers from the get_hosting_provider() callable --- packages/sync/src/class-functions.php | 4 +- .../test_class.jetpack-sync-callables.php | 52 ++++++++++++++----- 2 files changed, 40 insertions(+), 16 deletions(-) diff --git a/packages/sync/src/class-functions.php b/packages/sync/src/class-functions.php index 40783381d2659..12f95a027575d 100644 --- a/packages/sync/src/class-functions.php +++ b/packages/sync/src/class-functions.php @@ -161,8 +161,6 @@ public static function get_post_type_features() { * @return string Hosting provider. */ public static function get_hosting_provider() { - $hosting_provider = 'unknown'; - $hosting_provider_detection_methods = array( 'get_hosting_provider_by_known_constant', 'get_hosting_provider_by_known_class', @@ -177,7 +175,7 @@ public static function get_hosting_provider() { } } - return $hosting_provider; + return 'unknown'; } /** diff --git a/tests/php/sync/test_class.jetpack-sync-callables.php b/tests/php/sync/test_class.jetpack-sync-callables.php index 35e7c20b5f15d..a60ac77088224 100644 --- a/tests/php/sync/test_class.jetpack-sync-callables.php +++ b/tests/php/sync/test_class.jetpack-sync-callables.php @@ -1059,8 +1059,16 @@ public function test_sync_callable_recursive_gets_checksum() { * * @return void */ - public function test_get_hosting_provider_callable() { - // Get hosting provider by known constant. + public function test_get_hosting_provider_callable_with_unknown_host() { + $this->assertEquals( Functions::get_hosting_provider(), 'unknown' ); + } + + /** + * Test getting a hosting provider by a known constant + * + * @return void + */ + public function test_get_hosting_provider_by_known_constant() { $functions = new Functions(); Constants::set_constant( 'GD_SYSTEM_PLUGIN_DIR', 'set' ); $this->assertEquals( $functions->get_hosting_provider_by_known_constant(), 'gd-managed-wp' ); @@ -1069,8 +1077,16 @@ public function test_get_hosting_provider_callable() { Constants::set_constant( 'UNKNOWN', 'set' ); $this->assertFalse( $functions->get_hosting_provider_by_known_constant() ); Constants::clear_constants(); + } + + /** + * Test getting a hosting provider by a known class + * + * @return void + */ + public function test_get_hosting_provider_by_known_class() { + $functions = new Functions(); - // Get hosting provider by known class. $this->assertFalse( $functions->get_hosting_provider_by_known_class() ); $class_mock = $this->getMockBuilder( '\\WPaaS\\Plugin' ) @@ -1078,22 +1094,32 @@ public function test_get_hosting_provider_callable() { $this->assertEquals( $functions->get_hosting_provider_by_known_class(), 'gd-managed-wp' ); + } + + /** + * Test getting a hosting provider by a known function + * + * @return bool + */ + public function test_get_hosting_provider_by_known_function() { + + /** + * Stub is_wpe for testing function exists + * + * @return boolean + */ + function is_wpe() { + return true; + } + + $functions = new Functions(); + // Get hosting provider by known function. $this->assertEquals( $functions->get_hosting_provider_by_known_function(), 'wpe' ); - } } -/** - * Used for test_get_hosting_provider_callable() - * - * @return boolean - */ -function is_wpe() { - return true; -} - function jetpack_recursive_banana() { $banana = new StdClass; $banana->arr = array(); From 0a16fbf7cef60baa37e6d56993b848eb825faa95 Mon Sep 17 00:00:00 2001 From: Oli Date: Fri, 10 Jan 2020 15:50:42 -0700 Subject: [PATCH 9/9] Update class-functions.php Update function get_hosting_provider_by_known_constant() to loop through known hosting provider constants in place of a switch --- packages/sync/src/class-functions.php | 41 +++++++++++---------------- 1 file changed, 17 insertions(+), 24 deletions(-) diff --git a/packages/sync/src/class-functions.php b/packages/sync/src/class-functions.php index 12f95a027575d..cfdc2bd87c068 100644 --- a/packages/sync/src/class-functions.php +++ b/packages/sync/src/class-functions.php @@ -184,33 +184,26 @@ public static function get_hosting_provider() { * @return mixed A host identifier string or false. */ public function get_hosting_provider_by_known_constant() { - $hosting_provider = false; + $hosting_provider_constants = array( + 'GD_SYSTEM_PLUGIN_DIR' => 'gd-managed-wp', + 'MM_BASE_DIR' => 'bh', + 'PAGELYBIN' => 'pagely', + 'KINSTAMU_VERSION' => 'kinsta', + 'FLYWHEEL_CONFIG_DIR' => 'flywheel', + 'IS_PRESSABLE' => 'pressable', + 'VIP_GO_ENV' => 'vip-go', + ); - switch ( true ) { - case ( Constants::is_defined( 'GD_SYSTEM_PLUGIN_DIR' ) ): - $hosting_provider = 'gd-managed-wp'; - break; - case ( Constants::is_defined( 'MM_BASE_DIR' ) ): - $hosting_provider = 'bh'; - break; - case ( Constants::is_defined( 'PAGELYBIN' ) ): - $hosting_provider = 'pagely'; - break; - case ( Constants::is_defined( 'KINSTAMU_VERSION' ) ): - $hosting_provider = 'kinsta'; - break; - case ( Constants::is_defined( 'FLYWHEEL_CONFIG_DIR' ) ): - $hosting_provider = 'flywheel'; - break; - case ( Constants::is_defined( 'IS_PRESSABLE' ) ): - $hosting_provider = 'pressable'; - break; - case ( Constants::is_defined( 'VIP_GO_ENV' ) && false !== Constants::get_constant( 'VIP_GO_ENV' ) ): - $hosting_provider = 'vip-go'; - break; + foreach ( $hosting_provider_constants as $constant => $constant_value ) { + if ( Constants::is_defined( $constant ) ) { + if ( 'VIP_GO_ENV' === $constant && false === Constants::get_constant( 'VIP_GO_ENV' ) ) { + continue; + } + return $constant_value; + } } - return $hosting_provider; + return false; } /**