有没有用于限制上传到woo-commerce产品的图像数量的插件
我经历了不同的插件,但是找不到符合我要求的插件。
您可以设置最大附件发送限制。
add_filter('wp_handle_upload_prefilter','limit_wp_handle_upload_prefilter');
function yoursite_wp_handle_upload_prefilter($file) {
// This bit is for the flash uploader
if ($file['type']=='application/octet-stream' && isset($file['tmp_name'])) {
$file_size = getimagesize($file['tmp_name']);
if (isset($file_size['error']) && $file_size['error']!=0) {
$file['error'] = "Unexpected Error: {$file_size['error']}";
return $file;
} else {
$file['type'] = $file_size['mime'];
}
}
if ($post_id = (isset($_REQUEST['post_id']) ? $_REQUEST['post_id'] : false)) {
if (count(get_posts("post_type=attachment&post_parent={$post_id}"))>4)
$file['error'] = "Sorry,you cannot upload more than four (5) image.";
}
return $file;
}