I have created custom divi module and then convert it to the plugin.
Now I want to active plugin only if Divi theme is activated.
when i write code like this way it shows notice everytime.
function my_admin_notice(){
echo '<div class="updated">
<p>test Admin notice.</p>
</div>';
}
add_action('admin_notices', 'my_admin_notice');
But when I write code with conditions based
function angelleye_setup_For_paypal_divi_install()
{
if (function_exists('et_setup_theme')) {
// Divi is the current theme or the active theme's parent.
// trigger our function that registers PayPal for Divi plugin.
angelleye_setup_for_paypal_divi();
}
else{
// code when theme is not activated.
add_action('admin_notices', 'my_admin_notice');
}
}
register_activation_hook( __FILE__, 'angelleye_setup_For_paypal_divi_install' );
function my_admin_notice(){
echo '<div class="updated">
<p>test Admin notice.</p>
</div>';
}
I copied code for showing admin notice here https://wptheming.com/2011/08/admin-notices-in-wordpress/
Now add_action I am calling in function angelleye_setup_For_paypal_divi_install
But in the function add_action is not working,.
2
Answers
The problem with your code is that you are missing two requirements of admin notices
{class}
and{message}
as mentioned in https://codex.wordpress.org/Plugin_API/Action_Reference/admin_noticestry
You are adding condition in wrong place. Please remove condition from here.
Add this code after activation function for display admin notice