I decided to namespace my plugin, and I got it all to work, except in my main plugin file.
I added two actions in that plugin, before calling the init method of the plugin.
<?php
namespace myPlugin;
add_action( 'admin_init', 'add_activation_notice' );
function add_activation_notice() {
add_action( 'admin_notices', 'activation_notice' );
}
function activation_notice() {
echo 'Notice!';
}
But this throws error
Uncaught Error: Undefined constant 'myPlugin\myPlugin\add_activation_notice'
I'm rather new to namespacing, so I don't know why this happens.
The two functions add_activation_notice
and activation_notice
are in the myPlugin
namespace. Most of the code I found online reference methods inside classes, but I need these to be outside of a class so that I can have plugin activation notice.
EDIT:
When I try with
add_action( 'admin_init', \add_activation_notice() );
I get
Fatal error: Uncaught Error: Call to undefined function add_activation_notice()