Wordpress wp_schedule_事件不调用与其关联的函数
我试图每小时安排一次事件,该事件应该将一些数据存储到mlab数据库(mongo db),但函数没有被调用Wordpress wp_schedule_事件不调用与其关联的函数,wordpress,cron,Wordpress,Cron,我试图每小时安排一次事件,该事件应该将一些数据存储到mlab数据库(mongo db),但函数没有被调用 class plug_Activator{ public function __construct() { add_action( 'my_hourly_event', 'tmpp' ); } function activate() { if ( ! wp_next_scheduled( 'tmpp' ) ) {
class plug_Activator{
public function __construct() {
add_action( 'my_hourly_event', 'tmpp' );
}
function activate() {
if ( ! wp_next_scheduled( 'tmpp' ) ) {
wp_schedule_event( time() - 3540, 'hourly', 'my_hourly_event');
}
}
function tmpp(){
$args= array(
"website"=> "www.xyz.com",
"post"=> "wasupp"
);
$response = wp_remote_post( 'https://api.mlab.com/api/1/databases/todo/collections/todos?apiKey=xxxx', array(
'headers' => array('Content-Type' => 'application/json; charset=utf-8'),
'body' => json_encode($args),
'method' => 'POST'
));
}}
“但是函数没有被调用”-你到底是如何验证的?您是否知道这种“cron”机制需要在您的页面上进行活动,并且是这样(您是否有用户访问该页面,以便触发该机制)?@CBroe是的,在激活插件后,我会亲自访问该页面。但是我仍然没有在数据库中获得任何数据,你的
activate
方法被调用where?@CBroe该方法在另一个文件中被调用,该文件在插件被激活时调用该方法。函数activate_plug(){require_once plugin_dir_path(文件)。'includes/plug activator.php';plug_activator::activate()}