Sometimes written, too. For example, in Japanese doujins, we have the Touhou Project/ZUN issuing an explicit license where Touhou creators are given permission to do their thing, but if they want to sell their works outside a convention like Reitaisai or a doujin-focused reseller like Toranoana, they have to contact him and work out a licensing agreement.
JKR is on the record as no longer opposing non-slash fanfiction:
so this is probably a bit paranoid. But I suppose your second paragraph makes sense.
A big part of the cease-fire between IP holders and fanfic authors is probably the unwritten rule that the fanfic shall not be directly monetized.
Sometimes written, too. For example, in Japanese doujins, we have the Touhou Project/ZUN issuing an explicit license where Touhou creators are given permission to do their thing, but if they want to sell their works outside a convention like Reitaisai or a doujin-focused reseller like Toranoana, they have to contact him and work out a licensing agreement.