WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 4 years ago

#12859 closed defect (bug) (fixed)

Preview new, blank page/post creates broken preview

Reported by: duck_ Owned by:
Milestone: 3.0 Priority: normal
Severity: normal Version: 3.0
Component: General Keywords: has-patch needs-testing
Focuses: Cc:

Description

Steps:

  1. Add new post or page, don't add any content
  2. Click "Preview"

Actual:
Redirected to preview page with large number of errors.

Expected:
WordPress execution killed with message 'Preview not available. Please save as a draft first.' (2.9.2 behaviour)

I believe this is occurring because all new pages and posts are now created with a postID (see r12987). Therefore the check for $post_ID < 1 in post_preview() (wp-admin/includes/post.php, line 1288) is rendered ineffective.

Instead of checking the post_ID variable I think the function should check for status being auto_draft. However, if this is done, after autosaving a title a new post will still generate this error when previewing (create new post, type a title, let it autosave, click preview). This is because in wp-admin/js/autosave.js (autosave_update_post_ID function) checks value of #post_ID field against the newly autosaved ID, if they're equal the function terminates and so #auto_draft field is not set to '0'. I think the check was there to stop unnecessary ajax requests, but the function no longer does this... removing this also has benefit of reenabling the publishing buttons quicker than default 5000ms.

Attachments (2)

preview-blank.diff (1.2 KB) - added by duck_ 4 years ago.
12859.diff (496 bytes) - added by duck_ 4 years ago.

Download all attachments as: .zip

Change History (6)

duck_4 years ago

comment:1 duck_4 years ago

Similarly, clicking save draft or move to trash (not sure if you should be even able to do that on a completely new post, I know it used to be hidden) yields unexpected behaviour. Unsure whether they should have separate tickets or be grouped as the underlying problem is the fact that all new posts have an ID straight away.

comment:2 duck_4 years ago

Related: #11082

Previous ticket (didn't notice it) about trying to save empty draft.

duck_4 years ago

comment:3 duck_4 years ago

Refreshed patch with better behaviour when previewing post/page with content but no title (for example)

comment:4 ryan4 years ago

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

(In [14643]) Don't allow previewing auto-draft. Props duck_. fixes #12859

Note: See TracTickets for help on using tickets.