• 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

96.23
/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() {
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 {
41
                $this->update_checker = new UpdateChecker( $response );
1✔
42

43
                if ( $this->update_checker->should_autoupdate( true ) ) {
1✔
NEW
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
                // Handle dangling <p> tags from the default update message.
58
                $update_message = sprintf( '</p>%s<p class="hidden">', $update_message );
1✔
59

60
                // Output the JS for the modal.
61
                add_action( 'admin_print_footer_scripts', [ $this, 'modal_js' ] );
1✔
62

63
                echo wp_kses_post( $update_message );
1✔
64
        }
65

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

79
                if ( empty( $plugins ) ) {
1✔
NEW
80
                        return '';
×
81
                }
82

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

90
                <?php
1✔
91
                return (string) ob_get_clean();
1✔
92
        }
93

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

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

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

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

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