Make WordPress Core

Changeset 64072


Ignore:
Timestamp:
10/02/2026 11:29:44 PM (8 days ago)
Author:
SergeyBiryukov
Message:

Code Quality: Resolve variable.undefined errors in wp-mail.php and wp-trackback.php.

  1. src/wp-mail.php: Initialize $subject = ''; alongside the other per-message variables ($bodysignal, $boundary, $charset, etc.) before the foreach ( $message as $line ) loop. Without this, $subject is only assigned when a line matches /Subject: /i, so PHPStan correctly flags it as potentially undefined when the loop completes without a match.
  1. src/wp-trackback.php: Add global $wpdb, $posts; with @global docblocks in file scope. $wpdb is used four times (two prepare calls, one get_results, one insert_id) and $posts once ($posts[0]->ID), all reachable after require wp-load.php.
  1. tests/phpstan/baselines/variable.undefined.neon: Remove the three resolved suppression entries (6 errors total).

Developed in ​https://github.com/WordPress/wordpress-develop/pull/13880.

Follow-up to r51850, r53719.

Props therssoftware, mukesh27.
See #65817.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-mail.php

    r63914 r64072  
    8484
    8585        $bodysignal                = false;
    86         $boundary                  = '';
    8786        $charset                   = '';
    8887        $content                   = '';
    8988        $content_type              = '';
    9089        $content_transfer_encoding = '';
     90        $boundary                  = '';
     91        $subject                   = '';
    9192        $post_author               = 1;
    9293        $author_found              = false;
    93         $post_date                 = null;
    94         $post_date_gmt             = null;
     94        $post_date                 = '';
     95        $post_date_gmt             = '';
    9596
    9697        foreach ( $message as $line ) {
  • trunk/src/wp-trackback.php

    r62956 r64072  
    9292$blog_name = wp_slash( $blog_name );
    9393
     94/**
     95 * @global wpdb      $wpdb  WordPress database abstraction object.
     96 * @global WP_Post[] $posts Array of post objects.
     97 */
     98global $wpdb, $posts;
     99
    94100if ( is_single() || is_page() ) {
    95101        $post_id = $posts[0]->ID;
  • trunk/tests/phpstan/baselines/variable.undefined.neon

    r64046 r64072  
    910910                        path: ../../../src/wp-login.php
    911911                -
    912                         message: '#^Variable \$subject might not be defined\.$#'
    913                         identifier: variable.undefined
    914                         count: 1
    915                         path: ../../../src/wp-mail.php
    916                 -
    917912                        message: '#^Variable \$table_prefix might not be defined\.$#'
    918913                        identifier: variable.undefined
    … …  
    924919                        count: 1
    925920                        path: ../../../src/wp-settings.php
    926                 -
    927                         message: '#^Variable \$posts might not be defined\.$#'
    928                         identifier: variable.undefined
    929                         count: 1
    930                         path: ../../../src/wp-trackback.php
    931                 -
    932                         message: '#^Variable \$wpdb might not be defined\.$#'
    933                         identifier: variable.undefined
    934                         count: 4
    935                         path: ../../../src/wp-trackback.php
Note: See TracChangeset for help on using the changeset viewer.