Skip to content

Instantly share code, notes, and snippets.

@benhuson
Created July 15, 2015 12:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benhuson/07dcd69ebd1aa2c2debc to your computer and use it in GitHub Desktop.
Save benhuson/07dcd69ebd1aa2c2debc to your computer and use it in GitHub Desktop.
How to remain detached (when insert a WordPress image into a post)
<?php
/**
* Implement 'wp_ajax_send-attachment-to-editor' to not attach an unattached media item.
*
* In WordPress TRAC 22085 there was a change.
* that caused unattached media files (images) to be attached to posts if they are inserted into the post.
*
* If you don't like this strategy you can disable it using this simple, rather hacky, action hook.
*
* Trac Ticket: https://core.trac.wordpress.org/ticket/32999
* See: http://herbmiller.me/2015/07/15/h2gd-part-45-how-to-remain-detached/
*/
function dont_attach( $blah ) {
$_POST['post_id'] = 0;
}
/*
* Hook into the AJAX request before WordPress, using priority 0
*/
add_action( 'wp_ajax_send-attachment-to-editor', 'dont_attach', 0 );
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment