This code right here is in my functions.php file and was written to change the text in the media upload button, since I'm using the media uploader to allow site users to upload a personal business card if they choose. When I realized I'd actually like to hide several page elements in the WP uploader, as well as pulling the contents of the "link URL" field in an uploaded file, this function was the only place where the JQuery and CSS would actually work. How can I integrate this code into the site in the "proper" way? Are there hooks I can use to attach these lines of JQuery and CSS properly?
add_filter('attachment_fields_to_edit', 'my_action_button', 20, 2);
function my_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"); ?>
<!-- This breaks the media uploader, but it does what it's supposed to do. Probably needs to be on a different page, but I don't know where. -->
<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;
}