Skip to content

Commit d1b25df

Browse files
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. 2. **`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`. 3. **`tests/phpstan/baselines/variable.undefined.neon`**: Remove the three resolved suppression entries (6 errors total). Developed in WordPress#13880. Follow-up to r51850, r53719. Props therssoftware, mukesh27. See #65817. git-svn-id: https://develop.svn.wordpress.org/trunk@64072 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 774837f commit d1b25df

3 files changed

Lines changed: 10 additions & 18 deletions

File tree

‎src/wp-mail.php‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,16 @@
8383
$message = $pop3->get( $i );
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 ) {
9798
// Body signal.

‎src/wp-trackback.php‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,12 @@ function trackback_response( $error = 0, $error_message = '' ) {
9191
$excerpt = wp_slash( $excerpt );
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+
*/
98+
global $wpdb, $posts;
99+
94100
if ( is_single() || is_page() ) {
95101
$post_id = $posts[0]->ID;
96102
}

‎tests/phpstan/baselines/variable.undefined.neon‎

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -908,11 +908,6 @@ parameters:
908908
identifier: variable.undefined
909909
count: 2
910910
path: ../../../src/wp-login.php
911-
-
912-
message: '#^Variable \$subject might not be defined\.$#'
913-
identifier: variable.undefined
914-
count: 1
915-
path: ../../../src/wp-mail.php
916911
-
917912
message: '#^Variable \$table_prefix might not be defined\.$#'
918913
identifier: variable.undefined
@@ -923,13 +918,3 @@ parameters:
923918
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

0 commit comments

Comments
 (0)