views
2 years ago
class-wc-plugin-updates.php
5 years ago
class-wc-plugins-screen-updates.php
5 years ago
class-wc-updates-screen-updates.php
5 years ago
class-wc-updates-screen-updates.php
103 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Manages WooCommerce plugin updating on the Updates screen. |
| 4 | * |
| 5 | * @package WooCommerce\Admin |
| 6 | * @version 3.2.0 |
| 7 | */ |
| 8 | |
| 9 | use Automattic\Jetpack\Constants; |
| 10 | |
| 11 | if ( ! defined( 'ABSPATH' ) ) { |
| 12 | exit; |
| 13 | } |
| 14 | |
| 15 | if ( ! class_exists( 'WC_Plugin_Updates' ) ) { |
| 16 | include_once dirname( __FILE__ ) . '/class-wc-plugin-updates.php'; |
| 17 | } |
| 18 | |
| 19 | /** |
| 20 | * Class WC_Updates_Screen_Updates |
| 21 | */ |
| 22 | class WC_Updates_Screen_Updates extends WC_Plugin_Updates { |
| 23 | |
| 24 | /** |
| 25 | * Constructor. |
| 26 | */ |
| 27 | public function __construct() { |
| 28 | add_action( 'admin_print_footer_scripts', array( $this, 'update_screen_modal' ) ); |
| 29 | } |
| 30 | |
| 31 | /** |
| 32 | * Show a warning message on the upgrades screen if the user tries to upgrade and has untested plugins. |
| 33 | */ |
| 34 | public function update_screen_modal() { |
| 35 | $updateable_plugins = get_plugin_updates(); |
| 36 | if ( empty( $updateable_plugins['woocommerce/woocommerce.php'] ) |
| 37 | || empty( $updateable_plugins['woocommerce/woocommerce.php']->update ) |
| 38 | || empty( $updateable_plugins['woocommerce/woocommerce.php']->update->new_version ) ) { |
| 39 | return; |
| 40 | } |
| 41 | |
| 42 | $version_type = Constants::get_constant( 'WC_SSR_PLUGIN_UPDATE_RELEASE_VERSION_TYPE' ); |
| 43 | if ( ! is_string( $version_type ) ) { |
| 44 | $version_type = 'none'; |
| 45 | } |
| 46 | |
| 47 | $this->new_version = wc_clean( $updateable_plugins['woocommerce/woocommerce.php']->update->new_version ); |
| 48 | $this->major_untested_plugins = $this->get_untested_plugins( $this->new_version, $version_type ); |
| 49 | |
| 50 | if ( ! empty( $this->major_untested_plugins ) ) { |
| 51 | echo $this->get_extensions_modal_warning(); // phpcs:ignore WordPress.XSS.EscapeOutput.OutputNotEscaped |
| 52 | $this->update_screen_modal_js(); |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * JS for the modal window on the updates screen. |
| 58 | */ |
| 59 | protected function update_screen_modal_js() { |
| 60 | ?> |
| 61 | <script> |
| 62 | ( function( $ ) { |
| 63 | var modal_dismissed = false; |
| 64 | |
| 65 | // Show the modal if the WC upgrade checkbox is checked. |
| 66 | var show_modal_if_checked = function() { |
| 67 | if ( modal_dismissed ) { |
| 68 | return; |
| 69 | } |
| 70 | var $checkbox = $( 'input[value="woocommerce/woocommerce.php"]' ); |
| 71 | if ( $checkbox.prop( 'checked' ) ) { |
| 72 | $( '#wc-upgrade-warning' ).trigger( 'click' ); |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | $( '#plugins-select-all, input[value="woocommerce/woocommerce.php"]' ).on( 'change', function() { |
| 77 | show_modal_if_checked(); |
| 78 | } ); |
| 79 | |
| 80 | // Add a hidden thickbox link to use for bringing up the modal. |
| 81 | $('body').append( '<a href="#TB_inline?height=600&width=550&inlineId=wc_untested_extensions_modal" class="wc-thickbox" id="wc-upgrade-warning" style="display:none"></a>' ); |
| 82 | |
| 83 | // Don't show the modal again once it's been accepted. |
| 84 | $( '#wc_untested_extensions_modal .accept' ).on( 'click', function( evt ) { |
| 85 | evt.preventDefault(); |
| 86 | modal_dismissed = true; |
| 87 | tb_remove(); |
| 88 | }); |
| 89 | |
| 90 | // Uncheck the WC update checkbox if the modal is canceled. |
| 91 | $( '#wc_untested_extensions_modal .cancel' ).on( 'click', function( evt ) { |
| 92 | evt.preventDefault(); |
| 93 | $( 'input[value="woocommerce/woocommerce.php"]' ).prop( 'checked', false ); |
| 94 | tb_remove(); |
| 95 | }); |
| 96 | })( jQuery ); |
| 97 | </script> |
| 98 | <?php |
| 99 | $this->generic_modal_js(); |
| 100 | } |
| 101 | } |
| 102 | new WC_Updates_Screen_Updates(); |
| 103 |