Skip to content

Instantly share code, notes, and snippets.

@jrobinsonc
Created June 25, 2016 04:56
Show Gist options
  • Save jrobinsonc/7ebcbb34c2f91ecdd534bee5c07bb574 to your computer and use it in GitHub Desktop.
Save jrobinsonc/7ebcbb34c2f91ecdd534bee5c07bb574 to your computer and use it in GitHub Desktop.
WordPress: Required plugins hook.
<?php
add_action('admin_notices', function()
{
$plugin_messages = array();
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
$required_plugins = [
'wordpress-seo/wp-seo.php' => 'Yoast SEO',
'sendgrid-email-delivery-simplified/wpsendgrid.php' => 'SendGrid',
'w3-total-cache/w3-total-cache.php' => 'W3 Total Cache',
'woocommerce/woocommerce.php' => 'W3 Total Cache',
];
foreach ($required_plugins as $plugin_slug => $plugin_label)
{
if(!is_plugin_active($plugin_slug))
{
$plugin_messages[] = "Activate plugin: {$plugin_label}.";
}
}
if(count($plugin_messages) > 0)
{
echo '<div id="message" class="error">';
foreach($plugin_messages as $message)
{
echo '<p><strong>'.$message.'</strong></p>';
}
echo '</div>';
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment