From 3c3077d305a40041774c1ec32422da3bfa5f5a4b Mon Sep 17 00:00:00 2001 From: Konstantin Kovshenin Date: Thu, 18 Jan 2018 12:28:00 +0300 Subject: [PATCH 1/3] Helper: Prompt a Helper connection only on relevant screens. Fixes #18452 --- includes/admin/helper/class-wc-helper.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/includes/admin/helper/class-wc-helper.php b/includes/admin/helper/class-wc-helper.php index e7d092b86cd..87a95e73201 100644 --- a/includes/admin/helper/class-wc-helper.php +++ b/includes/admin/helper/class-wc-helper.php @@ -1237,6 +1237,27 @@ class WC_Helper { * Prompt a Helper connection if the user has WooCommerce.com extensions. */ private static function _prompt_helper_connect( $screen_id ) { + $screens = array( + 'plugins', + 'product', + 'edit-product', + 'edit-product_cat', + 'edit-product_tag', + 'product_page_product_attributes', + 'shop_order', + 'edit-shop_order', + 'shop_coupon', + 'edit-shop_coupon', + 'woocommerce_page_wc-reports', + 'woocommerce_page_wc-settings', + 'woocommerce_page_wc-status', + 'woocommerce_page_wc-addons', + ); + + if ( ! in_array( $screen_id, $screens ) ) { + return; + } + // Don't show the notice on the Helper screens. if ( 'woocommerce_page_wc-addons' == $screen_id && ! empty( $_REQUEST['section'] ) && 'helper' == $_REQUEST['section'] ) { return; From 9a496e5d88d3aacc8da792fc48532af31448497d Mon Sep 17 00:00:00 2001 From: Konstantin Kovshenin Date: Fri, 19 Jan 2018 20:58:36 +0300 Subject: [PATCH 2/3] Helper: Fix some code problems in the connection prompt. * Use `wc_get_screen_ids()` instead of hard-coding a list. * Use the `$strict` param in `in_array()` * Run the WooCommerce string through l10n to make sure we target the correct screen in non-English installs --- includes/admin/helper/class-wc-helper.php | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) diff --git a/includes/admin/helper/class-wc-helper.php b/includes/admin/helper/class-wc-helper.php index 87a95e73201..7367e6dec5e 100644 --- a/includes/admin/helper/class-wc-helper.php +++ b/includes/admin/helper/class-wc-helper.php @@ -1237,29 +1237,16 @@ class WC_Helper { * Prompt a Helper connection if the user has WooCommerce.com extensions. */ private static function _prompt_helper_connect( $screen_id ) { - $screens = array( - 'plugins', - 'product', - 'edit-product', - 'edit-product_cat', - 'edit-product_tag', - 'product_page_product_attributes', - 'shop_order', - 'edit-shop_order', - 'shop_coupon', - 'edit-shop_coupon', - 'woocommerce_page_wc-reports', - 'woocommerce_page_wc-settings', - 'woocommerce_page_wc-status', - 'woocommerce_page_wc-addons', - ); + $screens = wc_get_screen_ids(); + $screens[] = 'plugins'; - if ( ! in_array( $screen_id, $screens ) ) { + if ( ! in_array( $screen_id, $screens, true ) ) { return; } // Don't show the notice on the Helper screens. - if ( 'woocommerce_page_wc-addons' == $screen_id && ! empty( $_REQUEST['section'] ) && 'helper' == $_REQUEST['section'] ) { + $screen_addons = sanitize_title( __( 'WooCommerce', 'woocommerce' ) ) . '_page_wc-addons'; + if ( $screen_addons == $screen_id && ! empty( $_REQUEST['section'] ) && 'helper' == $_REQUEST['section'] ) { return; } From 02ebd8f2ee91ea6658ec88c41ddfd0cf1c5344ff Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Mon, 22 Jan 2018 15:43:23 +0000 Subject: [PATCH 3/3] Coding standards --- includes/admin/helper/class-wc-helper.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/includes/admin/helper/class-wc-helper.php b/includes/admin/helper/class-wc-helper.php index 7367e6dec5e..1dd3f701602 100644 --- a/includes/admin/helper/class-wc-helper.php +++ b/includes/admin/helper/class-wc-helper.php @@ -1235,9 +1235,11 @@ class WC_Helper { /** * Prompt a Helper connection if the user has WooCommerce.com extensions. + * + * @param string $screen_id Current screen ID. */ private static function _prompt_helper_connect( $screen_id ) { - $screens = wc_get_screen_ids(); + $screens = wc_get_screen_ids(); $screens[] = 'plugins'; if ( ! in_array( $screen_id, $screens, true ) ) { @@ -1246,11 +1248,12 @@ class WC_Helper { // Don't show the notice on the Helper screens. $screen_addons = sanitize_title( __( 'WooCommerce', 'woocommerce' ) ) . '_page_wc-addons'; - if ( $screen_addons == $screen_id && ! empty( $_REQUEST['section'] ) && 'helper' == $_REQUEST['section'] ) { + + if ( $screen_addons === $screen_id && ! empty( $_REQUEST['section'] ) && 'helper' === $_REQUEST['section'] ) { return; } - // We believe have an active connection. + // We believe we have an active connection. $auth = WC_Helper_Options::get( 'auth' ); if ( ! empty( $auth['access_token'] ) ) { return;