Nenhuma Descrição

class-wc-updates-screen-updates.php 3.1KB

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