这段代码就在我的函数中。php文件,用于更改media upload按钮中的文本,因为我使用media uploader允许站点用户上传个人名片(如果他们选择的话)。当我意识到我实际上想在WP上传器中隐藏几个页面元素,以及在上传的文件中提取“link URL”字段的内容时,这个函数是JQuery和CSS实际工作的唯一地方。如何以“正确”的方式将此代码集成到站点中?有没有钩子可以用来正确地附加JQuery和CSS的这些行?
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;
}