This is how far I've got with my first experimental plugin. I have learned how to take the selection and it's alpha channel into account. But I don't know how to merge that dynamically created layer to the base image. At least it seems to be the good style that typical plugin affects the active layer rather than leaves a new layer floating around.
I also don't understand should I use those img.disable_undo() and img.enable_undo()? My script works without those just fine. Or perhaps I should use those related to undo groups? I have no idea what's the difference and generally suggested practice.
I think I'd be not asking here some very specific dumb questions, if I could find any decent reference online. I really tried to find some, but failed. Or perhaps I don't know how to search for it? I mean something like API documentation, where all the objects and their methods are described. And perhaps some best practices, too. Right now, most of my plugin research is lines of painful trial-error attempts, feels like very inefficient way to spend my time. The only reasonable reference about Gimp-Python scripting I've found is here: http://www.gimp.org/docs/python/index.html But it certainly is very, very incomplete.
The plugin code is attached.