Make WordPress Core

Changeset 61191


Ignore:
Timestamp:
11/10/2025 08:26:46 PM (3 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.

Location:
trunk/src/wp-includes
Files:
2 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.
  • trunk/src/wp-includes/class-wpdb.php

    r61102 r61191  
    468468     * @since 3.0.0
    469469     *
    470      * @var string
     470     * @var string|null
    471471     */
    472472    public $blogs;
     
    477477     * @since 5.1.0
    478478     *
    479      * @var string
     479     * @var string|null
    480480     */
    481481    public $blogmeta;
     
    486486     * @since 3.0.0
    487487     *
    488      * @var string
     488     * @var string|null
    489489     */
    490490    public $registration_log;
     
    495495     * @since 3.0.0
    496496     *
    497      * @var string
     497     * @var string|null
    498498     */
    499499    public $signups;
     
    504504     * @since 3.0.0
    505505     *
    506      * @var string
     506     * @var string|null
    507507     */
    508508    public $site;
     
    513513     * @since 3.0.0
    514514     *
    515      * @var string
     515     * @var string|null
    516516     */
    517517    public $sitecategories;
     
    522522     * @since 3.0.0
    523523     *
    524      * @var string
     524     * @var string|null
    525525     */
    526526    public $sitemeta;
Note: See TracChangeset for help on using the changeset viewer.