Created
March 21, 2018 20:21
-
-
Save BenFausch/20461145fe00bbcd3bb628e4535faf60 to your computer and use it in GitHub Desktop.
wp_cron_is_a_pain.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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