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

equalizedigital / accessibility-checker / 16057813270

03 Jul 2025 06:21PM UTC coverage: 28.915% (-0.1%) from 29.05%
16057813270

push

github

web-flow
Merge pull request #1029 from equalizedigital/william/pro-165-urls-missing-utm-parameters-in-plugin

Update some links through the plugin to properly attribute them

32 of 160 new or added lines in 15 files covered. (20.0%)

18 existing lines in 5 files now uncovered.

1527 of 5281 relevant lines covered (28.91%)

1.66 hits per line

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

0.0
/admin/class-frontend-highlight.php
1
<?php
2
/**
3
 * Accessibility Checker plugin file.
4
 *
5
 * @package Accessibility_Checker
6
 */
7

8
namespace EDAC\Admin;
9

10
use EqualizeDigital\AccessibilityChecker\Admin\AdminPage\FixesPage;
11
use EqualizeDigital\AccessibilityChecker\Fixes\FixesManager;
12

13
/**
14
 * Class EDAC_Frontend_Highlight
15
 *
16
 * A class that handles AJAX requests for frontend highlighting of accessibility issues.
17
 */
18
class Frontend_Highlight {
19

20
        /**
21
         * Constructor function for the class.
22
         */
23
        public function __construct() {
24
        }
×
25

26
        /**
27
         * Initialize hooks.
28
         *
29
         * @return void
30
         */
31
        public function init_hooks() {
32
                add_action( 'wp_ajax_edac_frontend_highlight_ajax', [ $this, 'ajax' ] );
×
33

34
                /**
35
                 * Filter the visibility of the frontend highlighter.
36
                 *
37
                 * 'edac_filter_frontend_highlighter_visibility' is a filter that can be used
38
                 * to allow users without edit permissions on the post to see the frontend
39
                 * highlighter. You can use the filter to perform additional permission checks
40
                 * on who can see it.
41
                 *
42
                 * @since 1.14.0
43
                 *
44
                 * @param bool $visibility The visibility of the frontend highlighter. Default is false, return true to show the frontend highlighter.
45
                 */
46
                if ( apply_filters( 'edac_filter_frontend_highlighter_visibility', false ) ) {
×
47
                        // A nopriv endpoint allows logged-out users to access the endpoint.
48
                        add_action( 'wp_ajax_nopriv_edac_frontend_highlight_ajax', [ $this, 'ajax' ] );
×
49
                }
50
        }
51

52
        /**
53
         * Retrieves accessibility issues for a specific post.
54
         *
55
         * @param int $post_id The ID of the post.
56
         *
57
         * @return array|null The array of issues or null if no issues found.
58
         */
59
        public function get_issues( $post_id ) {
60
                global $wpdb;
×
61
                $table_name = $wpdb->prefix . 'accessibility_checker';
×
62
                $post_id    = (int) $post_id;
×
63
                $siteid     = get_current_blog_id();
×
64
                $results    = $wpdb->get_results( $wpdb->prepare( 'SELECT id, rule, ignre, object, ruletype FROM %i where postid = %d and siteid = %d', $table_name, $post_id, $siteid ), ARRAY_A ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Safe variable used for table name.
×
65
                if ( ! $results ) {
×
66
                        return null;
×
67
                }
68

69
                return Helpers::filter_results_to_only_active_rules( $results );
×
70
        }
71

72
        /**
73
         * AJAX handler function for frontend highlighting requests.
74
         */
75
        public function ajax() {
76

77
                // nonce security.
78
                if ( ! isset( $_REQUEST['nonce'] ) || ! wp_verify_nonce( sanitize_text_field( $_REQUEST['nonce'] ), 'ajax-nonce' ) ) {
×
79
                        $error = new \WP_Error( '-1', __( 'Permission Denied', 'accessibility-checker' ) );
×
80
                        wp_send_json_error( $error );
×
81
                }
82

83
                if ( ! isset( $_REQUEST['post_id'] ) ) {
×
84
                        $error = new \WP_Error( '-2', __( 'The id value was not set', 'accessibility-checker' ) );
×
85
                        wp_send_json_error( $error );
×
86
                }
87

88
                $post_id = isset( $_REQUEST['post_id'] ) ? (int) $_REQUEST['post_id'] : 0;
×
89
                $results = $this->get_issues( $post_id );
×
90

91
                if ( ! $results ) {
×
92
                        $error = new \WP_Error( '-3', __( 'Issue query returned no results', 'accessibility-checker' ) );
×
93
                        wp_send_json_error( $error );
×
94
                }
95

96
                $rules = edac_register_rules();
×
97

98
                $issues = [];
×
99
                $fixes  = [];
×
100
                foreach ( $results as $result ) {
×
101
                        $array = [];
×
102
                        $rule  = edac_filter_by_value( $rules, 'slug', $result['rule'] );
×
103

104
                        // When rules are filtered out, they are not in the rules array and this can be empty. Skip when the rule
105
                        // is empty to avoid php warnings and passing null values to the frontend highlighter.
106
                        if ( ! $rule ) {
×
107
                                continue;
×
108
                        }
109

110
                        $rule_type = ( true === (bool) $result['ignre'] ) ? 'ignored' : $rule[0]['rule_type'];
×
111

112
                        $array['rule_type']  = $rule_type;
×
113
                        $array['slug']       = $rule[0]['slug'];
×
114
                        $array['rule_title'] = $rule[0]['title'];
×
115
                        $array['summary']    = $rule[0]['summary'];
×
NEW
116
                        $array['link']       = edac_link_wrapper( $rule[0]['info_url'], 'frontend-highlighter', $rule[0]['slug'], false );
×
117
                        $array['object']     = html_entity_decode( esc_html( $result['object'] ) );
×
118
                        $array['id']         = $result['id'];
×
119
                        $array['ignored']    = $result['ignre'];
×
120

121
                        $issues[] = $array;
×
122

123
                        if ( ! isset( $fixes[ $rule[0]['slug'] ] ) ) {
×
124
                                $fixes_for_rule = $rule[0]['fixes'] ?? [];
×
125

126
                                foreach ( $fixes_for_rule as $fix_for_rule ) {
×
127
                                        $fix = FixesManager::get_instance()->get_fix( $fix_for_rule );
×
128
                                        if ( $fix && method_exists( $fix, 'get_fields_array' ) ) {
×
129
                                                $fixes[ $rule[0]['slug'] ] = isset( $fixes[ $rule[0]['slug'] ] ) ? array_merge( $fixes[ $rule[0]['slug'] ], $fix->get_fields_array() ) : $fix->get_fields_array();
×
130
                                        }
131
                                }
132
                        }
133
                }
134

135
                if ( ! $issues ) {
×
136

137
                        $error = new \WP_Error( '-5', __( 'Object query returned no results', 'accessibility-checker' ) );
×
138
                        wp_send_json_error( $error );
×
139

140
                }
141

142
                // if we have fixes then create fields for each of the groups.
143
                if ( ! empty( $fixes ) ) {
×
144
                        foreach ( $fixes as $key => $fix ) {
×
145
                                // count the number of fields in the fix.
146
                                $fields_count      = count( $fix );
×
147
                                $itteration        = 0;
×
148
                                $fix_fields_markup = '';
×
149
                                foreach ( $fix as $index => $field ) {
×
150
                                        ++$itteration;
×
151
                                        $field_type = $field['type'] ?? 'checkbox';
×
152
                                        ob_start();
×
153
                                        if ( isset( $field['group_name'] ) ) {
×
154
                                                // if this is anything other than the first field in the group then close the fieldset.
155
                                                if ( 1 !== $itteration ) {
×
156
                                                        ?>
157
                                                        </fieldset>
×
158
                                                        <?php
×
159
                                                }
160
                                                ?>
161
                                                <fieldset>
×
162
                                                <legend><h3 class="title"><?php echo esc_html( $field['group_name'] ); ?></h3></legend>
×
163
                                                <?php
164
                                        }
165
                                        FixesPage::{$field_type}(
×
166
                                                array_merge(
×
167
                                                        [
×
168
                                                                'name'     => $index,
×
169
                                                                'location' => 'frontend-highlighter',
×
170
                                                        ],
×
171
                                                        $field
×
172
                                                )
×
173
                                        );
×
174
                                        if ( $fields_count === $itteration ) {
×
175
                                                ?>
176
                                                </fieldset>
×
177
                                                <?php
×
178
                                        }
179
                                        $fix_fields_markup .= ob_get_clean();
×
180
                                }
181
                                $fixes[ $key ]['fields'] = $fix_fields_markup . PHP_EOL . '</fieldset>';
×
182
                        }
183
                }
184

185
                wp_send_json_success(
×
186
                        wp_json_encode(
×
187
                                [
×
188
                                        'issues' => $issues,
×
189
                                        'fixes'  => $fixes,
×
190
                                ]
×
191
                        )
×
192
                );
×
193
        }
194
}
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