plugin updates

This commit is contained in:
Tony Volpe
2024-11-15 13:53:04 -05:00
parent 1293d604ca
commit 0238f0c4ca
2009 changed files with 163492 additions and 89543 deletions

View File

@@ -85,6 +85,7 @@ class WC_Helper_Admin {
if ( WC_Helper::is_site_connected() ) {
$settings['wccomHelper']['subscription_expired_notice'] = PluginsHelper::get_expired_subscription_notice( false );
$settings['wccomHelper']['subscription_expiring_notice'] = PluginsHelper::get_expiring_subscription_notice( false );
$settings['wccomHelper']['subscription_missing_notice'] = PluginsHelper::get_missing_subscription_notice();
}
return $settings;

View File

@@ -40,11 +40,13 @@ class WC_Helper_Updater {
}
if ( WC_Helper::is_site_connected() ) {
add_action( 'load-plugins.php', array( __CLASS__, 'setup_message_for_expired_and_expiring_subscriptions' ), 11 );
add_action( 'load-plugins.php', array( __CLASS__, 'setup_message_for_plugins_without_subscription' ), 11 );
}
}
/**
* Add the hook for modifying default WPCore update notices on the plugins management page.
* This is for plugins with expired or expiring subscriptions.
*/
public static function setup_message_for_expired_and_expiring_subscriptions() {
foreach ( WC_Helper::get_local_woo_plugins() as $plugin ) {
@@ -52,6 +54,16 @@ class WC_Helper_Updater {
}
}
/**
* Add the hook for modifying default WPCore update notices on the plugins management page.
* This is for plugins without a subscription.
*/
public static function setup_message_for_plugins_without_subscription() {
foreach ( WC_Helper::get_local_woo_plugins() as $plugin ) {
add_action( 'in_plugin_update_message-' . $plugin['_filename'], array( __CLASS__, 'display_notice_for_plugins_without_subscription' ), 10, 2 );
}
}
/**
* Runs in a cron thread, or in a visitor thread if triggered
* by _maybe_update_plugins(), or in an auto-update thread.
@@ -294,10 +306,11 @@ class WC_Helper_Updater {
$renew_link = add_query_arg(
array(
'add-to-cart' => $product_id,
'utm_source' => 'pu',
'utm_campaign' => 'pu_plugin_screen_renew',
),
PluginsHelper::WOO_SUBSCRIPTION_PAGE_URL
PluginsHelper::WOO_CART_PAGE_URL
);
/* translators: 1: Product regular price */
@@ -340,6 +353,52 @@ class WC_Helper_Updater {
}
}
/**
* Runs on in_plugin_update_message-{file-name}, show a message if plugin is without a subscription.
* Only Woo local plugins are passed to this function.
*
* @see setup_message_for_plugins_without_subscription
* @param object $plugin_data An array of plugin metadata.
* @param object $response An object of metadata about the available plugin update.
*
* @return void.
*/
public static function display_notice_for_plugins_without_subscription( $plugin_data, $response ) {
// Extract product ID from the response.
$product_id = preg_replace( '/[^0-9]/', '', $response->id );
if ( WC_Helper::has_product_subscription( $product_id ) ) {
return;
}
// Prepare the expiry notice based on subscription status.
$purchase_link = add_query_arg(
array(
'add-to-cart' => $product_id,
'utm_source' => 'pu',
'utm_campaign' => 'pu_plugin_screen_purchase',
),
PluginsHelper::WOO_CART_PAGE_URL,
);
$notice = sprintf(
/* translators: 1: URL to My Subscriptions page */
__( ' You don\'t have a subscription, <a href="%1$s" class="woocommerce-purchase-subscription">subscribe</a> to update.', 'woocommerce' ),
esc_url( $purchase_link ),
);
// Display the expiry notice.
echo wp_kses(
$notice,
array(
'a' => array(
'href' => array(),
'class' => array(),
),
)
);
}
/**
* Get update data for all plugins.
*