/', '/&1'; $output = []; $exit_code = 0; exec($full_cmd, $output, $exit_code); return [ 'command' => 'wp ' . $command, 'exit_code' => $exit_code, 'success' => $exit_code === 0, 'output' => implode("\n", $output), ]; } public static function isAvailable(array $args): array { $available = self::isWpCliAvailable(); $version = null; if ($available) { $wp_cli = self::findWpCli(); $version = trim((string) shell_exec(escapeshellarg($wp_cli) . ' --version --allow-root --no-color 2>&1')); } return [ 'available' => $available, 'path' => $available ? self::findWpCli() : null, 'version' => $version, 'allowed_cmds' => self::$ALLOWED_COMMANDS, ]; } private static function isWpCliAvailable(): bool { return !empty(self::findWpCli()); } private static function findWpCli(): string { foreach (['/usr/local/bin/wp', '/usr/bin/wp'] as $path) { if (file_exists($path) && is_executable($path)) return $path; } $matches = glob('/home/*/bin/wp'); if ($matches) return $matches[0]; $which = trim((string) shell_exec('which wp 2>/dev/null')); return $which; } }