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;
});

使用上面这段代码之后,在后台再上传图片的时候,就会出现:

限制素材数量


©我爱水煮鱼,本站推荐使用的主机:阿里云,国外主机建议使用BlueHost

本站长期承接 WordPress 优化建站业务,请联系微信:「chenduopapa」。