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
|
|
|
if ( ! defined( 'ABSPATH' ) ) { |
10
|
|
|
exit; |
11
|
|
|
} |
12
|
|
|
|
13
|
|
|
if ( ! class_exists( 'WC_Plugin_Updates' ) ) { |
14
|
|
|
include_once dirname( __FILE__ ) . '/class-wc-plugin-updates.php'; |
15
|
|
|
} |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Class WC_Updates_Screen_Updates |
19
|
|
|
*/ |
20
|
|
|
class WC_Updates_Screen_Updates extends WC_Plugin_Updates { |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Constructor. |
24
|
|
|
*/ |
25
|
|
|
public function __construct() { |
26
|
|
|
add_action( 'admin_print_footer_scripts', array( $this, 'update_screen_modal' ) ); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Show a warning message on the upgrades screen if the user tries to upgrade and has untested plugins. |
31
|
|
|
*/ |
32
|
|
|
public function update_screen_modal() { |
33
|
|
|
$updateable_plugins = get_plugin_updates(); |
34
|
|
|
if ( empty( $updateable_plugins['woocommerce/woocommerce.php'] ) |
35
|
|
|
|| empty( $updateable_plugins['woocommerce/woocommerce.php']->update ) |
36
|
|
|
|| empty( $updateable_plugins['woocommerce/woocommerce.php']->update->new_version ) ) { |
37
|
|
|
return; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
$this->new_version = wc_clean( $updateable_plugins['woocommerce/woocommerce.php']->update->new_version ); |
|
|
|
|
41
|
|
|
$this->major_untested_plugins = $this->get_untested_plugins( $this->new_version, 'major' ); |
|
|
|
|
42
|
|
|
|
43
|
|
|
if ( ! empty( $this->major_untested_plugins ) ) { |
44
|
|
|
echo $this->get_extensions_modal_warning(); // phpcs:ignore WordPress.XSS.EscapeOutput.OutputNotEscaped |
45
|
|
|
$this->update_screen_modal_js(); |
|
|
|
|
46
|
|
|
} |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* JS for the modal window on the updates screen. |
51
|
|
|
*/ |
52
|
|
|
protected function update_screen_modal_js() { |
53
|
|
|
?> |
54
|
|
|
<script> |
55
|
|
|
( function( $ ) { |
56
|
|
|
var modal_dismissed = false; |
57
|
|
|
|
58
|
|
|
// Show the modal if the WC upgrade checkbox is checked. |
59
|
|
|
var show_modal_if_checked = function() { |
60
|
|
|
if ( modal_dismissed ) { |
61
|
|
|
return; |
62
|
|
|
} |
63
|
|
|
var $checkbox = $( 'input[value="woocommerce/woocommerce.php"]' ); |
64
|
|
|
if ( $checkbox.prop( 'checked' ) ) { |
65
|
|
|
$( '#wc-upgrade-warning' ).click(); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
$( '#plugins-select-all, input[value="woocommerce/woocommerce.php"]' ).on( 'change', function() { |
70
|
|
|
show_modal_if_checked(); |
71
|
|
|
} ); |
72
|
|
|
|
73
|
|
|
// Add a hidden thickbox link to use for bringing up the modal. |
74
|
|
|
$('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>' ); |
75
|
|
|
|
76
|
|
|
// Don't show the modal again once it's been accepted. |
77
|
|
|
$( '#wc_untested_extensions_modal .accept' ).on( 'click', function( evt ) { |
78
|
|
|
evt.preventDefault(); |
79
|
|
|
modal_dismissed = true; |
80
|
|
|
tb_remove(); |
81
|
|
|
}); |
82
|
|
|
|
83
|
|
|
// Uncheck the WC update checkbox if the modal is canceled. |
84
|
|
|
$( '#wc_untested_extensions_modal .cancel' ).on( 'click', function( evt ) { |
85
|
|
|
evt.preventDefault(); |
86
|
|
|
$( 'input[value="woocommerce/woocommerce.php"]' ).prop( 'checked', false ); |
87
|
|
|
tb_remove(); |
88
|
|
|
}); |
89
|
|
|
})( jQuery ); |
90
|
|
|
</script> |
91
|
|
|
<?php |
92
|
|
|
$this->generic_modal_js(); |
|
|
|
|
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
new WC_Updates_Screen_Updates(); |
96
|
|
|
|
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountId
that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theid
property of an instance of theAccount
class. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.