[wp-hackers] Prevent attaching unattached attachments (nice!) on sending to editor

J.D. Grimes jdg at codesymphony.co
Fri Sep 4 15:55:30 UTC 2015

Hi Barry,

When the attachment is updated, wp_insert_post() is ultimately called to update the post_parent field. In that function you have several filters that you could hook into. wp_insert_post_parent or wp_insert_attachment_data seem like good options. You'd just need to check that that Ajax request is being performed and the post being saved is an attachment, and not modify the post array otherwise.

Another possibility would be to add your own Ajax handler for that action and unhook the core one. This might actually be the most straightforward and least buggy approach.


> On Sep 4, 2015, at 11:31 AM, Barry Ceelen <barry at multipop.org> wrote:
> Hi All,
> Unattached images inserted into a post via the media library tab automatically get attached to the post.
> I’m looking to prevent this from happening.
> The wp_ajax_send_attachment_to_editor() function (https://developer.wordpress.org/reference/functions/wp_ajax_send_attachment_to_editor/) has a filter at the end, but by that time the attachment is already attached.
> Any tips on handling this?
> Thanks!
> Barry
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers

More information about the wp-hackers mailing list