From c4f4db79607e9068b8319121f6886d5091e1a922 Mon Sep 17 00:00:00 2001 From: denisbaranov Date: Fri, 15 Nov 2019 18:31:17 +0200 Subject: [PATCH] Fix issue that appears if we try to update several plugins at once --- includes/admin/core/class-admin-notices.php | 6 ++++- includes/class-init.php | 5 +++-- includes/core/class-plugin-updater.php | 25 ++++++++++++++++++++- 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/includes/admin/core/class-admin-notices.php b/includes/admin/core/class-admin-notices.php index 03804197..b598b8d0 100644 --- a/includes/admin/core/class-admin-notices.php +++ b/includes/admin/core/class-admin-notices.php @@ -266,7 +266,11 @@ if ( ! class_exists( 'um\admin\core\Admin_Notices' ) ) { $active_plugins = UM()->dependencies()->get_active_plugins(); foreach ( $slugs as $slug ) { if ( in_array( $slug, $active_plugins ) ) { - $plugin_data = get_plugin_data( um_path . '..' . DIRECTORY_SEPARATOR . $slug ); + $path = wp_normalize_path( WP_PLUGIN_DIR . DIRECTORY_SEPARATOR . $slug ); + if(!file_exists( $path)){ + continue; + } + $plugin_data = get_plugin_data( $path ); if ( version_compare( '2.0', $plugin_data['Version'], '>' ) ) { $show = true; break; diff --git a/includes/class-init.php b/includes/class-init.php index 4e43c487..5397c187 100644 --- a/includes/class-init.php +++ b/includes/class-init.php @@ -519,8 +519,9 @@ if ( ! class_exists( 'UM' ) ) { $this->columns(); $this->admin()->notices(); $this->admin_navmenu(); - $this->theme_updater(); $this->access(); + $this->plugin_updater(); + $this->theme_updater(); } elseif ( $this->is_request( 'admin' ) ) { $this->admin(); $this->admin_menu(); @@ -532,9 +533,9 @@ if ( ! class_exists( 'UM' ) ) { $this->admin()->notices(); $this->users(); $this->dragdrop(); - $this->plugin_updater(); $this->admin_gdpr(); $this->admin_navmenu(); + $this->plugin_updater(); $this->theme_updater(); } elseif ( $this->is_request( 'frontend' ) ) { $this->enqueue(); diff --git a/includes/core/class-plugin-updater.php b/includes/core/class-plugin-updater.php index 78cc33ed..f87ab86d 100644 --- a/includes/core/class-plugin-updater.php +++ b/includes/core/class-plugin-updater.php @@ -28,6 +28,9 @@ if ( ! class_exists( 'um\core\Plugin_Updater' ) ) { //cron request to UM()->store_url; add_action( 'um_check_extensions_licenses', array( &$this, 'um_checklicenses' ) ); + + // clean update plugin cache + add_action( 'upgrader_process_complete', array( &$this, 'clean_update_plugins_cache' ), 20, 2 ); //update plugin info add_filter( 'pre_set_site_transient_update_plugins', array( &$this, 'check_update' ) ); @@ -36,6 +39,22 @@ if ( ! class_exists( 'um\core\Plugin_Updater' ) ) { add_filter( 'plugins_api', array( &$this, 'plugin_information' ), 9999, 3 ); } + + /** + * This action is documented in wp-admin/includes/class-wp-upgrader.php + * + * @see file /wp-admin/includes/class-plugin-upgrader.php method bulk_upgrade() + * @since 2.1.1 [2019-11-15] + * + * @param Plugin_Upgrader $Plugin_Upgrader + * @param array $action + */ + public function clean_update_plugins_cache( $Plugin_Upgrader, $action = array() ) { + if ( is_a( $Plugin_Upgrader, 'Plugin_Upgrader' ) && isset( $Plugin_Upgrader->result ) && isset( $Plugin_Upgrader->result['destination_name'] ) && strpos( $Plugin_Upgrader->result['destination_name'], 'um-' ) === 0 && $action['action'] === 'update' && $action['action'] === 'plugin' ) { + wp_clean_plugins_cache( true ); + } + } + /** * Get all paid UM extensions @@ -337,7 +356,11 @@ if ( ! class_exists( 'um\core\Plugin_Updater' ) ) { continue; } - $plugin_data = get_plugin_data( WP_PLUGIN_DIR . DIRECTORY_SEPARATOR . $slug ); + $path = wp_normalize_path( WP_PLUGIN_DIR . DIRECTORY_SEPARATOR . $slug ); + if(!file_exists( $path)){ + continue; + } + $plugin_data = get_plugin_data( $path ); $version_info = $this->get_cached_version_info( $slug ); if ( false === $version_info ) {