4

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?

brasofilo
  • 25,496
  • 15
  • 91
  • 179
SKG
  • 510
  • 4
  • 20

2 Answers2

6

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');
}
hildende
  • 832
  • 1
  • 13
  • 19
3

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.

Krunal Shah
  • 2,083
  • 12
  • 27