Upgarded to 4.17.4
This commit is contained in:
@ -23,6 +23,8 @@ final class ET_Core_Updates {
|
||||
private static $_this;
|
||||
|
||||
function __construct( $core_url, $product_version ) {
|
||||
global $wp_version;
|
||||
|
||||
// Don't allow more than one instance of the class
|
||||
if ( isset( self::$_this ) ) {
|
||||
wp_die( sprintf( esc_html__( '%s: You cannot create a second instance of this class.', 'et-core' ),
|
||||
@ -49,7 +51,13 @@ final class ET_Core_Updates {
|
||||
|
||||
add_filter( 'wp_prepare_themes_for_js', array( $this, 'replace_theme_update_notification' ) );
|
||||
add_filter( 'upgrader_package_options', array( $this, 'check_upgrading_product' ) );
|
||||
add_filter( 'upgrader_pre_download', array( $this, 'update_error_message' ), 20, 2 );
|
||||
|
||||
// The 4th paramenter, $hook_extra was added in WordPress 5.5.0.
|
||||
if ( version_compare( $wp_version, '5.5.0', '>=' ) ) {
|
||||
add_filter( 'upgrader_pre_download', array( $this, 'update_error_message' ), 20, 4 );
|
||||
} else {
|
||||
add_filter( 'upgrader_pre_download', array( $this, 'update_error_message' ), 20, 3 );
|
||||
}
|
||||
|
||||
add_filter( 'pre_set_site_transient_update_plugins', array( $this, 'check_plugins_updates' ) );
|
||||
add_filter( 'plugins_api', array( $this, 'maybe_modify_plugins_changelog' ), 20, 3 );
|
||||
@ -103,7 +111,9 @@ final class ET_Core_Updates {
|
||||
return;
|
||||
}
|
||||
|
||||
$message = et_get_safe_localization( __( 'For all Elegant Themes products, please <a href="http://www.elegantthemes.com/gallery/divi/documentation/update/" target="_blank">authenticate your subscription</a> via the Updates tab in your theme & plugin settings to enable product updates. Make sure that your Username and API Key have been entered correctly.', 'et-core' ) );
|
||||
$message = empty( $custom_message = $this->get_custom_update_notification_message( $plugin_data['url'] ) )
|
||||
? et_get_safe_localization( __( 'For all Elegant Themes products, please <a href="http://www.elegantthemes.com/gallery/divi/documentation/update/" target="_blank">authenticate your subscription</a> via the Updates tab in your theme & plugin settings to enable product updates. Make sure that your Username and API Key have been entered correctly.', 'et-core' ) )
|
||||
: $custom_message;
|
||||
echo "</p><p>{$message}";
|
||||
}
|
||||
|
||||
@ -128,6 +138,22 @@ final class ET_Core_Updates {
|
||||
$this->force_update_requests();
|
||||
}
|
||||
|
||||
function get_custom_update_notification_message( $update_message ) {
|
||||
$is_valid_api_key_status = empty( $account_api_key_status = get_site_option( 'et_account_api_key_status' ) ) || 'invalid' !== $account_api_key_status;
|
||||
|
||||
if ( $is_valid_api_key_status && false !== strpos( $update_message, '/wp-json/api/v1/changelog/product_id/' ) ) {
|
||||
return et_get_safe_localization( __( '<em>The license for this Divi Marketplace product has expired. Please <a target="_blank" href="https://www.elegantthemes.com/members-area/marketplace/">renew the license</a> to continue receiving product updates and support.</em>', 'et-core' ) );
|
||||
}
|
||||
|
||||
if ( false !== strpos( $update_message, 'Automatic update is unavailable for this theme' ) ) {
|
||||
return 'expired' === $this->account_status
|
||||
? et_get_safe_localization( __( '<em>Your Elegant Themes subscription has expired. You must <a href="https://www.elegantthemes.com/members-area/renew/" target="_blank">renew your account</a> to regain access to product updates and support.</em>', 'et-core' ) )
|
||||
: et_get_safe_localization( __( '<em>Before you can receive product updates, you must first authenticate your Elegant Themes subscription. To do this, you need to enter both your Elegant Themes Username and your Elegant Themes API Key into the Updates Tab in your theme and plugin settings. To locate your API Key, <a href="https://www.elegantthemes.com/members-area/api/" target="_blank">log in</a> to your Elegant Themes account and navigate to the <strong>Account > API Key</strong> page. <a href="http://www.elegantthemes.com/gallery/divi/documentation/update/" target="_blank">Learn more here</a></em>. If you still get this message, please make sure that your Username and API Key have been entered correctly', 'et-core' ) );
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
function replace_theme_update_notification( $themes_array ) {
|
||||
if ( empty( $themes_array ) ) {
|
||||
return $themes_array;
|
||||
@ -139,14 +165,16 @@ final class ET_Core_Updates {
|
||||
|
||||
foreach ( $themes_array as $id => $theme_data ) {
|
||||
// replace default error message with custom message for ET themes.
|
||||
if (
|
||||
in_array( $id, $this->all_et_products_domains['theme'] )
|
||||
&& false !== strpos( $theme_data['update'], 'Automatic update is unavailable for this theme' )
|
||||
) {
|
||||
if ( ! in_array( $id, $this->all_et_products_domains['theme'] )
|
||||
|| false === strpos( $theme_data['update'], 'Automatic update is unavailable for this theme' ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( ! empty( $custom_message = $this->get_custom_update_notification_message( $theme_data['update'] ) ) ) {
|
||||
$themes_array[ $id ]['update'] = sprintf(
|
||||
'<p>%1$s<br/> %2$s</p>',
|
||||
$theme_data['update'],
|
||||
et_get_safe_localization( __( '<em>Before you can receive product updates, you must first authenticate your Elegant Themes subscription. To do this, you need to enter both your Elegant Themes Username and your Elegant Themes API Key into the Updates Tab in your theme and plugin settings. To locate your API Key, <a href="https://www.elegantthemes.com/members-area/api/" target="_blank">log in</a> to your Elegant Themes account and navigate to the <strong>Account > API Key</strong> page. <a href="http://www.elegantthemes.com/gallery/divi/documentation/update/" target="_blank">Learn more here</a></em>. If you still get this message, please make sure that your Username and API Key have been entered correctly', 'et-core' ) )
|
||||
$custom_message
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -154,7 +182,7 @@ final class ET_Core_Updates {
|
||||
return $themes_array;
|
||||
}
|
||||
|
||||
function update_error_message( $reply, $package ) {
|
||||
function update_error_message( $reply, $package, $upgrader, $hook_extra = array() ) {
|
||||
if ( ! $this->upgrading_et_product ) {
|
||||
return $reply;
|
||||
}
|
||||
@ -166,8 +194,25 @@ final class ET_Core_Updates {
|
||||
return $reply;
|
||||
}
|
||||
|
||||
$hook_name = ! empty( $hook_extra['theme'] ) ? 'theme' : 'plugin';
|
||||
$site_transient = 'theme' === $hook_name ? get_site_transient( 'et_update_themes' ) : get_site_transient( 'et_update_all_plugins' );
|
||||
|
||||
$changelog_url = '';
|
||||
if ( isset( $site_transient->response ) && ! empty( $site_transient->response[ $hook_extra[ $hook_name ] ] ) ) {
|
||||
$changelog_url = 'theme' === $hook_name
|
||||
? $site_transient->response[ $hook_extra[ $hook_name ] ]['url']
|
||||
: $site_transient->response[ $hook_extra[ $hook_name ] ]->url;
|
||||
}
|
||||
|
||||
if ( false !== strpos( $changelog_url, '/wp-json/api/v1/changelog/product_id/' ) ) {
|
||||
$error_message = $this->get_custom_update_notification_message( $changelog_url );
|
||||
} else {
|
||||
$error_message = 'expired' === $this->account_status
|
||||
? et_get_safe_localization( __( '<em>Your Elegant Themes subscription has expired. You must <a href="https://www.elegantthemes.com/members-area/renew/" target="_blank">renew your account</a> to regain access to product updates and support.</em>', 'et-core' ) )
|
||||
: et_get_safe_localization( __( '<em>Before you can receive product updates, you must first authenticate your Elegant Themes subscription. To do this, you need to enter both your Elegant Themes Username and your Elegant Themes API Key into the Updates Tab in your theme and plugin settings. To locate your API Key, <a href="https://www.elegantthemes.com/members-area/api/" target="_blank">log in</a> to your Elegant Themes account and navigate to the <strong>Account > API Key</strong> page. <a href="http://www.elegantthemes.com/gallery/divi/documentation/update/" target="_blank">Learn more here</a></em>. If you still get this message, please make sure that your Username and API Key have been entered correctly', 'et-core' ) );
|
||||
}
|
||||
|
||||
// output custom error message for ET Products if package is empty
|
||||
$error_message = et_get_safe_localization( __( '<em>Before you can receive product updates, you must first authenticate your Elegant Themes subscription. To do this, you need to enter both your Elegant Themes Username and your Elegant Themes API Key into the Updates Tab in your theme and plugin settings. To locate your API Key, <a href="https://www.elegantthemes.com/members-area/api/" target="_blank">log in</a> to your Elegant Themes account and navigate to the <strong>Account > API Key</strong> page. <a href="http://www.elegantthemes.com/gallery/divi/documentation/update/" target="_blank">Learn more here</a></em>. If you still get this message, please make sure that your Username and API Key have been entered correctly', 'et-core' ) );
|
||||
|
||||
return new WP_Error( 'no_package', $error_message );
|
||||
}
|
||||
@ -360,6 +405,15 @@ final class ET_Core_Updates {
|
||||
}
|
||||
|
||||
foreach ( $_plugins as $file => $plugin ) {
|
||||
$update_uri = isset( $plugin['UpdateURI'] ) ? $plugin['UpdateURI'] : '';
|
||||
$is_et_uri = false !== strpos( $update_uri, 'elegantthemes.com' );
|
||||
|
||||
// Continue to the next iteration if the Update URI
|
||||
// is not empty and not using Elegant Themes's domain.
|
||||
if ( ! empty( $update_uri ) && ! $is_et_uri ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$plugins[ $file ] = $plugin['Version'];
|
||||
}
|
||||
|
||||
@ -676,17 +730,15 @@ final class ET_Core_Updates {
|
||||
return $url;
|
||||
}
|
||||
|
||||
$matches = array();
|
||||
|
||||
$update_transient = get_site_transient( 'et_update_all_plugins' );
|
||||
|
||||
if ( ! is_object( $update_transient ) || empty( $update_transient->response ) ) {
|
||||
return $url;
|
||||
}
|
||||
|
||||
$matches = array();
|
||||
$update_transient = get_site_transient( 'et_update_all_plugins' );
|
||||
$et_updated_plugins_data = get_transient( 'et_updated_plugins_data' );
|
||||
$has_last_checked = ! empty( $update_transient->last_checked ) && ! empty( $et_updated_plugins_data->last_checked );
|
||||
|
||||
if ( ! is_object( $update_transient ) ) {
|
||||
return $url;
|
||||
}
|
||||
|
||||
/*
|
||||
* Attempt to use a cached list of updated plugins.
|
||||
* Re-save the list, whenever the update transient last checked time changes.
|
||||
@ -701,14 +753,18 @@ final class ET_Core_Updates {
|
||||
foreach ( $update_transient->response as $response_plugin_settings ) {
|
||||
$slug = sanitize_text_field( $response_plugin_settings->slug );
|
||||
|
||||
$et_updated_plugins_data->changelogs[ $slug ] = $response_plugin_settings->url . '?TB_iframe=true&width=1024&height=800';
|
||||
$et_updated_plugins_data->changelogs[ $slug ] = esc_url_raw( $response_plugin_settings->url . '?TB_iframe=true&width=1024&height=800' );
|
||||
}
|
||||
|
||||
set_transient( 'et_updated_plugins_data', $et_updated_plugins_data );
|
||||
}
|
||||
|
||||
if ( empty( $et_updated_plugins_data->changelogs ) ) {
|
||||
return $url;
|
||||
if ( ! empty( $update_transient->no_update ) ) {
|
||||
foreach ( $update_transient->no_update as $no_update_plugin_settings ) {
|
||||
$slug = sanitize_text_field( $no_update_plugin_settings->slug );
|
||||
|
||||
$et_updated_plugins_data->changelogs[ $slug ] = esc_url_raw( $no_update_plugin_settings->url . '?TB_iframe=true&width=1024&height=800' );
|
||||
}
|
||||
}
|
||||
|
||||
preg_match( '/plugin=([^&]*)/', $path, $matches );
|
||||
|
Reference in New Issue
Block a user