Run a php file daily at specific time

You can include the PHP file and do the tasks, if WP-cron is your only option. // Scheduled Action Hook function run_my_script( ) { require_once(‘related/path/to/php/file.php’); } // Schedule Cron Job Event function USERS_MONITORING() { if ( ! wp_next_scheduled( ‘USERS_MONITORING’ ) ) { wp_schedule_event( strtotime(’07:00:00′), ‘daily’, ‘USERS_MONITORING’ ); } } add_action( ‘USERS_MONITORING’, ‘run_my_script’ ); Note that … Read more

Wp cron event is set but the function isn’t getting fired

I needed the hook name and not the function name so instead of this: if ( ! wp_next_scheduled( ‘do_this_in_an_hour’ ) ) { wp_schedule_single_event( time() + 40, ‘do_this_in_an_hour’ ); } That: if ( ! wp_next_scheduled( ‘my_new_event’ ) ) { wp_schedule_single_event( time() + 40, ‘my_new_event’ ); }

Why would wp_schedule_single_event get delayed start?

Cron execution may differ depending on when the system cron is actually being run. For example, if your system is running cron at 5 minutes interval, even a cron scheduled for immediate run will execute between a few seconds to 5 minutes. You may use the WP Crontrol Plugin to check the cron schedules set … Read more

Why cron doesn’t work to me?

Do you have define(‘DISABLE_WP_CRON’, true); set in wp-config? You need it to have the system cron fire up the wp-cron tasks. Go to the bottom of the database settings in wp-config.php, typically around line 37, and add it. Then setup the system cron to fire up the wp-cron tasks: */5 * * * * wget … Read more

wp_get_schedule and wp_next_scheduled don’t find my scheduled wp-cron job

Well, I found the answer in the actual documentation: https://developer.wordpress.org/reference/functions/wp_next_scheduled/ in form of a comment by “ub3rst4r”: Note the $args parameter! Not specifying the $args parameter in wp_next_scheduled but having $args for wp_schedule_event will cause many events to be scheduled (instead of just one). Bad Example: if ( ! wp_next_scheduled( ‘myevent’ ) ) { // … Read more