WordPress.org

Make WordPress Core

#22572 closed defect (bug) (fixed)

PHP Notice: Undefined index: post_id in /wp-admin/media-new.php on line 27

Reported by: Chouby Owned by: ryan
Milestone: 3.5 Priority: normal
Severity: normal Version: 3.5
Component: Media Keywords: has-patch commit
Focuses: Cc:

Description

Test done in WP 3.5 RC1

In the new "Add media" modal, I use the browser uploader instead of the default multifile uploader. Unlike in WP 3.4 in which we stayed in the modal, here I am redirected to the media library upload.

I upload the file and get the notice:
PHP Notice: Undefined index: post_id in /wp-admin/media-new.php on line 27

Unlike in WP 3.4, the media is not attached to the post I was editing.

I come back to the post I was editing, and the content I just typed is gone... (as probably the post was not saved before the redirection)

Attachments (5)

22572.patch (1.5 KB) - added by ocean90 17 months ago.
22572.2.patch (1.9 KB) - added by ocean90 17 months ago.
22572.3.patch (2.4 KB) - added by ocean90 17 months ago.
22572.diff (2.2 KB) - added by nacin 17 months ago.
22572.2.diff (2.2 KB) - added by nacin 17 months ago.

Download all attachments as: .zip

Change History (15)

comment:1 ocean9017 months ago

  • Keywords needs-patch added
  • Milestone changed from Awaiting Review to 3.5

I can reproduce the notice, but not the lost of post content. The browser uploader should open in a new tab, was it the same tab for you?

The browser upload should probably get the post id too, so that it gets attached.

media-new.php?browser-uploader&post_id=X.

comment:2 ocean9017 months ago

[22752] adds unset( $_REQUEST['post_id'] ), but it's used in media_handle_upload('async-upload', $_REQUEST['post_id']).

ocean9017 months ago

comment:3 Chouby17 months ago

Sorry, too much tabs were open. And I did not noticed that a new one was opened.

So I used the new opened tab (and not the old one in which I first edited my post) to go back to my post (after the upload, clicked on Posts then edit). I remade the test. Sometimes the last post content modification is there, sometimes it is not there (autosave fired or not). Of course, it's normal as we should not edit a post in two different tabs. But this new tab, automatically created, confused me.

ocean9017 months ago

comment:4 ocean9017 months ago

  • Keywords has-patch added; needs-patch removed

comment:5 follow-up: nacin17 months ago

  • Keywords needs-patch added; has-patch removed

For us to go with 22572.2.patch (which I like), we need to bring back some of the edit_post checks that were in media-upload.php: http://core.trac.wordpress.org/browser/tags/3.4.2/wp-admin/media-upload.php

In the new "Add media" modal, I use the browser uploader instead of the default multifile uploader

I'm curious, why do you use the browser uploader? The "Select Files" button is just as effective.

comment:6 in reply to: ↑ 5 Chouby17 months ago

Replying to nacin:

I'm curious, why do you use the browser uploader? The "Select Files" button is just as effective.

Yes, of course your are right. In fact, this was for test purpose only. Since quite a lot of things break in my plugin with all the changes in the Media management, I do quite a lot of tests around this.

ocean9017 months ago

comment:7 ocean9017 months ago

  • Keywords has-patch added; needs-patch removed

22572.3.patch​ adds the cap checks back.

Version 0, edited 17 months ago by ocean90 (next)

comment:8 ocean9017 months ago

  • Summary changed from Post content lost when using the browser uploader in the new "Add media" modal to PHP Notice: Undefined index: post_id in /wp-admin/media-new.php on line 27

nacin17 months ago

nacin17 months ago

comment:9 nacin17 months ago

  • Keywords commit added

comment:10 ryan17 months ago

  • Owner set to ryan
  • Resolution set to fixed
  • Status changed from new to closed

In 22853:

In media_upload_flash_bypass(), pass the post id in the media-new.php url.
In media-new.php, use post_id from REQUEST if passed and the current user can edit the post.
Fixes adding media with the browser uploader.

Props nacin, ocean90
fixes #22572

Note: See TracTickets for help on using tickets.