Before going too far down this path I would suggest that you familiarize yourself with PHP name resolution rules.
To answer your actual question –
When you namespace functions, the fully qualified name of those functions includes the namespace.
In your example, you have defined two functions: \myPlugin\add_activation_notice
and \myPlugin\activation_notice
.
When calling either of these from within the myPlugin
namespace, you can use the unqualified name (i.e. activation_notice()
) but outside of the myPlugin
namespace you have to follow the name resolution rules linked above.
In the case of add_action()
– while this is called from within your myPlugin
namespace, you are not passing the actual function but rather the function name as a string. WordPress later attempts to call that function from the global namespace.
The solution to your problem should be to include the myPlugin
namespace in the function name passed to add_action
(pay special attention to the escaped backslash):
add_action( 'admin_init', 'myPlugin\\add_activation_notice' );
add_action( 'admin_notice', 'myPlugin\\activation_notice' );
My preferred method of doing this would be by concatenating the __NAMESPACE__
magic constant which simplifies things slightly if you should you ever decide to change your namespaces:
add_action( 'admin_init', __NAMESPACE__ . '\\add_activation_notice' );
add_action( 'admin_notice', __NAMESPACE__ . '\\activation_notice' );