• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

wp-graphql / wp-graphql / #887

16 Jan 2025 10:08PM UTC coverage: 83.189% (-0.8%) from 83.968%
#887

push

php-coveralls

web-flow
Merge pull request #3272 from wp-graphql/release/v1.30.0

release: v1.30.0

473 of 718 new or added lines in 23 files covered. (65.88%)

2 existing lines in 2 files now uncovered.

12995 of 15621 relevant lines covered (83.19%)

298.21 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.65
/src/Admin/Updates/UpdatesScreenLoader.php
1
<?php
2
/**
3
 * Handles plugin update checks and notifications on the plugins screen.
4
 *
5
 * Code is inspired by and adapted from WooCommerce's WC_Updates_Screen_Updates class.
6
 *
7
 * @see https://github.com/woocommerce/woocommerce/blob/5f04212f8188e0f7b09f6375d1a6c610fac8a631/plugins/woocommerce/includes/admin/plugin-updates/class-wc-updates-screen-updates.php
8
 *
9
 * @package WPGraphQL\Admin\Updates
10
 */
11

12
namespace WPGraphQL\Admin\Updates;
13

14
/**
15
 * Class UpdatesScreenLoader
16
 */
17
class UpdatesScreenLoader {
18
        /**
19
         * The UpdateChecker instance.
20
         *
21
         * @var \WPGraphQL\Admin\Updates\UpdateChecker
22
         */
23
        private $update_checker;
24

25
        /**
26
         * The class constructor.
27
         *
28
         * Class properties are set inside the action.
29
         */
30
        public function __construct() {
31
                add_action( 'admin_print_footer_scripts', [ $this, 'update_screen_modal' ] );
3✔
32
        }
33

34
        /**
35
         * Show a warning message on the upgrades screen if the user tries to upgrade and has untested plugins.
36
         */
37
        public function update_screen_modal(): void {
38
                // Bail if the plugin is not on the update list.
39
                $updateable_plugins = get_plugin_updates();
1✔
40

41
                if ( empty( $updateable_plugins['wp-graphql/wp-graphql.php']->update->new_version ) ) {
1✔
42
                        return;
1✔
43
                }
44

45
                $this->update_checker = new UpdateChecker( $updateable_plugins['wp-graphql/wp-graphql.php']->update );
1✔
46

47
                if ( $this->update_checker->should_autoupdate( true ) ) {
1✔
NEW
48
                        return;
×
49
                }
50

51
                $untested_plugins = $this->update_checker->get_untested_plugins( 'major' );
1✔
52

53
                if ( empty( $untested_plugins ) ) {
1✔
NEW
54
                        return;
×
55
                }
56

57
                // Output the modal.
58
                echo wp_kses_post( $this->update_checker->get_untested_plugins_modal( $untested_plugins ) );
1✔
59

60
                $this->modal_js();
1✔
61
        }
62

63
        /**
64
         * The modal JS for the plugin update message.
65
         */
66
        public function modal_js(): void {
67
                ?>
68
                <script>
1✔
69
                        ( function( $ ) {
1✔
70
                                var modal_dismissed = false;
1✔
71

72
                                // Show the modal if the WC upgrade checkbox is checked.
1✔
73
                                var show_modal_if_checked = function() {
1✔
74
                                        if ( modal_dismissed ) {
1✔
75
                                                return;
1✔
76
                                        }
1✔
77
                                        var $checkbox = $( 'input[value="wp-graphql/wp-graphql.php"]' );
1✔
78
                                        if ( $checkbox.prop( 'checked' ) ) {
1✔
79
                                                $( '#wp-graphql-upgrade-warning' ).trigger( 'click' );
1✔
80
                                        }
1✔
81
                                }
1✔
82

83
                                $( '#plugins-select-all, input[value="wp-graphql/wp-graphql.php"]' ).on( 'change', function() {
1✔
84
                                        show_modal_if_checked();
1✔
85
                                } );
1✔
86

87
                                // Add a hidden thickbox link to use for bringing up the modal.
1✔
88
                                $('body').append( '<a href="#TB_inline?height=600&width=550&inlineId=wp-graphql-update-modal" class="wp-graphql-thickbox" id="wp-graphql-upgrade-warning" style="display:none"></a>' );
1✔
89

90
                                // Don't show the modal again once it's been accepted.
1✔
91
                                $( '#wp-graphql-update-modal .accept' ).on( 'click', function( evt ) {
1✔
92
                                        evt.preventDefault();
1✔
93
                                        modal_dismissed = true;
1✔
94
                                        tb_remove();
1✔
95
                                });
1✔
96

97
                                // Uncheck the WC update checkbox if the modal is canceled.
1✔
98
                                $( '#wp-graphql-update-modal .cancel' ).on( 'click', function( evt ) {
1✔
99
                                        evt.preventDefault();
1✔
100
                                        $( 'input[value="wp-graphql/wp-graphql.php"]' ).prop( 'checked', false );
1✔
101
                                        tb_remove();
1✔
102
                                });
1✔
103
                        })( jQuery );
1✔
104
                </script>
1✔
105

106
                <?php
1✔
107
                $this->update_checker->modal_js();
1✔
108
        }
109
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc