plugin updates
This commit is contained in:
@@ -33,7 +33,7 @@ class WC_Helper {
|
||||
* @return string The absolute path to the view file.
|
||||
*/
|
||||
public static function get_view_filename( $view ) {
|
||||
return dirname( __FILE__ ) . "/views/$view";
|
||||
return __DIR__ . "/views/$view";
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -119,7 +119,7 @@ class WC_Helper {
|
||||
$subscriptions_list_data = self::get_subscription_list_data();
|
||||
$subscriptions = array_filter(
|
||||
$subscriptions_list_data,
|
||||
function( $subscription ) {
|
||||
function ( $subscription ) {
|
||||
return ! empty( $subscription['product_key'] );
|
||||
}
|
||||
);
|
||||
@@ -362,9 +362,9 @@ class WC_Helper {
|
||||
*/
|
||||
public static function add_utm_params_to_url_for_subscription_link( $url, $utm_content ) {
|
||||
$utm_params = 'utm_source=subscriptionsscreen&' .
|
||||
'utm_medium=product&' .
|
||||
'utm_campaign=wcaddons&' .
|
||||
'utm_content=' . $utm_content;
|
||||
'utm_medium=product&' .
|
||||
'utm_campaign=wcaddons&' .
|
||||
'utm_content=' . $utm_content;
|
||||
|
||||
// there are already some URL parameters
|
||||
if ( strpos( $url, '?' ) ) {
|
||||
@@ -879,7 +879,8 @@ class WC_Helper {
|
||||
$request = WC_Helper_API::post(
|
||||
'oauth/access_token',
|
||||
array(
|
||||
'body' => array(
|
||||
'timeout' => 30,
|
||||
'body' => array(
|
||||
'request_token' => wp_unslash( $_GET['request_token'] ), // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
|
||||
'home_url' => home_url(),
|
||||
),
|
||||
@@ -1554,28 +1555,36 @@ class WC_Helper {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the connected user's subscription list data.
|
||||
* This is used by the My Subscriptions page.
|
||||
* Get the connected user's subscription list data. Here, we merge connected
|
||||
* subscriptions with locally installed Woo plugins and themes. We also
|
||||
* add in information about available updates.
|
||||
*
|
||||
* Used by the My Subscriptions page.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function get_subscription_list_data() {
|
||||
// First, connected subscriptions.
|
||||
$subscriptions = self::get_subscriptions();
|
||||
|
||||
// Installed plugins and themes, with or without an active subscription.
|
||||
// Then, installed plugins and themes, with or without an active subscription.
|
||||
$woo_plugins = self::get_local_woo_plugins();
|
||||
$woo_themes = self::get_local_woo_themes();
|
||||
|
||||
// Get the product IDs of the subscriptions.
|
||||
$subscriptions_product_ids = wp_list_pluck( $subscriptions, 'product_id' );
|
||||
|
||||
// Get the site ID.
|
||||
$auth = WC_Helper_Options::get( 'auth' );
|
||||
$site_id = isset( $auth['site_id'] ) ? absint( $auth['site_id'] ) : 0;
|
||||
|
||||
// Installed products without a subscription.
|
||||
// Now, merge installed products without a subscription.
|
||||
foreach ( array_merge( $woo_plugins, $woo_themes ) as $filename => $data ) {
|
||||
if ( in_array( $data['_product_id'], $subscriptions_product_ids, true ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// We add these as subscriptions to the previous connected subscriptions list.
|
||||
$subscriptions[] = array(
|
||||
'product_key' => '',
|
||||
'product_id' => $data['_product_id'],
|
||||
@@ -1587,6 +1596,7 @@ class WC_Helper {
|
||||
'key_type_label' => '',
|
||||
'lifetime' => false,
|
||||
'product_status' => 'publish',
|
||||
// Connections is empty because this is not a connected subscription.
|
||||
'connections' => array(),
|
||||
'expires' => 0,
|
||||
'expired' => true,
|
||||
@@ -1598,11 +1608,13 @@ class WC_Helper {
|
||||
);
|
||||
}
|
||||
|
||||
// Fetch updates so we can refine subscriptions with information about updates.
|
||||
$updates = WC_Helper_Updater::get_update_data();
|
||||
|
||||
// Add local data to merged subscriptions list (both locally installed and purchased).
|
||||
foreach ( $subscriptions as &$subscription ) {
|
||||
$subscription['active'] = in_array( $site_id, $subscription['connections'], true );
|
||||
|
||||
$updates = WC_Helper_Updater::get_update_data();
|
||||
|
||||
$subscription['local'] = self::get_subscription_local_data( $subscription );
|
||||
|
||||
$subscription['has_update'] = false;
|
||||
@@ -1613,12 +1625,17 @@ class WC_Helper {
|
||||
if ( ! empty( $updates[ $subscription['product_id'] ] ) ) {
|
||||
$subscription['version'] = $updates[ $subscription['product_id'] ]['version'];
|
||||
}
|
||||
|
||||
// If the update endpoint returns a URL, we prefer it over the default PluginURI.
|
||||
if ( ! empty( $updates[ $subscription['product_id'] ]['url'] ) ) {
|
||||
$subscription['product_url'] = $updates[ $subscription['product_id'] ]['url'];
|
||||
}
|
||||
}
|
||||
|
||||
// Sort subscriptions by name and expiration date.
|
||||
usort(
|
||||
$subscriptions,
|
||||
function( $a, $b ) {
|
||||
function ( $a, $b ) {
|
||||
$compare_value = strcasecmp( $a['product_name'], $b['product_name'] );
|
||||
if ( 0 === $compare_value ) {
|
||||
return strcasecmp( $a['expires'], $b['expires'] );
|
||||
@@ -1823,7 +1840,7 @@ class WC_Helper {
|
||||
}
|
||||
|
||||
// No more sites available in this subscription.
|
||||
if ( $_sub['sites_max'] && $_sub['sites_active'] >= $_sub['sites_max'] ) {
|
||||
if ( isset( $_sub['maxed'] ) && $_sub['maxed'] ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -1938,7 +1955,7 @@ class WC_Helper {
|
||||
);
|
||||
|
||||
if ( wp_remote_retrieve_response_code( $deactivation_response ) === 200 ) {
|
||||
$deactivated++;
|
||||
++$deactivated;
|
||||
|
||||
/**
|
||||
* Fires when the Helper activates a product successfully.
|
||||
@@ -2011,7 +2028,7 @@ class WC_Helper {
|
||||
|
||||
$product_id = $data['_product_id'];
|
||||
if ( version_compare( $updates[ $product_id ]['version'], $data['Version'], '>' ) ) {
|
||||
$available++;
|
||||
++$available;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2065,6 +2082,7 @@ class WC_Helper {
|
||||
'oauth/me',
|
||||
array(
|
||||
'authenticated' => true,
|
||||
'timeout' => 30,
|
||||
)
|
||||
);
|
||||
|
||||
@@ -2261,6 +2279,42 @@ class WC_Helper {
|
||||
|
||||
return $woo_com_base_url . 'auto-install-init/';
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve notice for connected store.
|
||||
*
|
||||
* @return array An array containing notice data.
|
||||
*/
|
||||
public static function get_notices() {
|
||||
$cache_key = '_woocommerce_helper_notices';
|
||||
$cached_data = get_transient( $cache_key );
|
||||
|
||||
if ( false !== $cached_data ) {
|
||||
return $cached_data;
|
||||
}
|
||||
|
||||
// Fetch notice data for connected store.
|
||||
$request = WC_Helper_API::get(
|
||||
'notices',
|
||||
array(
|
||||
'authenticated' => true,
|
||||
)
|
||||
);
|
||||
|
||||
if ( 200 !== wp_remote_retrieve_response_code( $request ) ) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
WC_Helper::load();
|
||||
|
||||
Reference in New Issue
Block a user