2017-08-02 21:57:17 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Manages WooCommerce plugin updating on the Updates screen.
|
|
|
|
*
|
2020-08-05 16:36:24 +00:00
|
|
|
* @package WooCommerce\Admin
|
2017-08-02 21:57:17 +00:00
|
|
|
* @version 3.2.0
|
|
|
|
*/
|
2018-03-06 13:34:18 +00:00
|
|
|
|
2021-02-23 12:27:06 +00:00
|
|
|
use Automattic\Jetpack\Constants;
|
|
|
|
|
2017-08-02 21:57:17 +00:00
|
|
|
if ( ! defined( 'ABSPATH' ) ) {
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ! class_exists( 'WC_Plugin_Updates' ) ) {
|
2018-03-05 18:59:17 +00:00
|
|
|
include_once dirname( __FILE__ ) . '/class-wc-plugin-updates.php';
|
2017-08-02 21:57:17 +00:00
|
|
|
}
|
|
|
|
|
2018-03-06 13:34:18 +00:00
|
|
|
/**
|
|
|
|
* Class WC_Updates_Screen_Updates
|
|
|
|
*/
|
2017-08-02 21:57:17 +00:00
|
|
|
class WC_Updates_Screen_Updates extends WC_Plugin_Updates {
|
|
|
|
|
2017-08-03 18:42:19 +00:00
|
|
|
/**
|
|
|
|
* Constructor.
|
|
|
|
*/
|
2017-08-02 21:57:17 +00:00
|
|
|
public function __construct() {
|
|
|
|
add_action( 'admin_print_footer_scripts', array( $this, 'update_screen_modal' ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show a warning message on the upgrades screen if the user tries to upgrade and has untested plugins.
|
|
|
|
*/
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2021-02-23 12:27:06 +00:00
|
|
|
$version_type = Constants::get_constant( 'WC_SSR_PLUGIN_UPDATE_RELEASE_VERSION_TYPE' );
|
|
|
|
if ( ! is_string( $version_type ) ) {
|
|
|
|
$version_type = 'none';
|
|
|
|
}
|
|
|
|
|
2017-10-17 04:50:44 +00:00
|
|
|
$this->new_version = wc_clean( $updateable_plugins['woocommerce/woocommerce.php']->update->new_version );
|
2021-02-23 12:27:06 +00:00
|
|
|
$this->major_untested_plugins = $this->get_untested_plugins( $this->new_version, $version_type );
|
2017-10-17 04:50:44 +00:00
|
|
|
|
|
|
|
if ( ! empty( $this->major_untested_plugins ) ) {
|
2018-03-06 13:34:18 +00:00
|
|
|
echo $this->get_extensions_modal_warning(); // phpcs:ignore WordPress.XSS.EscapeOutput.OutputNotEscaped
|
2017-10-17 04:50:44 +00:00
|
|
|
$this->update_screen_modal_js();
|
|
|
|
}
|
2017-08-02 21:57:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* JS for the modal window on the updates screen.
|
|
|
|
*/
|
|
|
|
protected function update_screen_modal_js() {
|
|
|
|
?>
|
|
|
|
<script>
|
|
|
|
( function( $ ) {
|
|
|
|
var modal_dismissed = false;
|
|
|
|
|
|
|
|
// Show the modal if the WC upgrade checkbox is checked.
|
|
|
|
var show_modal_if_checked = function() {
|
|
|
|
if ( modal_dismissed ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var $checkbox = $( 'input[value="woocommerce/woocommerce.php"]' );
|
|
|
|
if ( $checkbox.prop( 'checked' ) ) {
|
2021-02-04 20:31:28 +00:00
|
|
|
$( '#wc-upgrade-warning' ).trigger( 'click' );
|
2017-08-02 21:57:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$( '#plugins-select-all, input[value="woocommerce/woocommerce.php"]' ).on( 'change', function() {
|
|
|
|
show_modal_if_checked();
|
|
|
|
} );
|
|
|
|
|
|
|
|
// Add a hidden thickbox link to use for bringing up the modal.
|
|
|
|
$('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>' );
|
|
|
|
|
|
|
|
// Don't show the modal again once it's been accepted.
|
|
|
|
$( '#wc_untested_extensions_modal .accept' ).on( 'click', function( evt ) {
|
|
|
|
evt.preventDefault();
|
|
|
|
modal_dismissed = true;
|
|
|
|
tb_remove();
|
|
|
|
});
|
|
|
|
|
|
|
|
// Uncheck the WC update checkbox if the modal is canceled.
|
2017-08-08 16:12:50 +00:00
|
|
|
$( '#wc_untested_extensions_modal .cancel' ).on( 'click', function( evt ) {
|
2017-08-02 21:57:17 +00:00
|
|
|
evt.preventDefault();
|
|
|
|
$( 'input[value="woocommerce/woocommerce.php"]' ).prop( 'checked', false );
|
|
|
|
tb_remove();
|
|
|
|
});
|
|
|
|
})( jQuery );
|
|
|
|
</script>
|
|
|
|
<?php
|
|
|
|
$this->generic_modal_js();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
new WC_Updates_Screen_Updates();
|