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

wp-graphql / wp-graphql / 18505163881

14 Oct 2025 05:40PM UTC coverage: 84.575%. Remained the same
18505163881

push

github

actions-user
release: merge develop into master for v2.3.8

15884 of 18781 relevant lines covered (84.57%)

262.11 hits per line

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

96.43
/src/Admin/Updates/PluginsScreenLoader.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_Plugins_Screen_Updates class.
6
 *
7
 * @see https://github.com/woocommerce/woocommerce/blob/5f04212f8188e0f7b09f6375d1a6c610fac8a631/plugins/woocommerce/includes/admin/plugin-updates/class-wc-plugins-screen-updates.php
8
 * *
9
 * @package WPGraphQL\Admin\Updates
10
 */
11

12
namespace WPGraphQL\Admin\Updates;
13

14
/**
15
 * Class PluginsScreenLoader
16
 */
17
class PluginsScreenLoader {
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() {
3✔
31
                add_action( 'in_plugin_update_message-wp-graphql/wp-graphql.php', [ $this, 'in_plugin_update_message' ], 10, 2 );
3✔
32
        }
33

34
        /**
35
         * Injects a warning message into the plugin update message.
36
         *
37
         * @param array<string,mixed> $args The plugin update message arguments.
38
         * @param object              $response The plugin update response.
39
         */
40
        public function in_plugin_update_message( $args, $response ): void {
1✔
41
                $this->update_checker = new UpdateChecker( $response );
1✔
42

43
                if ( $this->update_checker->should_autoupdate( true ) ) {
1✔
44
                        return;
×
45
                }
46

47
                // @todo - maybe show upgrade notice?
48
                $update_message = '';
1✔
49

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

52
                if ( ! empty( $untested_plugins ) ) {
1✔
53
                        $update_message .= $this->get_untested_plugins_message( $untested_plugins );
1✔
54
                        $update_message .= $this->update_checker->get_untested_plugins_modal( $untested_plugins );
1✔
55
                }
56

57
                // Output the JS for the modal.
58
                add_action( 'admin_print_footer_scripts', [ $this, 'modal_js' ] );
1✔
59

60
                // Output the update message directly, without forced paragraph wrapping, to avoid duplicate or broken HTML.
61
                echo wp_kses_post( $update_message );
1✔
62
        }
63

64
        /**
65
         * Gets the untested plugins warning message.
66
         *
67
         * @param array<string,array<string,mixed>> $untested_plugins The untested plugins.
68
         */
69
        private function get_untested_plugins_message( array $untested_plugins ): string {
1✔
70
                $plugins = array_map(
1✔
71
                        static function ( $plugin ) {
1✔
72
                                return $plugin['Name'];
1✔
73
                        },
1✔
74
                        $untested_plugins
1✔
75
                );
1✔
76

77
                if ( empty( $plugins ) ) {
1✔
78
                        return '';
×
79
                }
80

81
                ob_start();
1✔
82
                ?>
83
                <div class="wp-graphql-update-notice">
1✔
84
                        <p class="warning"><strong><?php echo esc_html__( 'Untested Plugins:', 'wp-graphql' ); ?></strong></p>
1✔
85
                        <?php echo wp_kses_post( $this->update_checker->get_compatibility_warning_message( $untested_plugins ) ); ?>
1✔
86
                </div>
1✔
87

88
                <?php
1✔
89
                return (string) ob_get_clean();
1✔
90
        }
91

92
        /**
93
         * The modal JS for the plugin update message.
94
         */
95
        public function modal_js(): void {
1✔
96
                ?>
97
                <script>
1✔
98
                        ( function( $ ) {
1✔
99
                                var $update_box = $( '#wp-graphql-update' );
1✔
100
                                var $update_link = $update_box.find('a.update-link').first();
1✔
101
                                var update_url = $update_link.attr( 'href' );
1✔
102

103
                                // Set up thickbox.
1✔
104
                                $update_link.removeClass( 'update-link' );
1✔
105
                                $update_link.addClass( 'wp-graphql-thickbox' );
1✔
106
                                $update_link.attr( 'href', '#TB_inline?height=600&width=550&inlineId=wp-graphql-update-modal' );
1✔
107

108
                                // Trigger the update if the user accepts the modal's warning.
1✔
109
                                $( '#wp-graphql-update-modal .accept' ).on( 'click', function( evt ) {
1✔
110
                                        evt.preventDefault();
1✔
111
                                        tb_remove();
1✔
112
                                        $update_link.removeClass( 'wc-thickbox open-plugin-details-modal' );
1✔
113
                                        $update_link.addClass( 'update-link' );
1✔
114
                                        $update_link.attr( 'href', update_url );
1✔
115
                                        $update_link.trigger( 'click' );
1✔
116
                                });
1✔
117

118
                                $( '#wp-graphql-update-modal .cancel' ).on( 'click', function( evt ) {
1✔
119
                                        evt.preventDefault();
1✔
120
                                        tb_remove();
1✔
121
                                });
1✔
122
                        })( jQuery );
1✔
123
                </script>
1✔
124

125
                <?php
1✔
126
                $this->update_checker->modal_js();
1✔
127
        }
128
}
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

© 2025 Coveralls, Inc