Opened 12 years ago
Closed 10 years ago
#21963 closed defect (bug) (fixed)
Consolidate post insertion APIs
Reported by: | nacin | Owned by: | wonderboymusic |
---|---|---|---|
Milestone: | 4.0 | Priority: | normal |
Severity: | normal | Version: | |
Component: | Posts, Post Types | Keywords: | has-patch needs-unit-tests 3.6-early |
Focuses: | Cc: |
Description
In wp-includes, we have:
- wp_insert_post()
- wp_insert_attachment()
- wp_update_post()
- wp_publish_post()
For saving from the admin, we have:
- edit_post()
- wp_write_post()
- write_post()
wp_publish_post() is, as of [21942], now wraps wp_insert_post().
wp_update_post() is a fairly mundane wrapper of wp_insert_post(), but we really should eliminate the differences between the two functions and make it a straight-up wrapper.
wp_insert_attachment() was a fork of wp_insert_post(), and wp_insert_post() has gotten a lot of improvements that haven't reached wp_insert_attachment(). It doesn't take much to merge these two, though, and make wp_insert_attachment() a wrapper.
wp_write_post() calls edit_post() if it has a post ID. And since we have had a post ID since the days of auto-drafts, this function is dead code. It's wrapper, write_post(), can also be deprecated.
I'm attaching a patch that takes care of wp_insert_post(), wp_write_post(), and write_post(). wp_update_post() will require a bit more concentration.
Needs testing and unit tests.
Attachments (8)
Change History (46)
#19
@
10 years ago
21963.3.diff makes wp_insert_attachment()
a wrapper for wp_insert_post()
. I am fairly confident all is good, plus I messed with them both a lot last week during #22400, but I will wait for someone else to chime in.
All unit tests pass.
#20
@
10 years ago
- Milestone changed from Future Release to 4.0
O_o purdy.
21963.4.diff updates the inline docs for wp_insert_attachment()
and changes the $object
parameter to $args
since we're basically overwriting the function anyway.
#22
@
10 years ago
21963.5.diff restores the hook docs for wp_insert_attachment_data
removed in r28579, and moves the hook docs for wp_insert_post_data
to the proper place.
#25
@
10 years ago
This broke stuff. Specifically, was causing major issues with attachment metadata. I went with a revert for now as I previously looked at merging these functions and I was having all sorts of problems, so I suspect it is not an easy/quick fix.
#26
follow-up:
↓ 27
@
10 years ago
Killer - what specifically exploded? We should add unit tests for whatever it is. Every minor change I made to those functions caused like 500 tests to fail, but everything looked good in the end.
#27
in reply to:
↑ 26
@
10 years ago
Replying to wonderboymusic: Patch + unit tests incoming.
#28
@
10 years ago
It looks like update_attached_file() runs when updating the attachment, like adding a caption from the media modal, hence the _wp_attached_file meta value is gone. In wp_insert_attachment() we checked file with if ( $file )
before calling update_attached_file() which was false for updates, but in wp_insert_post() that became isset()
which is always true because wp_insert_attachment() always sets the file argument.
I attached two patches. 21963.6.diff is against r28600 (before the revert) which shows what went wrong + a unit test. And 21963.7.diff which reverse-merges r28601 and applies .7.diff.
#29
@
10 years ago
- Owner set to nacin
- Status changed from new to assigned
Please review at your leisure. Looks good to me, but I want it to be your fault next time.
This ticket was mentioned in IRC in #wordpress-dev by helen. View the logs.
10 years ago
#32
@
10 years ago
Not sure what you mean, my patch is just empty vs. isset, which is pretty obvious and the first thing that broke. I haven't thoroughly tested the rest of it.
This ticket was mentioned in IRC in #wordpress-dev by rmccue. View the logs.
10 years ago
#34
@
10 years ago
- Owner changed from nacin to wonderboymusic
- Status changed from assigned to reviewing
#35
@
10 years ago
The original issue when we dropped this in last time was obvious once @kovshenin found it, he fixed it, and tests were added.
- Use @kovshenin's patch ---> I tested it
- Moved the
guid
logic outside of the attachment if/else - it should never be empty as per #18310. This fixes a unit test that would have broken when this ticket was marked closed. - Updated the unit test in
Tests_Media::test_wp_prepare_attachment_for_js()
to account forurl
no longer being empty - I can't imagine a scenario where this was ever desired
Let's try this again.
See #11399. If [21942] needs to be reverted, we can do that here. See also [4077] #2737 #2715 #4620 for some history.