• I’m trying to set up a one time event in a plugin. The below code is within an IF statement, so that this is only called when an event needs to be set up:

    $myFile = "schedulelog.txt";
    	$fh = fopen($myFile, 'a') or die("can't open file");
    	$stringData = "\r\rSet at " . time() . "";
    	fwrite($fh, $stringData);
    	fclose($fh);
    
    	do_action( 'send_reminder_emails_'.$new_workshop_id );
    	add_action( 'send_reminder_emails_'.$new_workshop_id, 'send_reminders' );
    
    	if (!wp_next_scheduled('send_reminder_emails_'.$new_workshop_id)) {
    		wp_schedule_single_event( time()+30, 'send_reminder_emails_'.$new_workshop_id );
    	}

    This code is at the top of the plugin PHP file, below the plugin info:

    function send_reminders() {
    	$myFile = "schedulelog.txt";
    	$fh = fopen($myFile, 'a') or die("can't open file");
    	$stringData = "\rRan at " . time();
    	fwrite($fh, $stringData);
    	fclose($fh);
    }

    The idea behind all of the logging is that I have no other way to tell if it’s running or not. The first log, when the task is created, DOES work. I’m using the Core Control plugin to ensure tasks are indeed being created and scheduled properly. They are, and they are apparently executing at the correct time (for testing purposes, 30 seconds after creation). I’ve been forcing the task to run by repeatedly visiting a page around the 30 second mark or manually using Core Control. Both times, the task is triggered and disappears from the schedule, but it NEVER runs the function. I’ve also included wp_mail functions in there to see if that works rather than file logging, but I know both work and neither is happening.

    I’m sure my issue has something to do with the placement of the actual target function of the scheduled action, send_reminders. I’ve tried it where it is currently, above the scheduling code, and with and without do_action().

    I’m totally out of ideas, any help is appreciated!

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Cron tasks running, but not executing my function’ is closed to new replies.