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.
- First we’re going to hook into the
admin_noticeshook in wordrpess and run a function called
- We create our function
showAdminMessagesand create an empty array
- Since we’re going to be using the function
is_plugin_activewe have to require the following file
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
- We then use an if statement to check if the plugin is not active
!is_plugin_activeto check the plugins main file.
- If the plugin is not active we add a message to our
$plugin_messagesarray notifying the user that the plugin is required and a link to downlod.
- 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">
- You can see the full code in action below.