WordPress.org

Make WordPress Core

Opened 7 years ago

Closed 7 years ago

Last modified 5 years ago

#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)

3757.diff (766 bytes) - added by mdawaffe 7 years ago.
3757b.diff (2.3 KB) - added by mdawaffe 7 years ago.

Download all attachments as: .zip

Change History (18)

comment:1 andy7 years ago

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.

comment:2 foolswisdom7 years ago

  • Milestone changed from 2.3 to 2.2

comment:3 mdawaffe7 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).

mdawaffe7 years ago

comment:4 mdawaffe7 years ago

This is only a partial solution. I'll look into why the post_parent wasn't updated to begin with.

comment:5 foolswisdom7 years ago

  • Milestone changed from 2.2 to 2.1.1

mdawaffe7 years ago

comment:6 mdawaffe7 years ago

  • Keywords has-patch commit added

3757b.diff

  1. Regex fix from previous patch.
  2. Make sure we call relocate_children() at the appropriate times with the appropriate args.

comment:7 markjaquith7 years ago

mdawaffe, does this fix the issue or is this still only a partial fix?

comment:8 mdawaffe7 years ago

Oops, forgot to say :)

Full fix (to the best of my soothsaying abilities).

comment:9 mdawaffe7 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.

comment:10 markjaquith7 years ago

  • Resolution set to fixed
  • Status changed from assigned to closed

(In [4884]) Make sure attachments uploaded on unsaved drafts get reunited with their parent post. Props mdawaffe. fixes #3757

comment:11 markjaquith7 years ago

  • Resolution fixed deleted
  • Status changed from closed to reopened

Reopening for 2.1.1

comment:12 markjaquith7 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?

comment:13 mdawaffe7 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.)

  1. Go to post-new.php.
  2. Write a post.
  3. Allow autosave to fire.
  4. Upload image. Do NOT send image to editor. Just upload it.
  5. Publish.
  6. 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:

  1. Not associated with post and no valid post_parent object.
  2. No permalink.
  3. ?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.

comment:14 markjaquith7 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.

comment:15 mdawaffe7 years ago

That's correct. It will annoy authors looking for photos and potentially plugins that deal with attachments, but not visitors of the site.

comment:16 markjaquith7 years ago

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

(In [4889]) Fix fix_attachment_link() regex. Props mdawaffe. fixes #3757

Note: See TracTickets for help on using tickets.