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

Barry Ceelen barry at multipop.org
Sun Sep 6 00:28:36 UTC 2015


Hi J.D.

When I use filters inside wp_update_post(), besides probably knowing I’m DOING_AJAX and that I’m dealing with an attachment, I lose context insofar as that I cannot know if the update was triggered by sending an attachment to the editor.
Or am I missing something here?
I went with your suggestion of replacing the core handler, works like a charm.

Thanks for your reply!


> On 04 Sep 2015, at 17:55, J.D. Grimes <jdg at codesymphony.co> wrote:
> 
> 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.
> 
> -J.D.
> 
>> 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
> 
> _______________________________________________
> 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