plugin development – wp_schedule_event not executing function call, even with add_action

Question

I have looked at a lot of code and I just can not see why the function call is not being executed. Even my cron plugin manager, shows the event is there, but the function call is not listed.

Can someone see where I am going wrong? Mind you, in the cron manager, it shows the event but with no action associated with it. So I am not sure what is wrong with the add action

Here is the code:

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)
}

in progress 0
Debbie Kurth 2 weeks 2021-11-12T19:24:58-05:00 0 Answer 0 views 0

Answer ( 1 )

    0
    2021-11-15T12:23:23-05:00

    Ahg…solved the problem, but why oh why.

    Ok, the solution is to put the add_action outside the function.

    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' );  
    
    

    Hopefully this can help someone else.

Leave an answer

Browse
Browse