Limiting Number of galleries per user

You can limit the no,. of galleries a user can create in bp-gallery.
here is a sample code
[sourcecode language="php"]

function limit_gallery_count_for_user($can_create,$owner_type,$owner_id){
    global $bp;

      return $can_create;//do not handle for other components
return $can_create;//do not handle if this is not the gallery create action
//if we are here, we are going to create a gallery for user
//check if gallery allowed or not

if(gallery_count_available_for_user( $owner_id,null))//replace null with $_POST["gallery_type"] if you want to restrict 1 gallery for each gallery type for user
     return $can_create; //if user has permission, do not change it
    return false; //deny the permission if the count exceeded

function gallery_count_available_for_user($user_id,$type){
$gallery_count=BP_Gallery_Gallery::get_gallery_count_by_type($type, "user", $user_id, null);
//how many to allow
$allowed_count=5;//only 5 galleries in total change it with your number
return true;//if there does not exist a gallery of this type allow to create 

return false;