You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: admin/class-insert-rule-data.php
+16-5Lines changed: 16 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -12,6 +12,14 @@
12
12
/**
13
13
* Class for inserting rule data into the database
14
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
+
*
15
23
* @since 1.10.0
16
24
*/
17
25
class Insert_Rule_Data {
@@ -73,15 +81,17 @@ public function insert( object $post, string $rule, string $ruletype, string $ru
73
81
}
74
82
75
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).
76
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.
77
87
$results = $wpdb->get_results(
78
88
$wpdb->prepare(
79
-
'SELECT postid, ignre FROM %i where type = %s and postid = %d and rule = %s and object = %s and siteid = %d',
89
+
'SELECT postid, ignre FROM %i where type = %s and postid = %d and rule = %s and selector = %s and siteid = %d',
80
90
$table_name,
81
91
$rule_data['type'],
82
92
$rule_data['postid'],
83
93
$rule_data['rule'],
84
-
$rule_data['object'],
94
+
$rule_data['selector'],
85
95
$rule_data['siteid']
86
96
),
87
97
ARRAY_A
@@ -97,22 +107,23 @@ public function insert( object $post, string $rule, string $ruletype, string $ru
97
107
}
98
108
99
109
// update existing record.
110
+
// Use selector for WHERE clause instead of object to match on unique identifier.
100
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.
101
112
$wpdb->query(
102
113
$wpdb->prepare(
103
-
'UPDATE %i SET recordcheck = %d, landmark = %s, landmark_selector = %s, selector = %s, ancestry = %s, xpath = %s, ignre = %d WHERE siteid = %d and postid = %d and rule = %s and object = %s and type = %s',
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',
// Add the selector to the violation message as empty paragraphs are almost always
269
-
// duplicate html fragments. Adding the selector makes it unique, so it can be saved.
270
-
if ( 'empty_paragraph_tag' === $rule_id ) {
271
-
$html .= $violation['selector'][0]
272
-
? '// {{ ' . $violation['selector'][0] . ' }}'
273
-
: '';
274
-
}
275
-
267
+
publicfunctionfilter_js_validation_html( string$html, string$rule_id, array$violation ): string { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed, VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable -- the variable was used previously and will be used in future most likely.
276
268
// Use just the opening <html> and closing </html> tag, prevents storing entire page as the affected code.
0 commit comments