0

I'm trying to add an admin alert that reminds the user to install a certain plugin in case it is missing. I have found a way to generally add an alert box:

function addAlert() { ?>
<script type="text/javascript">
$j = jQuery;
$j().ready(function(){
$j('.wrap > h2').parent().prev().after('<div class="update-nag">This is a test alert. Do with it what you want.</div>');
});
</script>
<?php } add_action('admin_head','addAlert');

How do I only make it appear if the plugin is missing? I was thinking about something in the lines of <?php if ( function_exists('...') ) ?> but I am not too sure.

I also need a way of adding a link to the plugin and a link to dismiss the box.

1

To check if a plugin is installed and activated, use the is_plugin_active() function.

Note that you need to include this function first on the front-end before you can use it:

include_once ABSPATH.'wp-admin/includes/plugin.php';

Avoid function_exists() for doing the check. Plugins may refactor their code and a previously existing function might disappear. You never know.

2
  • Tried this, but I keep getting the following error: Call to undefined function is_plugin_active() What could be causing this? Dec 11 '12 at 17:03
  • You need to include it first on the front-end. I'll update my answer.
    – Geert
    Dec 11 '12 at 17:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.