Fix warning#60
Conversation
Modify the get_all_for_export function to always use $wpdb->prepare for SQL query preparation, improving consistency and reducing the risk of SQL injection. Previously, the function used a conditional approach where $wpdb->prepare would not be called if no $values were present. This change ensures that query preparation is uniform, which enhances security and maintains best practices in database interaction.
Simplify the query preparation logic in the get_all_for_export function by eliminating the separate assignment of the $prepared variable. This change directly prepares the SQL query in the conditional block where $values are checked, streamlining the code and improving readability. The refactoring ensures that prepared statements are used consistently while maintaining the same functionality.
Update phpcs ignore comments in `get_all_for_export` method to include `PluginCheck.Security.DirectDB.UnescapedDBParameter`. This change ensures compliance with the new security guidelines and helps prevent potential security issues related to unescaped database parameters when executing direct queries.
Reviewer's guide (collapsed on small PRs)Reviewer's GuideEnsures all export queries consistently use $wpdb->prepare(), even when no dynamic values are provided, aligning with WordPress coding standards and silencing related warnings. Sequence diagram for standardized export query preparationsequenceDiagram
participant Caller
participant SvaDb as SvaDb
participant Wpdb as wpdb
Caller->>SvaDb: get_all_for_export(args)
alt values not empty
SvaDb->>Wpdb: prepare(sql, values...)
SvaDb->>Wpdb: get_results(prepared_sql, ARRAY_A)
else values empty
SvaDb->>Wpdb: prepare(sql)
SvaDb->>Wpdb: get_results(prepared_sql, ARRAY_A)
end
SvaDb-->>Caller: rows array
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
Warning Review limit reached
More reviews will be available in 57 minutes and 33 seconds. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more credits in the billing tab to continue. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits. 🚦 How do rate limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, the refill rate gradually slows as usage increases. The highest same-day bursts are limited more strictly. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- Calling
$wpdb->prepare( $sql )when there are no placeholders in$sqlis unnecessary and can itself trigger WordPress warnings; consider reverting to$wpdb->get_results( $sql, ARRAY_A )in theelsebranch and only adjusting the PHPCS ignore annotations to satisfy the new sniff.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Calling `$wpdb->prepare( $sql )` when there are no placeholders in `$sql` is unnecessary and can itself trigger WordPress warnings; consider reverting to `$wpdb->get_results( $sql, ARRAY_A )` in the `else` branch and only adjusting the PHPCS ignore annotations to satisfy the new sniff.
## Individual Comments
### Comment 1
<location path="includes/class-sva-db.php" line_range="399" />
<code_context>
$rows = $wpdb->get_results( $wpdb->prepare( $sql, ...$values ), ARRAY_A ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching,WordPress.DB.PreparedSQL.NotPrepared,PluginCheck.Security.DirectDB.UnescapedDBParameter
} else {
- $rows = $wpdb->get_results( $sql, ARRAY_A ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching,WordPress.DB.PreparedSQL.NotPrepared,WordPress.DB.PreparedSQL.InterpolatedNotPrepared
+ $rows = $wpdb->get_results( $wpdb->prepare( $sql ), ARRAY_A ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching,WordPress.DB.PreparedSQL.NotPrepared,PluginCheck.Security.DirectDB.UnescapedDBParameter
}
</code_context>
<issue_to_address>
**issue (bug_risk):** Using `$wpdb->prepare( $sql )` with no placeholders will likely trigger `_doing_it_wrong` and return false, breaking the query.
For the empty `$values` branch, avoid calling `prepare()` with only `$sql`. Instead, keep `get_results( $sql, ARRAY_A )` (with the PHPCS ignore) or otherwise bypass `prepare()` when there are no placeholders, so the query runs reliably and matches `$wpdb`’s intended usage.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
|
🔍 WordPress Plugin Check Report
📊 Report
|
| 📍 Line | 🔖 Check | 💬 Message |
|---|---|---|
397 |
PluginCheck.Security.DirectDB.UnescapedDBParameter | Unescaped parameter $sql used in $wpdb->get_results()\n$sql assigned unsafely at line 394. |
🤖 Generated by WordPress Plugin Check Action • Learn more about Plugin Check



📑 Description
✅ Checks
☢️ Does this introduce a breaking change?
Summary by Sourcery
Bug Fixes: