WordPress.org

Make WordPress Core

Opened 6 years ago

Closed 5 years ago

#7530 closed defect (bug) (worksforme)

update_postmeta_cache fails while create new posts

Reported by: so1o Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: General Keywords: reporter-feedback has-patch
Focuses: Cc:

Description

when a new post is created but not saved, the regex fails because the post id is negative at that point..

preg_replace('|[^0-9,]|', '', $post_ids);

needs to be changed to

preg_replace('|[^0-9,-]|', '', $post_ids);

or needs to be filtered as

preg_replace(apply_filters('update_postmeta_cache_regex','|[^0-9,]|'), '', $post_ids);

Attachments (2)

7530-option1.patch (411 bytes) - added by so1o 6 years ago.
Option 1 Patch
7530-option2.patch (455 bytes) - added by so1o 6 years ago.
Option 2 patch

Download all attachments as: .zip

Change History (11)

so1o6 years ago

Option 1 Patch

so1o6 years ago

Option 2 patch

comment:1 so1o6 years ago

  • Keywords has-patch added

comment:2 follow-up: azaozz6 years ago

  • Keywords reporter-feedback added; has-patch removed

Which version of WordPress are you using. In the current trunk (2.7) adding a custom field (post meta) inserts the post and gets proper ID even if both title and content are empty.

comment:3 so1o6 years ago

2.6..

i created the patch off the trunk.. so i am assuming this should happen in trunk also.

comment:4 in reply to: ↑ 2 so1o6 years ago

Replying to azaozz:

Which version of WordPress are you using. In the current trunk (2.7) adding a custom field (post meta) inserts the post and gets proper ID even if both title and content are empty.

yes. the way its programmed is, the meta is stored with the -ive post id and when the post is saved all the meta from the -ive post id is updated to the new generated post id. only this one function fails..

comment:5 so1o6 years ago

  • Keywords has-patch added

comment:6 ryan6 years ago

We don't really need the preg_replace since we array_map intval later.

comment:7 ryan5 years ago

  • Milestone 2.7 deleted
  • Resolution set to worksforme
  • Status changed from new to closed

I think we've fixed the bugs where negative posts ID could sneak into meta. I think this is a non-issue now. Resolving as worksforme. Reopen if this can be reproduced against 2.7.

comment:8 so1o5 years ago

  • Resolution worksforme deleted
  • Status changed from closed to reopened

but i think we should keep it open to saving -ive post ID into meta.

an example application is - we have created a plugin to replace the video uploader. the new video uploader have meta data for the video file that needs to be saved - even when the post is not saved. in this case the meta data is associated and saved with the temp -ive ID. when the post is saved we hook into post save and re associate everything with the temp ID to the newly generated ID.

comment:9 Denis-de-Bernardy5 years ago

  • Resolution set to worksforme
  • Status changed from reopened to closed

agreed with ryan

@so1o: I've a couple plugins that deal with metadata too.

two functions I frequently add to my classes are:

  • save_post($post_id) -> on save_post
  • meta_box($post) -> add using add_meta_box

in save_post(), the first thing I do is:

if ( wp_is_post_revision($post_id) ) return;

hope this helps.

Note: See TracTickets for help on using tickets.