plugin updates

This commit is contained in:
Tony Volpe
2024-09-05 11:04:01 -04:00
parent ed6b060261
commit 50cd64dd3d
925 changed files with 16918 additions and 13003 deletions

View File

@@ -63,6 +63,7 @@ class WC_Helper {
include_once __DIR__ . '/class-wc-helper-admin.php';
include_once __DIR__ . '/class-wc-helper-subscriptions-api.php';
include_once __DIR__ . '/class-wc-helper-orders-api.php';
include_once __DIR__ . '/class-wc-product-usage-notice.php';
}
/**
@@ -785,6 +786,14 @@ class WC_Helper {
$redirect_url_args['install'] = sanitize_text_field( wp_unslash( $_GET['install'] ) );
}
if ( isset( $_GET['utm_source'] ) ) {
$redirect_url_args['utm_source'] = wc_clean( wp_unslash( $_GET['utm_source'] ) );
}
if ( isset( $_GET['utm_campaign'] ) ) {
$redirect_url_args['utm_campaign'] = wc_clean( wp_unslash( $_GET['utm_campaign'] ) );
}
$redirect_uri = add_query_arg(
$redirect_url_args,
admin_url( 'admin.php' )
@@ -1296,6 +1305,60 @@ class WC_Helper {
return ! empty( $subscription );
}
/**
* Get the user's connected subscriptions that are installed on the current
* site.
*
* @return array
*/
public static function get_installed_subscriptions() {
static $installed_subscriptions = null;
// Cache installed_subscriptions in the current request.
if ( is_null( $installed_subscriptions ) ) {
$auth = WC_Helper_Options::get( 'auth' );
$site_id = isset( $auth['site_id'] ) ? absint( $auth['site_id'] ) : 0;
if ( 0 === $site_id ) {
$installed_subscriptions = array();
return $installed_subscriptions;
}
$installed_subscriptions = array_filter(
self::get_subscriptions(),
function ( $subscription ) use ( $site_id ) {
return in_array( $site_id, $subscription['connections'], true );
}
);
}
return $installed_subscriptions;
}
/**
* Get subscription state of a given product ID.
*
* @since TBD
*
* @param int $product_id The product id.
*
* @return array Array of state_name => (bool) state
*/
public static function get_product_subscription_state( $product_id ) {
$product_subscriptions = wp_list_filter( self::get_installed_subscriptions(), array( 'product_id' => $product_id ) );
$subscription = ! empty( $product_subscriptions )
? array_shift( $product_subscriptions )
: array();
return array(
'unregistered' => empty( $subscription ),
'expired' => ( isset( $subscription['expired'] ) && $subscription['expired'] ),
'expiring' => ( isset( $subscription['expiring'] ) && $subscription['expiring'] ),
'key' => $subscription['product_key'] ?? '',
'order_id' => $subscription['order_id'] ?? '',
);
}
/**
* Get a subscription entry from product_id. If multiple subscriptions are
* found with the same product id and $single is set to true, will return the
@@ -1482,6 +1545,41 @@ class WC_Helper {
return $woo_themes;
}
/**
* Get rules for displaying notice regarding marketplace product usage.
*
* @return array
*/
public static function get_product_usage_notice_rules() {
$cache_key = '_woocommerce_helper_product_usage_notice_rules';
$data = get_transient( $cache_key );
if ( false !== $data ) {
return $data;
}
$request = WC_Helper_API::get(
'product-usage-notice-rules',
array(
'authenticated' => false,
)
);
// Retry in 15 minutes for non-200 response.
if ( wp_remote_retrieve_response_code( $request ) !== 200 ) {
set_transient( $cache_key, array(), 15 * MINUTE_IN_SECONDS );
return array();
}
$data = json_decode( wp_remote_retrieve_body( $request ), true );
if ( empty( $data ) || ! is_array( $data ) ) {
$data = array();
}
set_transient( $cache_key, $data, 1 * HOUR_IN_SECONDS );
return $data;
}
/**
* Get the connected user's subscriptions.
*