plugin updates
This commit is contained in:
@@ -50,6 +50,8 @@ class WC_Helper_Admin {
|
||||
$installed_products
|
||||
);
|
||||
|
||||
$woo_connect_notice_type = WC_Helper_Updater::get_woo_connect_notice_type();
|
||||
|
||||
$settings['wccomHelper'] = array(
|
||||
'isConnected' => WC_Helper::is_site_connected(),
|
||||
'connectURL' => self::get_connection_url(),
|
||||
@@ -63,6 +65,7 @@ class WC_Helper_Admin {
|
||||
'wooUpdateManagerInstallUrl' => WC_Woo_Update_Manager_Plugin::generate_install_url(),
|
||||
'wooUpdateManagerPluginSlug' => WC_Woo_Update_Manager_Plugin::WOO_UPDATE_MANAGER_SLUG,
|
||||
'wooUpdateCount' => WC_Helper_Updater::get_updates_count_based_on_site_status(),
|
||||
'woocomConnectNoticeType' => $woo_connect_notice_type,
|
||||
);
|
||||
|
||||
return $settings;
|
||||
|
||||
@@ -33,7 +33,7 @@ class WC_Helper_Updater {
|
||||
* Add the hook for modifying default WPCore update notices on the plugins management page.
|
||||
*/
|
||||
public static function add_hook_for_modifying_update_notices() {
|
||||
if ( ! WC_Woo_Update_Manager_Plugin::is_plugin_active() ) {
|
||||
if ( ! WC_Woo_Update_Manager_Plugin::is_plugin_active() || ! WC_Helper::is_site_connected() ) {
|
||||
add_action( 'load-plugins.php', array( __CLASS__, 'setup_update_plugins_messages' ), 11 );
|
||||
}
|
||||
}
|
||||
@@ -155,12 +155,47 @@ class WC_Helper_Updater {
|
||||
* @return void.
|
||||
*/
|
||||
public static function setup_update_plugins_messages() {
|
||||
$is_site_connected = WC_Helper::is_site_connected();
|
||||
foreach ( WC_Helper::get_local_woo_plugins() as $plugin ) {
|
||||
$filename = $plugin['_filename'];
|
||||
add_action( 'in_plugin_update_message-' . $filename, array( __CLASS__, 'add_install_marketplace_plugin_message' ), 10, 2 );
|
||||
if ( $is_site_connected ) {
|
||||
add_action( 'in_plugin_update_message-' . $filename, array( __CLASS__, 'add_install_marketplace_plugin_message' ), 10, 2 );
|
||||
} else {
|
||||
add_action( 'in_plugin_update_message-' . $filename, array( __CLASS__, 'add_connect_woocom_plugin_message' ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs on in_plugin_update_message-{file-name}, show a message to connect to woocommerce.com for unconnected stores
|
||||
*
|
||||
* @return void.
|
||||
*/
|
||||
public static function add_connect_woocom_plugin_message() {
|
||||
$connect_page_url = add_query_arg(
|
||||
array(
|
||||
'page' => 'wc-admin',
|
||||
'tab' => 'my-subscriptions',
|
||||
'path' => rawurlencode( '/extensions' ),
|
||||
),
|
||||
admin_url( 'admin.php' )
|
||||
);
|
||||
|
||||
printf(
|
||||
wp_kses(
|
||||
/* translators: 1: Woo Update Manager plugin install URL */
|
||||
__( ' <a href="%1$s" class="woocommerce-connect-your-store">Connect your store</a> to woocommerce.com to update.', 'woocommerce' ),
|
||||
array(
|
||||
'a' => array(
|
||||
'href' => array(),
|
||||
'class' => array(),
|
||||
),
|
||||
)
|
||||
),
|
||||
esc_url( $connect_page_url ),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs on in_plugin_update_message-{file-name}, show a message to install the Woo Marketplace plugin, on plugin update notification,
|
||||
* if the Woo Marketplace plugin isn't already installed.
|
||||
@@ -404,6 +439,9 @@ class WC_Helper_Updater {
|
||||
* @return array Update data for each requested product.
|
||||
*/
|
||||
private static function _update_check( $payload ) {
|
||||
if ( empty( $payload ) ) {
|
||||
return array();
|
||||
}
|
||||
ksort( $payload );
|
||||
$hash = md5( wp_json_encode( $payload ) );
|
||||
|
||||
@@ -422,13 +460,22 @@ class WC_Helper_Updater {
|
||||
'errors' => array(),
|
||||
);
|
||||
|
||||
$request = WC_Helper_API::post(
|
||||
'update-check',
|
||||
array(
|
||||
'body' => wp_json_encode( array( 'products' => $payload ) ),
|
||||
'authenticated' => true,
|
||||
)
|
||||
);
|
||||
if ( WC_Helper::is_site_connected() ) {
|
||||
$request = WC_Helper_API::post(
|
||||
'update-check',
|
||||
array(
|
||||
'body' => wp_json_encode( array( 'products' => $payload ) ),
|
||||
'authenticated' => true,
|
||||
)
|
||||
);
|
||||
} else {
|
||||
$request = WC_Helper_API::post(
|
||||
'update-check-public',
|
||||
array(
|
||||
'body' => wp_json_encode( array( 'products' => $payload ) ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if ( wp_remote_retrieve_response_code( $request ) !== 200 ) {
|
||||
$data['errors'][] = 'http-error';
|
||||
@@ -503,7 +550,7 @@ class WC_Helper_Updater {
|
||||
*/
|
||||
public static function get_updates_count_based_on_site_status() {
|
||||
if ( ! WC_Helper::is_site_connected() ) {
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
$count = self::get_updates_count() ?? 0;
|
||||
@@ -514,6 +561,45 @@ class WC_Helper_Updater {
|
||||
return $count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the type of woo connect notice to be shown in the WC Settings and Marketplace pages.
|
||||
* - If a store is connected to woocommerce.com or has no installed woo plugins, return 'none'.
|
||||
* - If a store has installed woo plugins but no updates, return 'short'.
|
||||
* - If a store has an installed woo plugin with update, return 'long'.
|
||||
*
|
||||
* @return string The notice type, 'none', 'short', or 'long'.
|
||||
*/
|
||||
public static function get_woo_connect_notice_type() {
|
||||
if ( WC_Helper::is_site_connected() ) {
|
||||
return 'none';
|
||||
}
|
||||
|
||||
$woo_plugins = WC_Helper::get_local_woo_plugins();
|
||||
|
||||
if ( empty( $woo_plugins ) ) {
|
||||
return 'none';
|
||||
}
|
||||
|
||||
$update_data = self::get_update_data();
|
||||
|
||||
if ( empty( $update_data ) ) {
|
||||
return 'short';
|
||||
}
|
||||
|
||||
// Scan local plugins.
|
||||
foreach ( $woo_plugins as $plugin ) {
|
||||
if ( empty( $update_data[ $plugin['_product_id'] ] ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( version_compare( $plugin['Version'], $update_data[ $plugin['_product_id'] ]['version'], '<' ) ) {
|
||||
return 'long';
|
||||
}
|
||||
}
|
||||
|
||||
return 'short';
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the updates count markup.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user