From 343b3913a4ff536c80ca41b477fca5954978be1c Mon Sep 17 00:00:00 2001 From: claudiulodro Date: Tue, 1 Aug 2017 15:04:11 -0700 Subject: [PATCH 1/3] Updates screen modal. --- .../admin/class-wc-admin-plugin-updates.php | 128 +++++++++++++++--- includes/admin/class-wc-admin.php | 1 + .../html-notice-untested-extensions-modal.php | 1 + 3 files changed, 113 insertions(+), 17 deletions(-) diff --git a/includes/admin/class-wc-admin-plugin-updates.php b/includes/admin/class-wc-admin-plugin-updates.php index 3ad345b9d87..b71dcf48685 100644 --- a/includes/admin/class-wc-admin-plugin-updates.php +++ b/includes/admin/class-wc-admin-plugin-updates.php @@ -57,7 +57,19 @@ class WC_Admin_Plugin_Updates { */ public function __construct() { add_filter( 'extra_plugin_headers', array( $this, 'enable_wc_plugin_headers' ) ); - add_action( 'in_plugin_update_message-woocommerce/woocommerce.php', array( $this, 'in_plugin_update_message' ), 10, 2 ); + + $screen = get_current_screen(); + if ( ! $screen ) { + return; + } + + if ( 'plugins' === $screen->id ) { + add_action( 'in_plugin_update_message-woocommerce/woocommerce.php', array( $this, 'in_plugin_update_message' ), 10, 2 ); + } + + if ( 'update-core' === $screen->id ) { + add_action( 'admin_print_footer_scripts', array( $this, 'update_screen_modal' ) ); + } } /** @@ -73,7 +85,7 @@ class WC_Admin_Plugin_Updates { } /** - * Show plugin changes. Code adapted from W3 Total Cache. + * Show plugin changes on the plugins screen. Code adapted from W3 Total Cache. * * @param array $args */ @@ -93,33 +105,46 @@ class WC_Admin_Plugin_Updates { if ( ! empty( $this->major_untested_plugins ) ) { $this->upgrade_notice .= $this->get_extensions_modal_warning(); - add_action( 'admin_print_footer_scripts', array( $this, 'modal_js' ) ); + add_action( 'admin_print_footer_scripts', array( $this, 'plugin_screen_modal_js' ) ); } echo apply_filters( 'woocommerce_in_plugin_update_message', $this->upgrade_notice ? '

' . wp_kses_post( $this->upgrade_notice ) . '

' : '' ); } /** - * JS for the modal window. + * Show a warning message on the upgrades screen if the user tries to upgrade and has untested plugins. */ - public function modal_js() { + public function update_screen_modal() { + $updateable_plugins = get_plugin_updates(); + if ( empty( $updateable_plugins['woocommerce/woocommerce.php'] ) + || empty( $updateable_plugins['woocommerce/woocommerce.php']->update ) + || empty( $updateable_plugins['woocommerce/woocommerce.php']->update->new_version ) ) { + return; + } + + $this->new_version = wc_clean( $updateable_plugins['woocommerce/woocommerce.php']->update->new_version ); + $this->major_untested_plugins = $this->get_untested_plugins( $this->new_version, 'major' ); + if ( empty( $this->major_untested_plugins ) ) { + return; + } + + echo $this->get_extensions_modal_warning(); + $this->update_screen_modal_js(); + } + + /** + * Common JS for initializing and managing the modals. + */ + protected function generic_modal_js() { ?> + + generic_modal_js(); + } + + /** + * JS for the modal window on the updates screen. + */ + public function update_screen_modal_js() { + ?> + + generic_modal_js(); } /* diff --git a/includes/admin/class-wc-admin.php b/includes/admin/class-wc-admin.php index f00c89a661e..9b87db21c91 100644 --- a/includes/admin/class-wc-admin.php +++ b/includes/admin/class-wc-admin.php @@ -101,6 +101,7 @@ class WC_Admin { include( 'class-wc-admin-permalink-settings.php' ); break; case 'plugins' : + case 'update-core' : include( 'class-wc-admin-plugin-updates.php' ); break; case 'users' : diff --git a/includes/admin/views/html-notice-untested-extensions-modal.php b/includes/admin/views/html-notice-untested-extensions-modal.php index b413e932f86..0f6bfe18b13 100644 --- a/includes/admin/views/html-notice-untested-extensions-modal.php +++ b/includes/admin/views/html-notice-untested-extensions-modal.php @@ -44,5 +44,6 @@ if ( ! defined( 'ABSPATH' ) ) {

+ From 9b22463c693b53ee7fabcb5faa2cd675458a9790 Mon Sep 17 00:00:00 2001 From: claudiulodro Date: Tue, 1 Aug 2017 15:17:35 -0700 Subject: [PATCH 2/3] Little cleanup --- includes/admin/class-wc-admin-plugin-updates.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/includes/admin/class-wc-admin-plugin-updates.php b/includes/admin/class-wc-admin-plugin-updates.php index b71dcf48685..47ce01b3093 100644 --- a/includes/admin/class-wc-admin-plugin-updates.php +++ b/includes/admin/class-wc-admin-plugin-updates.php @@ -183,9 +183,7 @@ class WC_Admin_Plugin_Updates { ( function( $ ) { var $update_box = $( '#woocommerce-update' ); var $update_link = $update_box.find('a.update-link').first(); - var update_url = $update_link.attr( 'href' ); - var old_tb_position = false; // Initialize thickbox. $update_link.removeClass( 'update-link' ); @@ -215,7 +213,7 @@ class WC_Admin_Plugin_Updates { /** * JS for the modal window on the updates screen. */ - public function update_screen_modal_js() { + protected function update_screen_modal_js() { ?>