Created
July 15, 2015 12:19
-
-
Save benhuson/07dcd69ebd1aa2c2debc to your computer and use it in GitHub Desktop.
How to remain detached (when insert a WordPress image into a post)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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