0 ) ); } // Count all scheduled events. $total_events = 0; $event_hooks = array(); $overdue = 0; $current_time = time(); foreach ( $crons as $timestamp => $hooks ) { if ( ! is_array( $hooks ) ) { continue; } foreach ( $hooks as $hook => $events ) { if ( ! is_array( $events ) ) { continue; } $count = count( $events ); $total_events += $count; if ( ! isset( $event_hooks[ $hook ] ) ) { $event_hooks[ $hook ] = 0; } $event_hooks[ $hook ] += $count; // Check for overdue events. if ( $timestamp < $current_time ) { $overdue += $count; } } } // Sort by frequency. arsort( $event_hooks ); $top_events = array_slice( $event_hooks, 0, 5, true ); $details = array( 'total_events' => $total_events, 'unique_hooks' => count( $event_hooks ), 'overdue' => $overdue, 'top_events' => $top_events, ); // Check for issues. if ( $overdue > 20 ) { return static::fail( 'medium', sprintf( /* translators: %d: number of overdue tasks */ \__( 'You have %d overdue scheduled tasks. This usually means WordPress cron isn\'t running properly, which can cause updates, emails, and other scheduled functions to fail.', '0-day-analytics' ), $overdue ), \__( 'Check with your hosting provider to ensure WP-Cron is working, or set up a real server cron job. Some security plugins or caching can interfere with WP-Cron.', '0-day-analytics' ), $details ); } if ( $total_events > 100 ) { return static::warning( sprintf( /* translators: %d: number of scheduled tasks */ \__( 'Your site has %d scheduled tasks. This is higher than typical and may indicate plugins are creating too many recurring tasks.', '0-day-analytics' ), $total_events ), \__( 'Review your plugins - some may be scheduling excessive background tasks. You can use a plugin like WP Crontrol to audit and manage scheduled tasks.', '0-day-analytics' ), $details ); } if ( $total_events > 50 ) { return static::info( sprintf( /* translators: %d: number of scheduled tasks */ \__( 'Your site has %d scheduled tasks. This is within normal range for a site with several plugins.', '0-day-analytics' ), $total_events ), $details ); } return static::pass( sprintf( /* translators: %d: number of scheduled tasks */ \__( 'Your site has %d scheduled tasks, which is a healthy amount. WordPress cron is handling background tasks efficiently.', '0-day-analytics' ), $total_events ), $details ); } } }