WordPress.org

Make WordPress Core

Opened 17 months ago

Last modified 17 months ago

#22641 new enhancement

Request: include post_id on media_send_to_editor filter call in wp_ajax_send_attachment_to_editor

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

Description

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?

e.g.

$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.

Thanks,

Adrian

Change History (3)

comment:1 nacin17 months 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.

comment:2 adrianhardy17 months 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.

Adrian

Last edited 17 months ago by adrianhardy (previous) (diff)

comment:3 nacin17 months 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.

Note: See TracTickets for help on using tickets.