WordPress.org

Make WordPress Core

Opened 10 years ago

Last modified 5 months ago

#11465 accepted defect (bug)

custom field duplicated

Reported by: ericr23 Owned by: westi
Milestone: Priority: normal
Severity: minor Version: 2.8.4
Component: Options, Meta APIs Keywords: has-patch
Focuses: Cc:
PR Number:

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 (3)

11465.patch (291 bytes) - added by collinsinternet 5 years ago.
Changed from add_post_meta to update_post_meta to resolve issue of duplication.
11465.2.patch (345 bytes) - added by collinsinternet 5 years ago.
Last patch was exported incorrectly.
11465.3.diff (411 bytes) - added by MikeHansenMe 4 years ago.
refreshed from src dir

Download all attachments as: .zip

Change History (17)

#1 follow-up: @scribu
10 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
10 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
10 years ago

  • Keywords needs-patch added

#4 @westi
10 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
10 years ago

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

#6 @hakre
10 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
10 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
9 years ago

  • Milestone changed from 3.0 to 3.1

#9 @nacin
9 years ago

  • Milestone changed from Awaiting Triage to Future Release

#10 @SergeyBiryukov
8 years ago

Closed #20344 as a duplicate.

#11 @nacin
6 years ago

  • Component changed from General to Options and Meta

@collinsinternet
5 years ago

Changed from add_post_meta to update_post_meta to resolve issue of duplication.

#12 @collinsinternet
5 years ago

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

@collinsinternet
5 years ago

Last patch was exported incorrectly.

@MikeHansenMe
4 years ago

refreshed from src dir

#13 @MikeHansenMe
4 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
4 years ago

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

Note: See TracTickets for help on using tickets.