From 79551e9843d7927797539f81a9c242b913764b86 Mon Sep 17 00:00:00 2001 From: claudiulodro Date: Wed, 13 Jun 2018 11:36:36 -0700 Subject: [PATCH 1/3] Wootenberg JITM --- includes/admin/class-wc-admin-notices.php | 39 +++++++++++++++++++ .../admin/views/html-notice-wootenberg.php | 23 +++++++++++ 2 files changed, 62 insertions(+) create mode 100644 includes/admin/views/html-notice-wootenberg.php diff --git a/includes/admin/class-wc-admin-notices.php b/includes/admin/class-wc-admin-notices.php index 959bded7d3e..a2b7dc13db7 100644 --- a/includes/admin/class-wc-admin-notices.php +++ b/includes/admin/class-wc-admin-notices.php @@ -34,6 +34,7 @@ class WC_Admin_Notices { 'simplify_commerce' => 'simplify_commerce_notice', 'regenerating_thumbnails' => 'regenerating_thumbnails_notice', 'no_secure_connection' => 'secure_connection_notice', + 'wootenberg' => 'wootenberg_feature_plugin_notice', ); /** @@ -49,6 +50,7 @@ class WC_Admin_Notices { if ( current_user_can( 'manage_woocommerce' ) ) { add_action( 'admin_print_styles', array( __CLASS__, 'add_notices' ) ); + add_action( 'activate_gutenberg/gutenberg.php', array( __CLASS__, 'add_wootenberg_feature_plugin_notice_on_gutenberg_activate' ) ); } } @@ -91,6 +93,7 @@ class WC_Admin_Notices { WC_Admin_Notices::add_notice( 'no_secure_connection' ); } + WC_Admin_Notices::add_wootenberg_feature_plugin_notice(); self::add_notice( 'template_files' ); } @@ -357,6 +360,42 @@ class WC_Admin_Notices { include dirname( __FILE__ ) . '/views/html-notice-secure-connection.php'; } + + /** + * If Gutenberg is active, tell people about the Products block feature plugin. + * + * @since 3.4.3 + * @todo Remove this notice and associated code once the feature plugin has been merged into core. + */ + public static function add_wootenberg_feature_plugin_notice() { + if ( is_plugin_active( 'gutenberg/gutenberg.php' ) && ! is_plugin_active( 'woo-gutenberg-products-block/woocommerce-gutenberg-products-block.php' ) ) { + self::add_notice( 'wootenberg' ); + } + } + + /** + * Tell people about the Products block feature plugin when they activate Gutenberg. + * + * @since 3.4.3 + * @todo Remove this notice and associated code once the feature plugin has been merged into core. + */ + public static function add_wootenberg_feature_plugin_notice_on_gutenberg_activate() { + if ( ! is_plugin_active( 'woo-gutenberg-products-block/woocommerce-gutenberg-products-block.php' ) ) { + self::add_notice( 'wootenberg' ); + } + } + + /** + * Notice about trying the Products block. + */ + public static function wootenberg_feature_plugin_notice() { + if ( is_plugin_active( 'woo-gutenberg-products-block/woocommerce-gutenberg-products-block.php' ) ) { + self::remove_notice( 'wootenberg' ); + return; + } + + include dirname( __FILE__ ) . '/views/html-notice-wootenberg.php'; + } } WC_Admin_Notices::init(); diff --git a/includes/admin/views/html-notice-wootenberg.php b/includes/admin/views/html-notice-wootenberg.php new file mode 100644 index 00000000000..c828e2a26af --- /dev/null +++ b/includes/admin/views/html-notice-wootenberg.php @@ -0,0 +1,23 @@ + +
+ + +

+ WooCommerce Gutenberg Products Block for a powerful new way to feature products in your Gutenberg posts!', 'woocommerce' ) ), + 'https://wordpress.org/plugins/woo-gutenberg-products-block/' + ); + ?> +

+
From 7148f8da2d2410c3f5ab78af4ef38e0b0bd21f00 Mon Sep 17 00:00:00 2001 From: claudiulodro Date: Mon, 18 Jun 2018 10:42:52 -0700 Subject: [PATCH 2/3] Install/activate the plugin from the notice --- .../admin/views/html-notice-wootenberg.php | 24 +++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/includes/admin/views/html-notice-wootenberg.php b/includes/admin/views/html-notice-wootenberg.php index c828e2a26af..3e68cd1c639 100644 --- a/includes/admin/views/html-notice-wootenberg.php +++ b/includes/admin/views/html-notice-wootenberg.php @@ -12,12 +12,22 @@ if ( ! defined( 'ABSPATH' ) ) {

- WooCommerce Gutenberg Products Block for a powerful new way to feature products in your Gutenberg posts!', 'woocommerce' ) ), - 'https://wordpress.org/plugins/woo-gutenberg-products-block/' - ); - ?> +

+ +

+ +

+ + +

+ +

+ From 1890ef788d7ec9349ed2971d19b13dd0adba48c8 Mon Sep 17 00:00:00 2001 From: claudiulodro Date: Mon, 18 Jun 2018 10:54:01 -0700 Subject: [PATCH 3/3] Persist wootenberg notice dismissal --- includes/admin/class-wc-admin-notices.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/admin/class-wc-admin-notices.php b/includes/admin/class-wc-admin-notices.php index a2b7dc13db7..a96a6fd7812 100644 --- a/includes/admin/class-wc-admin-notices.php +++ b/includes/admin/class-wc-admin-notices.php @@ -389,7 +389,7 @@ class WC_Admin_Notices { * Notice about trying the Products block. */ public static function wootenberg_feature_plugin_notice() { - if ( is_plugin_active( 'woo-gutenberg-products-block/woocommerce-gutenberg-products-block.php' ) ) { + if ( get_user_meta( get_current_user_id(), 'dismissed_wootenberg_notice', true ) || is_plugin_active( 'woo-gutenberg-products-block/woocommerce-gutenberg-products-block.php' ) ) { self::remove_notice( 'wootenberg' ); return; }