Make WordPress Core

Opened 9 years ago

Closed 3 years ago

Last modified 3 years ago

#31249 closed defect (bug) (fixed)

PHP notice when viewing autosave

Reported by: iseulde's profile iseulde Owned by: adamsilverstein's profile adamsilverstein
Milestone: 5.7 Priority: normal
Severity: normal Version:
Component: Revisions Keywords: has-patch commit
Focuses: Cc:


Notice: Undefined offset: 2 in wp-admin/includes/revision.php on line 223

This happens when you view an autosave without any previous revisions and the original author's role is not author anymore.

Attachments (1)

31249.diff (785 bytes) - added by adamsilverstein 3 years ago.

Download all attachments as: .zip

Change History (11)

#1 @adamsilverstein
9 years ago

  • Owner set to adamsilverstein
  • Status changed from new to assigned

@iseulde Thanks for the bug report!

I will look into this, can you clarify the steps to reproduce? is this right?

  • Open an existing post without previous revisions (the default hello post, or can you also create a new post?)
  • ensure autosave fires
  • change role to contributor
  • edit the post and go to revisions screen

#2 @iseulde
9 years ago

Those sound like good steps to reproduce the issue. This happened to me when I imported the theme unit test data. A post was autosaved (no revisions) and when I came back later and clicked on "view autosave", I save the notice. Very minor issue I guess.

#3 @adamsilverstein
9 years ago

Ok, thanks. Will investigate.

Revisions incorrectly makes the assumption that there is always a saved revision, which is true when creating new posts, but false after an import or on a new install (sample posts).

Related #29044

#4 @adamsilverstein
4 years ago

  • Milestone set to 5.7

This ticket was mentioned in PR #953 on WordPress/wordpress-develop by adamsilverstein.

3 years ago

  • Keywords has-patch added; needs-patch removed

#7 @adamsilverstein
3 years ago

This is still reproducible and was also reported to me by another user.

It can easily happen when you:

  • import posts into WordPress (for example the test data @iseulde mentioned) and then
  • trigger an autosave by making a small edit and waiting until the autosave triggers, then
  • Reload the post and click the link to "View the Autosave".

Because the post is imported, the expected "initial" post revision is missing. Revisions takes care of this, but a bug meant the "author" it tried to use did not exist. We can just use the revision author here instead.

31249.diff fixes the issue.

Before this fix, I also saw a JavaScript error viewing these autosaves, after the fix the screen worked as expected.

#8 @adamsilverstein
3 years ago

  • Keywords commit added

#9 @adamsilverstein
3 years ago

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

In 50128:

Revisions: Address PHP/JS errors when viewing autosave on imported posts.

Fix an issue where viewing an autosave created on a post without any previous revisions would throw a PHP notice. Also fixes the revision screen which was broken in these cases and showed a console error.

Props iseulde.
Fixes #31249.

Note: See TracTickets for help on using tickets.