#3757 closed defect (bug) (fixed)
Uploads to post-new.php don't get associated with the post
Reported by: | JBoyd | Owned by: | mdawaffe |
---|---|---|---|
Milestone: | 2.1.1 | Priority: | normal |
Severity: | normal | Version: | 2.1 |
Component: | Administration | Keywords: | images uploader write has-patch commit |
Focuses: | Cc: |
Description
If a post has already been saved, using the inline uploader works as expected: the uploaded file is associated with the post. (You can tell it has worked, because the file appears in the uploader's "Browse" tab when editing the post, that is, when viewing a post with /wp-admin/post.php, under the "Manage" tab.)
But using the inline uploader before it has been saved (that is, when editing it with /wp-admin/post-new.php, displayed under the "Write" tab), uploaded files DO NOT get associated with the post, although they do get uploaded. (There is no "Browse" tab in the uploader, just a "Browse All.")
This is unexpected behavior and a change from WP 2.0.x. It's a significant problem anytime you need uploads and posts to be associated with one another (as many image plugins do, for instance). Naturally, the work around is to save first before uploading, but even so simple a work-around as that shouldn't be necessary, imho.
Attachments (2)
Change History (18)
#3
@
18 years ago
- Owner changed from anonymous to mdawaffe
- Status changed from new to assigned
fix_attachment_links() broke in [4478].
Attached fixes this. Re-edit posts (not attachments) to fix the issue (it will look at the attachment links in that post and re-parent any orphan attachments it finds).
#4
@
18 years ago
This is only a partial solution. I'll look into why the post_parent wasn't updated to begin with.
#6
@
18 years ago
- Keywords has-patch commit added
3757b.diff
- Regex fix from previous patch.
- Make sure we call relocate_children() at the appropriate times with the appropriate args.
#9
@
18 years ago
The regex (first patch) definitely needs to go into 2.1.1 - it's just reverting back to the unbroken version.
The other piece can wait if you don't want big changes in the double dot.
#11
@
18 years ago
- Resolution fixed deleted
- Status changed from closed to reopened
Reopening for 2.1.1
#12
@
18 years ago
mdawaffe,
What functional changes does the second part of the patch (the part not in the first patch) make? What bug will we have to endure in 2.1.1 if only the first patch goes in?
#13
@
18 years ago
First Part = regex fix that fixes fix_attachment_link() which provides the the following functionality.
When a post is saved, WP looks through the post content to see if there are any attachment links that do not adhere to the permalink structure. If it finds any, it fixes the link and also re-parents them if the attachment is an orphan.
Second Part = logic fix that fixes the following bug. (To reproduce, must follow exact order.)
- Go to post-new.php.
- Write a post.
- Allow autosave to fire.
- Upload image. Do NOT send image to editor. Just upload it.
- Publish.
- Observe that uploaded image still has negative ID. (Easy to see since it is not available in that post's "Browse" tab, only in the "Browse All" Tab.)
If we include the regex fix in 2.1.1 but not the fix for the above bug, images uploaded via the above steps will have negative ID. Consequences:
- Not associated with post and no valid post_parent object.
- No permalink.
- ?attachment_id=xxx link will generate 404 to non-logged in users due to WP_Query oddity.
BUT, if such an orphaned image is Sent to Editor, fix_attachment_links() (which will now work), will re-parent the image and fix the above consequences for that image only.
#14
@
18 years ago
Doesn't seem so bad. As I'm reading it, there should be no public link to the orphaned image (as it has never been linked to from within an entry), so consequence #3 should never be triggered. If that's correct, I'm okay with leaving the second part of the patch for 2.2. Let me know if that's correct.
The uploader uses a temporary negative post ID for attachments on posts that do not exist in the database. When it is first saved, any orphaned attachments are supposed to have their post_parent updated. I suspect the negative ID is being lost or ignored due to autosave.