From 11148a7b6c0b710e6d7e8b5d8969053c62d3268d Mon Sep 17 00:00:00 2001 From: Vraja Das Date: Thu, 2 Nov 2023 12:52:15 +0100 Subject: [PATCH 01/18] add notification when WooCommerce new product beta editor is enabled --- .../woocommerce-beta-editor-watcher.php | 137 ++++++++++++++++++ ...commerce-beta-product-editor-presenter.php | 60 ++++++++ 2 files changed, 197 insertions(+) create mode 100644 src/integrations/watchers/woocommerce-beta-editor-watcher.php create mode 100644 src/presenters/admin/woocommerce-beta-product-editor-presenter.php diff --git a/src/integrations/watchers/woocommerce-beta-editor-watcher.php b/src/integrations/watchers/woocommerce-beta-editor-watcher.php new file mode 100644 index 00000000000..bb44e19cd4b --- /dev/null +++ b/src/integrations/watchers/woocommerce-beta-editor-watcher.php @@ -0,0 +1,137 @@ +notification_center = $notification_center; + $this->notification_helper = $notification_helper; + $this->presenter = new Woocommerce_Beta_Editor_Presenter(); + } + + /** + * Initializes the integration. + * + * On admin_init, it is checked whether the notification about Woocommerce product beta editor enabled should be shown. + * + * @return void + */ + public function register_hooks() { + \add_action( 'admin_init', [ $this, 'manage_woocommerce_beta_editor_notification' ] ); + + } + + /** + * Manage the Woocommerce product beta editor notification. + * + * Shows the notification if needed and deletes it if needed. + * + * @return void + */ + public function manage_woocommerce_beta_editor_notification() { + if ( ! $this->woocommerce_beta_editor_enabled() ) { + $this->remove_woocommerce_beta_editor_notification_if_exists(); + } + else { + $this->maybe_add_woocommerce_beta_editor_notification(); + } + } + + /** + * Remove the Woocommerce product beta editor enabled notification if it exists. + * + * @return void + */ + protected function remove_woocommerce_beta_editor_notification_if_exists() { + $this->notification_center->remove_notification_by_id( self::NOTIFICATION_ID ); + } + + /** + * Add the Woocommerce product beta editor enabled notification if it does not exist yet. + * + * @return void + */ + protected function maybe_add_woocommerce_beta_editor_notification() { + if ( ! $this->notification_center->get_notification_by_id( self::NOTIFICATION_ID ) ) { + $notification = $this->notification(); + $this->notification_helper->restore_notification( $notification ); + $this->notification_center->add_notification( $notification ); + } + } + + /** + * Checks whether Woocommerce product beta editor enabled. + * + * @return bool Whether Woocommerce product beta editor is enabled. + */ + protected function woocommerce_beta_editor_enabled() { + return (string) \get_option( 'woocommerce_feature_product_block_editor_enabled' ) === 'yes'; + } + + /** + * Returns an instance of the notification. + * + * @return Yoast_Notification The notification to show. + */ + protected function notification() { + return new Yoast_Notification( + $this->presenter->present(), + [ + 'type' => Yoast_Notification::ERROR, + 'id' => self::NOTIFICATION_ID, + 'capabilities' => 'wpseo_manage_options', + 'priority' => 1, + ] + ); + } +} diff --git a/src/presenters/admin/woocommerce-beta-product-editor-presenter.php b/src/presenters/admin/woocommerce-beta-product-editor-presenter.php new file mode 100644 index 00000000000..84007c0735e --- /dev/null +++ b/src/presenters/admin/woocommerce-beta-product-editor-presenter.php @@ -0,0 +1,60 @@ +short_link_helper = $short_link_helper; + } + + + /** + * Returns the notification as an HTML string. + * + * @return string The notification in an HTML string representation. + */ + public function present() { + $notification_text = '

'; + $notification_text .= $this->get_message(); + $notification_text .= '

'; + + return $notification_text; + } + + /** + * Returns the message to show. + * + * @return string The message. + */ + protected function get_message() { + return \sprintf( + '%1$s %2$s', + \esc_html__( 'Compatibility issue: Yoast SEO is incompatible with the beta WooCommerce product editor.', 'wordpress-seo' ), + \sprintf( + /* translators: 1: Link start tag to the WordPress Reading Settings page, 2: Link closing tag. */ + \esc_html__( 'The Yoast SEO interface is currently unavailable in the beta WooCommerce product editor. To resolve any issues, please disable the beta editor. %1$sLearn how to disable the beta WooCommerce product editor.%2$s', 'wordpress-seo' ), + '', + '' + ), + ); + } +} From 1bd397e3653526b378ce6bc00bdad24edae42311 Mon Sep 17 00:00:00 2001 From: Vraja Das Date: Thu, 2 Nov 2023 12:58:23 +0100 Subject: [PATCH 02/18] fix shortlink dependency --- .../watchers/woocommerce-beta-editor-watcher.php | 15 +++++++++++++-- .../woocommerce-beta-product-editor-presenter.php | 2 +- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/integrations/watchers/woocommerce-beta-editor-watcher.php b/src/integrations/watchers/woocommerce-beta-editor-watcher.php index bb44e19cd4b..b7c1e497ec3 100644 --- a/src/integrations/watchers/woocommerce-beta-editor-watcher.php +++ b/src/integrations/watchers/woocommerce-beta-editor-watcher.php @@ -6,6 +6,7 @@ use Yoast\WP\SEO\Helpers\Notification_Helper; use Yoast\WP\SEO\Integrations\Integration_Interface; use Yoast\WP\SEO\Presenters\Admin\Woocommerce_Beta_Editor_Presenter; +use Yoast\WP\SEO\Helpers\Short_Link_Helper; use Yoast_Notification; use Yoast_Notification_Center; @@ -23,6 +24,13 @@ class Woocommerce_Beta_Editor_Watcher implements Integration_Interface { */ const NOTIFICATION_ID = 'wpseo-woocommerce-beta-editor-warning'; + /** + * The short link helper. + * + * @var Short_Link_Helper + */ + protected $short_link_helper; + /** * The Yoast notification center. * @@ -49,14 +57,17 @@ class Woocommerce_Beta_Editor_Watcher implements Integration_Interface { * * @param Yoast_Notification_Center $notification_center The notification center. * @param Notification_Helper $notification_helper The notification helper. + * @param Short_Link_Helper $short_link_helper The short link helper. */ public function __construct( Yoast_Notification_Center $notification_center, - Notification_Helper $notification_helper + Notification_Helper $notification_helper, + Short_Link_Helper $short_link_helper ) { $this->notification_center = $notification_center; $this->notification_helper = $notification_helper; - $this->presenter = new Woocommerce_Beta_Editor_Presenter(); + $this->short_link_helper = $short_link_helper; + $this->presenter = new Woocommerce_Beta_Editor_Presenter( $this->short_link_helper ); } /** diff --git a/src/presenters/admin/woocommerce-beta-product-editor-presenter.php b/src/presenters/admin/woocommerce-beta-product-editor-presenter.php index 84007c0735e..5a7d43f383c 100644 --- a/src/presenters/admin/woocommerce-beta-product-editor-presenter.php +++ b/src/presenters/admin/woocommerce-beta-product-editor-presenter.php @@ -52,7 +52,7 @@ protected function get_message() { \sprintf( /* translators: 1: Link start tag to the WordPress Reading Settings page, 2: Link closing tag. */ \esc_html__( 'The Yoast SEO interface is currently unavailable in the beta WooCommerce product editor. To resolve any issues, please disable the beta editor. %1$sLearn how to disable the beta WooCommerce product editor.%2$s', 'wordpress-seo' ), - '', + '', '' ), ); From 1b786c828a2b53513fca5d2905a650cfab41ec9b Mon Sep 17 00:00:00 2001 From: Vraja Das Date: Thu, 2 Nov 2023 13:55:47 +0100 Subject: [PATCH 03/18] fix translation comment --- .../admin/woocommerce-beta-product-editor-presenter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/presenters/admin/woocommerce-beta-product-editor-presenter.php b/src/presenters/admin/woocommerce-beta-product-editor-presenter.php index 5a7d43f383c..208fcfdb9d7 100644 --- a/src/presenters/admin/woocommerce-beta-product-editor-presenter.php +++ b/src/presenters/admin/woocommerce-beta-product-editor-presenter.php @@ -50,7 +50,7 @@ protected function get_message() { '%1$s %2$s', \esc_html__( 'Compatibility issue: Yoast SEO is incompatible with the beta WooCommerce product editor.', 'wordpress-seo' ), \sprintf( - /* translators: 1: Link start tag to the WordPress Reading Settings page, 2: Link closing tag. */ + /* translators: 1: Link start tag to the Learn more link, 2: Link closing tag. */ \esc_html__( 'The Yoast SEO interface is currently unavailable in the beta WooCommerce product editor. To resolve any issues, please disable the beta editor. %1$sLearn how to disable the beta WooCommerce product editor.%2$s', 'wordpress-seo' ), '', '' From 8bc0b10a8820966a9f08100483152f9e24f07eae Mon Sep 17 00:00:00 2001 From: Vraja Das Date: Thu, 2 Nov 2023 14:04:03 +0100 Subject: [PATCH 04/18] add target to link --- .../admin/woocommerce-beta-product-editor-presenter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/presenters/admin/woocommerce-beta-product-editor-presenter.php b/src/presenters/admin/woocommerce-beta-product-editor-presenter.php index 208fcfdb9d7..c4dac006be9 100644 --- a/src/presenters/admin/woocommerce-beta-product-editor-presenter.php +++ b/src/presenters/admin/woocommerce-beta-product-editor-presenter.php @@ -52,7 +52,7 @@ protected function get_message() { \sprintf( /* translators: 1: Link start tag to the Learn more link, 2: Link closing tag. */ \esc_html__( 'The Yoast SEO interface is currently unavailable in the beta WooCommerce product editor. To resolve any issues, please disable the beta editor. %1$sLearn how to disable the beta WooCommerce product editor.%2$s', 'wordpress-seo' ), - '', + '', '' ), ); From ecf560cc8dbb22ceee084479cb0c63c6e218e6bf Mon Sep 17 00:00:00 2001 From: Vraja Das Date: Thu, 2 Nov 2023 14:28:56 +0100 Subject: [PATCH 05/18] fix php cs --- .../watchers/woocommerce-beta-editor-watcher.php | 5 ++--- .../admin/woocommerce-beta-product-editor-presenter.php | 1 - 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/integrations/watchers/woocommerce-beta-editor-watcher.php b/src/integrations/watchers/woocommerce-beta-editor-watcher.php index b7c1e497ec3..ac62d4a056d 100644 --- a/src/integrations/watchers/woocommerce-beta-editor-watcher.php +++ b/src/integrations/watchers/woocommerce-beta-editor-watcher.php @@ -57,7 +57,7 @@ class Woocommerce_Beta_Editor_Watcher implements Integration_Interface { * * @param Yoast_Notification_Center $notification_center The notification center. * @param Notification_Helper $notification_helper The notification helper. - * @param Short_Link_Helper $short_link_helper The short link helper. + * @param Short_Link_Helper $short_link_helper The short link helper. */ public function __construct( Yoast_Notification_Center $notification_center, @@ -66,7 +66,7 @@ public function __construct( ) { $this->notification_center = $notification_center; $this->notification_helper = $notification_helper; - $this->short_link_helper = $short_link_helper; + $this->short_link_helper = $short_link_helper; $this->presenter = new Woocommerce_Beta_Editor_Presenter( $this->short_link_helper ); } @@ -79,7 +79,6 @@ public function __construct( */ public function register_hooks() { \add_action( 'admin_init', [ $this, 'manage_woocommerce_beta_editor_notification' ] ); - } /** diff --git a/src/presenters/admin/woocommerce-beta-product-editor-presenter.php b/src/presenters/admin/woocommerce-beta-product-editor-presenter.php index c4dac006be9..4275888c699 100644 --- a/src/presenters/admin/woocommerce-beta-product-editor-presenter.php +++ b/src/presenters/admin/woocommerce-beta-product-editor-presenter.php @@ -26,7 +26,6 @@ public function __construct( Short_Link_Helper $short_link_helper ) { $this->short_link_helper = $short_link_helper; } - /** * Returns the notification as an HTML string. * From a1b5cc38f975ac271a1674b2b16e0b8c7468af66 Mon Sep 17 00:00:00 2001 From: Vraja Das Date: Thu, 2 Nov 2023 14:29:30 +0100 Subject: [PATCH 06/18] add unit tests to woo beta editor presenter --- ...rce-beta-product-editor-presenter-test.php | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 tests/unit/presenters/admin/woocommerce-beta-product-editor-presenter-test.php diff --git a/tests/unit/presenters/admin/woocommerce-beta-product-editor-presenter-test.php b/tests/unit/presenters/admin/woocommerce-beta-product-editor-presenter-test.php new file mode 100644 index 00000000000..ce07d31c820 --- /dev/null +++ b/tests/unit/presenters/admin/woocommerce-beta-product-editor-presenter-test.php @@ -0,0 +1,71 @@ +stubTranslationFunctions(); + $this->short_link_helper = Mockery::mock( Short_Link_Helper::class ); + $this->instance = new Woocommerce_Beta_Editor_Presenter( $this->short_link_helper ); + } + + /** + * Tests returning the notification as an HTML string. + * + * @covers ::present + * @covers ::get_message + */ + public function test_present() { + + Monkey\Functions\expect( 'esc_url' ) + ->once() + ->with( 'https://yoa.st/learn-how-disable-beta-woocommerce-product-editor' ) + ->andReturn( 'https://yoa.st/learn-how-disable-beta-woocommerce-product-editor' ); + + $this->short_link_helper + ->expects( 'get' ) + ->once() + ->with( 'https://yoa.st/learn-how-disable-beta-woocommerce-product-editor' ) + ->andReturn( 'https://yoa.st/learn-how-disable-beta-woocommerce-product-editor' ); + + + $expected = '

Compatibility issue: Yoast SEO is incompatible with the beta WooCommerce product editor. The Yoast SEO interface is currently unavailable in the beta WooCommerce product editor. To resolve any issues, please disable the beta editor. Learn how to disable the beta WooCommerce product editor.

'; + + $this->assertSame( $expected, $this->instance->present() ); + } +} From 13858d07d02b460e8f05b5ef1a6fba9dff190635 Mon Sep 17 00:00:00 2001 From: Vraja Das Date: Thu, 2 Nov 2023 14:46:29 +0100 Subject: [PATCH 07/18] reduced methods --- .../woocommerce-beta-editor-watcher.php | 26 +++---------------- 1 file changed, 4 insertions(+), 22 deletions(-) diff --git a/src/integrations/watchers/woocommerce-beta-editor-watcher.php b/src/integrations/watchers/woocommerce-beta-editor-watcher.php index ac62d4a056d..9a1717f7caf 100644 --- a/src/integrations/watchers/woocommerce-beta-editor-watcher.php +++ b/src/integrations/watchers/woocommerce-beta-editor-watcher.php @@ -89,29 +89,20 @@ public function register_hooks() { * @return void */ public function manage_woocommerce_beta_editor_notification() { - if ( ! $this->woocommerce_beta_editor_enabled() ) { - $this->remove_woocommerce_beta_editor_notification_if_exists(); + if ( (string) \get_option( 'woocommerce_feature_product_block_editor_enabled' ) === 'yes' ) { + $this->maybe_add_woocommerce_beta_editor_notification(); } else { - $this->maybe_add_woocommerce_beta_editor_notification(); + $this->notification_center->remove_notification_by_id( self::NOTIFICATION_ID ); } } - /** - * Remove the Woocommerce product beta editor enabled notification if it exists. - * - * @return void - */ - protected function remove_woocommerce_beta_editor_notification_if_exists() { - $this->notification_center->remove_notification_by_id( self::NOTIFICATION_ID ); - } - /** * Add the Woocommerce product beta editor enabled notification if it does not exist yet. * * @return void */ - protected function maybe_add_woocommerce_beta_editor_notification() { + public function maybe_add_woocommerce_beta_editor_notification() { if ( ! $this->notification_center->get_notification_by_id( self::NOTIFICATION_ID ) ) { $notification = $this->notification(); $this->notification_helper->restore_notification( $notification ); @@ -119,15 +110,6 @@ protected function maybe_add_woocommerce_beta_editor_notification() { } } - /** - * Checks whether Woocommerce product beta editor enabled. - * - * @return bool Whether Woocommerce product beta editor is enabled. - */ - protected function woocommerce_beta_editor_enabled() { - return (string) \get_option( 'woocommerce_feature_product_block_editor_enabled' ) === 'yes'; - } - /** * Returns an instance of the notification. * From 56d96931fcd00ed3f4535876c4a339d24f6a23a8 Mon Sep 17 00:00:00 2001 From: Vraja Das Date: Thu, 2 Nov 2023 14:46:46 +0100 Subject: [PATCH 08/18] fix variable comment --- .../admin/woocommerce-beta-product-editor-presenter-test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/presenters/admin/woocommerce-beta-product-editor-presenter-test.php b/tests/unit/presenters/admin/woocommerce-beta-product-editor-presenter-test.php index ce07d31c820..cccc85d9c4f 100644 --- a/tests/unit/presenters/admin/woocommerce-beta-product-editor-presenter-test.php +++ b/tests/unit/presenters/admin/woocommerce-beta-product-editor-presenter-test.php @@ -20,7 +20,7 @@ class Woocommerce_Beta_Editor_Presenter_Test extends TestCase { /** * The short link helper. * - * @var Short_Link_Helper + * @var Mockery\MockInterface|Short_Link_Helper */ protected $short_link_helper; From 036088a7c04562ae747ff79127389aa11693f5d3 Mon Sep 17 00:00:00 2001 From: Vraja Das Date: Thu, 2 Nov 2023 16:20:09 +0100 Subject: [PATCH 09/18] refactor condition --- src/integrations/watchers/woocommerce-beta-editor-watcher.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/integrations/watchers/woocommerce-beta-editor-watcher.php b/src/integrations/watchers/woocommerce-beta-editor-watcher.php index 9a1717f7caf..2fb6185318d 100644 --- a/src/integrations/watchers/woocommerce-beta-editor-watcher.php +++ b/src/integrations/watchers/woocommerce-beta-editor-watcher.php @@ -89,7 +89,7 @@ public function register_hooks() { * @return void */ public function manage_woocommerce_beta_editor_notification() { - if ( (string) \get_option( 'woocommerce_feature_product_block_editor_enabled' ) === 'yes' ) { + if ( \get_option( 'woocommerce_feature_product_block_editor_enabled' ) === 'yes' ) { $this->maybe_add_woocommerce_beta_editor_notification(); } else { From 46176f2f174384ba6a9844748109399d3cb086a7 Mon Sep 17 00:00:00 2001 From: Vraja Das Date: Thu, 2 Nov 2023 16:20:30 +0100 Subject: [PATCH 10/18] add unit tests to woocommerce beta editor watcher --- .../woocommerce-beta-editor-watcher-test.php | 184 ++++++++++++++++++ 1 file changed, 184 insertions(+) create mode 100644 tests/unit/integrations/watchers/woocommerce-beta-editor-watcher-test.php diff --git a/tests/unit/integrations/watchers/woocommerce-beta-editor-watcher-test.php b/tests/unit/integrations/watchers/woocommerce-beta-editor-watcher-test.php new file mode 100644 index 00000000000..d42ca2f4305 --- /dev/null +++ b/tests/unit/integrations/watchers/woocommerce-beta-editor-watcher-test.php @@ -0,0 +1,184 @@ +stubTranslationFunctions(); + + $this->notification_center = Mockery::mock( Yoast_Notification_Center::class ); + $this->notification_helper = Mockery::mock( Notification_Helper::class ); + $this->short_link_helper = Mockery::mock( Short_Link_Helper::class ); + + + $this->instance = new Woocommerce_Beta_Editor_Watcher( + $this->notification_center, + $this->notification_helper, + $this->short_link_helper + ); + } + + /** + * Tests the constructor. + * + * @covers ::__construct + */ + public function test_constructor() { + self::assertInstanceOf( + Yoast_Notification_Center::class, + self::getPropertyValue( $this->instance, 'notification_center' ) + ); + self::assertInstanceOf( + Notification_Helper::class, + self::getPropertyValue( $this->instance, 'notification_helper' ) + ); + self::assertInstanceOf( + Short_Link_Helper::class, + self::getPropertyValue( $this->instance, 'short_link_helper' ) + ); + } + + /** + * Tests registering the hooks. + * + * @covers ::register_hooks + */ + public function test_register_hooks() { + $this->instance->register_hooks(); + + $this->assertNotFalse( \has_action( 'admin_init', [ $this->instance, 'manage_woocommerce_beta_editor_notification' ] ) ); + } + + /** + * Tests the admin_init callback when woocommerce_beta_editor is diabled. + * + * @covers ::manage_woocommerce_beta_editor_notification + */ + public function test_manage_woocommerce_beta_editor_disable() { + + Monkey\Functions\expect( 'get_option' ) + ->once() + ->with( 'woocommerce_feature_product_block_editor_enabled' ) + ->andReturn( 'no' ); + + $this->notification_center + ->expects( 'remove_notification_by_id' ) + ->once() + ->with( 'wpseo-woocommerce-beta-editor-warning' ); + + $this->instance->manage_woocommerce_beta_editor_notification(); + } + + /** + * Tests the admin_init callback when woocommerce_beta_editor is enabled with active notification. + * + * @covers ::manage_woocommerce_beta_editor_notification + */ + public function test_manage_woocommerce_beta_editor_notification_active_and_enable() { + + Monkey\Functions\expect( 'get_option' ) + ->once() + ->with( 'woocommerce_feature_product_block_editor_enabled' ) + ->andReturn( 'yes' ); + + $this->notification_center + ->expects( 'get_notification_by_id' ) + ->once() + ->with( 'wpseo-woocommerce-beta-editor-warning' ) + ->andReturn( true ); + + $this->instance->manage_woocommerce_beta_editor_notification(); + } + + /** + * Tests the admin_init callback when woocommerce_beta_editor is enabled with no active notification. + * + * @covers ::manage_woocommerce_beta_editor_notification + * @covers ::notification + */ + public function test_manage_woocommerce_beta_editor_notification_not_active_and_enable() { + + Monkey\Functions\expect( 'get_option' ) + ->once() + ->with( 'woocommerce_feature_product_block_editor_enabled' ) + ->andReturn( 'yes' ); + + $this->notification_center + ->expects( 'get_notification_by_id' ) + ->once() + ->with( 'wpseo-woocommerce-beta-editor-warning' ) + ->andReturn( false ); + + Monkey\Functions\expect( 'esc_url' ) + ->once(); + + $this->short_link_helper + ->expects( 'get' ) + ->once() + ->with( 'https://yoa.st/learn-how-disable-beta-woocommerce-product-editor' ) + ->andReturn( 'https://yoa.st/learn-how-disable-beta-woocommerce-product-editor' ); + + Monkey\Functions\expect( 'wp_get_current_user' ) + ->once() + ->andReturn( (object) [ 'ID' => 1 ] ); + + $this->notification_helper + ->expects( 'restore_notification' ) + ->once(); + + $this->notification_center + ->expects( 'add_notification' ) + ->once(); + + $this->instance->manage_woocommerce_beta_editor_notification(); + } +} From a452dbdff123dc548153951e88c6947d1d7d77c5 Mon Sep 17 00:00:00 2001 From: Vraja Das Date: Thu, 2 Nov 2023 16:24:18 +0100 Subject: [PATCH 11/18] rename classes --- ...editor-presenter.php => woocommerce-beta-editor-presenter.php} | 0 ...senter-test.php => woocommerce-beta-editor-presenter-test.php} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename src/presenters/admin/{woocommerce-beta-product-editor-presenter.php => woocommerce-beta-editor-presenter.php} (100%) rename tests/unit/presenters/admin/{woocommerce-beta-product-editor-presenter-test.php => woocommerce-beta-editor-presenter-test.php} (100%) diff --git a/src/presenters/admin/woocommerce-beta-product-editor-presenter.php b/src/presenters/admin/woocommerce-beta-editor-presenter.php similarity index 100% rename from src/presenters/admin/woocommerce-beta-product-editor-presenter.php rename to src/presenters/admin/woocommerce-beta-editor-presenter.php diff --git a/tests/unit/presenters/admin/woocommerce-beta-product-editor-presenter-test.php b/tests/unit/presenters/admin/woocommerce-beta-editor-presenter-test.php similarity index 100% rename from tests/unit/presenters/admin/woocommerce-beta-product-editor-presenter-test.php rename to tests/unit/presenters/admin/woocommerce-beta-editor-presenter-test.php From d3a0f0f5d4fde151aca988eb870252b7c02eb4bd Mon Sep 17 00:00:00 2001 From: Vraja Das Date: Thu, 2 Nov 2023 16:36:39 +0100 Subject: [PATCH 12/18] php fix cs --- src/presenters/admin/woocommerce-beta-editor-presenter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/presenters/admin/woocommerce-beta-editor-presenter.php b/src/presenters/admin/woocommerce-beta-editor-presenter.php index 4275888c699..a8c976e15a0 100644 --- a/src/presenters/admin/woocommerce-beta-editor-presenter.php +++ b/src/presenters/admin/woocommerce-beta-editor-presenter.php @@ -53,7 +53,7 @@ protected function get_message() { \esc_html__( 'The Yoast SEO interface is currently unavailable in the beta WooCommerce product editor. To resolve any issues, please disable the beta editor. %1$sLearn how to disable the beta WooCommerce product editor.%2$s', 'wordpress-seo' ), '', '' - ), + ) ); } } From c38c2232e085e8b531a653f8d9741635366f8f14 Mon Sep 17 00:00:00 2001 From: Enrico Battocchi Date: Fri, 3 Nov 2023 10:31:39 +0100 Subject: [PATCH 13/18] Add conditionals to load the watcher only on the backend and when not serving an AJAX call --- .../watchers/woocommerce-beta-editor-watcher.php | 16 ++++++++++++---- .../woocommerce-beta-editor-watcher-test.php | 11 +++++++++++ 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/integrations/watchers/woocommerce-beta-editor-watcher.php b/src/integrations/watchers/woocommerce-beta-editor-watcher.php index 2fb6185318d..ba10f5c3296 100644 --- a/src/integrations/watchers/woocommerce-beta-editor-watcher.php +++ b/src/integrations/watchers/woocommerce-beta-editor-watcher.php @@ -2,11 +2,12 @@ namespace Yoast\WP\SEO\Integrations\Watchers; -use Yoast\WP\SEO\Conditionals\No_Conditionals; +use Yoast\WP\SEO\Conditionals\Admin_Conditional; +use Yoast\WP\SEO\Conditionals\Not_Admin_Ajax_Conditional; use Yoast\WP\SEO\Helpers\Notification_Helper; +use Yoast\WP\SEO\Helpers\Short_Link_Helper; use Yoast\WP\SEO\Integrations\Integration_Interface; use Yoast\WP\SEO\Presenters\Admin\Woocommerce_Beta_Editor_Presenter; -use Yoast\WP\SEO\Helpers\Short_Link_Helper; use Yoast_Notification; use Yoast_Notification_Center; @@ -17,8 +18,6 @@ */ class Woocommerce_Beta_Editor_Watcher implements Integration_Interface { - use No_Conditionals; - /** * The notification ID. */ @@ -70,6 +69,15 @@ public function __construct( $this->presenter = new Woocommerce_Beta_Editor_Presenter( $this->short_link_helper ); } + /** + * Returns the conditionals based on which this loadable should be active. + * + * @return string[] The conditionals. + */ + public static function get_conditionals() { + return [ Admin_Conditional::class, Not_Admin_Ajax_Conditional::class ]; + } + /** * Initializes the integration. * diff --git a/tests/unit/integrations/watchers/woocommerce-beta-editor-watcher-test.php b/tests/unit/integrations/watchers/woocommerce-beta-editor-watcher-test.php index d42ca2f4305..10bf0fca6b1 100644 --- a/tests/unit/integrations/watchers/woocommerce-beta-editor-watcher-test.php +++ b/tests/unit/integrations/watchers/woocommerce-beta-editor-watcher-test.php @@ -4,6 +4,8 @@ use Brain\Monkey; use Mockery; +use Yoast\WP\SEO\Conditionals\Admin_Conditional; +use Yoast\WP\SEO\Conditionals\Not_Admin_Ajax_Conditional; use Yoast\WP\SEO\Helpers\Short_Link_Helper; use Yoast\WP\SEO\Helpers\Notification_Helper; use Yoast\WP\SEO\Integrations\Watchers\Woocommerce_Beta_Editor_Watcher; @@ -87,6 +89,15 @@ public function test_constructor() { ); } + /** + * Tests that the integration is loaded under the right conditions. + * + * @covers ::get_conditionals + */ + public function test_get_conditionals() { + self::assertEquals( [ Admin_Conditional::class, Not_Admin_Ajax_Conditional::class ], Woocommerce_Beta_Editor_Watcher::get_conditionals() ); + } + /** * Tests registering the hooks. * From 033414b8b3bc26521b053998ad1794c929262f74 Mon Sep 17 00:00:00 2001 From: Enrico Battocchi Date: Fri, 3 Nov 2023 10:32:01 +0100 Subject: [PATCH 14/18] Inject 'Yoast SEO' in the string --- src/presenters/admin/woocommerce-beta-editor-presenter.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/presenters/admin/woocommerce-beta-editor-presenter.php b/src/presenters/admin/woocommerce-beta-editor-presenter.php index a8c976e15a0..048121b51c6 100644 --- a/src/presenters/admin/woocommerce-beta-editor-presenter.php +++ b/src/presenters/admin/woocommerce-beta-editor-presenter.php @@ -49,8 +49,9 @@ protected function get_message() { '%1$s %2$s', \esc_html__( 'Compatibility issue: Yoast SEO is incompatible with the beta WooCommerce product editor.', 'wordpress-seo' ), \sprintf( - /* translators: 1: Link start tag to the Learn more link, 2: Link closing tag. */ - \esc_html__( 'The Yoast SEO interface is currently unavailable in the beta WooCommerce product editor. To resolve any issues, please disable the beta editor. %1$sLearn how to disable the beta WooCommerce product editor.%2$s', 'wordpress-seo' ), + /* translators: 1: Yoast SEO, 2: Link start tag to the Learn more link, 3: Link closing tag. */ + \esc_html__( 'The %1$s interface is currently unavailable in the beta WooCommerce product editor. To resolve any issues, please disable the beta editor. %2$sLearn how to disable the beta WooCommerce product editor.%3$s', 'wordpress-seo' ), + 'Yoast SEO', '', '' ) From 22b490fce993098c3330deb4385ee5baf0e92bff Mon Sep 17 00:00:00 2001 From: Vraja Das Date: Fri, 3 Nov 2023 10:39:46 +0100 Subject: [PATCH 15/18] fix introduction modal for admin pages --- .../ai-generator/components/modal-content.js | 49 +++++++++ ...generate-titles-and-descriptions-upsell.js | 101 +++++++----------- 2 files changed, 88 insertions(+), 62 deletions(-) diff --git a/packages/js/src/ai-generator/components/modal-content.js b/packages/js/src/ai-generator/components/modal-content.js index f7e78615313..0e91da3b9b3 100644 --- a/packages/js/src/ai-generator/components/modal-content.js +++ b/packages/js/src/ai-generator/components/modal-content.js @@ -1,6 +1,8 @@ +/* eslint-disable complexity */ import { useDispatch, useSelect } from "@wordpress/data"; import { useMemo } from "@wordpress/element"; import { AiGenerateTitlesAndDescriptionsUpsell } from "../../shared-admin/components"; +import { __, sprintf } from "@wordpress/i18n"; const STORE = "yoast-seo/editor"; @@ -9,6 +11,52 @@ const STORE = "yoast-seo/editor"; */ export const ModalContent = () => { const learnMoreLink = useSelect( select => select( STORE ).selectLink( "https://www.yoa.st/ai-generator-learn-more" ), [] ); + const upsellLinkPremium = useSelect( select => select( STORE ).selectLink( "https://yoa.st/ai-generator-upsell" ), [] ); + const upsellLinkWooPremiumBundle = useSelect( select => select( STORE ).selectLink( "https://yoa.st/ai-generator-upsell-woo-seo-premium-bundle" ), [] ); + const upsellLinkWoo = useSelect( select => select( STORE ).selectLink( "https://yoa.st/ai-generator-upsell-woo-seo" ), [] ); + const isPremium = useSelect( select => select( STORE ).getIsPremium(), [] ); + const isWooSeoUpsell = useSelect( select => select( STORE ).getIsWooSeoUpsell(), [] ); + const isProduct = useSelect( select => select( STORE ).getIsProduct(), [] ); + const wooSeoNoPremium = isProduct && ! isWooSeoUpsell && ! isPremium; + const isProductCopy = isWooSeoUpsell || wooSeoNoPremium; + const postModalprops = { + isProductCopy, + upsellLink: upsellLinkPremium, + }; + + if ( isProductCopy ) { + const upsellPremiumWooLabel = sprintf( + /* translators: %1$s expands to Yoast SEO Premium, %2$s expands to Yoast WooCommerce SEO. */ + __( "%1$s + %2$s", "wordpress-seo" ), + "Yoast SEO Premium", + "Yoast WooCommerce SEO" + ); + postModalprops.newToText = sprintf( + /* translators: %1$s expands to Yoast SEO Premium and Yoast WooCommerce SEO. */ + __( "New to %1$s", "wordpress-seo" ), + upsellPremiumWooLabel + ); + postModalprops.title = __( "Generate product titles & descriptions with AI!", "wordpress-seo" ); + if ( ! isPremium && isWooSeoUpsell ) { + postModalprops.upsellLabel = `${ sprintf( + /* translators: %1$s expands to Woo Premium bundle. */ + __( "Unlock with the %1$s", "wordpress-seo" ), + "Woo Premium bundle" + )}*`; + postModalprops.bundleNote =
+ { `*${upsellPremiumWooLabel}` } +
; + postModalprops.upsellLink = upsellLinkWooPremiumBundle; + } + if ( isPremium ) { + postModalprops.upsellLabel = sprintf( + /* translators: %1$s expands to Yoast WooCommerce SEO. */ + __( "Unlock with %1$s", "wordpress-seo" ), + "Yoast WooCommerce SEO" + ); + postModalprops.upsellLink = upsellLinkWoo; + } + } const imageLink = useSelect( select => select( STORE ).selectImageLink( "ai-generator-preview.png" ), [] ); @@ -29,6 +77,7 @@ export const ModalContent = () => { learnMoreLink={ learnMoreLink } thumbnail={ thumbnail } wistiaEmbedPermission={ wistiaEmbedPermission } + { ...postModalprops } /> ); }; diff --git a/packages/js/src/shared-admin/components/ai-generate-titles-and-descriptions-upsell.js b/packages/js/src/shared-admin/components/ai-generate-titles-and-descriptions-upsell.js index 6535d57be53..91f22364d45 100644 --- a/packages/js/src/shared-admin/components/ai-generate-titles-and-descriptions-upsell.js +++ b/packages/js/src/shared-admin/components/ai-generate-titles-and-descriptions-upsell.js @@ -1,38 +1,36 @@ -/* eslint-disable complexity */ import { LockOpenIcon } from "@heroicons/react/outline"; import { ArrowNarrowRightIcon } from "@heroicons/react/solid"; import { createInterpolateElement } from "@wordpress/element"; -import { useSelect } from "@wordpress/data"; import { __, sprintf } from "@wordpress/i18n"; import { Badge, Button, useModalContext } from "@yoast/ui-library"; import PropTypes from "prop-types"; import { OutboundLink, VideoFlow } from "."; -const STORE = "yoast-seo/editor"; - /** * @param {string} learnMoreLink The learn more link. * @param {Object} thumbnail The thumbnail: img props. * @param {Object} wistiaEmbedPermission The value, status and set for the Wistia embed permission. + * @param {string} upsellLink The upsell link. + * @param {boolean} isProductCopy Whether the upsell is for a product. + * @param {string} title The title. + * @param {string} upsellLabel The upsell label. + * @param {string} newToText The new to text. + * @param {string} bundleNote The bundle note. * @returns {JSX.Element} The element. */ -export const AiGenerateTitlesAndDescriptionsUpsell = ( { learnMoreLink, thumbnail, wistiaEmbedPermission } ) => { +export const AiGenerateTitlesAndDescriptionsUpsell = ( { + learnMoreLink, + thumbnail, + wistiaEmbedPermission, + upsellLink, + isProductCopy, + title, + upsellLabel, + newToText, + bundleNote, +} ) => { const { onClose, initialFocus } = useModalContext(); - const upsellLinkPremium = useSelect( select => select( STORE ).selectLink( "https://yoa.st/ai-generator-upsell" ), [] ); - const upsellLinkWooPremiumBundle = useSelect( select => select( STORE ).selectLink( "https://yoa.st/ai-generator-upsell-woo-seo-premium-bundle" ), [] ); - const upsellLinkWoo = useSelect( select => select( STORE ).selectLink( "https://yoa.st/ai-generator-upsell-woo-seo" ), [] ); - const isPremium = useSelect( select => select( STORE ).getIsPremium(), [] ); - const isWooSeoUpsell = useSelect( select => select( STORE ).getIsWooSeoUpsell(), [] ); - const isProduct = useSelect( select => select( STORE ).getIsProduct(), [] ); - const wooSeoNoPremium = isProduct && ! isWooSeoUpsell && ! isPremium; - const isProductCopy = isWooSeoUpsell || wooSeoNoPremium; - let upsellLink = upsellLinkPremium; - let newToText = sprintf( - /* translators: %1$s expands to Yoast SEO Premium. */ - __( "New to %1$s", "wordpress-seo" ), - "Yoast SEO Premium" - ); const learnMoreLinkStructure = { // eslint-disable-next-line jsx-a11y/anchor-has-content a: , }; - let upsellLabel = sprintf( - /* translators: %1$s expands to Yoast SEO Premium. */ - __( "Unlock with %1$s", "wordpress-seo" ), - "Yoast SEO Premium" - ); - let bundleNote = ""; - let title = __( "Generate titles & descriptions with Yoast AI!", "wordpress-seo" ); - - - if ( isProductCopy ) { - const upsellPremiumWooLabel = sprintf( - /* translators: %1$s expands to Yoast SEO Premium, %2$s expands to Yoast WooCommerce SEO. */ - __( "%1$s + %2$s", "wordpress-seo" ), - "Yoast SEO Premium", - "Yoast WooCommerce SEO" - ); - newToText = sprintf( - /* translators: %1$s expands to Yoast SEO Premium and Yoast WooCommerce SEO. */ - __( "New to %1$s", "wordpress-seo" ), - upsellPremiumWooLabel - ); - title = __( "Generate product titles & descriptions with AI!", "wordpress-seo" ); - if ( ! isPremium && isWooSeoUpsell ) { - upsellLabel = `${sprintf( - /* translators: %1$s expands to Woo Premium bundle. */ - __( "Unlock with the %1$s", "wordpress-seo" ), - "Woo Premium bundle" - )}*`; - bundleNote =
- { `*${upsellPremiumWooLabel}` } -
; - upsellLink = upsellLinkWooPremiumBundle; - } - if ( isPremium ) { - upsellLabel = sprintf( - /* translators: %1$s expands to Yoast WooCommerce SEO. */ - __( "Unlock with %1$s", "wordpress-seo" ), - "Yoast WooCommerce SEO" - ); - upsellLink = upsellLinkWoo; - } - } - return (
@@ -170,6 +125,7 @@ export const AiGenerateTitlesAndDescriptionsUpsell = ( { learnMoreLink, thumbnai }; AiGenerateTitlesAndDescriptionsUpsell.propTypes = { learnMoreLink: PropTypes.string.isRequired, + upsellLink: PropTypes.string.isRequired, thumbnail: PropTypes.shape( { src: PropTypes.string.isRequired, width: PropTypes.string, @@ -180,4 +136,25 @@ AiGenerateTitlesAndDescriptionsUpsell.propTypes = { status: PropTypes.string.isRequired, set: PropTypes.func.isRequired, } ).isRequired, + title: PropTypes.string, + upsellLabel: PropTypes.string, + newToText: PropTypes.string, + isProductCopy: PropTypes.bool, + bundleNote: PropTypes.string, +}; + +AiGenerateTitlesAndDescriptionsUpsell.defaultProps = { + title: __( "Generate titles & descriptions with Yoast AI!", "wordpress-seo" ), + upsellLabel: sprintf( + /* translators: %1$s expands to Yoast SEO Premium. */ + __( "Unlock with %1$s", "wordpress-seo" ), + "Yoast SEO Premium" + ), + newToText: sprintf( + /* translators: %1$s expands to Yoast SEO Premium. */ + __( "New to %1$s", "wordpress-seo" ), + "Yoast SEO Premium" + ), + isProductCopy: false, + bundleNote: "", }; From 35a1fe0d3d2bd4cf2befd96a486e02514148f18e Mon Sep 17 00:00:00 2001 From: Vraja Das Date: Fri, 3 Nov 2023 11:18:09 +0100 Subject: [PATCH 16/18] fix prop types errors --- packages/js/src/ai-generator/components/modal-content.js | 2 +- .../ai-generate-titles-and-descriptions-upsell.js | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/js/src/ai-generator/components/modal-content.js b/packages/js/src/ai-generator/components/modal-content.js index 0e91da3b9b3..eef9b049912 100644 --- a/packages/js/src/ai-generator/components/modal-content.js +++ b/packages/js/src/ai-generator/components/modal-content.js @@ -18,7 +18,7 @@ export const ModalContent = () => { const isWooSeoUpsell = useSelect( select => select( STORE ).getIsWooSeoUpsell(), [] ); const isProduct = useSelect( select => select( STORE ).getIsProduct(), [] ); const wooSeoNoPremium = isProduct && ! isWooSeoUpsell && ! isPremium; - const isProductCopy = isWooSeoUpsell || wooSeoNoPremium; + const isProductCopy = !! ( isWooSeoUpsell || wooSeoNoPremium ); const postModalprops = { isProductCopy, upsellLink: upsellLinkPremium, diff --git a/packages/js/src/shared-admin/components/ai-generate-titles-and-descriptions-upsell.js b/packages/js/src/shared-admin/components/ai-generate-titles-and-descriptions-upsell.js index 91f22364d45..1a06f87be8d 100644 --- a/packages/js/src/shared-admin/components/ai-generate-titles-and-descriptions-upsell.js +++ b/packages/js/src/shared-admin/components/ai-generate-titles-and-descriptions-upsell.js @@ -15,7 +15,7 @@ import { OutboundLink, VideoFlow } from "."; * @param {string} title The title. * @param {string} upsellLabel The upsell label. * @param {string} newToText The new to text. - * @param {string} bundleNote The bundle note. + * @param {string|JSX.Element } bundleNote The bundle note. * @returns {JSX.Element} The element. */ export const AiGenerateTitlesAndDescriptionsUpsell = ( { @@ -140,7 +140,10 @@ AiGenerateTitlesAndDescriptionsUpsell.propTypes = { upsellLabel: PropTypes.string, newToText: PropTypes.string, isProductCopy: PropTypes.bool, - bundleNote: PropTypes.string, + bundleNote: PropTypes.oneOfType( [ + PropTypes.string, + PropTypes.element, + ] ), }; AiGenerateTitlesAndDescriptionsUpsell.defaultProps = { From 57caa3c05759213cd46647a562fae8ea09df7e5a Mon Sep 17 00:00:00 2001 From: YoastBot Date: Fri, 3 Nov 2023 11:47:28 +0000 Subject: [PATCH 17/18] Add changelog --- readme.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/readme.txt b/readme.txt index 0c51232c5be..5afcdfde6d4 100644 --- a/readme.txt +++ b/readme.txt @@ -358,6 +358,7 @@ Release date: 2023-11-28 #### Other * Adds defensive coding to the supress warnings on archive pages with the `/%category%/%postname%/` permalink structure. Props to [@Mte90](https://github.com/Mte90). +* Adds notification when WooCommerce new beta product editor is enabled. = 21.5 = From dcf89ed35022282631619e6bf5c48df696744bd8 Mon Sep 17 00:00:00 2001 From: YoastBot Date: Fri, 3 Nov 2023 11:47:34 +0000 Subject: [PATCH 18/18] Bump version to 21.6-RC2 --- package.json | 2 +- wp-seo-main.php | 2 +- wp-seo.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index b7765a176ae..489f28c2409 100644 --- a/package.json +++ b/package.json @@ -83,7 +83,7 @@ "typescript": "^4.2.4" }, "yoast": { - "pluginVersion": "21.6-RC1" + "pluginVersion": "21.6-RC2" }, "version": "0.0.0" } diff --git a/wp-seo-main.php b/wp-seo-main.php index 18a098a2431..71d41c59242 100644 --- a/wp-seo-main.php +++ b/wp-seo-main.php @@ -15,7 +15,7 @@ * {@internal Nobody should be able to overrule the real version number as this can cause * serious issues with the options, so no if ( ! defined() ).}} */ -define( 'WPSEO_VERSION', '21.6-RC1' ); +define( 'WPSEO_VERSION', '21.6-RC2' ); if ( ! defined( 'WPSEO_PATH' ) ) { diff --git a/wp-seo.php b/wp-seo.php index c4b15abd7f8..f9a5a56611d 100644 --- a/wp-seo.php +++ b/wp-seo.php @@ -8,7 +8,7 @@ * * @wordpress-plugin * Plugin Name: Yoast SEO - * Version: 21.6-RC1 + * Version: 21.6-RC2 * Plugin URI: https://yoa.st/1uj * Description: The first true all-in-one SEO solution for WordPress, including on-page content analysis, XML sitemaps and much more. * Author: Team Yoast