Add plugin requirements to WordPress theme without breaking the site

After deciding to separate framework into a plugin for inhouse dev, I need to implement the feature to force my theme require framework plugin installed and activated. Since I use many helper functions in Framework, so the theme need Framework plugin to run without any issues.

It’s the solution how I can make my theme requires Framework plugin. I don’t think it’s the best solution but it works in my case (may be I will update the better solution in the future).

What I need will be:

  • Show notice in admin if the Framework plugin is not activated.
  • Make plugin requirement without any issues if the plugin haven’t been installed yet.

This is the final code I added to the very first line of my theme functions:

It will stop functions.php at the line checking for plugin active, so the theme doesn’t run the other code (with unknown Framework helper functions) and doesn’t break the site also.