0

I read carefully How to display notice in admin panel on Plugin Activation? which is similar, but I could not make it work correctly

class Shoutbox {
     function display_notice() {
         echo '<div class="updated">
           <p>I am a little yellow notice.</p>
        </div>';
        }
    
    public static function pluginActivated() {
      //exit("Plugin has been actived"); // this is displayed when not commented 
      add_action('admin_notices','display_notice'); // this notice is never displayed.

 }
}
 //add_action('admin_notices', array('Shoutbox', 'display_notice')); // this is displayed when not commented
new Shoutbox();

I also tried with

public static function display_notice() {

Any idea on how to display the admin notice inside pluginActivated() ?

yarek
  • 11,278
  • 30
  • 120
  • 219

1 Answers1

0

You need to pass the method to the add_action function as an array, with the first element being the class name, and the second element being the method name. you can follow my code :

class Shoutbox {
    public static function display_notice() {
        echo '<div class="updated">
           <p>I am a little yellow notice.</p>
        </div>';
    }
    
    public static function pluginActivated() {
        add_action('admin_notices', array(__CLASS__, 'display_notice'));
    }
}

new Shoutbox();
AR Riyad
  • 390
  • 8