Verified Commit 4f3b2efc authored by Erick Hitter's avatar Erick Hitter
Browse files

Validate timestamp when recreating cron array, lest invalid entries be shown

When the timestamp, action, or instance are corrupted, the REST endpoint will list the event, but it won't be able to run it. As a result, the event remains perpetually in a broken state because its identifying information isn't reliable.
parent 9b92d407
......@@ -110,8 +110,25 @@ class Cron_Options_CPT extends Singleton {
// Loop through results and built output Core expects
if ( ! empty( $jobs_posts ) ) {
foreach ( $jobs_posts as $jobs_post ) {
// Determine event timestamp
$timestamp = strtotime( $jobs_post->post_date_gmt );
// When timestamp is invalid, perhaps due to post date being set to `0000-00-00 00:00:00`, attempt to fall back to the original value
if ( $timestamp <= 0 ) {
$event_data = $jobs_post->post_title;
$event_data = explode( '|', $event_data );
if ( is_numeric( $event_data[0] ) ) {
$timestamp = (int) $event_data[0];
}
}
// If timestamp is still invalid, event is removed to let its source fix it
if ( $timestamp <= 0 ) {
$this->mark_job_post_completed( $jobs_post->ID );
continue;
}
$job_args = maybe_unserialize( $jobs_post->post_content_filtered );
if ( ! is_array( $job_args ) ) {
continue;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment