In WordPress currently I developing one extension for WooCommerce. So when user going to activate my extension without having WooCommerce plugins, I want to show them one warning message.
How to do that?
You can show messages with add_action('admin_notices', 'my_plugin_admin_notices');
add_action('admin_notices', 'my_plugin_admin_notices');
function my_plugin_admin_notices() {
if (!is_plugin_active('plugin-directory/plugin-file.php')) {
echo "<div class='updated'><p>Message to be shown</p></div>";
}
}
if you want the message to be shown only once you can use options:
if (!get_option('my_plugin_notice_shown') && !is_plugin_active('plugin-directory/plugin-file.php')) {
echo "<div class='updated'><p>Message to be shown</p></div>";
update_option('my_plugin_notice_shown', 'true');
}
you can simply check through below code in any file :
if($_GET['activate'] == true){
}
or
function _my_plugin_php_warning() {
echo '<div id="message" class="error">';
echo ' <p>Your Message</p>';
echo '</div>';
}
function activate_plugin_conditional() {
$plugin = plugin_basename(__FILE__);
if ( is_plugin_active($plugin) ) {
add_action('admin_notices', '_my_plugin_php_warning');
}
}
add_action( 'admin_init', 'activate_plugin_conditional' );
Thanks.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With