..., 'status' => 'ok'|'warning'|'error', 'message' => ...] */ final class SWPB_Preflight { private SWPB_Settings $settings; private SWPB_Fs $fs; public function __construct(SWPB_Settings $settings, SWPB_Fs $fs) { $this->settings = $settings; $this->fs = $fs; } public function run(): array { $checks = []; $checks[] = function_exists('gzopen') && function_exists('deflate_init') ? $this->ok(__('Compression (zlib)', 'seljebackup'), __('Available.', 'seljebackup')) : $this->error(__('Compression (zlib)', 'seljebackup'), __('The PHP zlib extension is missing. Backups cannot be created until your host enables it.', 'seljebackup')); $checks[] = SWPB_Crypto::is_available() ? $this->ok(__('Encryption for stored passwords', 'seljebackup'), __('Available.', 'seljebackup')) : $this->warning(__('Encryption for stored passwords', 'seljebackup'), __('Neither sodium nor OpenSSL is available, so cloud storage credentials cannot be saved. Local backups still work.', 'seljebackup')); $dir = $this->fs->base_dir(); $checks[] = wp_is_writable($dir) ? $this->ok(__('Backup folder', 'seljebackup'), sprintf( /* translators: %s: folder path */ __('Writable: %s', 'seljebackup'), $dir )) : $this->error(__('Backup folder', 'seljebackup'), sprintf( /* translators: %s: folder path */ __('Cannot write to %s. Ask your host to fix the folder permissions.', 'seljebackup'), $dir )); $free = $this->fs->free_space($dir); $db_size = $this->database_size(); if ($free === null) { $checks[] = $this->ok(__('Free disk space', 'seljebackup'), __('Could not be measured on this host.', 'seljebackup')); } elseif ($free < max(200 * MB_IN_BYTES, $db_size * 2)) { $checks[] = $this->warning(__('Free disk space', 'seljebackup'), sprintf( /* translators: %s: free disk space */ __('Only %s free. Large backups may fail; consider keeping fewer local backups and using cloud storage.', 'seljebackup'), size_format((int)$free) )); } else { $checks[] = $this->ok(__('Free disk space', 'seljebackup'), size_format((int)$free)); } $checks[] = $this->ok(__('Database size', 'seljebackup'), size_format($db_size)); $limit = (int)ini_get('max_execution_time'); $checks[] = ($limit > 0 && $limit < 30) ? $this->warning(__('PHP time limit', 'seljebackup'), sprintf( /* translators: %d: seconds */ __('%d seconds. Backups still work, but in very small steps.', 'seljebackup'), $limit )) : $this->ok(__('PHP time limit', 'seljebackup'), $limit > 0 ? sprintf( /* translators: %d: seconds */ __('%d seconds (backups run in short steps, so this is fine).', 'seljebackup'), $limit ) : __('Unlimited.', 'seljebackup')); if (defined('DISABLE_WP_CRON') && DISABLE_WP_CRON) { $checks[] = $this->warning(__('Scheduled tasks (WP-Cron)', 'seljebackup'), __('WP-Cron is disabled on this site. Make sure a server cron job calls wp-cron.php, or add the Cron URL from the "Remote access" tab to a free cron service.', 'seljebackup')); } else { $checks[] = $this->ok(__('Scheduled tasks (WP-Cron)', 'seljebackup'), __('Enabled. On low-traffic sites, adding the Cron URL (Remote access tab) to a cron service makes schedules more punctual.', 'seljebackup')); } if (is_multisite()) { $checks[] = $this->warning(__('Multisite', 'seljebackup'), __('Multisite networks are not officially supported yet. The whole network database and files are backed up together.', 'seljebackup')); } if (!function_exists('ftp_connect')) { $checks[] = $this->ok(__('FTP support', 'seljebackup'), __('The PHP FTP extension is not installed, so FTP storage is unavailable. All other storage types work.', 'seljebackup')); } return $checks; } public function database_size(): int { global $wpdb; $size = $wpdb->get_var($wpdb->prepare( 'SELECT SUM(DATA_LENGTH + INDEX_LENGTH) FROM information_schema.TABLES WHERE TABLE_SCHEMA = %s', DB_NAME )); return (int)$size; } private function ok(string $label, string $message): array { return ['label' => $label, 'status' => 'ok', 'message' => $message]; } private function warning(string $label, string $message): array { return ['label' => $label, 'status' => 'warning', 'message' => $message]; } private function error(string $label, string $message): array { return ['label' => $label, 'status' => 'error', 'message' => $message]; } }