Migrate to WordPress coding standards
Check ABSPATH to tell if script called directly.

This is more reliable than environment variables.
Improve intercepted message formatting