Skip to main content
Glama
wp-config-finder.ts1.08 kB
import * as fs from 'fs'; import * as path from 'path'; import { promisify } from 'util'; const readFileAsync = promisify(fs.readFile); const existsAsync = promisify(fs.exists); /** * Search for a wp-config.php file starting from the current directory * and moving up through parent directories */ export async function findWordPressConfig(startPath: string): Promise<string | null> { let currentPath = startPath; const rootPath = path.parse(startPath).root; // Keep searching up the directory tree until we reach the root while (currentPath !== rootPath) { const configPath = path.join(currentPath, 'wp-config.php'); if (await existsAsync(configPath)) { return configPath; } // Move up one directory level const parentPath = path.dirname(currentPath); // If we've reached the root or can't go up anymore, stop searching if (parentPath === currentPath) { break; } currentPath = parentPath; } return null; }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/sharmashivanand/mcp-wordpress'

If you have feedback or need assistance with the MCP directory API, please join our Discord server