WordPress 后台限制系列最后一篇,限制图片素材的数量,废话不多说,直接上代码:
add_filter('wp_handle_upload_prefilter', function($file){
$counts = wp_count_posts('attachment');
$total = array_sum((array)$counts);
if($total > WPJAM_ShopCountLimit::get_limit('attachment')){
$error = WPJAM_ShopCountLimit::get_error('attachment');
$file['error'] = $error->get_error_message();
}
return $file;
});
使用上面这段代码之后,在后台再上传图片的时候,就会出现:
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有