From d5223ad6d9fec9b03a9f19804e474e30c1dae4a2 Mon Sep 17 00:00:00 2001 From: Nabeel Molham Date: Thu, 26 Sep 2024 14:23:43 +1000 Subject: [PATCH 1/6] Deprecate Enhanced navigation feature integration --- woocommerce/class-sv-wc-helper.php | 21 +++++++++---------- .../class-sv-wc-plugin-compatibility.php | 4 ++-- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/woocommerce/class-sv-wc-helper.php b/woocommerce/class-sv-wc-helper.php index 698cf9dbd..2dab0a92a 100644 --- a/woocommerce/class-sv-wc-helper.php +++ b/woocommerce/class-sv-wc-helper.php @@ -1030,9 +1030,9 @@ public static function is_current_screen( $id, $prop = 'id' ) { * * @return bool */ - public static function is_enhanced_admin_screen() { - - return is_admin() && SV_WC_Plugin_Compatibility::is_enhanced_admin_available() && ( \Automattic\WooCommerce\Admin\Loader::is_admin_page() || \Automattic\WooCommerce\Admin\Loader::is_embed_page() ); + public static function is_enhanced_admin_screen() : bool + { + return is_admin() && SV_WC_Plugin_Compatibility::is_enhanced_admin_available() && (\Automattic\WooCommerce\Admin\PageController::is_admin_page() || \Automattic\WooCommerce\Admin\PageController::is_embed_page()); } @@ -1041,16 +1041,15 @@ public static function is_enhanced_admin_screen() { * * @since 5.10.6 * + * @deprecated with no alternatives + * * @return bool */ - public static function is_wc_navigation_enabled() { - - return - is_callable( [ \Automattic\WooCommerce\Admin\Features\Navigation\Screen::class, 'register_post_type' ] ) && - is_callable( [ \Automattic\WooCommerce\Admin\Features\Navigation\Menu::class, 'add_plugin_item' ] ) && - is_callable( [ \Automattic\WooCommerce\Admin\Features\Navigation\Menu::class, 'add_plugin_category' ] ) && - is_callable( [ \Automattic\WooCommerce\Admin\Features\Features::class, 'is_enabled' ] ) && - \Automattic\WooCommerce\Admin\Features\Features::is_enabled( 'navigation' ); + public static function is_wc_navigation_enabled() : bool + { + error_log('The Enhanced navigation feature has been deprecated since WooCommerce 9.3 with no alternative. Navigation classes will be removed in WooCommerce 9.4'); + + return false; } diff --git a/woocommerce/class-sv-wc-plugin-compatibility.php b/woocommerce/class-sv-wc-plugin-compatibility.php index 0980f03e3..f7cb0f796 100644 --- a/woocommerce/class-sv-wc-plugin-compatibility.php +++ b/woocommerce/class-sv-wc-plugin-compatibility.php @@ -191,8 +191,8 @@ public static function is_wc_version_gt( $version ) { * * @return bool */ - public static function is_enhanced_admin_available() { - + public static function is_enhanced_admin_available() : bool + { return self::is_wc_version_gte( '4.0' ) && function_exists( 'wc_admin_url' ); } From 4af7247a39a24ffeeff04f767751d3fb4ddf2fb7 Mon Sep 17 00:00:00 2001 From: Nabeel Molham Date: Mon, 30 Sep 2024 12:55:46 +1000 Subject: [PATCH 2/6] Always return false if WC >= 9.3 --- woocommerce/class-sv-wc-helper.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/woocommerce/class-sv-wc-helper.php b/woocommerce/class-sv-wc-helper.php index 2dab0a92a..0cbd23e44 100644 --- a/woocommerce/class-sv-wc-helper.php +++ b/woocommerce/class-sv-wc-helper.php @@ -1047,9 +1047,17 @@ public static function is_enhanced_admin_screen() : bool */ public static function is_wc_navigation_enabled() : bool { - error_log('The Enhanced navigation feature has been deprecated since WooCommerce 9.3 with no alternative. Navigation classes will be removed in WooCommerce 9.4'); + if (SV_WC_Plugin_Compatibility::is_wc_version_gte('9.3')) { + error_log('The Enhanced navigation feature has been deprecated since WooCommerce 9.3 with no alternative. Navigation classes will be removed in WooCommerce 9.4'); - return false; + return false; + } + + return is_callable([\Automattic\WooCommerce\Admin\Features\Navigation\Screen::class, 'register_post_type']) && + is_callable([\Automattic\WooCommerce\Admin\Features\Navigation\Menu::class, 'add_plugin_item']) && + is_callable([\Automattic\WooCommerce\Admin\Features\Navigation\Menu::class, 'add_plugin_category']) && + is_callable([\Automattic\WooCommerce\Admin\Features\Features::class, 'is_enabled']) && + \Automattic\WooCommerce\Admin\Features\Features::is_enabled('navigation'); } From f5c05db9e6f5fdf6ab93b9cdac515b6642baf061 Mon Sep 17 00:00:00 2001 From: Nabeel Molham Date: Mon, 30 Sep 2024 12:58:21 +1000 Subject: [PATCH 3/6] Always return false if WC >= 9.3 --- woocommerce/class-sv-wc-helper.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/woocommerce/class-sv-wc-helper.php b/woocommerce/class-sv-wc-helper.php index 0cbd23e44..ec90df86e 100644 --- a/woocommerce/class-sv-wc-helper.php +++ b/woocommerce/class-sv-wc-helper.php @@ -1048,8 +1048,7 @@ public static function is_enhanced_admin_screen() : bool public static function is_wc_navigation_enabled() : bool { if (SV_WC_Plugin_Compatibility::is_wc_version_gte('9.3')) { - error_log('The Enhanced navigation feature has been deprecated since WooCommerce 9.3 with no alternative. Navigation classes will be removed in WooCommerce 9.4'); - + self::enhancedNavigationDeprecationNotice(); return false; } @@ -1060,6 +1059,11 @@ public static function is_wc_navigation_enabled() : bool \Automattic\WooCommerce\Admin\Features\Features::is_enabled('navigation'); } + protected static function enhancedNavigationDeprecationNotice() : void + { + error_log('The Enhanced navigation feature has been deprecated since WooCommerce 9.3 with no alternative. Navigation classes will be removed in WooCommerce 9.4'); + } + /** * Determines if the current request is for a WC REST API endpoint. From 066a4fccd1299d55415b534d99189484720cd94e Mon Sep 17 00:00:00 2001 From: Nabeel Molham Date: Mon, 30 Sep 2024 13:06:52 +1000 Subject: [PATCH 4/6] Unit test SV_WC_Helper::is_wc_navigation_enabled method --- tests/unit/HelperTest.php | 54 ++++++++++++++++++++++++++++++ woocommerce/class-sv-wc-helper.php | 5 +++ 2 files changed, 59 insertions(+) create mode 100644 tests/unit/HelperTest.php diff --git a/tests/unit/HelperTest.php b/tests/unit/HelperTest.php new file mode 100644 index 000000000..28c8d5dcc --- /dev/null +++ b/tests/unit/HelperTest.php @@ -0,0 +1,54 @@ +mockStaticMethod(SV_WC_Plugin_Compatibility::class, 'is_wc_version_gte') + ->once() + ->with('9.3') + ->andReturnFalse(); + + $this->mockStaticMethod(SV_WC_Helper::class, 'isEnhancedNavigationFeatureEnabled') + ->once() + ->andReturnTrue(); + + $this->mockStaticMethod(SV_WC_Helper::class, 'enhancedNavigationDeprecationNotice') + ->never(); + + $this->assertTrue(SV_WC_Helper::is_wc_navigation_enabled()); + } + + /** + * @covers \SkyVerge\WooCommerce\PluginFramework\v5_15_0\SV_WC_Helper::is_wc_navigation_enabled() + * + * @throws ReflectionException + */ + public function testAlwaysDetermineNavigationFeaturedDisabled() : void + { + $this->mockStaticMethod(SV_WC_Plugin_Compatibility::class, 'is_wc_version_gte') + ->once() + ->with('9.3') + ->andReturnTrue(); + + $this->mockStaticMethod(SV_WC_Helper::class, 'enhancedNavigationDeprecationNotice') + ->once(); + + $this->mockStaticMethod(SV_WC_Helper::class, 'isEnhancedNavigationFeatureEnabled') + ->never(); + + $this->assertFalse(SV_WC_Helper::is_wc_navigation_enabled()); + } +} diff --git a/woocommerce/class-sv-wc-helper.php b/woocommerce/class-sv-wc-helper.php index ec90df86e..3e4a0472a 100644 --- a/woocommerce/class-sv-wc-helper.php +++ b/woocommerce/class-sv-wc-helper.php @@ -1052,6 +1052,11 @@ public static function is_wc_navigation_enabled() : bool return false; } + return self::isEnhancedNavigationFeatureEnabled(); + } + + protected static function isEnhancedNavigationFeatureEnabled() : bool + { return is_callable([\Automattic\WooCommerce\Admin\Features\Navigation\Screen::class, 'register_post_type']) && is_callable([\Automattic\WooCommerce\Admin\Features\Navigation\Menu::class, 'add_plugin_item']) && is_callable([\Automattic\WooCommerce\Admin\Features\Navigation\Menu::class, 'add_plugin_category']) && From 240797c04cc28e4b9a224b4cc9c7689386103616 Mon Sep 17 00:00:00 2001 From: Nabeel Molham <72820458+nmolham-godaddy@users.noreply.github.com> Date: Tue, 1 Oct 2024 16:01:57 +1000 Subject: [PATCH 5/6] Update woocommerce/class-sv-wc-helper.php Co-authored-by: Drew Jaynes <113622064+ajaynes-godaddy@users.noreply.github.com> --- woocommerce/class-sv-wc-helper.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/woocommerce/class-sv-wc-helper.php b/woocommerce/class-sv-wc-helper.php index 3e4a0472a..297d0838e 100644 --- a/woocommerce/class-sv-wc-helper.php +++ b/woocommerce/class-sv-wc-helper.php @@ -1055,6 +1055,13 @@ public static function is_wc_navigation_enabled() : bool return self::isEnhancedNavigationFeatureEnabled(); } + /** + * Determines whether Woo's Enhanced Eavigation feature is enabled. + * + * @since 5.15.1 + * + * @return bool + */ protected static function isEnhancedNavigationFeatureEnabled() : bool { return is_callable([\Automattic\WooCommerce\Admin\Features\Navigation\Screen::class, 'register_post_type']) && From abb938a4f343e42c7b3a67be57fe77ac2a3a1e6f Mon Sep 17 00:00:00 2001 From: Nabeel Molham <72820458+nmolham-godaddy@users.noreply.github.com> Date: Tue, 1 Oct 2024 16:02:11 +1000 Subject: [PATCH 6/6] Update woocommerce/class-sv-wc-helper.php Co-authored-by: Drew Jaynes <113622064+ajaynes-godaddy@users.noreply.github.com> --- woocommerce/class-sv-wc-helper.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/woocommerce/class-sv-wc-helper.php b/woocommerce/class-sv-wc-helper.php index 297d0838e..ff9480195 100644 --- a/woocommerce/class-sv-wc-helper.php +++ b/woocommerce/class-sv-wc-helper.php @@ -1071,6 +1071,13 @@ protected static function isEnhancedNavigationFeatureEnabled() : bool \Automattic\WooCommerce\Admin\Features\Features::is_enabled('navigation'); } + /** + * Logs a notice for the Enhanced Navigation feature being deprecated. + * + * @since 5.15.1 + * + * @return void + */ protected static function enhancedNavigationDeprecationNotice() : void { error_log('The Enhanced navigation feature has been deprecated since WooCommerce 9.3 with no alternative. Navigation classes will be removed in WooCommerce 9.4');