WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 8 months ago

#11082 closed defect (bug) (invalid)

Saving an empty draft dumps user out to edit.php

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

Download all attachments as: .zip

Change History (51)

comment:1 Denis-de-Bernardy4 years ago

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

comment:2 dd324 years ago

  • Type changed from enhancement to defect (bug)

comment:3 akhilasuram4 years ago

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

comment:4 westi4 years ago

  • Cc westi added

akhilasuram4 years ago

comment:5 follow-up: akhilasuram4 years ago

  • Keywords has-patch added; needs-patch removed

comment:6 ryan4 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 westi4 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?

ryan4 years ago

comment:8 ryan4 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: akhilasuram4 years ago

  • Status changed from accepted to assigned

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

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

i ll update the patch and upload it soon.

akhilasuram4 years ago

comment:11 akhilasuram4 years ago

  • Keywords has-patch added; needs-patch removed

comment:12 akhilasuram4 years ago

hi i have just added the patch.

comment:13 akhilasuram4 years ago

  • Keywords needs testing added

comment:14 akhilasuram4 years ago

  • Keywords needs testing removed

comment:15 nacin4 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).

akhilasuram4 years ago

comment:16 akhilasuram4 years ago

  • Keywords has-patch added; needs-patch removed

comment:17 nacin4 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.

akhilasuram4 years ago

comment:18 akhilasuram4 years ago

  • Keywords has-patch added; needs-patch removed

comment:19 akhilasuram4 years ago

  • Keywords needs testing added

comment:20 aaroncampbell4 years ago

  • Keywords needs-testing added; needs testing removed

comment:21 akhilasuram4 years ago

  • Keywords needs-testing removed

comment:22 follow-up: idealien4 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."

comment:23 akhilasuram4 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.

akhilasuram4 years ago

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

comment:25 nacin4 years ago

  • Keywords needs-refresh added

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

comment:26 follow-up: duck_4 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_4 years ago

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

comment:28 idealien4 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

comment:29 duck_4 years ago

  • Keywords needs-refresh removed

Patch updated for r14233.

duck_4 years ago

comment:30 idealien4 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.

comment:31 duck_4 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...

comment:32 duck_4 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...

comment:33 nacin4 years ago

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

comment:34 GDragoN4 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.

comment:35 nacin4 years ago

That's related to #13051.

duck_4 years ago

comment:36 duck_4 years ago

  • Keywords has-patch added; needs-patch removed

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

comment:37 nacin4 years ago

  • Milestone changed from 3.0 to 3.1

comment:38 nacin3 years ago

Closed #13985 as a duplicate.

comment:39 nacin3 years ago

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

Patch should need a refresh.

comment:41 follow-up: MikeHansenMe16 months 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.

comment:42 in reply to: ↑ 41 helen8 months 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.