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_notices
hook in wordrpess and run a function calledshowAdminMessages
. - We create our function
showAdminMessages
and create an empty array$plugin_messages
. - Since we’re going to be using the function
is_plugin_active
we have to require the following fileinclude_once( ABSPATH . 'wp-admin/includes/plugin.php' );
- We then use an if statement to check if the plugin is not active
!is_plugin_active
to check the plugins main file. - 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. - 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">