Commit 945291bfb5 for wordpress.org
commit 945291bfb5c092044d1aba9d780839eaf5eeecde
Author: westonruter <westonruter@git.wordpress.org>
Date: Fri Oct 2 04:46:47 2026 +0000
Code Quality: Declare the `$wpdb` global in wp-admin scripts.
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 https://github.com/WordPress/wordpress-develop/pull/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
diff --git a/wp-admin/network/site-new.php b/wp-admin/network/site-new.php
index 4eafec5938..70316ab330 100644
--- a/wp-admin/network/site-new.php
+++ b/wp-admin/network/site-new.php
@@ -140,6 +140,11 @@ if ( isset( $_REQUEST['action'] ) && 'add-site' === $_REQUEST['action'] ) {
do_action( 'network_site_new_created_user', $user_id );
}
+ /**
+ * @global wpdb $wpdb WordPress database abstraction object.
+ */
+ global $wpdb;
+
$wpdb->hide_errors();
$id = wpmu_create_blog( $newdomain, $path, $title, $user_id, $meta, get_current_network_id() );
$wpdb->show_errors();
diff --git a/wp-admin/options.php b/wp-admin/options.php
index b45cbb0038..9413eb3b1a 100644
--- a/wp-admin/options.php
+++ b/wp-admin/options.php
@@ -396,6 +396,11 @@ require_once ABSPATH . 'wp-admin/admin-header.php';
<input type="hidden" name="option_page" value="options" />
<table class="form-table" role="presentation">
<?php
+/**
+ * @global wpdb $wpdb WordPress database abstraction object.
+ */
+global $wpdb;
+
$options = $wpdb->get_results( "SELECT * FROM $wpdb->options ORDER BY option_name" );
foreach ( (array) $options as $option ) :
diff --git a/wp-admin/upload.php b/wp-admin/upload.php
index 7cf0f6fe10..3c30e2eb4d 100644
--- a/wp-admin/upload.php
+++ b/wp-admin/upload.php
@@ -262,6 +262,11 @@ if ( $doaction ) {
$post_ids = array();
if ( 'delete_all' === $doaction ) {
+ /**
+ * @global wpdb $wpdb WordPress database abstraction object.
+ */
+ global $wpdb;
+
$post_ids = $wpdb->get_col( "SELECT ID FROM $wpdb->posts WHERE post_type='attachment' AND post_status = 'trash'" );
$doaction = 'delete';
} elseif ( isset( $_REQUEST['media'] ) ) {
diff --git a/wp-admin/user-edit.php b/wp-admin/user-edit.php
index 8055de6b36..9a31f13e58 100644
--- a/wp-admin/user-edit.php
+++ b/wp-admin/user-edit.php
@@ -104,6 +104,11 @@ if ( is_multisite()
wp_die( __( 'Sorry, you are not allowed to edit this user.' ) );
}
+/**
+ * @global wpdb $wpdb WordPress database abstraction object.
+ */
+global $wpdb;
+
// Execute confirmed email change. See send_confirmation_on_profile_email().
if ( IS_PROFILE_PAGE && isset( $_GET['newuseremail'] ) && $current_user->ID ) {
$new_email = get_user_meta( $current_user->ID, '_new_email', true );
diff --git a/wp-admin/user-new.php b/wp-admin/user-new.php
index 453a0de54f..73d74aa6db 100644
--- a/wp-admin/user-new.php
+++ b/wp-admin/user-new.php
@@ -240,6 +240,11 @@ Please click the following link to confirm the invite:
);
if ( isset( $_POST['noconfirmation'] ) && current_user_can( 'manage_network_users' ) ) {
+ /**
+ * @global wpdb $wpdb WordPress database abstraction object.
+ */
+ global $wpdb;
+
$key = $wpdb->get_var( $wpdb->prepare( "SELECT activation_key FROM {$wpdb->signups} WHERE user_login = %s AND user_email = %s", $new_user_login, $new_user_email ) );
$new_user = wpmu_activate_signup( $key );
if ( is_wp_error( $new_user ) ) {
diff --git a/wp-includes/version.php b/wp-includes/version.php
index d3d368c238..40168f8f47 100644
--- a/wp-includes/version.php
+++ b/wp-includes/version.php
@@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
-$wp_version = '7.2-alpha-64045';
+$wp_version = '7.2-alpha-64046';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.