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
This commit is contained in:
Konstantin Kovshenin 2017-12-13 19:31:38 +03:00
parent a42ba4607e
commit 1928a9cbf6
1 changed files with 43 additions and 1 deletions

View File

@ -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 '<div class="updated woocommerce-message"><p>' . $notice . '</p></div>';
}
}
/**
* 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 = __( '<a href="%s">Connect your store</a> to WooCommerce.com to receive extensions updates and support.', 'woocommerce' );
$notice = sprintf( $notice, admin_url( 'admin.php?page=wc-addons&section=helper' ) );
echo '<div class="updated woocommerce-message"><p>' . $notice . '</p></div>';
}
}
/**
* Get an update notice if one or more Woo extensions has an update available.
*