/','/&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(); return [ 'available' => $available, 'path' => $available ? self::findWpCli() : null, 'version' => $available ? shell_exec(self::findWpCli() . ' --version --no-color 2>&1') : null, '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', '/home/*/bin/wp'] as $path) { if (strpos($path, '*') !== false) { $matches = glob($path); if ($matches) return $matches[0]; } elseif (file_exists($path) && is_executable($path)) { return $path; } } // Try which $which = trim(shell_exec('which wp 2>/dev/null') ?: ''); return $which; } }