Programmatically setting block permissions

I can’t help you with the coding but have a look at this post. There’s a whole other area of the Dashboard that might hold some clues for the way forward.