admin管理员组文章数量:1206198
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();
}
}
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();
}
}
Share
Improve this question
edited Mar 21, 2022 at 7:00
JuniorA
asked Mar 21, 2022 at 6:40
JuniorAJuniorA
11 bronze badge
2
- You haven't scheduled anything. That's what the Crontrol plugin shows; scheduled actions. See this for how to schedule things in WordPress: developer.wordpress.org/plugins/cron – Jacob Peattie Commented Mar 21, 2022 at 8:09
- Thank you for your suggestion, I posted my answer. – JuniorA Commented Mar 21, 2022 at 13:54
1 Answer
Reset to default -1I 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();
本文标签: phpHow to execute addaction() function from custom plugin to Crontrol plugin or doaction()
版权声明:本文标题:php - How to execute add_action() function from custom plugin to Crontrol plugin or do_action()? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738663784a2105580.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论