发布时间:2020-09-17
WordPress 技巧:限制素材数量,
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;
});
使用上面这段代码之后,在后台再上传图片的时候,就会出现:
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script>
本站推荐使用的主机:,国外主机建议使用。
全站搜索