Skip to content

Commit 9d9dd59

Browse files
Code Quality: Fix PHPStan undefined variables using isset/empty checks
1 parent 30d971c commit 9d9dd59

2 files changed

Lines changed: 11 additions & 11 deletions

File tree

src/wp-includes/ms-settings.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,8 @@
3333
* Use `get_current_network_id()` instead.
3434
* @global bool $public Deprecated. Whether the site found on load is public.
3535
* Use `get_site()->public` instead.
36-
* @global string $table_prefix Database table prefix.
37-
* @global wpdb $wpdb WordPress database abstraction object.
3836
*/
39-
global $current_site, $current_blog, $domain, $path, $site_id, $public, $table_prefix, $wpdb;
37+
global $current_site, $current_blog, $domain, $path, $site_id, $public;
4038

4139
/** WP_Network class */
4240
require_once ABSPATH . WPINC . '/class-wp-network.php';
@@ -101,9 +99,13 @@
10199
wp_load_core_site_options( $site_id );
102100
}
103101

104-
$wpdb->set_prefix( $table_prefix, false ); // $table_prefix can be set in sunrise.php.
105-
$wpdb->set_blog_id( $current_blog->blog_id, $current_blog->site_id );
106-
$table_prefix = $wpdb->get_blog_prefix();
102+
if ( isset( $wpdb ) ) {
103+
if ( isset( $table_prefix ) ) {
104+
$wpdb->set_prefix( $table_prefix, false ); // $table_prefix can be set in sunrise.php.
105+
}
106+
$wpdb->set_blog_id( $current_blog->blog_id, $current_blog->site_id );
107+
$table_prefix = $wpdb->get_blog_prefix();
108+
}
107109
$_wp_switched_stack = array();
108110
$switched = false;
109111

src/wp-settings.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,8 @@
2929
* @global string[] $required_php_extensions The names of required PHP extensions.
3030
* @global string $required_mysql_version The minimum required MySQL version string.
3131
* @global string $wp_local_package Locale code of the package.
32-
* @global array $wp_filter WordPress filter hooks.
33-
* @global string $table_prefix Database table prefix.
3432
*/
35-
global $wp_version, $wp_db_version, $tinymce_version, $required_php_version, $required_php_extensions, $required_mysql_version, $wp_local_package, $wp_filter, $table_prefix;
33+
global $wp_version, $wp_db_version, $tinymce_version, $required_php_version, $required_php_extensions, $required_mysql_version, $wp_local_package;
3634
require ABSPATH . WPINC . '/version.php';
3735
require ABSPATH . WPINC . '/compat-utf8.php';
3836
require ABSPATH . WPINC . '/compat.php';
@@ -102,7 +100,7 @@
102100
include WP_CONTENT_DIR . '/advanced-cache.php';
103101

104102
// Re-initialize any hooks added manually by advanced-cache.php.
105-
if ( $wp_filter ) {
103+
if ( ! empty( $wp_filter ) ) {
106104
$wp_filter = WP_Hook::build_preinitialized_hooks( $wp_filter );
107105
}
108106
}
@@ -142,7 +140,7 @@
142140
*
143141
* @global string $table_prefix The database table prefix.
144142
*/
145-
if ( ! isset( $GLOBALS['table_prefix'] ) ) {
143+
if ( ! isset( $GLOBALS['table_prefix'] ) && isset( $table_prefix ) ) {
146144
$GLOBALS['table_prefix'] = $table_prefix;
147145
}
148146

0 commit comments

Comments
 (0)