Use before_inclusion hooks to register plugins.

Fixes issue 2267 for the 2.1 stable branch.