Merged in feature/280-dev-dev01 (pull request #21)

auto-patch  280-dev-dev01-2024-01-19T16_41_58

* auto-patch  280-dev-dev01-2024-01-19T16_41_58
This commit is contained in:
Tony Volpe
2024-01-19 16:44:43 +00:00
parent 2699b5437a
commit be83910651
2125 changed files with 179300 additions and 35639 deletions

View File

@@ -99,11 +99,6 @@ class WC_Helper_Plugin_Info {
$results = json_decode( wp_remote_retrieve_body( $request ), true );
if ( ! empty( $results ) ) {
$response = (object) $results;
$product = array_shift( $products );
if ( isset( $product['package'] ) ) {
$response->download_link = $product['package'];
}
}
return $response;

View File

@@ -94,6 +94,22 @@ class WC_Helper_Subscriptions_API {
),
)
);
register_rest_route(
'wc/v3',
'/marketplace/subscriptions/install-url',
array(
'methods' => 'GET',
'callback' => array( __CLASS__, 'install_url' ),
'permission_callback' => array( __CLASS__, 'get_permission' ),
'args' => array(
'product_key' => array(
'required' => true,
'type' => 'string',
),
),
)
);
}
/**
@@ -257,6 +273,50 @@ class WC_Helper_Subscriptions_API {
),
);
}
/**
* Get the install URL for a WooCommerce.com product.
*
* @param WP_REST_Request $request Request object.
*/
public static function install_url( $request ) {
$product_key = $request->get_param( 'product_key' );
$subscription = WC_Helper::get_subscription( $product_key );
if ( ! $subscription ) {
wp_send_json_error(
array(
'message' => __( 'We couldn\'t find a subscription for this product.', 'woocommerce' ),
),
400
);
}
if ( true === $subscription['local']['installed'] ) {
wp_send_json_success(
array(
'message' => __( 'This product is already installed.', 'woocommerce' ),
),
);
}
$install_url = WC_Helper::get_subscription_install_url( $subscription['product_key'] );
if ( ! $install_url ) {
wp_send_json_error(
array(
'message' => __( 'There was an error getting the install URL for this product.', 'woocommerce' ),
),
400
);
}
wp_send_json_success(
array(
'url' => $install_url,
),
);
}
}
WC_Helper_Subscriptions_API::load();

View File

@@ -6,6 +6,7 @@
*/
use Automattic\Jetpack\Constants;
use Automattic\WooCommerce\Utilities\FeaturesUtil;
if ( ! defined( 'ABSPATH' ) ) {
exit;
@@ -648,6 +649,8 @@ class WC_Helper {
return;
}
self::maybe_redirect_to_new_marketplace_installer();
if ( empty( $_GET['section'] ) || 'helper' !== $_GET['section'] ) {
return;
}
@@ -681,17 +684,48 @@ class WC_Helper {
}
}
/**
* Maybe redirect to the new Marketplace installer.
*/
private static function maybe_redirect_to_new_marketplace_installer() {
// phpcs:disable WordPress.Security.NonceVerification.Recommended
// Redirect requires the "install" URL parameter to be passed.
if ( empty( $_GET['install'] ) ) {
return;
}
wp_safe_redirect(
self::get_helper_redirect_url(
array(
'page' => 'wc-addons',
'section' => 'helper',
),
isset( $_GET['redirect-to-wc-admin'] ),
sanitize_text_field( wp_unslash( $_GET['install'] ) )
)
);
// phpcs:enable WordPress.Security.NonceVerification.Recommended
}
/**
* Get helper redirect URL.
*
* @param array $args Query args.
* @param bool $redirect_to_wc_admin Whether to redirect to WC Admin.
* @param array $args Query args.
* @param bool $redirect_to_wc_admin Whether to redirect to WC Admin.
* @param string $install_product_key Optional Product key to install.
* @return string
*/
private static function get_helper_redirect_url( $args = array(), $redirect_to_wc_admin = false ) {
private static function get_helper_redirect_url( $args = array(), $redirect_to_wc_admin = false, $install_product_key = '' ) {
global $current_screen;
if ( true === $redirect_to_wc_admin && 'woocommerce_page_wc-addons' === $current_screen->id ) {
return add_query_arg(
if (
'woocommerce_page_wc-addons' === $current_screen->id &&
FeaturesUtil::feature_is_enabled( 'marketplace' ) &&
(
true === $redirect_to_wc_admin ||
false === empty( $install_product_key )
)
) {
$new_url = add_query_arg(
array(
'page' => 'wc-admin',
'tab' => 'my-subscriptions',
@@ -699,6 +733,15 @@ class WC_Helper {
),
admin_url( 'admin.php' )
);
if ( ! empty( $install_product_key ) ) {
$new_url = add_query_arg(
array(
'install' => $install_product_key,
),
$new_url
);
}
return $new_url;
}
return add_query_arg(
@@ -727,6 +770,10 @@ class WC_Helper {
$redirect_url_args['redirect-to-wc-admin'] = 1;
}
if ( isset( $_GET['install'] ) ) {
$redirect_url_args['install'] = sanitize_text_field( wp_unslash( $_GET['install'] ) );
}
$redirect_uri = add_query_arg(
$redirect_url_args,
admin_url( 'admin.php' )
@@ -795,7 +842,8 @@ class WC_Helper {
'page' => 'wc-addons',
'section' => 'helper',
),
isset( $_GET['redirect-to-wc-admin'] )
isset( $_GET['redirect-to-wc-admin'] ),
isset( $_GET['install'] ) ? sanitize_text_field( wp_unslash( $_GET['install'] ) ) : ''
)
);
die();
@@ -858,7 +906,8 @@ class WC_Helper {
'section' => 'helper',
'wc-helper-status' => 'helper-connected',
),
isset( $_GET['redirect-to-wc-admin'] )
isset( $_GET['redirect-to-wc-admin'] ),
isset( $_GET['install'] ) ? sanitize_text_field( wp_unslash( $_GET['install'] ) ) : ''
)
);
die();
@@ -884,7 +933,8 @@ class WC_Helper {
'section' => 'helper',
'wc-helper-status' => 'helper-disconnected',
),
isset( $_GET['redirect-to-wc-admin'] )
isset( $_GET['redirect-to-wc-admin'] ),
isset( $_GET['install'] ) ? sanitize_text_field( wp_unslash( $_GET['install'] ) ) : ''
);
self::disconnect();
@@ -911,7 +961,8 @@ class WC_Helper {
'filter' => self::get_current_filter(),
'wc-helper-status' => 'helper-refreshed',
),
isset( $_GET['redirect-to-wc-admin'] )
isset( $_GET['redirect-to-wc-admin'] ),
isset( $_GET['install'] ) ? sanitize_text_field( wp_unslash( $_GET['install'] ) ) : ''
);
wp_safe_redirect( $redirect_uri );
@@ -1126,6 +1177,40 @@ class WC_Helper {
return $deactivated;
}
/**
* Get a subscriptions install URL.
*
* @param string $product_key Subscription product key.
* @return string
*/
public static function get_subscription_install_url( $product_key ) {
$install_url_response = WC_Helper_API::post(
'install-url',
array(
'authenticated' => true,
'body' => wp_json_encode(
array(
'product_key' => $product_key,
'wc_version' => WC()->version,
)
),
)
);
$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'];
}
/**
* Deactivate a plugin.
*/