Skip to content

WPDBTrait::is_wpdb_method_call(): fix false positives for static method calls to non-global classes called wpdb#2753

Merged
jrfnl merged 2 commits into
developfrom
fix/2710-wpdb-static-non-global
Jul 9, 2026
Merged

WPDBTrait::is_wpdb_method_call(): fix false positives for static method calls to non-global classes called wpdb#2753
jrfnl merged 2 commits into
developfrom
fix/2710-wpdb-static-non-global

Conversation

@rodrigoprimo

Copy link
Copy Markdown
Contributor

Description

The WordPress.DB.PreparedSQL and WordPress.DB.PreparedSQLPlaceholders sniffs were producing false positives for static method calls to a class named wpdb that is preceded by a namespace (e.g. MyNamespace\wpdb::prepare()). The root cause was in WPDBTrait::is_wpdb_method_call(), which did not check whether the wpdb token was namespaced before treating it as a call to the global wpdb class.

The fix makes the method return false when the wpdb token is a namespaced call to a non-global wpdb class, so these calls are no longer mistaken for the global wpdb object.

Suggested changelog entry

WordPress.DB.PreparedSQL and WordPress.DB.PreparedSQLPlaceholders: fixed a false positive for static method calls to a non-global class named wpdb.

Related issues/external references

Fixes #2710

@jrfnl jrfnl added this to the 3.4.0 milestone Jul 8, 2026

@jrfnl jrfnl left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks @rodrigoprimo. I left one nitpick comment, but not a blocker.

Comment thread WordPress/Tests/DB/PreparedSQLPlaceholdersUnitTest.inc Outdated
@rodrigoprimo rodrigoprimo force-pushed the fix/2710-wpdb-static-non-global branch from 1e8eb9a to c0c3e9d Compare July 9, 2026 12:10
@rodrigoprimo

Copy link
Copy Markdown
Contributor Author

Thanks for your review, @jrfnl! I have applied your suggestion.

…od calls to non-global classes called wpdb

The `DB/PreparedSQL` and `DB/PreparedSQLPlaceholders` sniffs were producing false positives for static method calls to a class named `wpdb` that is preceded by a namespace. The root cause was in `WPDBTrait::is_wpdb_method_call()`, which did not check whether the `wpdb` token was namespaced before treating it as a call to the global `wpdb` class.

The fix makes the method return `false` when the `wpdb` token is a namespaced call to a non-global `wpdb` class.

Fixes 2710
@jrfnl jrfnl force-pushed the fix/2710-wpdb-static-non-global branch from c0c3e9d to e1e2260 Compare July 9, 2026 12:50
@jrfnl

jrfnl commented Jul 9, 2026

Copy link
Copy Markdown
Member

Thanks @rodrigoprimo I've squashed the third commit into the second now and will merge once the build has passed.

@jrfnl jrfnl enabled auto-merge July 9, 2026 12:51
@jrfnl jrfnl merged commit 81704c7 into develop Jul 9, 2026
42 checks passed
@jrfnl jrfnl deleted the fix/2710-wpdb-static-non-global branch July 9, 2026 13:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DB/PreparedSQL and DB/PreparedSQLPlaceholders: false positive for static method calls to non-global classes named wpdb

3 participants