plugin development - do_action from within a class does not seem to work

admin2025-06-03  3

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?

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1748953243a315113.html

最新回复(0)