plugin updates
This commit is contained in:
@@ -27,7 +27,19 @@ class WC_Helper_Admin {
|
||||
* @return void
|
||||
*/
|
||||
public static function load() {
|
||||
add_filter( 'woocommerce_admin_shared_settings', array( __CLASS__, 'add_marketplace_settings' ) );
|
||||
global $pagenow;
|
||||
|
||||
if ( is_admin() ) {
|
||||
$is_in_app_marketplace = ( 'admin.php' === $pagenow
|
||||
&& isset( $_GET['page'] ) && 'wc-admin' === $_GET['page'] //phpcs:ignore WordPress.Security.NonceVerification.Recommended
|
||||
&& isset( $_GET['path'] ) && '/extensions' === $_GET['path'] //phpcs:ignore WordPress.Security.NonceVerification.Recommended
|
||||
);
|
||||
|
||||
if ( $is_in_app_marketplace ) {
|
||||
add_filter( 'woocommerce_admin_shared_settings', array( __CLASS__, 'add_marketplace_settings' ) );
|
||||
}
|
||||
}
|
||||
|
||||
add_filter( 'rest_api_init', array( __CLASS__, 'register_rest_routes' ) );
|
||||
}
|
||||
|
||||
|
||||
@@ -139,6 +139,8 @@ class WC_Helper_Subscriptions_API {
|
||||
*/
|
||||
public static function refresh() {
|
||||
WC_Helper::refresh_helper_subscriptions();
|
||||
WC_Helper::get_subscriptions();
|
||||
WC_Helper::get_product_usage_notice_rules();
|
||||
self::get_subscriptions();
|
||||
}
|
||||
|
||||
|
||||
@@ -259,8 +259,13 @@ class WC_Helper_Updater {
|
||||
// Extract product ID from the response.
|
||||
$product_id = preg_replace( '/[^0-9]/', '', $response->id );
|
||||
|
||||
$installed_or_unconnected = array_merge(
|
||||
WC_Helper::get_installed_subscriptions(),
|
||||
WC_Helper::get_unconnected_subscriptions()
|
||||
);
|
||||
|
||||
// Product subscriptions.
|
||||
$subscriptions = wp_list_filter( WC_Helper::get_installed_subscriptions(), array( 'product_id' => $product_id ) );
|
||||
$subscriptions = wp_list_filter( $installed_or_unconnected, array( 'product_id' => $product_id ) );
|
||||
if ( empty( $subscriptions ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1007,6 +1007,7 @@ class WC_Helper {
|
||||
self::_flush_authentication_cache();
|
||||
self::_flush_subscriptions_cache();
|
||||
self::_flush_updates_cache();
|
||||
self::flush_product_usage_notice_rules_cache();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1334,6 +1335,34 @@ class WC_Helper {
|
||||
return $installed_subscriptions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the user's unconnected subscriptions.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function get_unconnected_subscriptions() {
|
||||
static $unconnected_subscriptions = null;
|
||||
|
||||
// Cache unconnected_subscriptions in the current request.
|
||||
if ( is_null( $unconnected_subscriptions ) ) {
|
||||
$auth = WC_Helper_Options::get( 'auth' );
|
||||
$site_id = isset( $auth['site_id'] ) ? absint( $auth['site_id'] ) : 0;
|
||||
if ( 0 === $site_id ) {
|
||||
$unconnected_subscriptions = array();
|
||||
return $unconnected_subscriptions;
|
||||
}
|
||||
|
||||
$unconnected_subscriptions = array_filter(
|
||||
self::get_subscriptions(),
|
||||
function ( $subscription ) use ( $site_id ) {
|
||||
return empty( $subscription['connections'] );
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
return $unconnected_subscriptions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get subscription state of a given product ID.
|
||||
*
|
||||
@@ -1561,6 +1590,7 @@ class WC_Helper {
|
||||
'product-usage-notice-rules',
|
||||
array(
|
||||
'authenticated' => false,
|
||||
'timeout' => 2,
|
||||
)
|
||||
);
|
||||
|
||||
@@ -1835,8 +1865,22 @@ class WC_Helper {
|
||||
return false;
|
||||
}
|
||||
|
||||
// If there are multiple subscriptions, but no active subscriptions, then mark the first one as installed.
|
||||
$product_subscription = array_shift( $product_subscriptions );
|
||||
// Find subscriptions that can be activated.
|
||||
$product_subscriptions_without_maxed_connections = wp_list_filter(
|
||||
$product_subscriptions,
|
||||
array(
|
||||
'maxed' => false,
|
||||
)
|
||||
);
|
||||
|
||||
if ( 0 < count( $product_subscriptions_without_maxed_connections ) ) {
|
||||
// Pick the first subscription available for activation.
|
||||
$product_subscription = array_shift( $product_subscriptions_without_maxed_connections );
|
||||
} else {
|
||||
// If there are multiple subscriptions, but no active subscriptions, then mark the first one as installed.
|
||||
$product_subscription = array_shift( $product_subscriptions );
|
||||
}
|
||||
|
||||
if ( $product_subscription['product_key'] === $subscription['product_key'] ) {
|
||||
return true;
|
||||
}
|
||||
@@ -2172,6 +2216,13 @@ class WC_Helper {
|
||||
delete_transient( '_woocommerce_helper_subscriptions' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Flush product-usage-notice-rules cache.
|
||||
*/
|
||||
public static function flush_product_usage_notice_rules_cache() {
|
||||
delete_transient( '_woocommerce_helper_product_usage_notice_rules' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Flush auth cache.
|
||||
*/
|
||||
@@ -2271,6 +2322,7 @@ class WC_Helper {
|
||||
|
||||
self::_flush_subscriptions_cache();
|
||||
self::_flush_updates_cache();
|
||||
self::flush_product_usage_notice_rules_cache();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2360,6 +2412,7 @@ class WC_Helper {
|
||||
|
||||
self::_flush_subscriptions_cache();
|
||||
self::_flush_updates_cache();
|
||||
self::flush_product_usage_notice_rules_cache();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user