Make WordPress Core

Opened 7 hours ago

Closed 4 hours ago

#64223 closed defect (bug) (fixed)

Undefined variable $comments_count

Reported by: zagna's profile zagna Owned by: westonruter's profile westonruter
Milestone: 6.9 Priority: normal
Severity: normal Version: trunk
Component: Comments Keywords: has-patch
Focuses: Cc:

Description

In function wp_dashboard_recent_comments if the foreach always goes to the continue, $comments_count is never set and gives a warning.

<?php
add_filter( 'register_post_post_type_args', function($args, $post_type) {
        $args['map_meta_cap'] = false;
        return $args;
}, 10, 2);

Adding this to twentytwentyfive functions.php for a quick reproduction on a fresh 6.9b4

Attachments (2)

phpstorm-static-anslysis.png (159.3 KB) - added by westonruter 5 hours ago.
phpstan-static-analysis.png (111.2 KB) - added by westonruter 5 hours ago.

Download all attachments as: .zip

Change History (7)

#1 @westonruter
5 hours ago

  • Keywords needs-patch added
  • Milestone changed from Awaiting Review to 6.9

This issue is flagged by PhpStorm's static analysis as well, see phpstorm-static-anslysis.png.

Here is the problematic code: https://github.com/WordPress/wordpress-develop/blob/328ab83beb153ffa6d5378b26bb4ef2ceee49c47/src/wp-admin/includes/dashboard.php#L1077-L1103

It seems a very simply fix, to just add before the do/while loop:

<?php
$comments_count = 0;

This issue appears to have been introduced in r60643 to fix #56499.

This ticket was mentioned in PR #10497 on WordPress/wordpress-develop by @westonruter.


5 hours ago
#2

  • Keywords has-patch added; needs-patch removed

#3 @westonruter
5 hours ago

  • Owner set to westonruter
  • Status changed from new to accepted

#4 @westonruter
5 hours ago

This issue is also detected by PHPStan: phpstan-static-analysis.png.

See #61175. /cc @justlevine

#5 @westonruter
4 hours ago

  • Resolution set to fixed
  • Status changed from accepted to closed

In 61192:

Coding Standards: Initialize $comments_count before loop in case not set during initial iteration.

Follow-up to [60643].

Props westonruter, mindctrl.
See #56499.
Fixes #64223.

Note: See TracTickets for help on using tickets.