i´m attempting to run a operate with a schedule however the response is empty. I’m growing a plugin the place i’ll ship a json encoded array to my IoT service. The service is okay. All different capabilities are working effective. i need to ship the replace counts to my iot service.
What i’ve is that this – my operate:
operate send_count_updates_to_iobroker() {
$updates = wp_get_update_data();
//Generate textual content if title is empty
if ( empty($updates['title'] )) {
$updatesTitle = "No updates available";
} else {
$updatesTitle = $updates['title'];
}
$datum_uhrzeit = datum_uhrzeit();
$serviceURL = get_option( 'iob_iot_service_url_count_updates' );
$information = wp_json_encode( (object) array(
'plugins' => $updates['counts']['plugins'],
'themes' => $updates['counts']['themes'],
'wordpress' => $updates['counts']['wordpress'],
'translations' => $updates['counts']['translations'],
'complete' => $updates['counts']['total'],
'title' => $updatesTitle,
'timestamp' => $datum_uhrzeit
), JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES );
$response = wp_remote_post( $serviceURL . $information );
return $response;
}
This operate will probably be executed each 5 minutes with a schedule:
// personal schedule 5 minutes
add_filter( 'cron_schedules', 'five_minute_cron_interval' );
operate five_minute_cron_interval( $schedules ) {
$schedules['five_minutes'] = array(
'interval' => 300,
'show' => esc_html__( 'Alle 5 Minuten' ), );
return $schedules;
}
I deactivated the wp-cron in wp-config.php and activate the serverside cron:
outline( 'DISABLE_WP_CRON', true);
*/5 * * * * wget -q -O - https://instance.com/wp-cron.php?doing_wp_cron >/dev/null 2>&1
The Cronjob is working – each 5 minutes it fires the occasions… However the response is all the time 0:
Aktualisiert: 05.10.2021 - 14:00:01 Uhr
Title: No updates out there
Plugins: 0
Themes: 0
Translations: 0
Core: 0
Complete: 0
Additionally i used for assessments the plugin Superior Cron Supervisor the place i can execute the occasions manually. This works effective. The response is:
Aktualisiert: 05.10.2021 - 14:01:00 Uhr
Title: 2 Plugin-Aktualisierungen
Plugins: 2
Themes: 0
Translations: 0
Core: 0
Complete: 2
Can anybody inform me what i´m doing improper?
Thanks quite a bit!
nukleuz
//Edit:
Right here is the lacking code:
register_activation_hook( __FILE__, 'jb_iobroker_iot_activation' );
add_action( 'jb_iobroker_iot_hourly_event', 'do_this_hourly' );
add_action( 'jb_iobroker_iot_5min_event', 'do_this_five_min_interval' );
operate jb_iobroker_iot_activation() {
wp_schedule_event( time(), 'hourly', 'jb_iobroker_iot_hourly_event' );
wp_schedule_event( time(), 'five_minutes', 'jb_iobroker_iot_5min_event' );
}
operate do_this_hourly() {
checkPluginUpdates();
send_bloginfo_to_iobroker();
}
operate do_this_five_min_interval() {
send_count_updates_to_iobroker();
}
register_deactivation_hook( __FILE__, 'jb_iobroker_iot_deactivation' );
operate jb_iobroker_iot_deactivation() {
wp_clear_scheduled_hook( 'jb_iobroker_iot_hourly_event' );
wp_clear_scheduled_hook( 'jb_iobroker_iot_5min_event' );
}
// personal schedule 5 minutes
add_filter( 'cron_schedules', 'five_minute_cron_interval' );
operate five_minute_cron_interval( $schedules ) {
$schedules['five_minutes'] = array(
'interval' => 300,
'show' => esc_html__( 'Alle 5 Minuten' ), );
return $schedules;
}