hooks - Unable to show a message after plugin activation

Based on:My actual codeclass Activation {function __construct() {add_action( 'admin_notices', array($this,&q

Based on:

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?

Based on: https://codex.wordpress/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?

Share Improve this question asked Jan 12, 2017 at 11:05 realteborealtebo 2672 silver badges15 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745397896a4625963.html

相关推荐

  • hooks - Unable to show a message after plugin activation

    Based on:My actual codeclass Activation {function __construct() {add_action( 'admin_notices', array($this,&q

    4小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信