如何在执行某些操作后在wordpress中设置单个计划事件

时间:2014-10-02 14:51:43

标签: php wordpress

我有一个在任务完成时发送电子邮件的功能

   function complete_task($id)
   {
      wp_mail('abc@mail.com','test subject', 'test message');
   }

现在我想更改此功能,因为当完成具有ID的特定任务时,它不应发送电子邮件而不是注册计划事件。我用wp_schedule_single_event

完成了这项工作

我的代码如下:

   function complete_task($id)
   {
      if($id!=3) // 3 is any ID
       {
            wp_mail('abc@mail.com','test subject', 'test message');
       }
       else
       {
           add_action( 'send_single_email_event', 'do_this_in_after_1_hour', 10, 3 );
       }
   }

我在add_action部分添加了else挂钩,因为在codex中有写入要在函数中添加此内容,您可以在此处查看 Schedule an event one hour from now

   // function for sending schedule event
   function do_this_in_after_1_hour() 
   {
     wp_mail( 'abc@mail.com', 'test subject', 'test message');
   }
   // singdle schedule event
   wp_schedule_single_event(time() + 3600, 'send_single_email_event');

它不起作用,意味着不发送电子邮件。

0 个答案:

没有答案
相关问题