Code Quality: Declare WP globals and initialize variables for PHPStan level 1#11979
Code Quality: Declare WP globals and initialize variables for PHPStan level 1#11979huzaifaalmesbah wants to merge 1 commit into
Conversation
…atisfy PHPStan level 1. Add `@global` docblocks and `global` declarations in `wp-admin/plugins.php`, `wp-admin/users.php`, and `wp-admin/user-edit.php` so variables provided by `WP_Plugins_List_Table`, `WP_Users_List_Table`, `$wpdb`, `$current_user`, `$wp_roles`, `$_wp_admin_css_colors`, and related core globals are visible to static analysis. Initialize `$redirect` in `wp-admin/users.php` for the empty request branch. In `wp-includes/user.php`, initialize `$user_id` and `$old_user_data` at the top of `wp_insert_user()`, and `$manage_url` in `_wp_privacy_send_request_confirmation_notification()` so they are always defined regardless of branch. Also fix a latent bug in `wp-admin/user-edit.php` where the multisite signup email update used a bare `$user_login` variable that was never defined; it should reference `$user->user_login`.
|
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. |
Resolves PHPStan level 1
variable.undefinederrors in four user/plugin admin files (98 of 564 project-wide level-1 errors). The project's enforced level (0) continues to pass.@globaldocblocks +globalstatements for core globals ($wpdb,$current_user,$wp_roles,$_wp_admin_css_colors,$status,$page,$plugins,$user_ID,$usersearch,$blog_id).$redirectinwp-admin/users.phpfor theempty( $_REQUEST )branch.$user_id,$old_user_dataat the top ofwp_insert_user()and$manage_urlin_wp_privacy_send_request_confirmation_notification()so they're always defined.wp-admin/user-edit.php:166referenced an undefined$user_loginin the multisite signup-email update query; corrected to$user->user_login.Files changed
src/wp-admin/plugins.phpsrc/wp-admin/users.phpsrc/wp-admin/user-edit.phpsrc/wp-includes/user.phpVerification
Expected: [OK] No errors
Trac ticket: https://core.trac.wordpress.org/ticket/64898