Make WordPress Core

Opened 12 years ago

Closed 12 years ago

#21512 closed defect (bug) (fixed)

Notice undefined variable $user when posting comment without cookies set

Reported by: c3mdigital's profile c3mdigital Owned by: ryan's profile ryan
Milestone: 3.5 Priority: normal
Severity: normal Version:
Component: Comments Keywords: has-patch
Focuses: Cc:

Description

Just noticed this in 3.5 (21468).
Theme: Twentytweleve
No Plugins active

Notice: Undefined variable: user in /Users/chris/Sites/newpatch/wp-includes/comment.php on line 658
Call Stack
#	Time	Memory	Function	Location
1	0.0025	268152	{main}( )	../wp-comments-post.php:0
2	0.2503	15399872 wp_new_comment( )	../wp-comments-post.php:90
3	0.2522	15414424	 wp_allow_comment( )	../comment.php:1358

Which also causes multiple cannot modify headers warnings:

Warning: Cannot modify header information - headers already sent by (output started at /Users/chris/Sites/newpatch/wp-includes/comment.php:658) in /Users/chris/Sites/newpatch/wp-includes/comment.php on line 586
Call Stack
#	Time	Memory	Function	Location
1	0.0025	268152	{main}( )../wp-comments-post.php:0
2	0.3219	16238192	  do_action( )	../wp-comments-post.php:93
3	0.3219	16239784	  call_user_func_array ( )	../plugin.php:406
4	0.3219	16239816	  wp_set_comment_cookies( )	../plugin.php:406
5	0.3219	16240416	  setcookie ( )	../comment.php:586
Warning: Cannot modify header information - headers already sent by (output started at /Users/chris/Sites/newpatch/wp-includes/comment.php:658) in /Users/chris/Sites/newpatch/wp-includes/pluggable.php on line 884
Call Stack
#	Time	Memory	Function	Location
1	0.0025	268152	{main}( )	../wp-comments-post.php:0
2	0.3246	16239184	wp_safe_redirect( )	../wp-comments-post.php:98
3	0.3250	16239512	wp_redirect( )	../pluggable.php:931
4	0.3254	16251096	header ( )	../pluggable.php:884

Steps to reproduce:

  1. Update to latest version
  2. Clear cookies and logout or start a new private browsing session.
  3. Post comment

Wrapping the $user variable with isset() fixes the problem.

Attachments (1)

21512.patch (605 bytes) - added by c3mdigital 12 years ago.

Download all attachments as: .zip

Change History (5)

@c3mdigital
12 years ago

#1 @nacin
12 years ago

Looks good. It's meant to be a truth check, so ! empty() is proper.

#2 @nacin
12 years ago

  • Keywords dev-feedback removed
  • Milestone changed from Awaiting Review to 3.5

#3 @SergeyBiryukov
12 years ago

Introduced in [21413].

#4 @ryan
12 years ago

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

In [21506]:

Add isset() check to avoid notice. Props c3mdigital. fixes #21512

Note: See TracTickets for help on using tickets.