Make WordPress Core

Opened 15 years ago

Closed 11 years ago

#11082 closed defect (bug) (invalid)

Saving an empty draft dumps user out to edit.php

Reported by: markel's profile markel Owned by: akhilasuram's profile akhilasuram
Milestone: Priority: low
Severity: minor Version: 2.7
Component: Editor Keywords: needs-refresh
Focuses: Cc:

Description

ENV: wp trunk r12138 (2.9-rare)

When a user starts up the editor for a new post and attempts to save a post with no title and no content, WordPress dumps the user back out to the list of posts in edit.php with no message or indication as to why this happened. You can edit the publish information (date, status, etc.), tags, and categories, but as long as there is nothing for either the post title or the post content, the behavior is the same.

It's expected that a post with no content whatsoever wouldn't be saved (there's nothing there!), but would be nice if the behavior were easier to understand or explained why nothing was happening.

Attachments (9)

#11082_patch.patch (934 bytes) - added by akhilasuram 15 years ago.
11082.diff (1.7 KB) - added by ryan 15 years ago.
#11082.patch (3.2 KB) - added by akhilasuram 15 years ago.
#11082_new.patch (2.0 KB) - added by akhilasuram 15 years ago.
new_#11082.patch (4.2 KB) - added by akhilasuram 15 years ago.
05-04-10_new.patch (2.2 KB) - added by akhilasuram 15 years ago.
11082.2.diff (3.8 KB) - added by duck_ 15 years ago.
11082.3.diff (3.5 KB) - added by duck_ 15 years ago.
11082.4.diff (2.9 KB) - added by duck_ 15 years ago.

Download all attachments as: .zip

Change History (51)

#1 @Denis-de-Bernardy
15 years ago

  • Keywords needs-patch added; confusing ux draft publish removed
  • Milestone changed from Unassigned to 3.0

#2 @dd32
15 years ago

  • Type changed from enhancement to defect (bug)

#3 @akhilasuram
15 years ago

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

#4 @westi
15 years ago

  • Cc westi added

#5 follow-up: @akhilasuram
15 years ago

  • Keywords has-patch added; needs-patch removed

#6 @ryan
15 years ago

When the 'post' action is processed we end up with a post_ID of 0. redirect_post() doesn't handle a 0 post ID properly. redirect_post() needs to be fixed.

#7 in reply to: ↑ 5 @westi
15 years ago

  • Keywords needs-patch added; has-patch removed

Replying to akhilasuram:

It doesn't look like you have changed the correct bit of code here.

I think Ryans comments may help you focus in on the piece of code that needs fixing do you want to have another go?

@ryan
15 years ago

#8 @ryan
15 years ago

Here's a quick patch for the post part that I think handles the root cause. Try that out and extend the patch to cover pages if you like it.

#9 follow-up: @akhilasuram
15 years ago

  • Status changed from accepted to assigned

Thanks for guidance.I 'll write a patch for it.

#10 in reply to: ↑ 9 @akhilasuram
15 years ago

i ll update the patch and upload it soon.

@akhilasuram
15 years ago

#11 @akhilasuram
15 years ago

  • Keywords has-patch added; needs-patch removed

#12 @akhilasuram
15 years ago

hi i have just added the patch.

#13 @akhilasuram
15 years ago

  • Keywords needs testing added

#14 @akhilasuram
15 years ago

  • Keywords needs testing removed

#15 @nacin
15 years ago

  • Keywords needs-patch added; has-patch removed

We would need die() or exit() statements after any wp_redirect() calls.

Also, you're going to want to svn up, as some files you have patched no longer exist -- some big changes occurred recently (see also #9674).

#16 @akhilasuram
15 years ago

  • Keywords has-patch added; needs-patch removed

#17 @nacin
15 years ago

  • Keywords needs-patch added; has-patch removed

Patch is already stale due to [12728] :)

