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 badges1 Answer
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.