> */ public static function all(): array { self::loadAdminFunctions(); $checks = array_merge([ self::coreUpdate(), self::pluginUpdates(), self::themeUpdates(), self::configFlags(), self::adminAccounts(), self::autoUpdates(), self::themes(), ], CoreChecks::all()); $accountScope = self::databaseAccountScope(); if ($accountScope !== null) { $checks[] = $accountScope; } return $checks; } /** * From where the site's database account may connect, as one word: * `local`, `any` or `specific` (the core's own classifier, the same row * the Laravel collector sends). The database server's answer to * CURRENT_USER() is reduced on the spot; the account name and the host * never leave the site. No answer, another database engine, a database * on another server or any failure sends no row at all: the panel reads * the row together with this server's own MySQL port. * * @return array{id: string, status: string, value: string}|null */ public static function databaseAccountScope(): ?array { global $wpdb; if (! is_object($wpdb) || ! method_exists($wpdb, 'get_var') || (isset($wpdb->is_mysql) && ! $wpdb->is_mysql)) { return null; } if (! DatabaseAccount::isLocalHost($wpdb->dbhost ?? null)) { return null; } $suppressed = method_exists($wpdb, 'suppress_errors') ? $wpdb->suppress_errors(true) : null; try { // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- A fixed statement with no input, read once per signed pull; WordPress has no function for the connected account. $account = $wpdb->get_var('SELECT CURRENT_USER()'); $scope = is_string($account) ? DatabaseAccount::scope($account) : null; } catch (\Throwable $exception) { $scope = null; } finally { if ($suppressed !== null) { $wpdb->suppress_errors((bool) $suppressed); } } if (! in_array($scope, ['local', 'any', 'specific'], true)) { return null; } return ['id' => 'db_account_scope', 'status' => 'ok', 'value' => $scope]; } /** * The installed plugins AND themes as the envelope's package inventory * (ecosystem `wordpress`; names are directory slugs; `kind` says which). * * @return array{ecosystem: string, source: string, lock_hash: string, items: array, dev_installed: bool} */ public static function pluginInventory(): array { self::loadAdminFunctions(); $items = []; $lines = []; foreach (self::plugins() as $file => $plugin) { $slug = self::slug($file); $version = isset($plugin['Version']) && is_scalar($plugin['Version']) ? trim((string) $plugin['Version']) : ''; if ($slug === null) { continue; } $items[] = ['name' => $slug, 'version' => $version === '' ? '0' : substr($version, 0, 64), 'kind' => 'plugin', 'active' => is_plugin_active($file)]; $lines[] = 'plugin|'.$slug.'|'.$version; } $activeTheme = (string) wp_get_theme()->get_stylesheet(); foreach (function_exists('wp_get_themes') ? wp_get_themes() : [] as $stylesheet => $theme) { $slug = self::slug((string) $stylesheet); $version = $theme instanceof \WP_Theme ? trim((string) $theme->get('Version')) : ''; if ($slug === null) { continue; } $items[] = ['name' => $slug, 'version' => $version === '' ? '0' : substr($version, 0, 64), 'kind' => 'theme', 'active' => (string) $stylesheet === $activeTheme]; $lines[] = 'theme|'.$slug.'|'.$version; } sort($lines); return [ 'ecosystem' => 'wordpress', 'source' => 'wordpress', 'lock_hash' => hash('sha256', implode("\n", $lines)), 'items' => $items, 'dev_installed' => false, ]; } /** * @return array */ private static function coreUpdate(): array { $installed = (string) get_bloginfo('version'); $cache = get_site_transient('update_core'); // WordPress' own cache is only evidence when it holds an answer: an empty or missing // cache (no admin visit, no cron) says nothing, so the status is unknown — the panel // compares the installed version with endoflife.date on its side anyway. if (! is_object($cache) || ! isset($cache->updates) || ! is_array($cache->updates) || $cache->updates === []) { return ['id' => 'wp_core_update', 'status' => 'unknown', 'value' => $installed, 'message' => 'msg.update_cache_missing']; } $latest = null; $sawAnswer = false; foreach ($cache->updates as $update) { if (! is_object($update) || ! isset($update->response)) { continue; } $sawAnswer = true; if ($update->response === 'upgrade' && isset($update->current)) { $latest = (string) $update->current; break; } } if (! $sawAnswer) { return ['id' => 'wp_core_update', 'status' => 'unknown', 'value' => $installed, 'message' => 'msg.update_cache_missing']; } if ($latest === null) { return ['id' => 'wp_core_update', 'status' => 'ok', 'value' => $installed]; } // Only the numeric prefix matters; a different major or minor version means // known fixes are missing, a patch behind is a warning. $installedParts = explode('.', $installed); $latestParts = explode('.', $latest); $status = ($installedParts[0] ?? '') !== ($latestParts[0] ?? '') || ($installedParts[1] ?? '') !== ($latestParts[1] ?? '') ? 'fail' : 'warn'; return ['id' => 'wp_core_update', 'status' => $status, 'value' => $installed, 'detail' => ['latest' => substr($latest, 0, 32)]]; } /** * @return array */ private static function pluginUpdates(): array { $plugins = self::plugins(); $cache = get_site_transient('update_plugins'); if (! is_object($cache) || ! isset($cache->response)) { return ['id' => 'wp_plugin_updates', 'status' => 'unknown', 'value' => null, 'message' => 'msg.update_cache_missing']; } $pending = is_array($cache->response) ? count(array_intersect_key($cache->response, $plugins)) : 0; $active = 0; foreach (array_keys($plugins) as $file) { if (is_plugin_active($file)) { $active++; } } return [ 'id' => 'wp_plugin_updates', 'status' => $pending === 0 ? 'ok' : ($pending >= 5 ? 'fail' : 'warn'), 'value' => $pending, 'detail' => ['installed' => count($plugins), 'active' => $active], ]; } /** * @return array */ private static function themeUpdates(): array { $cache = get_site_transient('update_themes'); if (! is_object($cache) || ! isset($cache->response)) { return ['id' => 'wp_theme_updates', 'status' => 'unknown', 'value' => null, 'message' => 'msg.update_cache_missing']; } $pending = is_array($cache->response) ? count($cache->response) : 0; return ['id' => 'wp_theme_updates', 'status' => $pending === 0 ? 'ok' : 'warn', 'value' => $pending]; } /** * @return array */ private static function configFlags(): array { global $wpdb; $debug = defined('WP_DEBUG') && WP_DEBUG; $debugDisplay = $debug && (! defined('WP_DEBUG_DISPLAY') || WP_DEBUG_DISPLAY); $fileEditDisallowed = defined('DISALLOW_FILE_EDIT') && DISALLOW_FILE_EDIT; $fileModsDisallowed = defined('DISALLOW_FILE_MODS') && DISALLOW_FILE_MODS; $forceSslAdmin = defined('FORCE_SSL_ADMIN') && FORCE_SSL_ADMIN; $autoUpdaterDisabled = defined('AUTOMATIC_UPDATER_DISABLED') && AUTOMATIC_UPDATER_DISABLED; $defaultPrefix = isset($wpdb->prefix) && $wpdb->prefix === 'wp_'; $saltsDefault = self::saltsLookDefault(); $risky = 0; $status = 'ok'; if ($debugDisplay || $saltsDefault) { $status = 'fail'; $risky += ($debugDisplay ? 1 : 0) + ($saltsDefault ? 1 : 0); } if ($debug && ! $debugDisplay) { $risky++; } if (! $fileEditDisallowed) { $risky++; } if ($status === 'ok' && $risky > 0) { $status = 'warn'; } return [ 'id' => 'wp_config_flags', 'status' => $status, 'value' => $risky, 'detail' => [ 'debug' => $debug, 'debug_display' => $debugDisplay, 'file_edit_disallowed' => $fileEditDisallowed, 'file_mods_disallowed' => $fileModsDisallowed, 'force_ssl_admin' => $forceSslAdmin, 'auto_updater_disabled' => $autoUpdaterDisabled, 'default_table_prefix' => $defaultPrefix, 'salts_default' => $saltsDefault, ], ]; } /** * @return array */ private static function adminAccounts(): array { $admins = get_users(['role' => 'administrator', 'fields' => ['ID', 'user_login'], 'number' => 200]); $count = count($admins); $hasAdminLogin = false; foreach ($admins as $user) { if (isset($user->user_login) && strtolower((string) $user->user_login) === 'admin') { $hasAdminLogin = true; } } $status = $hasAdminLogin ? 'warn' : ($count > 5 ? 'fail' : 'ok'); return ['id' => 'wp_admin_accounts', 'status' => $status, 'value' => $count, 'detail' => ['admin_login_exists' => $hasAdminLogin]]; } /** * @return array */ private static function autoUpdates(): array { $updaterDisabled = defined('AUTOMATIC_UPDATER_DISABLED') && AUTOMATIC_UPDATER_DISABLED; // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- WordPress core's own filter, applied only to read the setting in effect. $coreMinor = ! $updaterDisabled && (bool) apply_filters('allow_minor_auto_core_updates', true); $plugins = function_exists('wp_is_auto_update_enabled_for_type') && wp_is_auto_update_enabled_for_type('plugin'); $themes = function_exists('wp_is_auto_update_enabled_for_type') && wp_is_auto_update_enabled_for_type('theme'); return [ 'id' => 'wp_auto_updates', 'status' => $updaterDisabled ? 'fail' : ($coreMinor ? 'ok' : 'warn'), 'value' => $coreMinor ? 1 : 0, 'detail' => ['core_minor' => $coreMinor, 'plugins' => $plugins, 'themes' => $themes], ]; } /** * @return array */ private static function themes(): array { $theme = wp_get_theme(); $parent = $theme->parent(); $installed = function_exists('wp_get_themes') ? count(wp_get_themes()) : 0; return [ 'id' => 'wp_themes', 'status' => 'ok', 'value' => $installed, 'detail' => [ 'active' => substr((string) $theme->get_stylesheet(), 0, 64), 'version' => substr((string) $theme->get('Version'), 0, 32), 'parent' => $parent instanceof \WP_Theme ? substr((string) $parent->get_stylesheet(), 0, 64) : '', ], ]; } private static function saltsLookDefault(): bool { foreach (['AUTH_KEY', 'SECURE_AUTH_KEY', 'LOGGED_IN_KEY', 'NONCE_KEY', 'AUTH_SALT', 'SECURE_AUTH_SALT', 'LOGGED_IN_SALT', 'NONCE_SALT'] as $constant) { if (! defined($constant)) { return true; } $value = (string) constant($constant); if ($value === '' || strlen($value) < 32 || stripos($value, 'put your unique phrase here') !== false) { return true; } } return false; } /** * @return array> */ private static function plugins(): array { $plugins = get_plugins(); return is_array($plugins) ? $plugins : []; } private static function slug(string $file): ?string { $slug = strpos($file, '/') !== false ? strstr($file, '/', true) : preg_replace('/\.php$/', '', $file); $slug = strtolower((string) $slug); return preg_match('/^[a-z0-9][a-z0-9._-]{0,199}$/', $slug) === 1 ? $slug : null; } private static function loadAdminFunctions(): void { if (! function_exists('get_plugins')) { require_once ABSPATH.'wp-admin/includes/plugin.php'; } } }