2017-04-21 12:05:44 +00:00
|
|
|
<?php
|
2020-03-30 21:11:02 +00:00
|
|
|
/**
|
|
|
|
* The update helper for WooCommerce.com plugins.
|
|
|
|
*
|
|
|
|
* @class WC_Helper_Updater
|
2020-08-05 16:36:24 +00:00
|
|
|
* @package WooCommerce\Admin.
|
2020-03-30 21:11:02 +00:00
|
|
|
*/
|
|
|
|
|
2017-04-21 12:05:44 +00:00
|
|
|
if ( ! defined( 'ABSPATH' ) ) {
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
2017-04-26 15:50:38 +00:00
|
|
|
/**
|
|
|
|
* WC_Helper_Updater Class
|
|
|
|
*
|
|
|
|
* Contains the logic to fetch available updates and hook into Core's update
|
|
|
|
* routines to serve WooCommerce.com-provided packages.
|
|
|
|
*/
|
2017-04-21 12:05:44 +00:00
|
|
|
class WC_Helper_Updater {
|
2017-04-26 15:50:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Loads the class, runs on init.
|
|
|
|
*/
|
2017-04-21 12:05:44 +00:00
|
|
|
public static function load() {
|
|
|
|
add_action( 'pre_set_site_transient_update_plugins', array( __CLASS__, 'transient_update_plugins' ), 21, 1 );
|
|
|
|
add_action( 'pre_set_site_transient_update_themes', array( __CLASS__, 'transient_update_themes' ), 21, 1 );
|
2017-08-28 07:23:33 +00:00
|
|
|
add_action( 'upgrader_process_complete', array( __CLASS__, 'upgrader_process_complete' ) );
|
2020-03-30 21:11:02 +00:00
|
|
|
add_action( 'upgrader_pre_download', array( __CLASS__, 'block_expired_updates' ), 10, 2 );
|
2017-04-21 12:05:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Runs in a cron thread, or in a visitor thread if triggered
|
|
|
|
* by _maybe_update_plugins(), or in an auto-update thread.
|
2017-04-26 15:50:38 +00:00
|
|
|
*
|
|
|
|
* @param object $transient The update_plugins transient object.
|
|
|
|
*
|
|
|
|
* @return object The same or a modified version of the transient.
|
2017-04-21 12:05:44 +00:00
|
|
|
*/
|
|
|
|
public static function transient_update_plugins( $transient ) {
|
|
|
|
$update_data = self::get_update_data();
|
|
|
|
|
|
|
|
foreach ( WC_Helper::get_local_woo_plugins() as $plugin ) {
|
|
|
|
if ( empty( $update_data[ $plugin['_product_id'] ] ) ) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2018-03-05 18:59:17 +00:00
|
|
|
$data = $update_data[ $plugin['_product_id'] ];
|
2017-04-21 12:05:44 +00:00
|
|
|
$filename = $plugin['_filename'];
|
|
|
|
|
|
|
|
$item = array(
|
2018-03-05 18:59:17 +00:00
|
|
|
'id' => 'woocommerce-com-' . $plugin['_product_id'],
|
|
|
|
'slug' => 'woocommerce-com-' . $data['slug'],
|
|
|
|
'plugin' => $filename,
|
|
|
|
'new_version' => $data['version'],
|
|
|
|
'url' => $data['url'],
|
2020-03-30 21:11:02 +00:00
|
|
|
'package' => $data['package'],
|
2017-04-21 12:05:44 +00:00
|
|
|
'upgrade_notice' => $data['upgrade_notice'],
|
|
|
|
);
|
|
|
|
|
2020-03-30 21:11:02 +00:00
|
|
|
// 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'];
|
2017-04-21 12:05:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( version_compare( $plugin['Version'], $data['version'], '<' ) ) {
|
|
|
|
$transient->response[ $filename ] = (object) $item;
|
|
|
|
unset( $transient->no_update[ $filename ] );
|
|
|
|
} else {
|
|
|
|
$transient->no_update[ $filename ] = (object) $item;
|
|
|
|
unset( $transient->response[ $filename ] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-14 09:14:29 +00:00
|
|
|
$translations = self::get_translations_update_data();
|
|
|
|
$transient->translations = array_merge( isset( $transient->translations ) ? $transient->translations : array(), $translations );
|
2020-06-11 12:31:55 +00:00
|
|
|
|
2017-04-21 12:05:44 +00:00
|
|
|
return $transient;
|
|
|
|
}
|
|
|
|
|
2017-04-26 15:50:38 +00:00
|
|
|
/**
|
|
|
|
* Runs on pre_set_site_transient_update_themes, provides custom
|
|
|
|
* packages for WooCommerce.com-hosted extensions.
|
|
|
|
*
|
|
|
|
* @param object $transient The update_themes transient object.
|
|
|
|
*
|
|
|
|
* @return object The same or a modified version of the transient.
|
|
|
|
*/
|
2017-04-21 12:05:44 +00:00
|
|
|
public static function transient_update_themes( $transient ) {
|
|
|
|
$update_data = self::get_update_data();
|
|
|
|
|
|
|
|
foreach ( WC_Helper::get_local_woo_themes() as $theme ) {
|
|
|
|
if ( empty( $update_data[ $theme['_product_id'] ] ) ) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$data = $update_data[ $theme['_product_id'] ];
|
|
|
|
$slug = $theme['_stylesheet'];
|
|
|
|
|
|
|
|
$item = array(
|
2018-03-05 18:59:17 +00:00
|
|
|
'theme' => $slug,
|
2017-04-21 12:05:44 +00:00
|
|
|
'new_version' => $data['version'],
|
2018-03-05 18:59:17 +00:00
|
|
|
'url' => $data['url'],
|
|
|
|
'package' => '',
|
2017-04-21 12:05:44 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
if ( self::_has_active_subscription( $theme['_product_id'] ) ) {
|
|
|
|
$item['package'] = $data['package'];
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( version_compare( $theme['Version'], $data['version'], '<' ) ) {
|
|
|
|
$transient->response[ $slug ] = $item;
|
|
|
|
} else {
|
|
|
|
unset( $transient->response[ $slug ] );
|
|
|
|
$transient->checked[ $slug ] = $data['version'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $transient;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get update data for all extensions.
|
|
|
|
*
|
|
|
|
* Scans through all subscriptions for the connected user, as well
|
|
|
|
* as all Woo extensions without a subscription, and obtains update
|
|
|
|
* data for each product.
|
|
|
|
*
|
|
|
|
* @return array Update data {product_id => data}
|
|
|
|
*/
|
|
|
|
public static function get_update_data() {
|
|
|
|
$payload = array();
|
|
|
|
|
|
|
|
// Scan subscriptions.
|
|
|
|
foreach ( WC_Helper::get_subscriptions() as $subscription ) {
|
|
|
|
$payload[ $subscription['product_id'] ] = array(
|
|
|
|
'product_id' => $subscription['product_id'],
|
2018-03-05 18:59:17 +00:00
|
|
|
'file_id' => '',
|
2017-04-21 12:05:44 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Scan local plugins which may or may not have a subscription.
|
|
|
|
foreach ( WC_Helper::get_local_woo_plugins() as $data ) {
|
|
|
|
if ( ! isset( $payload[ $data['_product_id'] ] ) ) {
|
|
|
|
$payload[ $data['_product_id'] ] = array(
|
|
|
|
'product_id' => $data['_product_id'],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
$payload[ $data['_product_id'] ]['file_id'] = $data['_file_id'];
|
|
|
|
}
|
|
|
|
|
2020-03-30 21:11:02 +00:00
|
|
|
// Scan local themes.
|
2017-04-21 12:05:44 +00:00
|
|
|
foreach ( WC_Helper::get_local_woo_themes() as $data ) {
|
|
|
|
if ( ! isset( $payload[ $data['_product_id'] ] ) ) {
|
|
|
|
$payload[ $data['_product_id'] ] = array(
|
|
|
|
'product_id' => $data['_product_id'],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
$payload[ $data['_product_id'] ]['file_id'] = $data['_file_id'];
|
|
|
|
}
|
|
|
|
|
|
|
|
return self::_update_check( $payload );
|
|
|
|
}
|
|
|
|
|
2020-06-11 12:31:55 +00:00
|
|
|
/**
|
|
|
|
* Get translations updates informations.
|
|
|
|
*
|
|
|
|
* Scans through all subscriptions for the connected user, as well
|
|
|
|
* as all Woo extensions without a subscription, and obtains update
|
|
|
|
* data for each product.
|
|
|
|
*
|
|
|
|
* @return array Update data {product_id => data}
|
|
|
|
*/
|
|
|
|
public static function get_translations_update_data() {
|
2020-07-23 21:22:16 +00:00
|
|
|
$payload = array();
|
2020-06-11 12:31:55 +00:00
|
|
|
|
|
|
|
$installed_translations = wp_get_installed_translations( 'plugins' );
|
|
|
|
|
|
|
|
$locales = array_values( get_available_languages() );
|
|
|
|
/**
|
|
|
|
* Filters the locales requested for plugin translations.
|
|
|
|
*
|
|
|
|
* @since 3.7.0
|
|
|
|
* @since 4.5.0 The default value of the `$locales` parameter changed to include all locales.
|
|
|
|
*
|
|
|
|
* @param array $locales Plugin locales. Default is all available locales of the site.
|
|
|
|
*/
|
|
|
|
$locales = apply_filters( 'plugins_update_check_locales', $locales );
|
|
|
|
$locales = array_unique( $locales );
|
|
|
|
|
2020-07-28 09:49:01 +00:00
|
|
|
// No locales, the respone will be empty, we can return now.
|
2020-07-28 09:37:51 +00:00
|
|
|
if ( empty( $locales ) ) {
|
|
|
|
return array();
|
|
|
|
}
|
|
|
|
|
2020-06-11 12:31:55 +00:00
|
|
|
// Scan local plugins which may or may not have a subscription.
|
2020-07-20 15:16:18 +00:00
|
|
|
$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 ) {
|
|
|
|
return apply_filters( 'woocommerce_translations_updates_for_' . $plugins[ $plugin ]['slug'], false );
|
|
|
|
}
|
|
|
|
);
|
2020-06-11 12:31:55 +00:00
|
|
|
|
2020-07-22 10:16:20 +00:00
|
|
|
// Nothing to check for, exit.
|
|
|
|
if ( empty( $active_for_translations ) ) {
|
|
|
|
return array();
|
|
|
|
}
|
|
|
|
|
2020-06-11 12:31:55 +00:00
|
|
|
if ( wp_doing_cron() ) {
|
|
|
|
$timeout = 30;
|
|
|
|
} else {
|
|
|
|
// Three seconds, plus one extra second for every 10 plugins.
|
2020-07-20 15:16:18 +00:00
|
|
|
$timeout = 3 + (int) ( count( $active_for_translations ) / 10 );
|
2020-06-11 12:31:55 +00:00
|
|
|
}
|
|
|
|
|
2020-06-26 09:09:41 +00:00
|
|
|
$request_body = array(
|
|
|
|
'locales' => $locales,
|
|
|
|
'plugins' => array(),
|
|
|
|
);
|
2020-06-11 12:31:55 +00:00
|
|
|
|
2020-07-20 15:16:18 +00:00
|
|
|
foreach ( $active_for_translations as $active_plugin ) {
|
2020-06-26 09:09:41 +00:00
|
|
|
$plugin = $plugins[ $active_plugin ];
|
|
|
|
$request_body['plugins'][ $plugin['slug'] ] = array( 'version' => $plugin['Version'] );
|
|
|
|
}
|
2020-06-11 12:31:55 +00:00
|
|
|
|
2020-06-26 09:09:41 +00:00
|
|
|
$raw_response = wp_remote_post(
|
2020-07-22 08:56:04 +00:00
|
|
|
'https://translate.wordpress.com/api/translations-updates/woocommerce',
|
2020-06-26 09:09:41 +00:00
|
|
|
array(
|
|
|
|
'body' => json_encode( $request_body ),
|
|
|
|
'headers' => array( 'Content-Type: application/json' ),
|
|
|
|
'timeout' => $timeout,
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2020-07-20 15:16:18 +00:00
|
|
|
// Something wrong happened on the translate server side.
|
2020-06-26 09:09:41 +00:00
|
|
|
$response_code = wp_remote_retrieve_response_code( $raw_response );
|
|
|
|
if ( 200 !== $response_code ) {
|
|
|
|
return array();
|
|
|
|
}
|
2020-06-14 09:14:29 +00:00
|
|
|
|
2020-06-26 09:09:41 +00:00
|
|
|
$response = json_decode( wp_remote_retrieve_body( $raw_response ), true );
|
2020-06-14 09:14:29 +00:00
|
|
|
|
2020-06-26 09:09:41 +00:00
|
|
|
// API error, api returned but something was wrong.
|
|
|
|
if ( array_key_exists( 'success', $response ) && false === $response['success'] ) {
|
|
|
|
return array();
|
|
|
|
}
|
2020-06-14 09:14:29 +00:00
|
|
|
|
2020-07-20 15:16:18 +00:00
|
|
|
$translations = array();
|
|
|
|
|
|
|
|
foreach ( $response['data'] as $plugin_name => $language_packs ) {
|
|
|
|
foreach ( $language_packs as $language_pack ) {
|
|
|
|
// Maybe we have this language pack already installed so lets check revision date.
|
2020-07-23 20:52:59 +00:00
|
|
|
if ( array_key_exists( $plugin_name, $installed_translations ) && array_key_exists( $language_pack['wp_locale'], $installed_translations[ $plugin_name ] ) ) {
|
2020-07-20 15:16:18 +00:00
|
|
|
$installed_translation_revision_time = new DateTime( $installed_translations[ $plugin_name ][ $language_pack['wp_locale'] ]['PO-Revision-Date'] );
|
|
|
|
$new_translation_revision_time = new DateTime( $language_pack['last_modified'] );
|
|
|
|
// Skip if translation language pack is not newer than what is installed already.
|
|
|
|
if ( $new_translation_revision_time <= $installed_translation_revision_time ) {
|
|
|
|
continue;
|
|
|
|
}
|
2020-06-26 09:09:41 +00:00
|
|
|
}
|
2020-06-14 09:14:29 +00:00
|
|
|
$translations[] = array(
|
|
|
|
'type' => 'plugin',
|
2020-06-26 09:09:41 +00:00
|
|
|
'slug' => $plugin_name,
|
2020-07-20 15:16:18 +00:00
|
|
|
'language' => $language_pack['wp_locale'],
|
|
|
|
'version' => $language_pack['version'],
|
|
|
|
'updated' => $language_pack['last_modified'],
|
|
|
|
'package' => $language_pack['package'],
|
2020-06-26 09:09:41 +00:00
|
|
|
'autoupdate' => true,
|
2020-06-14 09:14:29 +00:00
|
|
|
);
|
|
|
|
}
|
2020-06-11 12:31:55 +00:00
|
|
|
}
|
|
|
|
|
2020-06-14 09:14:29 +00:00
|
|
|
return $translations;
|
2020-06-11 12:31:55 +00:00
|
|
|
}
|
|
|
|
|
2017-04-21 12:05:44 +00:00
|
|
|
/**
|
|
|
|
* Run an update check API call.
|
|
|
|
*
|
|
|
|
* The call is cached based on the payload (product ids, file ids). If
|
|
|
|
* the payload changes, the cache is going to miss.
|
|
|
|
*
|
2020-03-30 21:11:02 +00:00
|
|
|
* @param array $payload Information about the plugin to update.
|
2017-04-21 12:05:44 +00:00
|
|
|
* @return array Update data for each requested product.
|
|
|
|
*/
|
|
|
|
private static function _update_check( $payload ) {
|
|
|
|
ksort( $payload );
|
2019-02-20 12:00:47 +00:00
|
|
|
$hash = md5( wp_json_encode( $payload ) );
|
2017-04-21 12:05:44 +00:00
|
|
|
|
|
|
|
$cache_key = '_woocommerce_helper_updates';
|
2020-03-30 21:11:02 +00:00
|
|
|
$data = get_transient( $cache_key );
|
|
|
|
if ( false !== $data ) {
|
2017-04-21 12:05:44 +00:00
|
|
|
if ( hash_equals( $hash, $data['hash'] ) ) {
|
|
|
|
return $data['products'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$data = array(
|
2018-03-05 18:59:17 +00:00
|
|
|
'hash' => $hash,
|
|
|
|
'updated' => time(),
|
2017-04-21 12:05:44 +00:00
|
|
|
'products' => array(),
|
2018-03-05 18:59:17 +00:00
|
|
|
'errors' => array(),
|
2017-04-21 12:05:44 +00:00
|
|
|
);
|
|
|
|
|
2018-03-05 18:59:17 +00:00
|
|
|
$request = WC_Helper_API::post(
|
2019-12-20 18:25:23 +00:00
|
|
|
'update-check',
|
|
|
|
array(
|
2019-02-20 12:00:47 +00:00
|
|
|
'body' => wp_json_encode( array( 'products' => $payload ) ),
|
2018-03-05 18:59:17 +00:00
|
|
|
'authenticated' => true,
|
|
|
|
)
|
|
|
|
);
|
2017-04-21 12:05:44 +00:00
|
|
|
|
2017-05-03 10:34:55 +00:00
|
|
|
if ( wp_remote_retrieve_response_code( $request ) !== 200 ) {
|
2017-04-21 12:05:44 +00:00
|
|
|
$data['errors'][] = 'http-error';
|
|
|
|
} else {
|
|
|
|
$data['products'] = json_decode( wp_remote_retrieve_body( $request ), true );
|
|
|
|
}
|
|
|
|
|
|
|
|
set_transient( $cache_key, $data, 12 * HOUR_IN_SECONDS );
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2017-08-28 06:52:59 +00:00
|
|
|
/**
|
|
|
|
* Get the number of products that have updates.
|
|
|
|
*
|
|
|
|
* @return int The number of products with updates.
|
|
|
|
*/
|
|
|
|
public static function get_updates_count() {
|
2017-08-28 07:23:33 +00:00
|
|
|
$cache_key = '_woocommerce_helper_updates_count';
|
2020-03-30 21:11:02 +00:00
|
|
|
$count = get_transient( $cache_key );
|
|
|
|
if ( false !== $count ) {
|
2017-08-28 07:23:33 +00:00
|
|
|
return $count;
|
|
|
|
}
|
|
|
|
|
2017-08-28 06:52:59 +00:00
|
|
|
// Don't fetch any new data since this function in high-frequency.
|
|
|
|
if ( ! get_transient( '_woocommerce_helper_subscriptions' ) ) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ! get_transient( '_woocommerce_helper_updates' ) ) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-03-05 18:59:17 +00:00
|
|
|
$count = 0;
|
2017-08-28 07:23:33 +00:00
|
|
|
$update_data = self::get_update_data();
|
2017-08-30 14:46:33 +00:00
|
|
|
|
2017-08-28 07:23:33 +00:00
|
|
|
if ( empty( $update_data ) ) {
|
2017-08-30 14:46:33 +00:00
|
|
|
set_transient( $cache_key, $count, 12 * HOUR_IN_SECONDS );
|
|
|
|
return $count;
|
2017-08-28 06:52:59 +00:00
|
|
|
}
|
|
|
|
|
2017-08-28 07:23:33 +00:00
|
|
|
// Scan local plugins.
|
|
|
|
foreach ( WC_Helper::get_local_woo_plugins() as $plugin ) {
|
|
|
|
if ( empty( $update_data[ $plugin['_product_id'] ] ) ) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( version_compare( $plugin['Version'], $update_data[ $plugin['_product_id'] ]['version'], '<' ) ) {
|
|
|
|
$count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Scan local themes.
|
|
|
|
foreach ( WC_Helper::get_local_woo_themes() as $theme ) {
|
|
|
|
if ( empty( $update_data[ $theme['_product_id'] ] ) ) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( version_compare( $theme['Version'], $update_data[ $theme['_product_id'] ]['version'], '<' ) ) {
|
|
|
|
$count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
set_transient( $cache_key, $count, 12 * HOUR_IN_SECONDS );
|
|
|
|
return $count;
|
2017-08-28 06:52:59 +00:00
|
|
|
}
|
|
|
|
|
2017-08-30 14:19:06 +00:00
|
|
|
/**
|
|
|
|
* 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_html = sprintf( '<span class="update-plugins count-%d"><span class="update-count">%d</span></span>', $count, number_format_i18n( $count ) );
|
|
|
|
return $count_html;
|
|
|
|
}
|
|
|
|
|
2017-04-21 12:05:44 +00:00
|
|
|
/**
|
|
|
|
* Flushes cached update data.
|
|
|
|
*/
|
|
|
|
public static function flush_updates_cache() {
|
|
|
|
delete_transient( '_woocommerce_helper_updates' );
|
2017-08-28 07:23:33 +00:00
|
|
|
delete_transient( '_woocommerce_helper_updates_count' );
|
2018-04-24 14:44:30 +00:00
|
|
|
delete_site_transient( 'update_plugins' );
|
|
|
|
delete_site_transient( 'update_themes' );
|
2017-08-28 07:23:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fires when a user successfully updated a theme or a plugin.
|
|
|
|
*/
|
|
|
|
public static function upgrader_process_complete() {
|
|
|
|
delete_transient( '_woocommerce_helper_updates_count' );
|
2017-04-21 12:05:44 +00:00
|
|
|
}
|
2020-03-30 21:11:02 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Hooked into the upgrader_pre_download filter in order to better handle error messaging around expired
|
|
|
|
* plugin updates. Initially we were using an empty string, but the error message that no_package
|
|
|
|
* results in does not fit the cause.
|
|
|
|
*
|
|
|
|
* @since 4.1.0
|
|
|
|
* @param bool $reply Holds the current filtered response.
|
|
|
|
* @param string $package The path to the package file for the update.
|
|
|
|
* @return false|WP_Error False to proceed with the update as normal, anything else to be returned instead of updating.
|
|
|
|
*/
|
|
|
|
public static function block_expired_updates( $reply, $package ) {
|
|
|
|
// Don't override a reply that was set already.
|
|
|
|
if ( false !== $reply ) {
|
|
|
|
return $reply;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Only for packages with expired subscriptions.
|
|
|
|
if ( 0 !== strpos( $package, 'woocommerce-com-expired-' ) ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return new WP_Error(
|
|
|
|
'woocommerce_subscription_expired',
|
|
|
|
sprintf(
|
|
|
|
// 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§ion=helper' ) )
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
2017-04-21 12:05:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
WC_Helper_Updater::load();
|