I have created a WP cron job, my code for the cron job is shown below:
public function run_import(){
if ( isset($_POST["run_import"])) {
add_action( 'import_execution_event_test', array($this, 'run_execution_script' ));
if(!wp_next_scheduled('import_execution_event_test')){
wp_schedule_event( time(), 'every_two_minutes', 'import_execution_event_test');
}
}
include ( plugin_dir_path( __FILE__ ) . 'views/view-import.php' );
}
Bear in mind here, I also have a custom schedule time here of every two minutes.
This is the function that should be executed every two minutes:
public function run_execution_script() {
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => 'http://dev2.mydevs.co.uk/wp-cron.php?import_key=_GNIHMERsu&import_id=8&action=processing',
CURLOPT_USERAGENT => 'Test Curl Request',
));
$resp = curl_exec($curl);
curl_close($curl);
}
All the the method does is make simple curl request, this curl request does work if I call the method manually.
So to summarize, the cron even does appear in the wp cron schedule, it appears to be being triggered every two minutes as expected, but my curl request isn't functioning from the cron.
Does anyone have any ideas why this might be?
wp_remote_get()
instead of cURL directly.every_two_minutes
?