How to Display an Admin Notice For Required Theme Plugins

required

I typically build all the functionality needed directly into each theme I release, but sometimes it makes sense to refer to a 3rd party plugin to achieve what you are looking to do. For instance, most of my video-centric themes require the Press75.com “Simple Video Embedder” plugin for embedding videos within each post. In my opinion, it makes sense to maintain that functionality separately within a plugin (1 source) rather than duplicating and maintaining multiple versions of the same functionality within each theme. The problem is that when you require 3rd party plugins for your themes to function properly, you will run into several end users who simply do not read the setup or usage instructions. In those cases, don’t be surprised if you get overwhelmed with support related questions regarding the installation of 3rd party plugins.

To eliminate this potential hassle for both you and your users, I would recommend that you implement a very simple “plugin check” that is triggered upon theme activation. Use the code below (2 parts) within your theme “functions.php” file to check and generate an admin notice for any required plugins that you may be using with your theme. Also… major props to James Lao who originally provided this code to use with my themes on Press75.com.

Part 1 – Check for the Required Plugin

The first part simply checks to see if the required plugin is available and activated within the users WordPress installation. Even if the plugin is available, this piece of code will return true until the plugin is actually activated.

// Check for Simple Video Embedder Plugin
sve_check();

function sve_check()
{
  if ( !function_exists('p75GetVideo') )
  {
    add_thickbox(); // Required for the plugin install dialog.
    add_action('admin_notices', 'sve_check_notice');
  }
}

The key to this portion of code is the function reference. Basically, we are looking to see if the “p75GetVideo” function is available. If not, the Simple Video Embedder plugin is most likely not installed and activated as required by the theme. When you apply this check for a different plugin, you will need to replace the “p75GetVideo” with a key function that is provided by the plugin you require for your theme to function properly.

Part 2 – Display an Admin Notice

Checking if the plugin is available really doesn’t do you any good unless you can actually display some sort of notice to your users. The code below will generate an admin notice if the required plugin is not available. It will even provide a link for your users to auto-intall the required plugin making things even easier.

// The Admin Notice
function sve_check_notice()
{
?>
  <div class='updated fade'>
    <p>The Simple Video Embedder plugin is required for this theme to function properly. <a href="<?php echo admin_url('plugin-install.php?tab=plugin-information&plugin=simple-video-embedder&TB_iframe=true&width=640&height=517'); ?>" class="thickbox onclick">Install now</a>.</p>
  </div>
<?php
}

Of course you will want to replace the admin notice text with something that is relevant to the plugin you require for your theme to function properly. You will also want to replace “simple-video-embedder” within the “Install Now” link with the plugin you are referring to. For example, if you require the BuddyPress plugin for your theme to function properly, you would replace “simple-video-embedder” with “buddypress”. This comes from the actual link within the WordPress.org plugin directory (e.g. “http://wordpress.org/extend/plugins/buddypress/”).

Jason Schuller
I’m a digital creative professional living and working in Seattle Washington. For the most part you will find me designing & developing projects for WordPress such as Press75.com, ThemeGarden.com and SimpleThe.me which is coming soon.

28 Comments on "How to Display an Admin Notice For Required Theme Plugins"

  1. Devin Price says:

    Nice and simple code snippet! Hopefully it’ll encourage more theme developers to provide theme support for plugins rather than bundling them directly.

  2. Reji Thomas says:

    Simple and straight forward. This will definitely educate theme developers and during the theme install process to identify “what-went-wrong?”

  3. Thank you. I just started my first commercial theme and have been considering OptionTree or Options Framework but I’ve been concerned that users would get thrown off by needing to install a plugin. This is an elegant solution.

  4. Marc Buurke says:

    Good snippet, very simple, and those are the snippets I tend up using the most.

  5. Eric says:

    Hey Jason,

    Works like a charm. The only thing you might add is a check if they are running multisite. When using admin_url() on multisite installs it doesn’t open the plugin details. You have to use network_admin_url() instead.

    Eric

  6. Thanks for pointing out the admin_notice hook, super helpful!

  7. This is a great snippet and I use it as well. I also add if ( ! current_user_can( 'install_plugins' ) ) return; to the beginning of the notice ( sve_check_notice() ) so that user’s that cannot install plugins won’t be nagged with a notice they cannot control.

    Something that I’ve wanted to add, but haven’t is a “Dismiss” option, incase the user does not want to install the plugin or see the notice. In any case, it is an extremely useful snippet.

  8. James says:

    How would you utilize this within a plug-in? I.e. notifying the user of a plug-in dependency for a plug-in?

  9. Mahbub says:

    The article help lot to add update/error notice to my plugins options page. Thanks man.

Trackbacks for This Post

  1. How to Display an Admin Notice For Required Theme Plugins | Theme.it | iamfriendly.com
  2. This Week’s News Bits and Coupons | ThemeSorter Blog
  3. WordPress Community Links: Mobile townhall edition | WPCandy
  4. WordPress Community Links: Mobile townhall edition
  5. WordPress: The Best of 2011 and Future Predictions | Wptuts+
  6. My Stream » WordPress Year in Review: The Best Tutorials of 2011
  7. Wordpress News - The Best WordPress Tips and Tutorials of 2011Wordpress News
  8. WordPress Year in Review: The Best Tutorials of 2011 | Graphfucker
  9. WordPress Year in Review: The Best Tutorials of 2011 | Simpler Design's
  10. Bangladesh Web Lab | Bangladeshi Web Designer and Developer Blogs – Best WordPress Tips and Tutorials of 2011
  11. WordPress Arena: A Blog for WordPress Developers, Designers and Blogger
  12. Display an admin notice in your WordPress theme for required plugins | OCHOLABS

Got something to say? Go for it!