Make WordPress Core

Opened 6 years ago

Closed 4 years ago

#22641 closed enhancement (maybelater)

Request: include post_id on media_send_to_editor filter call in wp_ajax_send_attachment_to_editor

Reported by: adrianhardy Owned by:
Milestone: Priority: normal
Severity: minor Version: 2.6
Component: Media Keywords:
Focuses: Cc:


Before 3.5, by combining some hidden fields on the add media popup (using attachment_fields_to_edit) and then looking for those fields in $attachment in the media_send_to_editor filter, you could alter the $html sent back to the editor on a per custom post type basis.

Here's a pre 3.5 tutorial on what I'm on about: http://shibashake.com/wordpress-theme/how-to-hook-into-the-media-upload-popup-interface - The relevant part is in step 4, "Set Our Own Action".

Because recent changes mean that the fields added by attachment_fields_to_edit are posted separately ("save-attachment-compat"), there's no way to identify the custom post type when hooking into the media_send_to_editor filter.

In wp_ajax_send_attachment_to_editor(), is there any reason we couldn't also include $_POSTpost_id? with the "media_send_to_editor" filter?


$html = apply_filters( 'media_send_to_editor', $html, $id, $attachment, $_POST['post_id']);

I'm new to WP, but I would've thought that wouldn't break anything because of the way most filter hooks will only look for params 1-3.



Change History (5)

#1 @nacin
6 years ago

save-attachment-compat and save-attachment both receive post_id in the same manner as before — $_POST['post_id']. This was done deliberately for backwards compatibility. So everything should work as before, even without the hook change.

#2 @adrianhardy
6 years ago

Thanks for the quick reply.

"media_send_to_editor" still doesn't know about the post to which the attachment relates though. I'm not using attachment_fields_to_edit to actually effect a change on the post or the attachment - that's just a means to an end - I'm only using it as a way of transporting data back round to media_send_to_editor.

Without media_send_to_editor knowing about the custom post type, I've no way of selectively changing the html sent back to the editor.

Of course, I could be using the wrong approach completely which is why I'm struggling.

Thanks again. 3.5 looks awesome.


Last edited 6 years ago by adrianhardy (previous) (diff)

#3 @nacin
6 years ago

  • Version changed from trunk to 2.6

Right, so in 3.4, media_send_to_editor did not receive a post_id. Individuals checked $_POST['post_id'] manually in their callbacks. I think this is a good potential change — obviously, it is much better to use a passed argument, than to infer from global state. But, this hook as been there untouched since 2.6 or so, so I'm not inclined to change it for 3.5.

#4 @wonderboymusic
4 years ago

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

#5 @wonderboymusic
4 years ago

  • Keywords needs-patch removed
  • Milestone Future Release deleted
  • Resolution set to maybelater
  • Status changed from new to closed

No one has asked for this for 22 months, I think the dust has adequately settled post-3.5

Note: See TracTickets for help on using tickets.