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

equalizedigital / accessibility-checker / 22634711490

03 Mar 2026 05:22PM UTC coverage: 59.97% (-0.7%) from 60.629%
22634711490

push

github

web-flow
Merge pull request #1332 from equalizedigital/william/pro-526-setup-integration-branch-for-ac-sidebar

Integration branch: Sidebar Metabox

385 of 814 new or added lines in 10 files covered. (47.3%)

10 existing lines in 3 files now uncovered.

4773 of 7959 relevant lines covered (59.97%)

4.7 hits per line

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

73.65
/admin/class-enqueue-admin.php
1
<?php
2
/**
3
 * Class file for Admin enqueueing styles and scripts.
4
 *
5
 * @package Accessibility_Checker
6
 */
7

8
namespace EDAC\Admin;
9

10
use EDAC\Admin\OptIn\Email_Opt_In;
11
use EqualizeDigital\AccessibilityChecker\Admin\IgnoreUI;
12

13
/**
14
 * Class that initializes and handles enqueueing styles and scripts for the admin.
15
 */
16
class Enqueue_Admin {
17

18

19
        /**
20
         * Constructor
21
         */
22
        public function __construct() {
23
        }
20✔
24

25

26
        /**
27
         * Enqueue the scripts and styles.
28
         */
29
        public static function enqueue() {
30
                self::enqueue_styles();
×
31
                self::maybe_enqueue_admin_and_editor_app_scripts();
×
NEW
32
                self::maybe_enqueue_sidebar_script();
×
NEW
33
                self::maybe_enqueue_issue_modal_script();
×
UNCOV
34
                self::maybe_enqueue_email_opt_in_script();
×
35
        }
36

37
        /**
38
         * Enqueue the admin styles.
39
         *
40
         * @return void
41
         */
42
        public static function enqueue_styles() {
43
                wp_enqueue_style( 'edac', plugin_dir_url( EDAC_PLUGIN_FILE ) . 'build/css/admin.css', [], EDAC_VERSION, 'all' );
×
44
        }
45

46
        /**
47
         * Enqueue the admin and editorApp scripts.
48
         *
49
         * @return void
50
         */
51
        public static function maybe_enqueue_admin_and_editor_app_scripts() {
52

53
                global $pagenow;
14✔
54
                $post_types        = Settings::get_scannable_post_types();
14✔
55
                $has_post_types    = is_array( $post_types ) && count( $post_types );
14✔
56
                $is_scannable_post = Helpers::is_current_post_type_scannable( $post_types );
14✔
57
                $page              = self::get_current_page_slug();
14✔
58
                $enabled_pages     = apply_filters(
14✔
59
                        'edac_filter_admin_scripts_slugs',
14✔
60
                        [
14✔
61
                                'accessibility_checker',
14✔
62
                                'accessibility_checker_settings',
14✔
63
                                'accessibility_checker_issues',
14✔
64
                                'accessibility_checker_ignored',
14✔
65
                        ]
14✔
66
                );
14✔
67

68
                if (
69
                        (
70
                                $has_post_types &&
14✔
71
                                (
14✔
72
                                        $is_scannable_post ||
14✔
73
                                        in_array( $page, $enabled_pages, true )
14✔
74
                                )
14✔
75
                        ) ||
76
                        'site-editor.php' !== $pagenow
14✔
77
                ) {
78

79
                        global $post;
14✔
80
                        $post_id = is_object( $post ) ? $post->ID : null;
14✔
81
                        wp_enqueue_script( 'edac', plugin_dir_url( EDAC_PLUGIN_FILE ) . 'build/admin.bundle.js', [ 'jquery' ], EDAC_VERSION, false );
14✔
82
                        wp_set_script_translations( 'edac', 'accessibility-checker', plugin_dir_path( EDAC_PLUGIN_FILE ) . 'languages' );
14✔
83

84
                        wp_localize_script(
14✔
85
                                'edac',
14✔
86
                                'edac_script_vars',
14✔
87
                                [
14✔
88
                                        'postID'             => $post_id,
14✔
89
                                        'nonce'              => wp_create_nonce( 'ajax-nonce' ),
14✔
90
                                        'edacApiUrl'         => esc_url_raw( rest_url() . 'accessibility-checker/v1' ),
14✔
91
                                        'restNonce'          => wp_create_nonce( 'wp_rest' ),
14✔
92
                                        'proUrl'             => esc_url_raw( edac_generate_link_type( [ 'utm_content' => '__name__' ] ) ),
14✔
93
                                        'hasDismissEndpoint' => method_exists( \EDAC\Inc\REST_Api::class, 'dismiss_issue' ),
14✔
94
                                ]
14✔
95
                        );
14✔
96

97
                        if ( 'post.php' === $pagenow || 'post-new.php' === $pagenow ) {
14✔
98

99
                                // Is this posttype setup to be checked?
100
                                $active = $is_scannable_post;
10✔
101

102
                                $pro = defined( 'EDACP_VERSION' ) && EDAC_KEY_VALID;
10✔
103

104
                                if ( EDAC_DEBUG || strpos( EDAC_VERSION, '-beta' ) !== false ) {
10✔
105
                                        $debug = true; // @codeCoverageIgnore
106
                                } else {
UNCOV
107
                                        $debug = false;
×
108
                                }
109

110
                                wp_enqueue_script( 'edac-editor-app', plugin_dir_url( EDAC_PLUGIN_FILE ) . 'build/editorApp.bundle.js', false, EDAC_VERSION, false );
10✔
111
                                wp_set_script_translations( 'edac-editor-app', 'accessibility-checker', plugin_dir_path( EDAC_PLUGIN_FILE ) . 'languages' );
10✔
112

113
                                // If this is the frontpage or homepage, preview URLs won't work. Use the live URL.
114
                                if ( (int) get_option( 'page_on_front' ) === $post_id || (int) get_option( 'page_for_posts' ) === $post_id ) {
10✔
115
                                        $scan_url = add_query_arg( 'edac_pageScanner', 1, get_permalink( $post_id ) );
4✔
116
                                } else {
117
                                        $post_view_link = apply_filters(
6✔
118
                                                'edac_get_origin_url_for_virtual_page',
6✔
119
                                                get_preview_post_link( $post_id ),
6✔
120
                                                $post_id
6✔
121
                                        );
6✔
122

123
                                        $scan_url = add_query_arg(
6✔
124
                                                [
6✔
125
                                                        'edac_pageScanner' => 1,
6✔
126
                                                ],
6✔
127
                                                $post_view_link
6✔
128
                                        );
6✔
129
                                }
130

131
                                wp_localize_script(
10✔
132
                                        'edac-editor-app',
10✔
133
                                        'edac_editor_app',
10✔
134
                                        [
10✔
135
                                                'postID'       => $post_id,
10✔
136
                                                'edacUrl'      => esc_url_raw( get_site_url() ),
10✔
137
                                                'edacApiUrl'   => esc_url_raw( rest_url() . 'accessibility-checker/v1' ),
10✔
138
                                                'baseurl'      => plugin_dir_url( __DIR__ ),
10✔
139
                                                'active'       => $active,
10✔
140
                                                'pro'          => $pro,
10✔
141
                                                'debug'        => $debug,
10✔
142
                                                'scanUrl'      => $scan_url,
10✔
143
                                                'maxAltLength' => max( 1, absint( apply_filters( 'edac_max_alt_length', 300 ) ) ),
10✔
144
                                                'version'      => EDAC_VERSION,
10✔
145
                                                'postStatus'   => get_post_status( $post_id ),
10✔
146
                                                'restNonce'    => wp_create_nonce( 'wp_rest' ),
10✔
147
                                        ]
10✔
148
                                );
10✔
149

150
                        }
151
                }
152
        }
153

154
        /**
155
         * Enqueue the Gutenberg sidebar script.
156
         *
157
         * @return void
158
         */
159
        public static function maybe_enqueue_sidebar_script() {
160
                global $pagenow;
6✔
161

162
                // Only load on post edit screens.
163
                if ( 'post.php' !== $pagenow && 'post-new.php' !== $pagenow ) {
6✔
NEW
164
                        return;
×
165
                }
166

167
                if ( ! Helpers::is_block_editor() ) {
6✔
168
                        return;
2✔
169
                }
170

171
                // Check if this post type is scannable.
172
                $post_types = Settings::get_scannable_post_types();
4✔
173
                if ( ! Helpers::is_current_post_type_scannable( $post_types ) ) {
4✔
174
                        return;
2✔
175
                }
176

177
                // Enqueue the sidebar script with WordPress dependencies.
178
                wp_enqueue_script(
2✔
179
                        'edac-sidebar',
2✔
180
                        plugin_dir_url( EDAC_PLUGIN_FILE ) . 'build/sidebar.bundle.js',
2✔
181
                        [
2✔
182
                                'wp-plugins',
2✔
183
                                'wp-edit-post',
2✔
184
                                'wp-editor',
2✔
185
                                'wp-element',
2✔
186
                                'wp-data',
2✔
187
                                'wp-i18n',
2✔
188
                                'wp-api-fetch',
2✔
189
                                'wp-components',
2✔
190
                        ],
2✔
191
                        EDAC_VERSION,
2✔
192
                        false
2✔
193
                );
2✔
194

195
                // Set translations for the sidebar.
196
                wp_set_script_translations( 'edac-sidebar', 'accessibility-checker', plugin_dir_path( EDAC_PLUGIN_FILE ) . 'languages' );
2✔
197

198
                // Localize script with necessary data.
199
                wp_localize_script(
2✔
200
                        'edac-sidebar',
2✔
201
                        'edac_sidebar_app',
2✔
202
                        [
2✔
203
                                'gutenbergEnabled'   => true,
2✔
204
                                'postID'             => get_the_ID(),
2✔
205
                                'highlightNonce'     => wp_create_nonce( 'edac_highlight' ),
2✔
206
                                'ajaxNonce'          => wp_create_nonce( 'ajax-nonce' ),
2✔
207
                                'ajaxUrl'            => admin_url( 'admin-ajax.php' ),
2✔
208
                                'edacApiUrl'         => esc_url_raw( rest_url() . 'accessibility-checker/v1' ),
2✔
209
                                'settingsUrl'        => esc_url_raw( admin_url( 'admin.php?page=accessibility_checker_settings' ) ),
2✔
210
                                'canManageSettings'  => current_user_can( apply_filters( 'edac_filter_settings_capability', 'manage_options' ) ),
2✔
211
                                'readabilityHelpUrl' => esc_url_raw( edac_link_wrapper( 'https://a11ychecker.com/help3265', 'wordpress-general', 'content-analysis-sidebar', false ) ),
2✔
212
                                'dismissReasons'     => IgnoreUI::get_reasons(),
2✔
213
                        ]
2✔
214
                );
2✔
215

216
                // Enqueue sidebar styles.
217
                wp_enqueue_style(
2✔
218
                        'edac-sidebar',
2✔
219
                        plugin_dir_url( EDAC_PLUGIN_FILE ) . 'build/css/sidebar.css',
2✔
220
                        [],
2✔
221
                        EDAC_VERSION,
2✔
222
                        'all'
2✔
223
                );
2✔
224

225
                // Enqueue CodeMirror for HTML syntax highlighting in the issue modal.
226
                wp_enqueue_code_editor( [ 'type' => 'text/html' ] );
2✔
227
        }
228

229
        /**
230
         * Enqueue the issue modal bundle (used in sidebar and other admin areas).
231
         *
232
         * @return void
233
         */
234
        public static function maybe_enqueue_issue_modal_script() {
NEW
235
                global $pagenow;
×
236

237
                // Only load on post edit screens where the sidebar is active.
NEW
238
                if ( 'post.php' !== $pagenow && 'post-new.php' !== $pagenow ) {
×
NEW
239
                        return;
×
240
                }
241

242
                // Check if this post type is scannable.
NEW
243
                $post_types = Settings::get_scannable_post_types();
×
NEW
244
                if ( ! Helpers::is_current_post_type_scannable( $post_types ) ) {
×
NEW
245
                        return;
×
246
                }
247

248
                // Enqueue the issue modal script with WordPress dependencies.
NEW
249
                wp_enqueue_script(
×
NEW
250
                        'edac-issue-modal',
×
NEW
251
                        plugin_dir_url( EDAC_PLUGIN_FILE ) . 'build/issueModal.bundle.js',
×
NEW
252
                        [
×
NEW
253
                                'wp-element',
×
NEW
254
                                'wp-components',
×
NEW
255
                                'wp-i18n',
×
NEW
256
                                'wp-api-fetch',
×
NEW
257
                                'wp-html-entities',
×
NEW
258
                        ],
×
NEW
259
                        EDAC_VERSION,
×
NEW
260
                        true
×
NEW
261
                );
×
262

263
                // Set translations for the issue modal.
NEW
264
                wp_set_script_translations( 'edac-issue-modal', 'accessibility-checker', plugin_dir_path( EDAC_PLUGIN_FILE ) . 'languages' );
×
265

266
                // Enqueue issue modal styles.
NEW
267
                wp_enqueue_style(
×
NEW
268
                        'edac-issue-modal',
×
NEW
269
                        plugin_dir_url( EDAC_PLUGIN_FILE ) . 'build/css/issueModal.css',
×
NEW
270
                        [ 'wp-components' ],
×
NEW
271
                        EDAC_VERSION,
×
NEW
272
                        'all'
×
NEW
273
                );
×
274

275
                // Enqueue CodeMirror for HTML syntax highlighting.
NEW
276
                wp_enqueue_code_editor( [ 'type' => 'text/html' ] );
×
277
        }
278

279
        /**
280
         * Enqueue the email opt-in script on the welcome page.
281
         *
282
         * @return void
283
         */
284
        public static function maybe_enqueue_email_opt_in_script() {
285

286
                $page = self::get_current_page_slug();
×
287
                if ( 'accessibility_checker' !== $page ) {
×
288
                        return;
×
289
                }
290

291
                $user_already_opted_in = (bool) get_user_meta( get_current_user_id(), Email_Opt_In::EDAC_USER_OPTIN_META_KEY, true );
×
292
                if ( $user_already_opted_in ) {
×
293
                        return;
×
294
                }
295

296
                $email_opt_in = new Email_Opt_In();
×
297
                $email_opt_in->enqueue_scripts();
×
298
        }
299

300

301
        /**
302
         * Gets the current admin page slug.
303
         *
304
         * @since 1.31.0
305
         * @return string|null The current page slug or null if not set.
306
         */
307
        private static function get_current_page_slug(): ?string {
308
                return isset( $_GET['page'] ) ? sanitize_key( wp_unslash( $_GET['page'] ) ) : null; // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- display only.
14✔
309
        }
310
}
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