Make WordPress Core


Ignore:
Timestamp:
11/10/2025 08:26:46 PM (9 months ago)
Author:
westonruter
Message:

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 https://github.com/WordPress/wordpress-develop/pull/10498

Follow-up to [60904], [60809], [37477].

Props westonruter, desrosj.
See #63061.
Fixes #63957.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-date-query.php

    r59465 r61191  
    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',
    494                 );
     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.
     492                );
     493
     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                }
    495503
    496504                // Attempt to detect a table prefix.
     
    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.
Note: See TracChangeset for help on using the changeset viewer.