claudeus-wp-mcp
Version:
The most comprehensive WordPress MCP server - 145 production-ready tools for complete WordPress management with AI
179 lines • 5.61 kB
JavaScript
/**
* Astra Theme API Client
* Handles Astra Pro addon features: Mega Menus, Custom Layouts, etc.
*/
import axios from 'axios';
export class AstraApiClient {
client;
_site;
constructor(site) {
this._site = site;
// Create client with base URL pointing to wp-json root (not wp/v2)
this.client = axios.create({
baseURL: `${site.url}/wp-json`,
auth: site.authType === 'basic' ? {
username: site.username,
password: site.auth
} : undefined,
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
...(site.authType === 'jwt' ? { 'Authorization': `Bearer ${site.auth}` } : {})
}
});
}
get site() {
return this._site;
}
// ==========================================
// MEGA MENUS
// ==========================================
/**
* Get mega menu configuration for a specific menu item
* @param menuItemId The menu item ID to get mega menu config for
*/
async getMegaMenu(menuItemId) {
try {
const response = await this.client.get(`/astra_addon/v1/mega_menu/${menuItemId}`);
return response.data;
}
catch (error) {
throw new Error(`Failed to get mega menu: ${error}`);
}
}
/**
* Create or update mega menu configuration
* @param data Mega menu configuration data
*/
async updateMegaMenu(data) {
try {
const response = await this.client.post('/astra_addon/v1/mega_menu', data);
return response.data;
}
catch (error) {
throw new Error(`Failed to update mega menu: ${error}`);
}
}
/**
* Enable mega menu for a menu item
* @param menuItemId The menu item ID to enable mega menu for
* @param columns Number of columns (2-6)
*/
async enableMegaMenu(menuItemId, columns = 3) {
return this.updateMegaMenu({
menu_item_id: menuItemId,
enabled: true,
columns,
});
}
/**
* Disable mega menu for a menu item
* @param menuItemId The menu item ID to disable mega menu for
*/
async disableMegaMenu(menuItemId) {
return this.updateMegaMenu({
menu_item_id: menuItemId,
enabled: false,
});
}
// ==========================================
// CUSTOM LAYOUTS
// ==========================================
/**
* Get all custom layouts
* Returns custom headers, footers, and hook layouts
*/
async getCustomLayouts() {
try {
const response = await this.client.get('/astra-addon/v1/custom-layouts');
return response.data;
}
catch (error) {
throw new Error(`Failed to get custom layouts: ${error}`);
}
}
/**
* Get a specific custom layout by ID
* @param id Custom layout ID
*/
async getCustomLayout(id) {
try {
const response = await this.client.get(`/wp/v2/astra-advanced-hook/${id}`);
return response.data;
}
catch (error) {
throw new Error(`Failed to get custom layout: ${error}`);
}
}
/**
* Create a new custom layout
* @param data Custom layout data
*/
async createCustomLayout(data) {
try {
const response = await this.client.post('/wp/v2/astra-advanced-hook', data);
return response.data;
}
catch (error) {
throw new Error(`Failed to create custom layout: ${error}`);
}
}
/**
* Update an existing custom layout
* @param id Custom layout ID
* @param data Updated layout data
*/
async updateCustomLayout(id, data) {
try {
const response = await this.client.put(`/wp/v2/astra-advanced-hook/${id}`, data);
return response.data;
}
catch (error) {
throw new Error(`Failed to update custom layout: ${error}`);
}
}
/**
* Delete a custom layout
* @param id Custom layout ID
* @param force Whether to force delete (bypass trash)
*/
async deleteCustomLayout(id, force = false) {
try {
const response = await this.client.delete(`/astra-addon/v1/custom-layouts/${id}${force ? '?force=true' : ''}`);
return response.data;
}
catch (error) {
throw new Error(`Failed to delete custom layout: ${error}`);
}
}
// ==========================================
// THEME SETTINGS
// ==========================================
/**
* Get Astra theme settings
* Returns all theme configuration (header, footer, colors, typography, etc.)
*/
async getThemeSettings() {
try {
const response = await this.client.get('/astra/v1/admin/settings');
return response.data;
}
catch (error) {
throw new Error(`Failed to get theme settings: ${error}`);
}
}
/**
* Update Astra theme settings
* @param settings Updated settings object
*/
async updateThemeSettings(settings) {
try {
const response = await this.client.post('/astra/v1/admin/settings', settings);
return response.data;
}
catch (error) {
throw new Error(`Failed to update theme settings: ${error}`);
}
}
}
//# sourceMappingURL=astra.js.map