From 1928a9cbf6e6f55f21307eae2289975490025b76 Mon Sep 17 00:00:00 2001 From: Konstantin Kovshenin Date: Wed, 13 Dec 2017 19:31:38 +0300 Subject: [PATCH] Helper: Prompt connection to WooCommerce.com for updates/support A persistent prompt for users to connect their store to their WooCommerce.com account, if they happen to have one or more active extensions provided by WooCommerce.com. Fixes #17501 --- includes/admin/helper/class-wc-helper.php | 44 ++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/includes/admin/helper/class-wc-helper.php b/includes/admin/helper/class-wc-helper.php index d50c0e4fb5c..e7d092b86cd 100644 --- a/includes/admin/helper/class-wc-helper.php +++ b/includes/admin/helper/class-wc-helper.php @@ -1205,12 +1205,18 @@ class WC_Helper { } /** - * Add a note about available extension updates if Woo core has an update available. + * Various Helper-related admin notices. */ public static function admin_notices() { + if ( apply_filters( 'woocommerce_helper_suppress_admin_notices', false ) ) { + return; + } + $screen = get_current_screen(); $screen_id = $screen ? $screen->id : ''; + self::_prompt_helper_connect( $screen_id ); + if ( 'update-core' !== $screen_id ) { return; } @@ -1220,12 +1226,48 @@ class WC_Helper { return; } + // Add a note about available extension updates if Woo core has an update available. $notice = self::_get_extensions_update_notice(); if ( ! empty( $notice ) ) { echo '

' . $notice . '

'; } } + /** + * Prompt a Helper connection if the user has WooCommerce.com extensions. + */ + private static function _prompt_helper_connect( $screen_id ) { + // Don't show the notice on the Helper screens. + if ( 'woocommerce_page_wc-addons' == $screen_id && ! empty( $_REQUEST['section'] ) && 'helper' == $_REQUEST['section'] ) { + return; + } + + // We believe have an active connection. + $auth = WC_Helper_Options::get( 'auth' ); + if ( ! empty( $auth['access_token'] ) ) { + return; + } + + $active_plugins = apply_filters( 'active_plugins', get_option( 'active_plugins' ) ); + if ( empty( $active_plugins ) ) { + return; + } + + $woo_plugins = self::get_local_woo_plugins(); + if ( empty( $woo_plugins ) ) { + return; + } + + $active_woo_plugins = array_intersect_key( $woo_plugins, array_flip( $active_plugins ) ); + + if ( count( $active_woo_plugins ) > 0 ) { + /* translators: %s: helper screen url */ + $notice = __( 'Connect your store to WooCommerce.com to receive extensions updates and support.', 'woocommerce' ); + $notice = sprintf( $notice, admin_url( 'admin.php?page=wc-addons§ion=helper' ) ); + echo '

' . $notice . '

'; + } + } + /** * Get an update notice if one or more Woo extensions has an update available. *