, descriptors:array, orphans:array, total_per_day:float} */ public function analyze(): array { $crons = function_exists( '_get_cron_array' ) ? (array) _get_cron_array() : array(); $schedules = wp_get_schedules(); if ( ! function_exists( 'get_plugins' ) ) { require_once ABSPATH . 'wp-admin/includes/plugin.php'; // Lists installed but inactive plugins as owners too. } $owner = new Owner( (array) get_option( 'bloatwright_overrides', array() ) ); $owners = array(); $desc = array(); $orphans = array(); $total = 0.0; global $wp_filter; foreach ( $crons as $timestamp => $hooks ) { foreach ( $hooks as $hook => $events ) { foreach ( (array) $events as $event ) { $schedule = (string) ( $event['schedule'] ?? '' ); $interval = (int) ( $event['interval'] ?? ( $schedules[ $schedule ]['interval'] ?? 0 ) ); $per_day = $interval > 0 ? DAY_IN_SECONDS / $interval : 0.0; // One-off events count 0/day. $callbacks = array(); if ( isset( $wp_filter[ $hook ] ) && $wp_filter[ $hook ] instanceof \WP_Hook ) { foreach ( $wp_filter[ $hook ]->callbacks as $cbs ) { foreach ( $cbs as $cb ) { $callbacks[] = $cb['function']; } } } $key = Owner::UNKNOWN; if ( $callbacks ) { $key = $owner->for_callable( $callbacks[0] ); } elseif ( 0 === strpos( (string) $hook, 'wp_' ) || in_array( $hook, array( 'recovery_mode_clean_expired_keys', 'delete_expired_transients', 'wp_privacy_delete_old_export_files' ), true ) ) { $key = Owner::CORE; } else { $slug = PrefixRegistry::match( (string) $hook ); if ( '' !== $slug ) { $key = 'plugin:' . $slug; } $orphans[] = array( 'hook' => (string) $hook, 'schedule' => $schedule, 'next' => (int) $timestamp, ); } if ( ! isset( $owners[ $key ] ) ) { $owners[ $key ] = array( 'per_day' => 0.0, 'events' => array(), 'min_interval_min' => 0.0, ); $desc[ $key ] = $owner->describe( $key ); } $owners[ $key ]['per_day'] += $per_day; $total += $per_day; if ( $interval > 0 ) { $mins = $interval / 60; $owners[ $key ]['min_interval_min'] = $owners[ $key ]['min_interval_min'] > 0 ? min( $owners[ $key ]['min_interval_min'], $mins ) : $mins; } $owners[ $key ]['events'][] = array( 'hook' => (string) $hook, 'schedule' => '' !== $schedule ? $schedule : 'once', 'interval' => $interval, 'per_day' => round( $per_day, 1 ), 'next' => (int) $timestamp, 'callback' => ! empty( $callbacks ), ); } } } foreach ( $owners as &$o ) { $o['per_day'] = round( $o['per_day'], 1 ); usort( $o['events'], static function ( $a, $b ) { return $b['per_day'] <=> $a['per_day']; } ); } unset( $o ); uasort( $owners, static function ( $a, $b ) { return $b['per_day'] <=> $a['per_day']; } ); return array( 'owners' => $owners, 'descriptors' => $desc, 'orphans' => $orphans, 'total_per_day' => round( $total, 1 ), ); } }