-
Notifications
You must be signed in to change notification settings - Fork 0
Description
π Analysis Verification
Issue 1: includes/class-wwlc-user-account.php:49 - DB Query in Constructor
Your analysis is: β PARTIALLY ACCURATE
What the code does:
// Line 49 in constructor
$this->total_unmoderated_users = $this->get_total_unmoderated_users();
// Lines 1080-1090
public function get_total_unmoderated_users() {
return count(
get_users(
array(
'fields' => array( 'ID' ),
'role' => WWLC_UNMODERATED_ROLE,
)
)
);
}Execution path:
- Plugin bootstrap runs on
after_setup_themehook (very early - runs on every page load) WooCommerce_Wholesale_Lead_Capture::instance()is called (line 48 in bootstrap)- Main plugin constructor runs β instantiates
WWLC_User_Account::instance()(line 93) WWLC_User_Accountconstructor runs β callsget_total_unmoderated_users()β DB QUERY
Severity Assessment:
| Factor | Value |
|---|---|
| Runs on every page load? | β Yes (frontend + backend) |
| Query type | get_users() with role filter |
| Cached? | β No explicit caching |
| Bounded? |
Verdict: TRUE PERFORMANCE ISSUE
The get_users() call happens on every page load. While WordPress internally optimizes get_users() somewhat, this is:
- Running on frontend pages where the count is never displayed
- Unbounded - could be slow if there are many unmoderated users
- The value
total_unmoderated_usersis only used for admin menu bubble notification
Recommended fix:
// Lazy-load: Only query when actually needed
public function get_total_unmoderated_users() {
if ( ! is_admin() ) {
return 0; // Don't query on frontend
}
// ... existing query
}Issue 2: includes/class-wwlc-shortcode.php lines 376 and 402 - Direct SQL Queries
Your analysis is:
What the code does:
// Lines 369-385 (wwlc_registration_form_loaded)
// Lines 395-411 (wwlc_login_form_loaded)
public function wwlc_registration_form_loaded() {
if ( is_plugin_active( 'page-builder-add/page-builder-add.php' ) ) {
global $wpdb;
$ulpb_front_page_id = $wpdb->get_row( "SELECT pm.post_id FROM..." );
// ...
}
}When are these methods called?
Looking at lines 120 and 189, these methods are called from:
// Line 120 - inside wwlc_login_form shortcode
if ( $this->wwlc_login_form_loaded() && ! is_product() ) { return; }
// Line 189 - inside wwlc_registration_form shortcode
if ( $this->wwlc_registration_form_loaded() && ! is_product() ) { return; }Key findings:
- These are NOT called on every page load
- They are only called when the shortcode is rendered (
[wwlc_login_form]or[wwlc_registration_form]) - The SQL query only runs if Landing Page Builder plugin is active (
is_plugin_active()check)
Severity Assessment:
| Factor | Value |
|---|---|
| Runs on every page load? | β No - only on pages with WWLC shortcodes |
| Guard present? | β
Yes - is_plugin_active() check |
| Query type | Direct $wpdb->get_row() - not using $wpdb->prepare() |
| SQL Injection risk? | β No - no user input in query |
Verdict: NOT A MAJOR PERFORMANCE ISSUE β
However, there are minor issues:
- DRY violation - Same SQL query duplicated in two methods (lines 376 and 402)
- Missing prepare() - While safe (no user input), best practice is to use
$wpdb->prepare() - Could be cached - The result could be cached with transients
π Summary
| Issue | Claimed | Actual | Severity |
|---|---|---|---|
class-wwlc-user-account.php:49 |
DB query every page load | β TRUE | HIGH - runs on every page (frontend + backend) |
class-wwlc-shortcode.php:376,402 |
SQL every page load | β FALSE | LOW - only runs when shortcode is rendered AND only if Landing Page Builder plugin is active |
The first issue is a real performance concern that should be fixed. The second issue is not as described - those queries are guarded by both shortcode rendering context AND plugin activation check.
Would you like me to add these findings to a project document or create detection patterns for these issues?