WP_Schedule_Event不执行函数调用,即使使用ADD_ACTION

时间:2021-11-13 作者:Debbie Kurth

我看过很多代码,但我不明白为什么没有执行函数调用。即使是我的cron插件管理器也显示事件存在,但函数调用未列出。

有人能看出我错在哪里吗?请注意,在cron管理器中,它显示事件,但没有与之关联的操作。所以我不确定add操作有什么问题

代码如下:

function mmd_wpusercleanup_create_interval( $schedules ) 
{
   if(isset($schedules["MMD_cleanupevent"]))    // already set
      return $schedules;

    $schedules[\'MMD_cleanupevent\'] = array(
        \'interval\' => 60,
        \'display\'  => __(\'Every 60 Seconds\')
    );
    return $schedules;
}
add_filter( \'cron_schedules\', \'mmd_wpusercleanup_create_interval\' );


function mmd_wpusercleanup_StartProcessingKeepList($nBatch)
{
$args = array(\'nBatch\' => $nBatch);

if (wp_next_scheduled(\'mmd_ProcessKeepBatch\'))
   wp_clear_scheduled_hook( \'mmd_ProcessKeepBatch\' );

 $Status = wp_schedule_event( current_time(\'timestamp\'), \'MMD_cleanupevent\', \'mmd_ProcessKeepBatch\', array( $args ) );
 add_action( \'mmd_ProcessKeepBatch\', \'mmd_wpusercleanup_ProcessKeepBatch\' );    
}


// this is the call to make
function mmd_wpusercleanup_ProcessKeepBatch()
{
mmd_wpusercleanup_DebugLog(\'mmd_wpusercleanup_ProcessKeepBatch()\');     
}


// THE IS WHAT STARTS THE EVENTS PROCESS BASED ON A USER CHOICE.  this code is not complete here.

function UseSelect()
{
  switch($DeleteType)
      {
       case 0: // Emails in file are to keep
       default:
         mmd_wpusercleanup_StartProcessingKeepList($nBatch);
       break;
       
       case 1: // Emails in file are to delete  
       break;
       
      }

 }  // if($bProcessDisplay==1)
}

1 个回复
SO网友:Debbie Kurth

啊哈。。。解决了问题,但为什么,为什么。

好的,解决方案是将add\\u操作放在函数之外。

function mmd_wpusercleanup_StartProcessingKeepList($nBatch)
{
$args = array(\'nBatch\' => $nBatch);

if (wp_next_scheduled(\'mmd_ProcessKeepBatch\'))
   wp_clear_scheduled_hook( \'mmd_ProcessKeepBatch\' );

 $Status = wp_schedule_event( current_time(\'timestamp\'), \'MMD_cleanupevent\', \'mmd_ProcessKeepBatch\', array( $args ) );  
}
// GOES HERE INSTEAD.
add_action( \'mmd_ProcessKeepBatch\', \'mmd_wpusercleanup_ProcessKeepBatch\' );  

希望这可以帮助其他人。

相关推荐