• 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

85.0
/admin/class-insert-rule-data.php
1
<?php
2
/**
3
 * Inserts rule data about a post to the database
4
 *
5
 * @since 1.10.0
6
 *
7
 * @package Accessibility_Checker
8
 */
9

10
namespace EDAC\Admin;
11

12
/**
13
 * Class for inserting rule data into the database
14
 *
15
 * The unique identifier for issues changed in version 1.0.5 of the database schema.
16
 * Previously, issues were identified by: postid + rule + object + type + siteid
17
 * Now, issues are identified by: postid + rule + selector + type + siteid
18
 *
19
 * This change allows duplicate code objects (e.g., two empty paragraphs) to be
20
 * stored as separate issues when they appear in different locations on the page.
21
 * The selector field provides the unique location identifier for each issue.
22
 *
23
 * @since 1.10.0
24
 */
25
class Insert_Rule_Data {
26

27
        /**
28
         * Insert rule data into database
29
         *
30
         * @since 1.10.0
31
         *
32
         * @param object      $post              The post object. Must have a valid ID.
33
         * @param string      $rule              The rule.
34
         * @param string      $ruletype          The rule type.
35
         * @param string      $rule_obj          The object.
36
         * @param string|null $landmark          The landmark type (main, header, footer, nav), optional.
37
         * @param string|null $landmark_selector The landmark selector, optional.
38
         * @param array       $selectors         An array of selectors that point to the object, optional.
39
         *
40
         * @return void|int|\WP_Error The ID of the inserted record, void if no
41
         * record was inserted or a WP_Error if the insert failed.
42
         */
43
        public function insert( object $post, string $rule, string $ruletype, string $rule_obj, ?string $landmark = null, ?string $landmark_selector = null, array $selectors = [] ) {
44

45
                if ( ! isset( $post->ID, $post->post_type )
4✔
46
                        || empty( $rule )
4✔
47
                        || empty( $ruletype )
4✔
48
                        || empty( $rule_obj )
4✔
49
                ) {
50
                        return;
×
51
                }
52

53
                global $wpdb;
4✔
54
                $table_name = $wpdb->prefix . 'accessibility_checker';
4✔
55

56
                // set up rule data array.
57
                $rule_data = [
4✔
58
                        'postid'            => $post->ID,
4✔
59
                        'siteid'            => get_current_blog_id(),
4✔
60
                        'type'              => $post->post_type,
4✔
61
                        'landmark'          => $landmark,
4✔
62
                        'landmark_selector' => $landmark_selector,
4✔
63
                        'selector'          => $selectors['selector'][0] ?? null,
4✔
64
                        'ancestry'          => $selectors['ancestry'][0] ?? null,
4✔
65
                        'xpath'             => $selectors['xpath'][0] ?? null,
4✔
66
                        'rule'              => $rule,
4✔
67
                        'ruletype'          => $ruletype,
4✔
68
                        'object'            => esc_attr( $rule_obj ),
4✔
69
                        'recordcheck'       => 1,
4✔
70
                        'user'              => get_current_user_id(),
4✔
71
                        'ignre'             => 0,
4✔
72
                        'ignre_user'        => null,
4✔
73
                        'ignre_date'        => null,
4✔
74
                        'ignre_comment'     => null,
4✔
75
                        'ignre_global'      => 0,
4✔
76
                ];
4✔
77

78
                // return if revision.
79
                if ( 'revision' === $rule_data['type'] ) {
4✔
80
                        return;
×
81
                }
82

83
                // Check if exists.
84
                // Use selector as the unique identifier instead of object to allow duplicate code objects
85
                // with different selectors (e.g., two empty paragraphs in different locations).
86
                // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Using direct query for adding data to database, caching not required for one time operation.
87
                $results = $wpdb->get_results(
4✔
88
                        $wpdb->prepare(
4✔
89
                                'SELECT postid, ignre FROM %i where type = %s and postid = %d and rule = %s and selector = %s and siteid = %d',
4✔
90
                                $table_name,
4✔
91
                                $rule_data['type'],
4✔
92
                                $rule_data['postid'],
4✔
93
                                $rule_data['rule'],
4✔
94
                                $rule_data['selector'],
4✔
95
                                $rule_data['siteid']
4✔
96
                        ),
4✔
97
                        ARRAY_A
4✔
98
                );
4✔
99

100
                // Loop existing records.
101
                if ( $results ) {
4✔
102
                        foreach ( $results as $row ) {
4✔
103

104
                                // if being ignored, don't overwrite value.
105
                                if ( true === (bool) $row['ignre'] ) {
4✔
106
                                        $rule_data['ignre'] = 1;
×
107
                                }
108

109
                                // update existing record.
110
                                // Use selector for WHERE clause instead of object to match on unique identifier.
111
                                // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Using direct query for adding data to database, caching not required for one time operation.
112
                                $wpdb->query(
4✔
113
                                        $wpdb->prepare(
4✔
114
                                                'UPDATE %i SET recordcheck = %d, landmark = %s, landmark_selector = %s, object = %s, ancestry = %s, xpath = %s, ignre = %d  WHERE siteid = %d and postid = %d and rule = %s and selector = %s and type = %s',
4✔
115
                                                $table_name,
4✔
116
                                                1,
4✔
117
                                                $rule_data['landmark'],
4✔
118
                                                $rule_data['landmark_selector'],
4✔
119
                                                $rule_data['object'],
4✔
120
                                                $rule_data['ancestry'],
4✔
121
                                                $rule_data['xpath'],
4✔
122
                                                $rule_data['ignre'],
4✔
123
                                                $rule_data['siteid'],
4✔
124
                                                $rule_data['postid'],
4✔
125
                                                $rule_data['rule'],
4✔
126
                                                $rule_data['selector'],
4✔
127
                                                $rule_data['type']
4✔
128
                                        )
4✔
129
                                );
4✔
130

131
                        }
132
                }
133

134
                // Insert new records.
135
                if ( ! $results ) {
4✔
136

137
                        /**
138
                         * Filter the rule data before inserting it into the database.
139
                         *
140
                         * This data will be sanitized after the filter is applied.
141
                         *
142
                         * @since 1.4.0
143
                         *
144
                         * @param array $rule_data The rule data.
145
                         */
146
                        $rule_data = apply_filters( 'edac_filter_insert_rule_data', $rule_data );
4✔
147

148
                        // Sanitize rule data since it is filtered, and we can't be sure
149
                        // the data is still as valid as it was when it was first set.
150
                        // Sanitize the filtered data.
151
                        $rule_data_sanitized = [
4✔
152
                                'postid'            => absint( $rule_data['postid'] ),
4✔
153
                                'siteid'            => absint( $rule_data['siteid'] ),
4✔
154
                                'type'              => sanitize_text_field( $rule_data['type'] ),
4✔
155
                                'landmark'          => isset( $rule_data['landmark'] ) ? sanitize_text_field( $rule_data['landmark'] ) : null,
4✔
156
                                'landmark_selector' => isset( $rule_data['landmark_selector'] ) ? sanitize_text_field( $rule_data['landmark_selector'] ) : null,
4✔
157
                                'selector'          => sanitize_text_field( $rule_data['selector'] ?? '' ),
4✔
158
                                'ancestry'          => sanitize_text_field( $rule_data['ancestry'] ?? '' ),
4✔
159
                                'xpath'             => sanitize_text_field( $rule_data['xpath'] ?? '' ),
4✔
160
                                'rule'              => sanitize_text_field( $rule_data['rule'] ),
4✔
161
                                'ruletype'          => sanitize_text_field( $rule_data['ruletype'] ),
4✔
162
                                'object'            => esc_attr( $rule_data['object'] ),
4✔
163
                                'recordcheck'       => absint( $rule_data['recordcheck'] ),
4✔
164
                                'user'              => absint( $rule_data['user'] ),
4✔
165
                                'ignre'             => absint( $rule_data['ignre'] ),
4✔
166
                                'ignre_user'        => isset( $rule_data['ignre_user'] ) ? absint( $rule_data['ignre_user'] ) : null,
4✔
167
                                'ignre_date'        => isset( $rule_data['ignre_date'] ) ? sanitize_text_field( $rule_data['ignre_date'] ) : null,
4✔
168
                                'ignre_comment'     => isset( $rule_data['ignre_comment'] ) ? null : null,
4✔
169
                                'ignre_global'      => absint( $rule_data['ignre_global'] ),
4✔
170
                        ];
4✔
171

172
                        if ( isset( $rule_data['ignre_comment'] ) ) {
4✔
NEW
173
                                $allowed_html = [
×
NEW
174
                                        'strong' => [],
×
NEW
175
                                        'b'      => [],
×
NEW
176
                                        'em'     => [],
×
NEW
177
                                        'i'      => [],
×
NEW
178
                                        'a'      => [
×
NEW
179
                                                'href'   => true,
×
NEW
180
                                                'target' => true,
×
NEW
181
                                                'rel'    => true,
×
NEW
182
                                        ],
×
NEW
183
                                ];
×
184
                                
NEW
185
                                $rule_data_sanitized['ignre_comment'] = esc_html( wp_kses( $rule_data['ignre_comment'], $allowed_html ) );
×
186
                        }
187

188
                        // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery -- Using direct query for adding data to database.
189
                        $wpdb->insert( $table_name, $rule_data_sanitized );
4✔
190

191
                        // Return insert id or error.
192
                        return $wpdb->insert_id;
4✔
193
                }
194
        }
195
}
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