我需要在加载图像时发送自定义表单数据参数。 对于媒体->添加新页面,该代码有效(加载图像时发送一个附加参数)。 如何获得也要在“媒体”->“库”页面上发送的参数?
add_action('pre-plupload-upload-ui', 'show_dropdown');
public function show_dropdown(){ ?>
<div id="dropdown-in-media">
<select onchange="changeWpUploaderInit()" name="locations" id="locations">
<option value="1">Option 1</option>
<option value="2">Option 2</option>
</select>
<script>
function changeWpUploaderInit() {
var locations = $('#locations');
var choiced_location = locations.val();
//Media -> Add new (it works)
if (window.location.pathname === '/wp-admin/media-new.php') {
if (wpUploaderInit !== undefined) {
wpUploaderInit.multipart_params.location = choiced_location;
}
}
//For the Library page does not work
if (window.location.pathname === '/wp-admin/upload.php') {
if (_wpPluploadSettings !== undefined) {
_wpPluploadSettings.defaults.multipart_params.location = choiced_location;
}
}
}
</script>
</div>
<?php }