I have a class within a plugin which is loaded via the below code:
<?php
add_action(
'plugins_loaded',
array ( 'Company_Store_Locator', 'init' )
);
class Company_Store_Locator{
public static function init() {
$class = __CLASS__;
new $class;
}
And I have a constructor with a number of add_actions
which are within my construct - these all work fine, however when I try and do_action
for one of these nothing appears to happen. I am trying to return an admin notice only if certain criteria within a function occurs. The function is running as expected but nothing happens for do_action
as I need to pass a variable to the admin notice function I cannot use add action here.
public function __construct() {
add_action( 'admin_notices', array($this,'sample_admin_notice__success'));
Inside my public function create_tables()
function:
$message = 'Tables created successfully';
do_action( 'sample_admin_notice__success', $message);
How would I get the do action to run in this scenario?
add_action
work for notices, so if I want to just do one on plugin init, but not thedo_action
where I run something specific and need to pass the variable.define( 'WP_DEBUG', true );
Make sure yoursample_admin_notice__success
is publicly accessible and the php file with the class is included.add_action
it works fine but fires the notice at the wrong point (init) and I cannot pass the message variable.