auto-patch 638-dev-dev01-2024-05-14T20_44_36

This commit is contained in:
root
2024-05-14 20:44:36 +00:00
parent a941559057
commit 5dbb0b284e
1812 changed files with 29671 additions and 14588 deletions

View File

@@ -5,6 +5,8 @@
* @package WooCommerce\Admin\Helper
*/
use Automattic\WooCommerce\Internal\Admin\Marketplace;
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
@@ -14,7 +16,7 @@ if ( ! defined( 'ABSPATH' ) ) {
*
* The main entry-point for all things related to the Helper.
* The Helper manages the connection between the store and
* an account on Woo.com.
* an account on WooCommerce.com.
*/
class WC_Helper_Admin {
@@ -48,21 +50,29 @@ 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(),
'userEmail' => $auth_user_email,
'userAvatar' => get_avatar_url( $auth_user_email, array( 'size' => '48' ) ),
'storeCountry' => wc_get_base_location()['country'],
'inAppPurchaseURLParams' => WC_Admin_Addons::get_in_app_purchase_url_params(),
'installedProducts' => $installed_products,
'isConnected' => WC_Helper::is_site_connected(),
'connectURL' => self::get_connection_url(),
'userEmail' => $auth_user_email,
'userAvatar' => get_avatar_url( $auth_user_email, array( 'size' => '48' ) ),
'storeCountry' => wc_get_base_location()['country'],
'inAppPurchaseURLParams' => WC_Admin_Addons::get_in_app_purchase_url_params(),
'installedProducts' => $installed_products,
'wooUpdateManagerInstalled' => WC_Woo_Update_Manager_Plugin::is_plugin_installed(),
'wooUpdateManagerActive' => WC_Woo_Update_Manager_Plugin::is_plugin_active(),
'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;
}
/**
* Generates the URL for connecting or disconnecting the store to/from Woo.com.
* Generates the URL for connecting or disconnecting the store to/from WooCommerce.com.
* Approach taken from existing helper code that isn't exposed.
*
* @return string
@@ -116,7 +126,7 @@ class WC_Helper_Admin {
}
/**
* Fetch featured products from Woo.com and serve them
* Fetch featured products from WooCommerce.com and serve them
* as JSON.
*/
public static function get_featured() {

View File

@@ -12,7 +12,7 @@ if ( ! defined( 'ABSPATH' ) ) {
/**
* WC_Helper_API Class
*
* Provides a communication interface with the Woo.com Helper API.
* Provides a communication interface with the WooCommerce.com Helper API.
*/
class WC_Helper_API {
/**
@@ -67,6 +67,61 @@ class WC_Helper_API {
return wp_safe_remote_request( $url, $args );
}
/**
* Create signature for a request.
*
* @param string $access_token_secret The access token secret.
* @param string $url The URL to add the access token and signature to.
* @param string $method The request method.
* @param array $body The body of the request.
* @return string The signature.
*/
private static function create_request_signature( string $access_token_secret, string $url, string $method, $body = null ): string {
$request_uri = wp_parse_url( $url, PHP_URL_PATH );
$query_string = wp_parse_url( $url, PHP_URL_QUERY );
if ( is_string( $query_string ) ) {
$request_uri .= '?' . $query_string;
}
$data = array(
'host' => wp_parse_url( $url, PHP_URL_HOST ),
'request_uri' => $request_uri,
'method' => $method,
);
if ( ! empty( $body ) ) {
$data['body'] = $body;
}
return hash_hmac( 'sha256', wp_json_encode( $data ), $access_token_secret );
}
/**
* Add the access token and signature to the provided URL.
*
* @param string $url The URL to add the access token and signature to.
* @return string
*/
public static function add_auth_parameters( string $url ): string {
$auth = WC_Helper_Options::get( 'auth' );
if ( empty( $auth['access_token'] ) || empty( $auth['access_token_secret'] ) ) {
return false;
}
$signature = self::create_request_signature( (string) $auth['access_token_secret'], $url, 'GET' );
return add_query_arg(
array(
'token' => $auth['access_token'],
'signature' => $signature,
),
$url
);
}
/**
* Adds authentication headers to an HTTP request.
*
@@ -81,24 +136,13 @@ class WC_Helper_API {
return false;
}
$request_uri = parse_url( $url, PHP_URL_PATH );
$query_string = parse_url( $url, PHP_URL_QUERY );
if ( is_string( $query_string ) ) {
$request_uri .= '?' . $query_string;
}
$data = array(
'host' => parse_url( $url, PHP_URL_HOST ),
'request_uri' => $request_uri,
'method' => ! empty( $args['method'] ) ? $args['method'] : 'GET',
$signature = self::create_request_signature(
(string) $auth['access_token_secret'],
$url,
! empty( $args['method'] ) ? $args['method'] : 'GET',
$args['body'] ?? null
);
if ( ! empty( $args['body'] ) ) {
$data['body'] = $args['body'];
}
$signature = hash_hmac( 'sha256', json_encode( $data ), $auth['access_token_secret'] );
if ( empty( $args['headers'] ) ) {
$args['headers'] = array();
}

View File

@@ -12,7 +12,7 @@ if ( ! defined( 'ABSPATH' ) ) {
/**
* WC_Helper_Orders_API
*
* Pings Woo.com to create an order and pull in the necessary data to start the installation process.
* Pings WooCommerce.com to create an order and pull in the necessary data to start the installation process.
*/
class WC_Helper_Orders_API {
/**
@@ -59,7 +59,7 @@ class WC_Helper_Orders_API {
}
/**
* Core function to create an order on Woo.com. Pings the API and catches the exceptions if any.
* Core function to create an order on WooCommerce.com. Pings the API and catches the exceptions if any.
*
* @param WP_REST_Request $request Request object.
*

View File

@@ -300,7 +300,10 @@ class WC_Helper_Subscriptions_API {
);
}
$install_url = WC_Helper::get_subscription_install_url( $subscription['product_key'] );
$install_url = WC_Helper::get_subscription_install_url(
$subscription['product_key'],
$subscription['product_slug']
);
if ( ! $install_url ) {
wp_send_json_error(

View File

@@ -1,6 +1,6 @@
<?php
/**
* The update helper for Woo.com plugins.
* The update helper for WooCommerce.com plugins.
*
* @class WC_Helper_Updater
* @package WooCommerce\Admin\Helper
@@ -14,7 +14,7 @@ if ( ! defined( 'ABSPATH' ) ) {
* WC_Helper_Updater Class
*
* Contains the logic to fetch available updates and hook into Core's update
* routines to serve Woo.com-provided packages.
* routines to serve WooCommerce.com-provided packages.
*/
class WC_Helper_Updater {
@@ -26,6 +26,16 @@ class WC_Helper_Updater {
add_action( 'pre_set_site_transient_update_themes', array( __CLASS__, 'transient_update_themes' ), 21, 1 );
add_action( 'upgrader_process_complete', array( __CLASS__, 'upgrader_process_complete' ) );
add_action( 'upgrader_pre_download', array( __CLASS__, 'block_expired_updates' ), 10, 2 );
add_action( 'plugins_loaded', array( __CLASS__, 'add_hook_for_modifying_update_notices' ) );
}
/**
* 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() || ! WC_Helper::is_site_connected() ) {
add_action( 'load-plugins.php', array( __CLASS__, 'setup_update_plugins_messages' ), 11 );
}
}
/**
@@ -53,21 +63,25 @@ class WC_Helper_Updater {
'plugin' => $filename,
'new_version' => $data['version'],
'url' => $data['url'],
'package' => $data['package'],
'package' => '',
'upgrade_notice' => $data['upgrade_notice'],
);
/**
* Filters the Woo plugin data before saving it in transient used for updates.
*
* @since 8.7.0
*
* @param array $item Plugin item to modify.
* @param array $data Subscription data fetched from Helper API for the plugin.
* @param int $product_id Woo product id assigned to the plugin.
*/
$item = apply_filters( 'update_woo_com_subscription_details', $item, $data, $plugin['_product_id'] );
if ( isset( $data['requires_php'] ) ) {
$item['requires_php'] = $data['requires_php'];
}
// We don't want to deliver a valid upgrade package when their subscription has expired.
// To avoid the generic "no_package" error that empty strings give, we will store an
// indication of expiration for the `upgrader_pre_download` filter to error on.
if ( ! self::_has_active_subscription( $plugin['_product_id'] ) ) {
$item['package'] = 'woocommerce-com-expired-' . $plugin['_product_id'];
}
if ( $transient instanceof stdClass ) {
if ( version_compare( $plugin['Version'], $data['version'], '<' ) ) {
$transient->response[ $filename ] = (object) $item;
@@ -89,7 +103,7 @@ class WC_Helper_Updater {
/**
* Runs on pre_set_site_transient_update_themes, provides custom
* packages for Woo.com-hosted extensions.
* packages for WooCommerce.com-hosted extensions.
*
* @param object $transient The update_themes transient object.
*
@@ -113,9 +127,16 @@ class WC_Helper_Updater {
'package' => '',
);
if ( self::_has_active_subscription( $theme['_product_id'] ) ) {
$item['package'] = $data['package'];
}
/**
* Filters the Woo plugin data before saving it in transient used for updates.
*
* @since 8.7.0
*
* @param array $item Plugin item to modify.
* @param array $data Subscription data fetched from Helper API for the plugin.
* @param int $product_id Woo product id assigned to the plugin.
*/
$item = apply_filters( 'update_woo_com_subscription_details', $item, $data, $theme['_product_id'] );
if ( version_compare( $theme['Version'], $data['version'], '<' ) ) {
$transient->response[ $slug ] = $item;
@@ -128,6 +149,88 @@ class WC_Helper_Updater {
return $transient;
}
/**
* Runs on load-plugins.php, adds a hook to show a custom plugin update message for WooCommerce.com hosted plugins.
*
* @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'];
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.
*
* @param object $plugin_data TAn array of plugin metadata.
* @param object $response An object of metadata about the available plugin update.
*
* @return void.
*/
public static function add_install_marketplace_plugin_message( $plugin_data, $response ) {
if ( ! empty( $response->package ) || WC_Woo_Update_Manager_Plugin::is_plugin_active() ) {
return;
}
if ( ! WC_Woo_Update_Manager_Plugin::is_plugin_installed() ) {
printf(
wp_kses(
/* translators: 1: Woo Update Manager plugin install URL */
__( ' <a href="%1$s">Install WooCommerce.com Update Manager</a> to update.', 'woocommerce' ),
array(
'a' => array(
'href' => array(),
),
)
),
esc_url( WC_Woo_Update_Manager_Plugin::generate_install_url() ),
);
return;
}
if ( ! WC_Woo_Update_Manager_Plugin::is_plugin_active() ) {
echo esc_html_e( ' Activate WooCommerce.com Update Manager to update.', 'woocommerce' );
}
}
/**
* Get update data for all plugins.
*
@@ -236,15 +339,20 @@ class WC_Helper_Updater {
}
// Scan local plugins which may or may not have a subscription.
$plugins = WC_Helper::get_local_woo_plugins();
$active_woo_plugins = array_intersect( array_keys( $plugins ), get_option( 'active_plugins', array() ) );
$plugins = WC_Helper::get_local_woo_plugins();
$active_woo_plugins = array_intersect( array_keys( $plugins ), get_option( 'active_plugins', array() ) );
/*
* Use only plugins that are subscribed to the automatic translations updates.
*/
$active_for_translations = array_filter(
$active_woo_plugins,
function( $plugin ) use ( $plugins ) {
function ( $plugin ) use ( $plugins ) {
/**
* Filters the plugins that are subscribed to the automatic translations updates.
*
* @since 3.7.0
*/
return apply_filters( 'woocommerce_translations_updates_for_' . $plugins[ $plugin ]['slug'], false );
}
);
@@ -267,16 +375,16 @@ class WC_Helper_Updater {
);
foreach ( $active_for_translations as $active_plugin ) {
$plugin = $plugins[ $active_plugin ];
$plugin = $plugins[ $active_plugin ];
$request_body['plugins'][ $plugin['slug'] ] = array( 'version' => $plugin['Version'] );
}
$raw_response = wp_remote_post(
'https://translate.wordpress.com/api/translations-updates/woocommerce',
array(
'body' => json_encode( $request_body ),
'headers' => array( 'Content-Type: application/json' ),
'timeout' => $timeout,
'body' => wp_json_encode( $request_body ),
'headers' => array( 'Content-Type: application/json' ),
'timeout' => $timeout,
)
);
@@ -349,13 +457,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';
@@ -367,44 +484,6 @@ class WC_Helper_Updater {
return $data['products'];
}
/**
* Check for an active subscription.
*
* Checks a given product id against all subscriptions on
* the current site. Returns true if at least one active
* subscription is found.
*
* @param int $product_id The product id to look for.
*
* @return bool True if active subscription found.
*/
private static function _has_active_subscription( $product_id ) {
if ( ! isset( $auth ) ) {
$auth = WC_Helper_Options::get( 'auth' );
}
if ( ! isset( $subscriptions ) ) {
$subscriptions = WC_Helper::get_subscriptions();
}
if ( empty( $auth['site_id'] ) || empty( $subscriptions ) ) {
return false;
}
// Check for an active subscription.
foreach ( $subscriptions as $subscription ) {
if ( $subscription['product_id'] != $product_id ) {
continue;
}
if ( in_array( absint( $auth['site_id'] ), $subscription['connections'] ) ) {
return true;
}
}
return false;
}
/**
* Get the number of products that have updates.
*
@@ -441,7 +520,7 @@ class WC_Helper_Updater {
}
if ( version_compare( $plugin['Version'], $update_data[ $plugin['_product_id'] ]['version'], '<' ) ) {
$count++;
++$count;
}
}
@@ -452,26 +531,81 @@ class WC_Helper_Updater {
}
if ( version_compare( $theme['Version'], $update_data[ $theme['_product_id'] ]['version'], '<' ) ) {
$count++;
++$count;
}
}
set_transient( $cache_key, $count, 12 * HOUR_IN_SECONDS );
return $count;
}
/**
* Get the update count to based on the status of the site.
*
* @return int
*/
public static function get_updates_count_based_on_site_status() {
if ( ! WC_Helper::is_site_connected() ) {
return 0;
}
$count = self::get_updates_count() ?? 0;
if ( ! WC_Woo_Update_Manager_Plugin::is_plugin_installed() || ! WC_Woo_Update_Manager_Plugin::is_plugin_active() ) {
++$count;
}
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.
*
* @return string Updates count markup, empty string if no updates avairable.
*/
public static function get_updates_count_html() {
$count = self::get_updates_count();
if ( ! $count ) {
return '';
}
$count = self::get_updates_count_based_on_site_status();
$count_html = sprintf( '<span class="update-plugins count-%d"><span class="update-count">%d</span></span>', $count, number_format_i18n( $count ) );
return $count_html;
}
@@ -516,7 +650,7 @@ class WC_Helper_Updater {
return new WP_Error(
'woocommerce_subscription_expired',
sprintf(
// translators: %s: URL of Woo.com subscriptions tab.
// translators: %s: URL of WooCommerce.com subscriptions tab.
__( 'Please visit the <a href="%s" target="_blank">subscriptions page</a> and renew to continue receiving updates.', 'woocommerce' ),
esc_url( admin_url( 'admin.php?page=wc-addons&section=helper' ) )
)

View File

@@ -54,14 +54,15 @@ class WC_Helper {
* Include supporting helper classes.
*/
protected static function includes() {
include_once dirname( __FILE__ ) . '/class-wc-helper-options.php';
include_once dirname( __FILE__ ) . '/class-wc-helper-api.php';
include_once dirname( __FILE__ ) . '/class-wc-helper-updater.php';
include_once dirname( __FILE__ ) . '/class-wc-helper-plugin-info.php';
include_once dirname( __FILE__ ) . '/class-wc-helper-compat.php';
include_once dirname( __FILE__ ) . '/class-wc-helper-admin.php';
include_once dirname( __FILE__ ) . '/class-wc-helper-subscriptions-api.php';
include_once dirname( __FILE__ ) . '/class-wc-helper-orders-api.php';
include_once __DIR__ . '/class-wc-helper-options.php';
include_once __DIR__ . '/class-wc-helper-api.php';
include_once __DIR__ . '/class-wc-woo-update-manager-plugin.php';
include_once __DIR__ . '/class-wc-helper-updater.php';
include_once __DIR__ . '/class-wc-plugin-api-updater.php';
include_once __DIR__ . '/class-wc-helper-compat.php';
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';
}
/**
@@ -169,7 +170,7 @@ class WC_Helper {
}
$subscription['download_primary'] = true;
$subscription['download_url'] = 'https://woo.com/my-account/downloads/';
$subscription['download_url'] = 'https://woocommerce.com/my-account/downloads/';
if ( ! $subscription['local']['installed'] && ! empty( $updates[ $subscription['product_id'] ] ) ) {
$subscription['download_url'] = $updates[ $subscription['product_id'] ]['package'];
}
@@ -225,7 +226,7 @@ class WC_Helper {
'message' => sprintf( __( 'This subscription has expired. Please <strong>renew</strong> to receive updates and support.', 'woocommerce' ) ),
'button_label' => __( 'Renew', 'woocommerce' ),
'button_url' => self::add_utm_params_to_url_for_subscription_link(
'https://woo.com/my-account/my-subscriptions/',
'https://woocommerce.com/my-account/my-subscriptions/',
'renew'
),
'status' => 'expired',
@@ -240,7 +241,7 @@ class WC_Helper {
'message' => __( 'Subscription is <strong>expiring</strong> soon.', 'woocommerce' ),
'button_label' => __( 'Enable auto-renew', 'woocommerce' ),
'button_url' => self::add_utm_params_to_url_for_subscription_link(
'https://woo.com/my-account/my-subscriptions/',
'https://woocommerce.com/my-account/my-subscriptions/',
'auto-renew'
),
'status' => 'expired',
@@ -254,7 +255,7 @@ class WC_Helper {
'message' => sprintf( __( 'This subscription is expiring soon. Please <strong>renew</strong> to continue receiving updates and support.', 'woocommerce' ) ),
'button_label' => __( 'Renew', 'woocommerce' ),
'button_url' => self::add_utm_params_to_url_for_subscription_link(
'https://woo.com/my-account/my-subscriptions/',
'https://woocommerce.com/my-account/my-subscriptions/',
'renew'
),
'status' => 'expired',
@@ -316,7 +317,7 @@ class WC_Helper {
} else {
$action = array(
/* translators: 1: subscriptions docs 2: subscriptions docs */
'message' => sprintf( __( 'To receive updates and support for this extension, you need to <strong>purchase</strong> a new subscription or consolidate your extensions to one connected account by <strong><a href="%1$s" title="Sharing Docs">sharing</a> or <a href="%2$s" title="Transferring Docs">transferring</a></strong> this extension to this connected account.', 'woocommerce' ), 'https://woo.com/document/managing-woocommerce-com-subscriptions/#section-10', 'https://woo.com/document/managing-woocommerce-com-subscriptions/#section-5' ),
'message' => sprintf( __( 'To receive updates and support for this extension, you need to <strong>purchase</strong> a new subscription or consolidate your extensions to one connected account by <strong><a href="%1$s" title="Sharing Docs">sharing</a> or <a href="%2$s" title="Transferring Docs">transferring</a></strong> this extension to this connected account.', 'woocommerce' ), 'https://woocommerce.com/document/managing-woocommerce-com-subscriptions/#section-10', 'https://woocommerce.com/document/managing-woocommerce-com-subscriptions/#section-5' ),
'button_label' => __( 'Purchase', 'woocommerce' ),
'button_url' => self::add_utm_params_to_url_for_subscription_link(
$data['_product_url'],
@@ -354,7 +355,7 @@ class WC_Helper {
/**
* Add tracking parameters to buttons (Renew, Purchase, etc.) on subscriptions page
*
* @param string $url URL to product page or to https://woo.com/my-account/my-subscriptions/.
* @param string $url URL to product page or to https://woocommerce.com/my-account/my-subscriptions/.
* @param string $utm_content value of utm_content query parameter used for tracking
*
* @return string URL including utm parameters for tracking
@@ -615,14 +616,14 @@ class WC_Helper {
case 'helper-connected':
$notices[] = array(
'message' => __( 'You have successfully connected your store to Woo.com', 'woocommerce' ),
'message' => __( 'You have successfully connected your store to WooCommerce.com', 'woocommerce' ),
'type' => 'updated',
);
break;
case 'helper-disconnected':
$notices[] = array(
'message' => __( 'You have successfully disconnected your store from Woo.com', 'woocommerce' ),
'message' => __( 'You have successfully disconnected your store from WooCommerce.com', 'woocommerce' ),
'type' => 'updated',
);
break;
@@ -832,6 +833,7 @@ class WC_Helper {
)
)
: '',
'wum-installed' => WC_Woo_Update_Manager_Plugin::is_plugin_installed() ? '1' : '0',
),
WC_Helper_API::url( 'oauth/authorize' )
);
@@ -841,7 +843,7 @@ class WC_Helper {
}
/**
* Return from Woo.com OAuth flow.
* Return from WooCommerce.com OAuth flow.
*/
private static function _helper_auth_return() {
if ( empty( $_GET['wc-helper-nonce'] ) || ! wp_verify_nonce( wp_unslash( $_GET['wc-helper-nonce'] ), 'connect' ) ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
@@ -910,7 +912,7 @@ class WC_Helper {
WC_Tracker::send_tracking_data( true );
}
// If connecting through in-app purchase, redirects back to Woo.com
// If connecting through in-app purchase, redirects back to WooCommerce.com
// for product installation.
if ( ! empty( $_GET['wccom-install-url'] ) ) {
wp_redirect( wp_unslash( $_GET['wccom-install-url'] ) );
@@ -930,7 +932,7 @@ class WC_Helper {
}
/**
* Disconnect from Woo.com, clear OAuth tokens.
* Disconnect from WooCommerce.com, clear OAuth tokens.
*/
private static function _helper_auth_disconnect() {
if ( empty( $_GET['wc-helper-nonce'] ) || ! wp_verify_nonce( wp_unslash( $_GET['wc-helper-nonce'] ), 'disconnect' ) ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
@@ -1193,34 +1195,18 @@ class WC_Helper {
* Get a subscriptions install URL.
*
* @param string $product_key Subscription product key.
* @param string $product_slug Subscription product slug.
* @return string
*/
public static function get_subscription_install_url( $product_key ) {
$install_url_response = WC_Helper_API::post(
'install-url',
public static function get_subscription_install_url( $product_key, $product_slug ) {
$install_url = add_query_arg(
array(
'authenticated' => true,
'body' => wp_json_encode(
array(
'product_key' => $product_key,
'wc_version' => WC()->version,
)
),
)
'product-key' => rawurlencode( $product_key ),
),
self::get_install_base_url() . "{$product_slug}/"
);
$code = wp_remote_retrieve_response_code( $install_url_response );
if ( 200 !== $code ) {
self::log( sprintf( 'Install URL API call returned a non-200 response code (%d)', $code ) );
return '';
}
$body = json_decode( wp_remote_retrieve_body( $install_url_response ), true );
if ( empty( $body['data']['url'] ) ) {
self::log( sprintf( 'Install URL API call returned an invalid body: %s', wp_remote_retrieve_body( $install_url_response ) ) );
return '';
}
return $body['data']['url'];
return WC_Helper_API::add_auth_parameters( $install_url );
}
/**
@@ -1517,6 +1503,8 @@ class WC_Helper {
$source = 'inbox-notes';
elseif ( stripos( $request_uri, 'admin-ajax.php' ) ) :
$source = 'heartbeat-api';
elseif ( stripos( $request_uri, 'installer' ) ) :
$source = 'wccom-site-installer';
elseif ( defined( 'WP_CLI' ) && WP_CLI ) :
$source = 'wc-cli';
endif;
@@ -2257,6 +2245,22 @@ class WC_Helper {
self::_flush_subscriptions_cache();
self::_flush_updates_cache();
}
/**
* Get base URL for plugin auto installer.
*
* @return string
*/
public static function get_install_base_url() {
/**
* Filter the base URL used to install the Woo hosted plugins.
*
* @since 8.7.0
*/
$woo_com_base_url = apply_filters( 'woo_com_base_url', 'https://woocommerce.com/' );
return $woo_com_base_url . 'auto-install-init/';
}
}
WC_Helper::load();

View File

@@ -1,21 +1,17 @@
<?php
/**
* WooCommerce Admin Helper Plugin Info
* Updates the Product API response from WP.org.
*
* @class WC_Plugin_Api_Updater
* @package WooCommerce\Admin\Helper
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
defined( 'ABSPATH' ) || exit;
/**
* WC_Helper_Plugin_Info Class
*
* Provides the "View Information" core modals with data for Woo.com
* hosted extensions.
* Class WC_Plugin_Api_Updater
*/
class WC_Helper_Plugin_Info {
class WC_Plugin_Api_Updater {
/**
* Loads the class, runs on init.
@@ -38,7 +34,8 @@ class WC_Helper_Plugin_Info {
if ( 'plugin_information' !== $action ) {
return $response;
}
return self::maybe_override_products_api( $response, $action, $args );
return self::override_products_api_response( $response, $action, $args );
}
/**
@@ -52,7 +49,8 @@ class WC_Helper_Plugin_Info {
if ( 'theme_information' !== $action ) {
return $response;
}
return self::maybe_override_products_api( $response, $action, $args );
return self::override_products_api_response( $response, $action, $args );
}
/**
@@ -62,12 +60,12 @@ class WC_Helper_Plugin_Info {
* @param string $action The requested action.
* @param object $args Arguments passed to the API.
*/
public static function maybe_override_products_api( $response, $action, $args ) {
public static function override_products_api_response( $response, $action, $args ) {
if ( empty( $args->slug ) ) {
return $response;
}
// Only for slugs that start with woo-
// Only for slugs that start with woocommerce-com-.
if ( 0 !== strpos( $args->slug, 'woocommerce-com-' ) ) {
return $response;
}
@@ -105,4 +103,4 @@ class WC_Helper_Plugin_Info {
}
}
WC_Helper_Plugin_Info::load();
WC_Plugin_Api_Updater::load();

View File

@@ -0,0 +1,130 @@
<?php
/**
* A utility class for Woo Update Manager plugin.
*
* @class WC_Woo_Update_Manager_Plugin
* @package WooCommerce\Admin\Helper
*/
use Automattic\WooCommerce\Admin\PageController;
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* WC_Helper_Plugin Class
*
* Contains the logic to manage the Woo Update Manager plugin.
*/
class WC_Woo_Update_Manager_Plugin {
const WOO_UPDATE_MANAGER_PLUGIN_MAIN_FILE = 'woo-update-manager/woo-update-manager.php';
const WOO_UPDATE_MANAGER_DOWNLOAD_URL = 'https://woocommerce.com/product-download/woo-update-manager';
const WOO_UPDATE_MANAGER_SLUG = 'woo-update-manager';
/**
* Loads the class, runs on init.
*
* @return void
*/
public static function load(): void {
add_action( 'admin_notices', array( __CLASS__, 'show_woo_update_manager_install_notice' ) );
}
/**
* Check if the Woo Update Manager plugin is active.
*
* @return bool
*/
public static function is_plugin_active(): bool {
return is_plugin_active_for_network( self::WOO_UPDATE_MANAGER_PLUGIN_MAIN_FILE ) || is_plugin_active( self::WOO_UPDATE_MANAGER_PLUGIN_MAIN_FILE );
}
/**
* Check if the Woo Update Manager plugin is installed.
*
* @return bool
*/
public static function is_plugin_installed(): bool {
return file_exists( WP_PLUGIN_DIR . '/' . self::WOO_UPDATE_MANAGER_PLUGIN_MAIN_FILE );
}
/**
* Generate the URL to install the Woo Update Manager plugin.
*
* @return string
*/
public static function generate_install_url(): string {
$install_url = WC_Helper::get_install_base_url() . self::WOO_UPDATE_MANAGER_SLUG . '/';
return WC_Helper_API::add_auth_parameters( $install_url );
}
/**
* Get the id of the Woo Update Manager plugin.
*
* @return int
*/
public static function get_plugin_slug(): string {
return self::WOO_UPDATE_MANAGER_SLUG;
}
/**
* Show a notice on the WC admin pages to install or activate the Woo Update Manager plugin.
*
* @return void
*/
public static function show_woo_update_manager_install_notice(): void {
if ( ! current_user_can( 'install_plugins' ) ) {
return;
}
if ( ! WC_Helper::is_site_connected() ) {
return;
}
if ( ! PageController::is_admin_or_embed_page() ) {
return;
}
if ( self::is_plugin_installed() && self::is_plugin_active() ) {
return;
}
if ( ! self::is_plugin_installed() ) {
if ( self::install_admin_notice_dismissed() ) {
return;
}
include __DIR__ . '/views/html-notice-woo-updater-not-installed.php';
return;
}
if ( self::activate_admin_notice_dismissed() ) {
return;
}
include __DIR__ . '/views/html-notice-woo-updater-not-activated.php';
}
/**
* Check if the installation notice has been dismissed.
*
* @return bool
*/
protected static function install_admin_notice_dismissed(): bool {
return get_user_meta( get_current_user_id(), 'dismissed_woo_updater_not_installed_notice', true );
}
/**
* Check if the activation notice has been dismissed.
*
* @return bool
*/
protected static function activate_admin_notice_dismissed(): bool {
return get_user_meta( get_current_user_id(), 'dismissed_woo_updater_not_activated_notice', true );
}
}
WC_Woo_Update_Manager_Plugin::load();

View File

@@ -21,9 +21,9 @@
<?php
printf(
wp_kses(
/* translators: Introduction to list of Woo.com extensions the merchant has subscriptions for. */
/* translators: Introduction to list of WooCommerce.com extensions the merchant has subscriptions for. */
__(
'Below is a list of extensions available on your Woo.com account. To receive extension updates please make sure the extension is installed, and its subscription activated and connected to your Woo.com account. Extensions can be activated from the <a href="%s">Plugins</a> screen.',
'Below is a list of extensions available on your WooCommerce.com account. To receive extension updates please make sure the extension is installed, and its subscription activated and connected to your WooCommerce.com account. Extensions can be activated from the <a href="%s">Plugins</a> screen.',
'woocommerce'
),
array(
@@ -135,7 +135,7 @@
</td>
<td class="wp-list-table__ext-actions">
<?php if ( ! $subscription['active'] && $subscription['maxed'] ) : ?>
<a class="button" href="https://woo.com/my-account/my-subscriptions/" target="_blank"><?php esc_html_e( 'Upgrade', 'woocommerce' ); ?></a>
<a class="button" href="https://woocommerce.com/my-account/my-subscriptions/" target="_blank"><?php esc_html_e( 'Upgrade', 'woocommerce' ); ?></a>
<?php elseif ( ! $subscription['local']['installed'] && ! $subscription['expired'] ) : ?>
<a class="button <?php echo empty( $subscription['download_primary'] ) ? 'button-secondary' : ''; ?>" href="<?php echo esc_url( $subscription['download_url'] ); ?>" target="_blank"><?php esc_html_e( 'Download', 'woocommerce' ); ?></a>
<?php elseif ( $subscription['active'] ) : ?>
@@ -190,7 +190,7 @@
<?php endforeach; ?>
<?php else : ?>
<tr>
<td colspan="3"><em><?php esc_html_e( 'Could not find any subscriptions on your Woo.com account', 'woocommerce' ); ?></td>
<td colspan="3"><em><?php esc_html_e( 'Could not find any subscriptions on your WooCommerce.com account', 'woocommerce' ); ?></td>
</tr>
<?php endif; ?>
</tbody>
@@ -198,7 +198,7 @@
<?php if ( ! empty( $no_subscriptions ) ) : ?>
<h2><?php esc_html_e( 'Installed Extensions without a Subscription', 'woocommerce' ); ?></h2>
<p>Below is a list of Woo.com products available on your site - but are either out-dated or do not have a valid subscription.</p>
<p>Below is a list of WooCommerce.com products available on your site - but are either out-dated or do not have a valid subscription.</p>
<table class="wp-list-table widefat fixed striped">
<?php /* Extensions without a subscription. */ ?>

View File

@@ -0,0 +1,26 @@
<?php
/**
* Helper Admin Notice - Woo Updater Plugin is not activated.
*
* @package WooCommerce\Views
*/
defined( 'ABSPATH' ) || exit;
?>
<div id="message" class="error woocommerce-message">
<a class="woocommerce-message-close notice-dismiss" href="<?php echo esc_url( wp_nonce_url( add_query_arg( 'wc-hide-notice', 'woo_updater_not_activated' ), 'woocommerce_hide_notices_nonce', '_wc_notice_nonce' ) ); ?>"><?php esc_html_e( 'Dismiss', 'woocommerce' ); ?></a>
<p>
<?php
echo wp_kses_post(
sprintf(
/* translators: 1: WP plugin management URL */
__(
'Please <a href="%1$s">activate the WooCommerce.com Update Manager</a> to continue receiving the updates and streamlined support included in your WooCommerce.com subscriptions.',
'woocommerce'
),
esc_url( admin_url( 'plugins.php' ) ),
)
);
?>
</p>
</div>

View File

@@ -0,0 +1,27 @@
<?php
/**
* Helper Admin Notice - Woo Updater Plugin is not Installed.
*
* @package WooCommerce\Views
*/
defined( 'ABSPATH' ) || exit;
?>
<div id="message" class="error woocommerce-message">
<a class="woocommerce-message-close notice-dismiss" href="<?php echo esc_url( wp_nonce_url( add_query_arg( 'wc-hide-notice', 'woo_updater_not_installed' ), 'woocommerce_hide_notices_nonce', '_wc_notice_nonce' ) ); ?>"><?php esc_html_e( 'Dismiss', 'woocommerce' ); ?></a>
<p>
<?php
echo wp_kses_post(
sprintf(
/* translators: 1: Woo Update Manager plugin install URL 2: Woo Update Manager plugin download URL */
__(
'Please <a href="%1$s">Install the WooCommerce.com Update Manager</a> to continue receiving the updates and streamlined support included in your WooCommerce.com subscriptions. Alternatively, you can <a href="%2$s">download</a> and install it manually.',
'woocommerce'
),
esc_url( WC_Woo_Update_Manager_Plugin::generate_install_url() ),
esc_url( WC_Woo_Update_Manager_Plugin::WOO_UPDATE_MANAGER_DOWNLOAD_URL )
)
);
?>
</p>
</div>

View File

@@ -1,6 +1,6 @@
<?php
/**
* Admin -> WooCommerce -> Extensions -> Woo.com Subscriptions main page.
* Admin -> WooCommerce -> Extensions -> WooCommerce.com Subscriptions main page.
*
* @package WooCommerce\Views
*/
@@ -23,7 +23,7 @@ defined( 'ABSPATH' ) || exit();
<?php endif; ?>
<h2><?php esc_html_e( 'Manage your subscriptions, get important product notifications, and updates, all from the convenience of your WooCommerce dashboard', 'woocommerce' ); ?></h2>
<p><?php esc_html_e( 'Once connected, your Woo.com purchases will be listed here.', 'woocommerce' ); ?></p>
<p><?php esc_html_e( 'Once connected, your WooCommerce.com purchases will be listed here.', 'woocommerce' ); ?></p>
<p><a class="button button-primary button-helper-connect" href="<?php echo esc_url( $connect_url ); ?>"><?php esc_html_e( 'Connect', 'woocommerce' ); ?></a></p>
</div>
</div>

View File

@@ -3,12 +3,12 @@
<a class="button button-update" href="<?php echo esc_url( $refresh_url ); ?>"><span class="dashicons dashicons-image-rotate"></span> <?php esc_html_e( 'Update', 'woocommerce' ); ?></a>
<div class="user-info">
<header>
<p><?php esc_html_e( 'Connected to Woo.com', 'woocommerce' ); ?> <span class="chevron dashicons dashicons-arrow-down-alt2"></span></p>
<p><?php esc_html_e( 'Connected to WooCommerce.com', 'woocommerce' ); ?> <span class="chevron dashicons dashicons-arrow-down-alt2"></span></p>
</header>
<section>
<p><?php echo get_avatar( $auth_user_data['email'], 48 ); ?> <?php echo esc_html( $auth_user_data['email'] ); ?></p>
<div class="actions">
<a class="" href="https://woo.com/my-account/my-subscriptions/" target="_blank"><span class="dashicons dashicons-admin-generic"></span> <?php esc_html_e( 'My Subscriptions', 'woocommerce' ); ?></a>
<a class="" href="https://woocommerce.com/my-account/my-subscriptions/" target="_blank"><span class="dashicons dashicons-admin-generic"></span> <?php esc_html_e( 'My Subscriptions', 'woocommerce' ); ?></a>
<a class="" href="<?php echo esc_url( $disconnect_url ); ?>"><span class="dashicons dashicons-no"></span> <?php esc_html_e( 'Disconnect', 'woocommerce' ); ?></a>
</div>
</section>

View File

@@ -21,7 +21,7 @@ defined( 'ABSPATH' ) || exit(); ?>
<?php
$count_html = WC_Helper_Updater::get_updates_count_html();
/* translators: %s: Woo.com Subscriptions tab count HTML. */
/* translators: %s: WooCommerce.com Subscriptions tab count HTML. */
$menu_title = sprintf( __( 'My Subscriptions %s', 'woocommerce' ), $count_html );
?>
<a href="<?php echo esc_url( admin_url( 'admin.php?page=wc-addons&section=helper' ) ); ?>" class="nav-tab nav-tab-active"><?php echo wp_kses_post( $menu_title ); ?></a>