WordPress.org

Make WordPress Core

Opened 11 years ago

Closed 11 years ago

#13401 closed defect (bug) (fixed)

Add custom field to new post doesn't create draft

Reported by: duck_ Owned by:
Milestone: 3.0 Priority: high
Severity: blocker Version: 3.0
Component: General Keywords: has-patch
Focuses: Cc:

Description

The add-meta case in admin-ajax.php no longer creates a draft post if custom field data is added to a new post. This is because it is checking for a post ID < 0 instead of checking for auto-draft status.

Steps:

  1. Add new post
  2. Add custom field - without letting autosave occur, so don't enter title etc.
  3. Leave page without saving

Expected: 2.9 behaviour was to create a draft with custom fields and draft title

Actual: New post stays as auto-draft so isn't displayed in list of posts to edit

Attachments (2)

13401.patch (1.3 KB) - added by ocean90 11 years ago.
First pass
13401.2.patch (1.6 KB) - added by ocean90 11 years ago.
edit_post() shouldn't start add_meta()

Download all attachments as: .zip

Change History (15)

#1 @duck_
11 years ago

Slightly related: #13400

#2 @nacin
11 years ago

  • Milestone changed from Unassigned to 3.0

@ocean90
11 years ago

First pass

#3 @ocean90
11 years ago

  • Keywords has-patch added; needs-patch removed

I added a patch, if you add a meta and post status is auto-draft then create a draft.

#4 @ocean90
11 years ago

  • Keywords needs-patch added; has-patch removed

edit_post() also use add_meta() => the meta gets added twice.

@ocean90
11 years ago

edit_post() shouldn't start add_meta()

#5 @ocean90
11 years ago

  • Keywords has-patch added; needs-patch removed

13401.2.patch: To prevent that edit_post() add the meta we can clear $_POST. Then fill it with the needed data and after edit_post() we can restore the original $_POST.

#6 @westi
11 years ago

  • Priority changed from normal to high
  • Severity changed from normal to blocker

#7 @ryan
11 years ago

You can pass post data to edit_post() instead of having it rely on the _POST super global. I think that will save some of the POST juggling the patch does.

#8 @ocean90
11 years ago

ryan, what do you mean? If i add the original $_POST to edit_post() it will add the meta to and I can't get the meta id, because it returns only the post id. Because of that I make a backup, send to edit_post() only title,status,post_id,post_type and then restore the original $_POST to add the meta (and then I have the meta id).

#9 follow-up: @ryan
11 years ago

$post_data = array();
$post_data['post_ID'] = $pid;
...
$pid = edit_post($post_data);

That way _POST can be left untouched.

#10 in reply to: ↑ 9 @duck_
11 years ago

Replying to ryan:

$post_data = array();
$post_data['post_ID'] = $pid;
...
$pid = edit_post($post_data);

That way _POST can be left untouched.

Unfortunately the problem with that is the issue of duplicate fields arises again. add_meta(), which is called as part of edit_post(), doesn't look at the array passed to edit_post() it only uses the $_POST super global.

#11 @ryan
11 years ago

Ah, that is lame. add_meta() should accept post_data then, just like edit_post() does. Getting rid of the extra add_meta() would be nice too.

#12 @ryan
11 years ago

(In [14886]) Fixing adding of custom fields to auto-drafts. Props ocean90. see #13401

#13 @ryan
11 years ago

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

Let's not complicate the matter and go with the current patch. If anyone feels like cleaning up add_meta(), re-open and go ahead.

I totally overlooked ocean90's comment explaining the POST juggling. Sorry for the confusion.

Note: See TracTickets for help on using tickets.