Last active
December 15, 2022 10:48
-
-
Save jstask82/0537da633ca78c62ffc06721057d162e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require_once ABSPATH . 'wp-admin/includes/plugin.php'; | |
//Your Plugins here | |
$required_plugins = [ | |
'Meta Box' => is_plugin_active('meta-box/meta-box.php'), | |
'MB Admin Columns' => is_plugin_active('mb-admin-columns/mb-admin-columns.php'), | |
]; | |
//Alternative Plugins here | |
$required_plugins_alt = [ | |
'Meta Box' => is_plugin_active('meta-box/meta-box.php'), | |
'Meta Box AIO' => is_plugin_active('meta-box-aio/meta-box-aio.php'), | |
]; | |
if (is_plugin_active('meta-box-aio/meta-box-aio.php')) { | |
$required_plugins = $required_plugins_alt; | |
} | |
$is_plugin_missing = (in_array(false, $required_plugins)); | |
if ($is_plugin_missing) { | |
add_action( | |
'admin_notices', | |
function () { | |
global $required_plugins; | |
global $required_plugins_alt; | |
$plugin_list = '<p>'; | |
foreach ($required_plugins as $plugin => $status) { | |
$status_string = $status ? __('(active)', 'text-domain') : __('(missing or deactivated)', 'text-domain'); | |
$plugin_list .= "$plugin <code>$status_string</code><br>"; | |
} | |
$plugin_list .= '</p><p><strong>' . __('or as a alternate setup', 'text-domain') . '</strong></p><p>'; | |
foreach ($required_plugins_alt as $plugin => $status) { | |
$status_string = $status ? __('(active)', 'text-domain') : __('(missing or deactivated)', 'text-domain'); | |
$plugin_list .= "$plugin <code>$status_string</code><br>"; | |
} | |
$plugin_list .= '</p>'; | |
echo "<div class='notice notice-error'> | |
<p><strong>" . __('This Project requires the following plugins', 'text-domain') . "</strong></p> | |
$plugin_list | |
</div>"; | |
} | |
); | |
return; //or whatever you want to do if plugins are missing | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment