I wrote some custom code which I've stuck into the media upload panel using a filter. It does a couple of things. First, it changes the text for the "submit" button for users who add things through the uploader. Second, it makes it so that the contents of the File URL field automatically enters the image upload input for a form I created when an image for it is uploaded through the media uploader. (that's the JQuery). Finally, there's CSS to hide elements of the media uploader that users don't need to see.
When this function is in the functions.php file, it causes the media library to stall in loading up the images. It just hangs on the spinning grey ball. But it also works.
How can I integrate this code into the site in a way that doesn't keep the media uploader from working?
add_filter('attachment_fields_to_edit', 'my_plugin_action_button', 20, 2);
function my_plugin_action_button($form_fields, $post) {
$send = "<input type='submit' class='button' name='send[$post->ID]' value='" . esc_attr__( 'Use Photo' ) . "' />";
$form_fields['buttons'] = array('tr' => "\t\t<tr class='submit'><td></td><td class='savesend'>$send</td></tr>\n");
?>
<script>
jQuery('.savesend input[type=submit]').click(function(){
var url = jQuery(this).parents('.describe').find('.urlfile').data('link-url');
var field = jQuery(this).parents('.describe').find('.urlfield');
field.val(url);
});
</script>
<style>
#media-head-125, #imgedit-response-125, .savebutton.ml-submit, .image-size, .align, .post_content, .post_excerpt, .image_alt, .post_title.form-required, .media-types.media-types-required-info, .url {
display: none !important;
}
</style>
<?php
return $form_fields;
}