我有这个密码。
$(\'.custom-browse-button\').on(\'click\', function(e) {
e.preventDefault();
var wpMedia = wp.media.frames.file_frame = wp.media({
\'library\': {
type: \'image\'
},
\'multiple\': true
});
wpMedia.open()
.on(\'select\', function(e) {
var uploaded_image = wpMedia.state().get(\'selection\').toJSON();
// already done with select.
console.log(uploaded_image);
});
});
在ajax请求中,方法帖子中有以下参数:
action:query-attachments
post_id:0
query[post_mime_type]:image
query[orderby]:date
query[order]:DESC
query[posts_per_page]:40
query[paged]:1
我想添加更多的预检查和挂钩。示例:
my_filtered_user_id=3
或
media_width_eqm=1000
如何在wp中添加这些内容。媒体
Update:现在我可以使用this answer.
但是,我仍然无法将GET或POST数据发送到浏览媒体挂钩(ajax_query_attachments_args
) 使用这个答案。
$(\'.custom-browse-button\').on(\'click\', function(e) {
e.preventDefault();
var wpMedia = wp.media.frames.file_frame = wp.media({
\'library\': {
type: \'image\'
},
\'multiple\': true
});
wpMedia.uploader.options.uploader.params.my_filtered_user_id = 3;
wpMedia.open()
.on(\'select\', function(e) {
var uploaded_image = wpMedia.state().get(\'selection\').toJSON();
// already done with select.
console.log(uploaded_image);
});
});
SO网友:webhead
我也一直在搜索这个答案,并使用this answer. 只需向库对象添加属性:
var wpMedia = wp.media.frames.file_frame = wp.media({
\'library\': {
type: \'image\',
custom_var: \'webhead\'
},
\'multiple\': true
});
然后在PHP中,您可以在
ajax_query_attachments_args
像这样钩住:
function webhead_ajax_query_attachments_args() {
var_dump($_REQUEST[\'query\'][\'custom_var\']);
exit;
}
add_filter( \'ajax_query_attachments_args\', \'webhead_ajax_query_attachments_args\' );