0

Based on: https://codex.wordpress.org/Plugin_API/Action_Reference/admin_notices

My actual code

class Activation {

  function __construct() {

    add_action( 
      'admin_notices', 
      array($this,"text_admin_notices")
    );

    Utils::update_option("is_activated", true);
  }

  function text_admin_notices () {
    ?>
        <div class="notice notice-success is-dismissible">
            <p> TEST MESSAGE</p>
        </div
    <?php
  }

}

I know that __construct() is being executed, because Utils::update_option (a simple wrapper) is working, it's creating the option in the option table.

So I expect that the call to add_action should show a message to the admin user that is activating my plugin.

Actually, the plugin is beign activated, but no message is shown.

I'm using Wordpress 4.7.1 (a fresh, clean, no-other-stuff, today's installation)

What's wrong in my code?

0
<?php
/*
  Plugin Name: Activation
  Description: This display notice message test plugin
  Author: Nanhe Kumar
  Version: 1.0
  Author URI: http://nanhe.in/
 */

class Activation {

    public static function init() {
        add_action('admin_notices', array(__CLASS__, 'text_admin_notice'));
    }

    public static function text_admin_notice() {
        ?>
        <div class="notice notice-success is-dismissible">
            <p> TEST MESSAGE</p>
        </div>
        <?php
    }

}
add_action('init', array('Activation', 'init'));

Your message not showing because your class constructor is not executing you can test through add die in your constructor then you can better understand what is happening.

  • I already tested AND my constructor is being executed regularry. – realtebo Jan 13 '17 at 8:09
  • @realtebo : Ok can you share complete code – Nanhe Kumar Jan 15 '17 at 14:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.