Make WordPress Core

Opened 14 years ago

Closed 14 years ago

#16977 closed defect (bug) (fixed)

PHP notice for undefined variable in wp_list_post_revisions()

Reported by: boonebgorges's profile boonebgorges Owned by:
Milestone: 3.2 Priority: normal
Severity: trivial Version: 3.1
Component: Revisions Keywords: has-patch
Focuses: Cc:

Description

I'm using wp_list_post_revisions() in a function, and noticed a bug related to $left_checked and $right_checked. Initial scenario/steps to reproduce:

1) Call wp_list_post_revisions(), within the loop, with the following arguments:

wp_list_post_revisions( get_the_ID(), array( 'format' => 'form-table' ) );

2) Load the page. Notice: Undefined variable: right_checked in /sites/yolanda/wp-includes/post-template.php on line 1369

The problem has to do with the fallback design of the form-table format. The logic at http://core.trac.wordpress.org/browser/trunk/wp-includes/post-template.php#L1365 is: if an explicit 'right' parameter is passed (the New revision), but no 'left' argument (the Old revision), the next oldest revision should be checked as tho Old revision. That's done by checking to see whether $right_checked was set on the previous iteration of the foreach loop. The problem is that, on the first iteration of the foreach loop, $right_checked hasn't been cast at all.

I'm marking the bug as trivial since it doesn't arise at all in WP core (where $left and $right arguments are always passed to the function). It's only an issue for edge-case plugins.

Patch attached.

Attachments (1)

16977.patch (426 bytes) - added by boonebgorges 14 years ago.

Download all attachments as: .zip

Change History (3)

@boonebgorges
14 years ago

#1 @nacin
14 years ago

  • Milestone changed from Awaiting Review to 3.2

Looks good.

#2 @nacin
14 years ago

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

(In [17564]) Initialize a variable. props boonebgorges, fixes #16977.

Note: See TracTickets for help on using tickets.