, themes: list} */ public static function components(): array { global $wp_version; if ( ! function_exists( 'get_plugins' ) ) { require_once ABSPATH . 'wp-admin/includes/plugin.php'; } $core_update = null; $core = get_site_transient( 'update_core' ); if ( is_object( $core ) && isset( $core->updates ) && is_array( $core->updates ) ) { foreach ( $core->updates as $offer ) { if ( is_object( $offer ) && isset( $offer->response, $offer->current ) && 'upgrade' === $offer->response ) { $core_update = self::version( (string) $offer->current ); break; } } } $plugin_updates = get_site_transient( 'update_plugins' ); $plugin_updates = is_object( $plugin_updates ) && isset( $plugin_updates->response ) && is_array( $plugin_updates->response ) ? $plugin_updates->response : array(); $plugins = array(); foreach ( get_plugins() as $file => $data ) { if ( count( $plugins ) >= self::MAX_PLUGINS ) { break; } $file = (string) $file; $update = isset( $plugin_updates[ $file ] ) && is_object( $plugin_updates[ $file ] ) && isset( $plugin_updates[ $file ]->new_version ) ? self::version( (string) $plugin_updates[ $file ]->new_version ) : null; $plugins[] = array( 'slug' => self::slug( false !== strpos( $file, '/' ) ? dirname( $file ) : basename( $file, '.php' ) ), 'name' => self::text( isset( $data['Name'] ) ? (string) $data['Name'] : $file ), 'version' => self::version( isset( $data['Version'] ) ? (string) $data['Version'] : '' ), 'active' => is_plugin_active( $file ), 'update' => $update, ); } $theme_updates = get_site_transient( 'update_themes' ); $theme_updates = is_object( $theme_updates ) && isset( $theme_updates->response ) && is_array( $theme_updates->response ) ? $theme_updates->response : array(); $active_theme = get_stylesheet(); $themes = array(); foreach ( wp_get_themes() as $stylesheet => $theme ) { if ( count( $themes ) >= self::MAX_THEMES ) { break; } $stylesheet = (string) $stylesheet; $offer = $theme_updates[ $stylesheet ] ?? null; $themes[] = array( 'slug' => self::slug( $stylesheet ), 'name' => self::text( (string) $theme->get( 'Name' ) ), 'version' => self::version( (string) $theme->get( 'Version' ) ), 'active' => $stylesheet === $active_theme, 'update' => is_array( $offer ) && isset( $offer['new_version'] ) ? self::version( (string) $offer['new_version'] ) : null, ); } return array( 'core' => array( 'version' => self::version( (string) $wp_version ), 'update' => $core_update, ), 'plugins' => $plugins, 'themes' => $themes, ); } /** * Site metrics. A value that cannot be read is null. * * @return array{memory_limit_mb: int|null, autoload_kb: int|null, db_size_mb: int|null, cron_overdue: int} */ public static function metrics(): array { $facts = ( new DatabaseCheck() )->facts(); $overdue = 0; $cutoff = time() - HOUR_IN_SECONDS; foreach ( _get_cron_array() as $timestamp => $hooks ) { if ( (int) $timestamp < $cutoff ) { $overdue += count( $hooks ); } } $memory = wp_convert_hr_to_bytes( (string) ini_get( 'memory_limit' ) ); return array( 'memory_limit_mb' => $memory > 0 ? (int) round( $memory / MB_IN_BYTES ) : null, 'autoload_kb' => null === $facts['autoload_bytes'] ? null : (int) round( $facts['autoload_bytes'] / KB_IN_BYTES ), 'db_size_mb' => null === $facts['db_bytes'] ? null : (int) round( $facts['db_bytes'] / MB_IN_BYTES ), 'cron_overdue' => min( 100000, $overdue ), ); } /** * Lowercase slug as the schema expects. * * @param string $value Raw slug. */ private static function slug( string $value ): string { $clean = (string) preg_replace( '/[^a-z0-9_.-]/', '', strtolower( $value ) ); return strlen( $clean ) > 100 ? substr( $clean, 0, 100 ) : $clean; } /** * Version string (max 32 characters). * * @param string $value Raw version. */ private static function version( string $value ): string { $value = trim( wp_strip_all_tags( $value ) ); return strlen( $value ) > 32 ? substr( $value, 0, 32 ) : $value; } /** * Display name (max 80 characters, tags removed). * * @param string $value Raw name. */ private static function text( string $value ): string { $value = trim( wp_strip_all_tags( $value ) ); return function_exists( 'mb_substr' ) ? mb_substr( $value, 0, 80 ) : substr( $value, 0, 80 ); } }