Here's what is needed:

  • A second new string in edit-form-advanced.php, for pages.
  • Whitespace improvements here: if( 0== $post_id ){ (See ryan's patch.)
  • Intendation improvements. (See ryan's patch.)
  • Don't remove the default: logic.

#18 @akhilasuram
15 years ago

  • Keywords has-patch added; needs-patch removed

#19 @akhilasuram
15 years ago

  • Keywords needs testing added

#20 @aaroncampbell
15 years ago

  • Keywords needs-testing added; needs testing removed

#21 @akhilasuram
15 years ago

  • Keywords needs-testing removed

#22 follow-up: @idealien
15 years ago

  • Cc idealien added

Tested with r13709 for both posts and pages doing both save draft and publish. In each case the expected result was performed - no posts / pages were added to the edit view. However, the status message received - i.e. "Page published. View Page" - was not consistent with what actually occured. Perhaps an additional status message should be added?

Suggestions:
-"[Post / Page] without any title or content will not be saved."
-"[Post / Page] not published. A minimum of title and/or content is required."

#23 @akhilasuram
15 years ago

hi idealien, i could not follow your comment. As far as the status message is concerned I m getting it as "You attempted to save or publish an empty post. Provide some content before saving." for an empty post and "You attempted to save or publish an empty page. Provide some content before saving." for an empty page. Can you please explain the issue with the patch more clearly. Thank you.

#24 in reply to: ↑ 22 @akhilasuram
15 years ago

#25 @nacin
15 years ago

  • Keywords needs-refresh added

Latest patch is not against trunk, also, other files are missing from it.

#26 follow-up: @duck_
15 years ago

  • Keywords needs-testing added; needs-refresh removed
  • Version changed from 2.9 to 2.7

Patch decides if post is new by checking if $_POST['auto_draft'] is set to '1'.

Requires the following (line 147 in wp-includes/autosave.dev.js):

if(postID==parseInt(jQuery("#post_ID").val(),10)){return}

to be removed from wp-includes/autosave.js, because otherwise auto_draft field is not set to '0' on autosave, so new posts with a title, content, etc. are classified as emptied (patch in related ticket #12859 also contains this fix for the same reason).

Only minimal testing with custom post types, so not sure how well it works with them. Even so, I noticed that it wouldn't work with a custom post type which didn't support 'title' and 'editor' as an autosave is not performed:

wp_nonce_field( 'autosave', 'autosavenonce', false );

is not called by edit-form-advanced.php unless an editor is included and a title is needed to trigger an autosave. Therefore, the auto_draft field is not set to '0'. (I decided to post this even in light of this as it might help someone else)

(Version bumped back to 2.7 as this behaviour existed then.)

@duck_
15 years ago

#27 in reply to: ↑ 26 @duck_
15 years ago

Replying to duck_:

Only minimal testing with custom post types, so not sure how well it works with them. Even so, I noticed that it wouldn't work with a custom post type which didn't support 'title' and 'editor' as an autosave is not performed

See #12867 for patch; patch for this ticket should be good.

#28 @idealien
15 years ago

  • Keywords needs-refresh added; needs-testing removed

Tested with r14233 and encountered conflicts to applying the patch specific to the edit-form-advanced.php file changes. Two blocks between lines 30 - 60 were source of issue that needs to be refreshed.

<demetris> Idealien: I am not familiar with that patch, but the conflicts most likely mean that something changed in core AFTER the patch was made, and now the patch will have to be refreshed.
<duck_> I wrote that patch, and yes probably needs a refresh then

#29 @duck_
15 years ago

  • Keywords needs-refresh removed

Patch updated for r14233.

@duck_
15 years ago

#30 @idealien
15 years ago

  • Keywords needs-work added

The patch needs additional work.
The new message is showing up in all post use cases, not just the expected one(s):
-Title / Editor both empty = No Draft Saved -> As expected
-Title empty / Editor has content = Draft Saved -> Default messaging expected
-Title has content / Editor empty = Draft Saved -> Default messaging expected
-Title / Editor both have content = Draft Saved -> Default messaging expected

Should not be applied to 3.0 based on current state.

#31 @duck_
15 years ago

  • Keywords needs-testing added; needs-work removed

Problem was that you were entering content/title without an autosave occurring so the post was still being treated as auto-draft. Update solves this by setting $_POST['auto_draft'] to 0 at the end of the edit_post function. Should all work now...

#32 @duck_
15 years ago

  • Keywords needs-work added; needs-testing removed

Oops, probably should've had more sleep, just realised the 'fix' broke what I was fixing in the first place...

#33 @nacin
15 years ago

  • Keywords needs-patch added; has-patch needs-work removed

#34 @GDragoN
15 years ago

When I updated to todays trunk, whenever I click update for the post or page (with or without changes made), I am redirected to this url:

/edit.php#038;action=edit

Not sure if it's directly related to this, but it might be.

#35 @nacin
15 years ago

That's related to #13051.

@duck_
15 years ago

#36 @duck_
15 years ago

  • Keywords has-patch added; needs-patch removed

New patch tests for status being 'auto-draft'.

#37 @nacin
15 years ago

  • Milestone changed from 3.0 to 3.1

#38 @nacin
14 years ago

Closed #13985 as a duplicate.

#39 @nacin
14 years ago

  • Keywords needs-refresh added; has-patch removed
  • Milestone changed from Awaiting Triage to Future Release

Patch should need a refresh.

#41 follow-up: @MikeHansenMe
12 years ago

  • Cc mdhansen@… added

The current behavior of saving a post with no title or content is it stays on post.php and shows message "Post published. View post" yet no post exists in the all post list or in the preview from "View Post" link. So, in summary it still seems to be a problem just slightly different and just as confusing.

#42 in reply to: ↑ 41 @helen
11 years ago

  • Milestone Future Release deleted
  • Resolution set to invalid
  • Status changed from assigned to closed

Replying to MikeHansenMe:

The current behavior of saving a post with no title or content is it stays on post.php and shows message "Post published. View post" yet no post exists in the all post list or in the preview from "View Post" link.

So it appears to me as well, which is what #17115 is reporting, so I'm going to close this, noting that the last patch from duck_ seems like it might still be relevant.

Note: See TracTickets for help on using tickets.