Make WordPress Core

Opened 15 years ago

Last modified 2 years ago

#11465 accepted defect (bug)

custom field duplicated

Reported by: ericr23's profile ericr23 Owned by: westi's profile westi
Milestone: Future Release Priority: normal
Severity: minor Version: 2.8.4
Component: Editor Keywords: needs-patch
Focuses: Cc:

Description

When I enter the information for a custom field and click on Preview without first clicking Add Custom Field, the custom field is saved. But then when I click Publish, it is saved again, appearing in the post twice.

If I click Add Custom Field before Preview, subsequent Publish does not duplicate the custom field. But it is very convenient and efficient to be able to avoid a separate save of the custom field.

Attachments (4)

11465.patch (291 bytes) - added by collinsinternet 10 years ago.
Changed from add_post_meta to update_post_meta to resolve issue of duplication.
11465.2.patch (345 bytes) - added by collinsinternet 10 years ago.
Last patch was exported incorrectly.
11465.3.diff (411 bytes) - added by MikeHansenMe 9 years ago.
refreshed from src dir
11465.4.diff (599 bytes) - added by 79mplus 6 months ago.

Download all attachments as: .zip

Change History (20)

#1 follow-up: @scribu
15 years ago

  • Milestone changed from Unassigned to Future Release
  • Severity changed from normal to minor

I guess you'll just have to click the "Add Custom Field" button before saving.

#2 in reply to: ↑ 1 @hakre
15 years ago

  • Milestone changed from Future Release to 2.9.1
  • Version changed from 2.8.5 to 2.9

I was able to reproduce with 2.9:

  1. edit an existing post.
  2. enter text in the name and value textboxes under Custom Fields.
  3. press the Preview Changes button.
  4. close the newly opened browser tab.
  5. press the Publish button.
  6. post now has two times the same custom field.

I was not able to reproduce when javascript is deactivated.

I think the last information is important to drill down to the cause of the bug.

#3 @hakre
15 years ago

  • Keywords needs-patch added

#4 @westi
15 years ago

  • Milestone changed from 2.9.1 to 3.0
  • Owner set to westi
  • Status changed from new to accepted
  • Version changed from 2.9 to 2.8.4

Tested in 2.8.4 and this bug exists there to.

Steps to reproduce:

  1. Create a new draft post.
  2. Enter a name and value but don't save the field
  3. Preview the post
  4. Publish the post

Moving to 3.0 as this is not a regression and there is currently know patch to fix the issue.

We should avoid these accidental duplicate custom fields but I don't think that this is a severe bug which needs fixing in a maintenance release.

#5 @scribu
15 years ago

This will not be a problem, if we fix the root cause: #10905

#6 @hakre
15 years ago

I can not say if that is the actual root cause, I assume something related to the workflow in the frontend javacript not reflecting a changed status in the persistent storage layer on the server-side.

But #10905 might prevent the duplicate add. But it won't prevent that the frontend tries to add again. Or is it the server side when I press publish. hmm.

=> First fix #10905

#7 @hakre
15 years ago

Can still confirm against current trunk. Might not be javascript related but this must be a check performed on save draft / publish post. Tried an alternative test:

  1. Create a new draft post.
  2. Enter a name and value but don't save the field
  3. Preview the post
  4. Add additional text in the posts content
  5. Preview the post again
  6. Publish the post

That results in more additional fields. So not only the publish but the preview save-action needs to handle custom field duplicates properly, draft fields maybe?

The evolved suggestion in #10905 to extend the API functions might be really usefull to deal with this case.

#8 @ryan
14 years ago

  • Milestone changed from 3.0 to 3.1

#9 @nacin
14 years ago

  • Milestone changed from Awaiting Triage to Future Release

#10 @SergeyBiryukov
12 years ago

Closed #20344 as a duplicate.

#11 @nacin
11 years ago

  • Component changed from General to Options and Meta

@collinsinternet
10 years ago

Changed from add_post_meta to update_post_meta to resolve issue of duplication.

#12 @collinsinternet
10 years ago

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

@collinsinternet
10 years ago

Last patch was exported incorrectly.

@MikeHansenMe
9 years ago

refreshed from src dir

#13 @MikeHansenMe
9 years ago

  • Keywords needs-testing removed

I was able to confirm this bug (not every try though). I was not able to reproduce it at all after applying the patch. 11465.3.diff is a refresh from the src dir.

#14 @MikeHansenMe
9 years ago

11465.3.diff still applies. This is a simple change and fixes the issue.

#15 @sabernhardt
2 years ago

  • Component changed from Options, Meta APIs to Editor
  • Keywords needs-testing added
  • Milestone set to 6.1

This can happen in 6.0 (beta 2), including with the block editor.

11465.3.diff seems to fix it.

#16 @sabernhardt
2 years ago

  • Keywords needs-patch added; has-patch needs-testing removed
  • Milestone changed from 6.1 to Future Release

Changing to update_post_meta() overwrites values if you want multiple values for a key (see ticket:47576#comment:1), so this would need a different patch.

@79mplus
6 months ago

Note: See TracTickets for help on using tickets.