Skip to content

Commit

Permalink
Log WP-Cron
Browse files Browse the repository at this point in the history
  • Loading branch information
szepeviktor authored Dec 18, 2024
1 parent 2d16608 commit 45e66a7
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions mu-plugins/_core-wp-cron-logger.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

/*
* Plugin Name: Log WP-Cron (HTTP) callback output and errors
* Plugin URI: https://github.com/szepeviktor/wordpress-website-lifecycle
*/

add_filter(
'cron_request',
static function ($cron_request_array) {
add_action(
'http_api_debug',
static function ($response) {
static $run_once = 0;
$run_once += 1;
if ($run_once !== 1) {
return;
}
if (is_wp_error($response)) {
error_log(sprintf(
'WP-Cron error: (%s) "%s"',
$response->get_error_code(),
$response->get_error_message()
));
return;
}
if ($response['body'] === '') {
return;
}
error_log(sprintf('WP-Cron output: "%s"', $response['body']));
},
10,
1
);
return $cron_request_array;
},
10,
1
);

0 comments on commit 45e66a7

Please sign in to comment.