Run a cron job (or similar) in the background of WP after post update/create

Alright, here’s some code I just whipped up. Completely untested, just wrote it right off the cuff…so don’t expect it to work 100% when you drop it in, but the core concept is there, as is a decent amount of the legwork add_action( ‘my_filter_posts_content’, ‘my_filter_content’ ); add_action( ‘save_post’, ‘my_set_content_filter’ ); if( !wp_next_scheduled( ‘my_filter_posts_content’ ) ) … Read more

Trigger a cron every 24h GMT -8

Almost, WP Cron jobs do not run at specific times, they are approximate, and all timestamps should be UTC, as WordPress always deals in UTC timestamps. If you want midnight PST, you’ll want to specify 8PM UTC. Also for example, your above code suggests midnight PST, but it may not run at midnight PST. If … Read more

WP Cron emails not working

This should be a comment, but I don’t have comment privelages 🙁 I had this exact problem not long ago, and felt stupid when I realised it was because I had set a password on the directory…

WP CRON runs only the first time

OK, so I’ve tested your code and I’m pretty sure it can’t run even once… And here’s why… If you’ll take a look at wp_schedule_event you’ll see this check at the top of the function: if ( !isset( $schedules[$recurrence] ) ) return false; It means that you can’t schedule event with unknown recurrence. So let’s … Read more

Long running action from plugin

You could use WordPress’ pseudo-cron and wp_schedule_single_event. <?php // add the action. add_action(‘wpse71941_cron’, ‘wpse71941_long_running’); function wpse71941_long_running($args) { // might need to call `set_time_limit` here set_time_limit(0); // do long running stuff here // return normal time limit if($l = ini_get(‘max_execution_time’)) set_time_limit($l); } // schedule the event for right now wp_schedule_single_event( time(), ‘wpse71941_cron’, array(‘args’ => ‘for’, ‘callback’ … Read more