WordPress.org

Make WordPress Core

#51263 closed defect (bug) (fixed)

PHP warning when editing comments in the administration comment edit screen

Reported by: regan.khadgi Owned by: SergeyBiryukov
Milestone: 5.5.2 Priority: normal
Severity: normal Version: 5.5
Component: Comments Keywords: has-screenshots commit fixed-major
Focuses: administration Cc:

Description

When I tried to edit any comment in the administration comment edit screen, I get two php warnings like below in my debug.log file

[07-Sep-2020 18:03:22 UTC] PHP Notice: Undefined index: c in D:\xampp\htdocs\free-plugins\wp-admin\comment.php on line 39
[07-Sep-2020 18:03:22 UTC] PHP Notice: Trying to get property 'comment_post_ID' of non-object in D:\xampp\htdocs\free-plugins\wp-admin\comment.php on line 43

I haven't enabled any plugins and my site is running default Twenty Twenty theme. I had tried with multiple WP installation including a fresh installation and error showed up on all installations. I have also included the links to the screenshot which shall make the issue more clear.

http://prntscr.com/ud79k9
http://prntscr.com/ud79c7

Change History (11)

#1 @SergeyBiryukov
13 months ago

  • Component changed from General to Comments
  • Keywords reporter-feedback added

Hi there, welcome to WordPress Trac! Thanks for the report.

Just noting that I could not reproduce the issue on a clean install.

What does the URL look like when you're editing a comment? It should look like this:

/wp-admin/comment.php?action=editcomment&c=123

where 123 is the ID of the comment being edited.

#2 @regan.khadgi
13 months ago

Hi there,

Thank you for the reply. Yes the URl looks like

comment.php?action=editcomment&c=2

The error doesn't show up on the screen itself but shows up on updating the comment when debug mode is set to true in wp-config.php file. Last day I checked in my localhost but today I checked in site hosted in hostgators and the error showed up in different installations in live servers too. So that's a bit strange that error is not being replicated.

http://prntscr.com/ude1ep

Last edited 13 months ago by regan.khadgi (previous) (diff)

#3 @regan.khadgi
13 months ago

Hello there,

I just debugged a bit more and it seems there is some issue with $_GET and $_POST. When I inspected in the comment edit form there is a input type hidden field with name as c which shall be addressed as

$_POST['c']

on the receiving end but when I checked in the comment.php file in exact line number then it is being addressed as

$_GET['c']

without checking isset or empty condition.

Please check these screenshot.
https://prntscr.com/udeaqu
http://prntscr.com/udecmn

So probable solution might be using $_REQUEST instead of $_GET or $_POST as since same screen is being used to submit and display the comment edit form.

#4 @SergeyBiryukov
13 months ago

  • Keywords reporter-feedback removed
  • Milestone changed from Awaiting Review to 5.5.2

Indeed, I was able to reproduce the issue now. Thanks!

It happens when submitting the Edit Comment form, not when opening the page, as I originally thought.

Moving to 5.5.2 for investigation.

Last edited 13 months ago by SergeyBiryukov (previous) (diff)

#5 @SergeyBiryukov
13 months ago

  • Version changed from 5.5.1 to 5.5

Introduced in [48050] / #37826.

#6 @SergeyBiryukov
13 months ago

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

#7 @SergeyBiryukov
13 months ago

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

In 48958:

Comments: Check if a valid comment ID was passed when editing a comment.

This avoids a PHP notice after submitting the Edit Comment form.

Props regan.khadgi.
Fixes #51263.

#8 @SergeyBiryukov
13 months ago

  • Keywords commit fixed-major added
  • Resolution fixed deleted
  • Status changed from closed to reopened

Reopening for backporting to the 5.5 branch.

#9 @regan.khadgi
13 months ago

I am glad that the issue has been reproduced and I could also see it has already been patched :) Waiting for the new version :)

#10 @SergeyBiryukov
13 months ago

Thanks again for the report :)

#11 @SergeyBiryukov
13 months ago

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

In 48959:

Comments: Check if a valid comment ID was passed when editing a comment.

This avoids a PHP notice after submitting the Edit Comment form.

Follow-up to [48050].

Props regan.khadgi.
Merges [48958] to the 5.5 branch.
Fixes #51263.

Note: See TracTickets for help on using tickets.