Repository navigation
Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
mukeshpanchal27
left a comment
There was a problem hiding this comment.
Thanks @robelsust for the PR!
Changes look good to me.
The `$wpdb` global is now explicitly declared, along with a `@global` tag, in `network/site-new.php`, `options.php`, `upload.php`, `user-edit.php` and `user-new.php`. Each declaration is placed just before the first use, in the narrowest block containing all uses. These scripts run at the top level after the admin bootstrap, so there is no change in behavior. The declarations let static analysis see that the variable is defined, resolving 21 `variable.undefined` errors from the PHPStan baseline. Developed in #13886. Follow-up to r63019, r64044. Props therssoftware, mukesh27. See #65817. git-svn-id: https://develop.svn.wordpress.org/trunk@64046 602fd350-edb4-49c9-b593-d223f7449a82
The `$wpdb` global is now explicitly declared, along with a `@global` tag, in `network/site-new.php`, `options.php`, `upload.php`, `user-edit.php` and `user-new.php`. Each declaration is placed just before the first use, in the narrowest block containing all uses. These scripts run at the top level after the admin bootstrap, so there is no change in behavior. The declarations let static analysis see that the variable is defined, resolving 21 `variable.undefined` errors from the PHPStan baseline. Developed in WordPress/wordpress-develop#13886. Follow-up to r63019, r64044. Props therssoftware, mukesh27. See #65817. Built from https://develop.svn.wordpress.org/trunk@64046 git-svn-id: http://core.svn.wordpress.org/trunk@63205 1a063a9b-81f0-0310-95a4-ce76da25c4cd
✅ Committed in r64046 (fee6a84).
Trac ticket: https://core.trac.wordpress.org/ticket/65817
Declares the
$wpdbglobal in fivewp-adminscripts where PHPStan reportsvariable.undefinederrors. All five files use$wpdbat file scope after bootstrapping viarequire admin.php→wp-load.php→wp-settings.php, which sets$GLOBALS['wpdb']. The variables are valid at runtime; the errors are static-analysis artifacts of file-level scoping acrossrequireboundaries.$wpdbusagesnetwork/site-new.phphide_errors(),show_errors()options.phpget_results()+ property accessupload.phpget_col()+ property accessuser-edit.phpget_var(),query(),prepare()(×2 blocks)user-new.phpget_var(),prepare()Changes
Each file receives a
global $wpdb;declaration with a@globaldocblock, placed immediately before the first$wpdbusage in scope:src/wp-admin/network/site-new.php: Before$wpdb->hide_errors()(line 143), inside the form submission handler.src/wp-admin/options.php: Before$wpdb->get_results()(line 399), inside the<?phpblock that renders the options table.src/wp-admin/upload.php: Before$wpdb->get_col()(line 265), inside thedelete_allbranch of the bulk action handler.src/wp-admin/user-edit.php: Before the email-change confirmation block (line 108), at file scope to cover both$wpdbusage sites (lines 114 and 170).src/wp-admin/user-new.php: Before$wpdb->get_var()(line 243), inside the no-confirmation signup activation branch.Background
All five files load
$wpdbthrough the standard admin bootstrap:require admin.php→wp-load.php→wp-settings.php, where$GLOBALS['wpdb']is instantiated. None of these files have ever declaredglobal $wpdb;at file scope, because the variable is already available via$GLOBALS. PHPStan cannot trace globals injected throughrequire, so each usage appears undefined.The
$wpdbusages in these files have been present for many years:network/site-new.php:$wpdb->hide_errors()/show_errors()aroundwpmu_create_blog()since the network admin was introduced.options.php:$wpdb->get_results()for the "All Options" screen since the earliest revisions.upload.php:$wpdb->get_col()for emptying the media trash, added in r11863.user-edit.php: Multisite signup table updates, added in r21923.user-new.php: Activation key lookup for no-confirmation signups, added in r21511.Testing instructions
trunk,npm run typecheck:phpreports[OK] No errors, because all five entries are baselined.$wpdbentries for these files fromtests/phpstan/baselines/variable.undefined.neonwithout applying the source changes, then run again. PHPStan reportsVariable $wpdb might not be defined.in each file.npm run typecheck:phpreports[OK] No errorswith all five baseline entries removed and no new errors elsewhere.composer lintis clean on all five changed files.composer phpstan:baselines -- --identifier=variable.undefined, not edited by hand.Use of AI Tools
AI assistance: Yes
Tool(s): Antigravity IDE
Model(s): Claude Opus 4
Used for: Identifying the five
$wpdbentries in the PHPStan baseline, verifying each file's bootstrap chain, and drafting this description. The source changes, baseline regeneration, and verification against PHPStan and PHPCS were reviewed and confirmed by me in a local development environment.