From 095e5bde51783c8fc8fcda50a2aa89a31c29194d Mon Sep 17 00:00:00 2001 From: Nick Green Date: Thu, 17 Oct 2024 10:50:00 -0700 Subject: [PATCH] Don't show msg if autoupdates aren't available or if plugin is deactivated e.g. If not connected to WC.com, updates for paid plugins won't be available, so we shouldn't show the autoupdated message. Also, plugins won't autoupdate if deactivated, so no message. --- class-plugin-autoupdate-filter.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/class-plugin-autoupdate-filter.php b/class-plugin-autoupdate-filter.php index b83cbef..a65b7f7 100644 --- a/class-plugin-autoupdate-filter.php +++ b/class-plugin-autoupdate-filter.php @@ -5,6 +5,8 @@ * @package Plugin_Autoupdate_Filter */ +use AutomateWoo\Error; + if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly } @@ -169,7 +171,7 @@ public function filter_enforce_delay( $update, $item ): bool { if ( false === $has_delay_passed ) { $option_key = 'plugin_update_delays'; $delays = get_option( $option_key, array() ); - if ( isset( $delays[ $plugin_file ][ $plugin_new_version ] ) && is_numeric( $delays[ $plugin_file ][ $plugin_new_version ] ) ) { + if ( isset( $delays[ $plugin_file ][ $plugin_new_version ] ) && is_numeric( $delays[ $plugin_file ][ $plugin_new_version ] ) && ( ! empty( $plugin_file ) && is_plugin_active( $plugin_file ) ) ) { $delay_date = $delays[ $plugin_file ][ $plugin_new_version ]; // Get the site's date and time format settings. @@ -180,8 +182,10 @@ public function filter_enforce_delay( $update, $item ): bool { // adds message to update notice box for that plugin on the plugins page add_filter( "in_plugin_update_message-{$plugin_file}", - function() use ( $plugin_new_version, $formatted_date ) { - echo ' For stability, autoupdates operate on a slight delay. Autoupdate to version ' . esc_html( $plugin_new_version ) . ' is currently estimated to run after ' . esc_html( $formatted_date ) . ' UTC.'; + function( $plugin_data, $response ) use ( $plugin_new_version, $formatted_date ) { + if ( ! empty( $response->package ) ) { + echo ' For stability, autoupdates operate on a slight delay. Autoupdate to version ' . esc_html( $plugin_new_version ) . ' is currently estimated to run after ' . esc_html( $formatted_date ) . ' UTC.'; + } }, 10, 2