Skip to content

Instantly share code, notes, and snippets.

@BenFausch
Created March 21, 2018 20:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BenFausch/20461145fe00bbcd3bb628e4535faf60 to your computer and use it in GitHub Desktop.
Save BenFausch/20461145fe00bbcd3bb628e4535faf60 to your computer and use it in GitHub Desktop.
wp_cron_is_a_pain.php
function_to_execute(){
//this schedules the event (time+3 seconds) with arguments that are passed to the function
wp_schedule_single_event( time() + 3, 'my_action', array($permalink) );
spawn_cron();
}
//this is the task that gets added via add_action, should go in functions.php or other parent-level functions file
function my_task($permalink) {
echo $permalink;
}
add_action( 'my_action', 'my_task' );
//this shows the cron queue
// error_log(print_r(_get_cron_array(),1));
WHERE:
my_action = tag that gets added via add_action, and recalled via schedule_single_event
my_task = function that connected to the tag, and run when called
$permalink = parameter that is passed from the scheduler to the future run function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment