[wp-hackers] Prevent attaching unattached attachments (nice!) on sending to editor
jdg at codesymphony.co
Sun Sep 6 20:01:07 UTC 2015
Replacing the handler seems less fragile, so its probably best that you do that anyway, but to answer you question: yes, you I think can know if the update was being triggered by sending an attachment to the editor, by checking that $_REQUEST['action'] is 'send_attachment_to_editor'. I guess I could have said that more clearly in my original reply. :-)
> On Sep 5, 2015, at 8:28 PM, Barry Ceelen <barry at multipop.org> wrote:
> 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.
>>> 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?
>>> wp-hackers mailing list
>>> wp-hackers at lists.automattic.com
>> wp-hackers mailing list
>> wp-hackers at lists.automattic.com
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
More information about the wp-hackers