How to execute add_action() function from custom plugin to Crontrol plugin or do_action()?

I created a custom plugin and I need to schedule add_action using Crontrol Plugin, the Setup class is from different php class. But the schedule action cant read the Crontrol even if I execute do_action('schedule') inside functions.php it is not working.

class Scheduler {
    
    public $setup;

    public function __construct()
    {

        add_action('scheduler', [$this, 'etf_scheduler_func']);
    }

    public function etf_scheduler_func() {
        $this-setup = new Setup();
        $this-setup-set_table();
    }
}

Topic wp-cron oop actions php plugin-development Wordpress

Category Web


I didn't call the class yet, this code is now working

class Scheduler {
    
    public $setup;
    public static $instance;

    public function __construct()
    {
        self::$instance =& $this;

        add_action('scheduler', [$this, 'etf_scheduler_func']);
    }

    public function etf_scheduler_func() {
        $this->setup = new Setup();
        $this->setup->set_table();
    }

    public static function &get_instance()
    {
        if ( ! isset( self::$instance ) )
            self::$instance = new self;

        return self::$instance;
    }
} 

Scheduler::get_instance();

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.