Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show message on plugins activation [duplicate]

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?

like image 951
SKG Avatar asked Jan 13 '23 03:01

SKG


2 Answers

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');
}
like image 113
hildende Avatar answered Jan 18 '23 09:01

hildende


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.

like image 27
Krunal Shah Avatar answered Jan 18 '23 10:01

Krunal Shah