Skip to content

Commit e504c71

Browse files
committed
Code Modernization: Fix instances of using null as an array offset.
This avoids using multisite-specific tables and columns in `WP_Date_Query::validate_column()` when on a non-multisite install. Attempting to use `$wpdb->blogs` as an array index when `null` on a non-multisite install causes a deprecation notice in PHP 8.5. This also updates the multisite table alias in `wpdb` to make it clear they could be `null`. Developed in #10498 Follow-up to [60904], [60809], [37477]. Props westonruter, desrosj. See #63061. Fixes #63957. git-svn-id: https://develop.svn.wordpress.org/trunk@61191 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 328ab83 commit e504c71

File tree

2 files changed

+30
-19
lines changed

2 files changed

+30
-19
lines changed

src/wp-includes/class-wp-date-query.php

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -482,17 +482,25 @@ public function validate_column( $column ) {
482482
global $wpdb;
483483

484484
$valid_columns = array(
485-
'post_date',
486-
'post_date_gmt',
487-
'post_modified',
488-
'post_modified_gmt',
489-
'comment_date',
490-
'comment_date_gmt',
491-
'user_registered',
492-
'registered',
493-
'last_updated',
485+
'post_date', // Part of $wpdb->posts.
486+
'post_date_gmt', // Part of $wpdb->posts.
487+
'post_modified', // Part of $wpdb->posts.
488+
'post_modified_gmt', // Part of $wpdb->posts.
489+
'comment_date', // Part of $wpdb->comments.
490+
'comment_date_gmt', // Part of $wpdb->comments.
491+
'user_registered', // Part of $wpdb->users.
494492
);
495493

494+
if ( is_multisite() ) {
495+
$valid_columns = array_merge(
496+
$valid_columns,
497+
array(
498+
'registered', // Part of $wpdb->blogs.
499+
'last_updated', // Part of $wpdb->blogs.
500+
)
501+
);
502+
}
503+
496504
// Attempt to detect a table prefix.
497505
if ( ! str_contains( $column, '.' ) ) {
498506
/**
@@ -525,11 +533,14 @@ public function validate_column( $column ) {
525533
$wpdb->users => array(
526534
'user_registered',
527535
),
528-
$wpdb->blogs => array(
536+
);
537+
538+
if ( is_multisite() ) {
539+
$known_columns[ $wpdb->blogs ] = array(
529540
'registered',
530541
'last_updated',
531-
),
532-
);
542+
);
543+
}
533544

534545
// If it's a known column name, add the appropriate table prefix.
535546
foreach ( $known_columns as $table_name => $table_columns ) {

src/wp-includes/class-wpdb.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ class wpdb {
467467
*
468468
* @since 3.0.0
469469
*
470-
* @var string
470+
* @var string|null
471471
*/
472472
public $blogs;
473473

@@ -476,7 +476,7 @@ class wpdb {
476476
*
477477
* @since 5.1.0
478478
*
479-
* @var string
479+
* @var string|null
480480
*/
481481
public $blogmeta;
482482

@@ -485,7 +485,7 @@ class wpdb {
485485
*
486486
* @since 3.0.0
487487
*
488-
* @var string
488+
* @var string|null
489489
*/
490490
public $registration_log;
491491

@@ -494,7 +494,7 @@ class wpdb {
494494
*
495495
* @since 3.0.0
496496
*
497-
* @var string
497+
* @var string|null
498498
*/
499499
public $signups;
500500

@@ -503,7 +503,7 @@ class wpdb {
503503
*
504504
* @since 3.0.0
505505
*
506-
* @var string
506+
* @var string|null
507507
*/
508508
public $site;
509509

@@ -512,7 +512,7 @@ class wpdb {
512512
*
513513
* @since 3.0.0
514514
*
515-
* @var string
515+
* @var string|null
516516
*/
517517
public $sitecategories;
518518

@@ -521,7 +521,7 @@ class wpdb {
521521
*
522522
* @since 3.0.0
523523
*
524-
* @var string
524+
* @var string|null
525525
*/
526526
public $sitemeta;
527527

0 commit comments

Comments
 (0)