Opened 4 years ago

Last modified 5 months ago

#11082 assigned defect (bug)

Saving an empty draft dumps user out to edit.php

Reported by: markel Owned by: akhilasuram
Priority: low Milestone: Future Release
Component: Editor Version: 2.7
Severity: minor Keywords: needs-refresh
Cc: westi, idealien, mdhansen@…

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 3 years ago.
11082.diff (1.7 KB) - added by ryan 3 years ago.
#11082.patch (3.2 KB) - added by akhilasuram 3 years ago.
#11082_new.patch (2.0 KB) - added by akhilasuram 3 years ago.
new_#11082.patch (4.2 KB) - added by akhilasuram 3 years ago.
05-04-10_new.patch (2.2 KB) - added by akhilasuram 3 years ago.
11082.2.diff (3.8 KB) - added by duck_ 3 years ago.
11082.3.diff (3.5 KB) - added by duck_ 3 years ago.
11082.4.diff (2.9 KB) - added by duck_ 3 years ago.

Download all attachments as: .zip

Change History (50)

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

comment:2   dd323 years ago

  • Type changed from enhancement to defect (bug)
  • Owner set to akhilasuram
  • Status changed from new to accepted
  • Cc westi added

comment:5 follow-up: ↓ 7   akhilasuram3 years ago

  • Keywords has-patch added; needs-patch removed

comment:6   ryan3 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.

comment:7 in reply to: ↑ 5   westi3 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?

ryan3 years ago

comment:8   ryan3 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.

comment:9 follow-up: ↓ 10   akhilasuram3 years ago

  • Status changed from accepted to assigned

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

comment:10 in reply to: ↑ 9   akhilasuram3 years ago

i ll update the patch and upload it soon.

  • Keywords has-patch added; needs-patch removed

hi i have just added the patch.

  • Keywords needs testing added
  • Keywords needs testing removed
  • 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).

  • Keywords has-patch added; needs-patch removed
  • 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.
  • Keywords has-patch added; needs-patch removed
  • Keywords needs testing added
  • Keywords needs-testing added; needs testing removed
  • Keywords needs-testing removed

comment:22 follow-up: ↓ 24   idealien3 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."

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.

comment:24 in reply to: ↑ 22   akhilasuram3 years ago

  • Keywords needs-refresh added

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

comment:26 follow-up: ↓ 27   duck_3 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_3 years ago

comment:27 in reply to: ↑ 26   duck_3 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.

  • 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

  • Keywords needs-refresh removed

Patch updated for r14233.

duck_3 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.

  • 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...

  • 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...

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

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.

That's related to #13051.

duck_3 years ago

  • Keywords has-patch added; needs-patch removed

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

  • Milestone changed from 3.0 to 3.1

Closed #13985 as a duplicate.

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

Patch should need a refresh.

  • 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.

Note: See TracTickets for help on using tickets.