Blog

Your Vision, Our Passion

WordPress Themes Required Plugins

This tutorial will show you how you can alert the users installing the theme that the plugin requires certain plugins to be installed.

When developing a theme you often times rely on certain plugins to add additional functionality to your theme. In this case the following theme relied on 2 Plugins. Testimonials by WooThemes, and Features by WooThemes


The following code was taken from http://www.paulund.co.uk/theme-users-required-plugins. We use it on our themes and I will explain what it does.

  1. First we’re going to hook into the admin_notices hook in wordrpess and run a function called showAdminMessages.
  2. We create our function showAdminMessages and create an empty array $plugin_messages.
  3. Since we’re going to be using the function is_plugin_active we have to require the following file
    include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
  4. We then use an if statement to check if the plugin is not active !is_plugin_active to check the plugins main file.
  5. If the plugin is not active we add a message to our $plugin_messages array notifying the user that the plugin is required and a link to downlod.
  6. We then use another if statement to count our $plugin_messages array > 0 and use foreach to loop through each message and echo out a <div id="message" class="error">