Check that a plugin is loaded when accessing its pages

A plugin can be registered yet fail to load for example due to unmet
dependencies.

Fixes #17359

Includes a couple of code cleanup commits.