get_cron_array(); $cleaned_count = 0; foreach ( $cron_array as $timestamp => $jobs ) { foreach ( $jobs as $hook => $instances ) { // Clean up old test events (older than 1 hour). if ( 0 === strpos( $hook, 'accessibility_audio_tts_cron_test_' ) && ( $timestamp < ( time() - 3600 ) ) ) { foreach ( $instances as $instance ) { wp_unschedule_event( $timestamp, $hook, isset( $instance['args'] ) ? $instance['args'] : array() ); ++$cleaned_count; } } } } if ( $cleaned_count > 0 ) { accessibility_audio_tts_debug_log( "Cron Event Manager: Cleaned up {$cleaned_count} old test events" ); } return $cleaned_count; } /** * Get all scheduled events for a specific hook. * * @param string $hook Hook name. * @return array Array of scheduled events. */ public function get_scheduled_events_for_hook( $hook ) { $events = array(); $cron_array = $this->get_cron_array(); foreach ( $cron_array as $timestamp => $jobs ) { if ( isset( $jobs[ $hook ] ) ) { foreach ( $jobs[ $hook ] as $instance ) { $events[] = array( 'timestamp' => $timestamp, 'formatted_time' => gmdate( 'Y-m-d H:i:s', $timestamp ), 'args' => isset( $instance['args'] ) ? $instance['args'] : array(), 'interval' => isset( $instance['interval'] ) ? $instance['interval'] : null, 'schedule' => isset( $instance['schedule'] ) ? $instance['schedule'] : null, ); } } } return $events; } /** * Get cron array safely. * * @return array Cron array or empty array on failure. */ private function get_cron_array() { $cron_array = array(); if ( function_exists( '_get_cron_array' ) ) { $cron_array = _get_cron_array(); if ( ! is_array( $cron_array ) ) { $cron_array = array(); } } return $cron_array; } /** * Check if a specific hook is scheduled. * * @param string $hook Hook name. * @return bool True if hook is scheduled. */ public function is_hook_scheduled( $hook ) { return false !== wp_next_scheduled( $hook ); } }