@robinpath/wordpress 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1007 @@
1
+ const config = new Map();
2
+ function getConfig(key) {
3
+ const val = config.get(key);
4
+ if (!val)
5
+ throw new Error(`WordPress: "${key}" not configured. Call wordpress.setCredentials first.`);
6
+ return val;
7
+ }
8
+ function getAuth() {
9
+ const username = getConfig("username");
10
+ const appPassword = getConfig("appPassword");
11
+ return btoa(`${username}:${appPassword}`);
12
+ }
13
+ function getBaseUrl() {
14
+ return getConfig("siteUrl").replace(/\/+$/, "");
15
+ }
16
+ async function wpApi(path, method = "GET", body) {
17
+ const res = await fetch(`${getBaseUrl()}/wp-json/wp/v2${path}`, {
18
+ method,
19
+ headers: {
20
+ Authorization: `Basic ${getAuth()}`,
21
+ "Content-Type": "application/json",
22
+ },
23
+ body: body ? JSON.stringify(body) : undefined,
24
+ });
25
+ if (!res.ok) {
26
+ const text = await res.text();
27
+ throw new Error(`WordPress API error (${res.status}): ${text}`);
28
+ }
29
+ if (res.status === 204)
30
+ return { success: true };
31
+ return res.json();
32
+ }
33
+ function buildQs(opts, keys) {
34
+ const params = new URLSearchParams();
35
+ for (const k of keys) {
36
+ if (opts[k] !== undefined && opts[k] !== null)
37
+ params.set(k, String(opts[k]));
38
+ }
39
+ const qs = params.toString();
40
+ return qs ? `?${qs}` : "";
41
+ }
42
+ // ── Credentials ─────────────────────────────────────────────────────
43
+ const setCredentials = (args) => {
44
+ const siteUrl = args[0];
45
+ const username = args[1];
46
+ const appPassword = args[2];
47
+ if (!siteUrl || !username || !appPassword)
48
+ throw new Error("wordpress.setCredentials requires siteUrl, username, and appPassword.");
49
+ config.set("siteUrl", siteUrl);
50
+ config.set("username", username);
51
+ config.set("appPassword", appPassword);
52
+ return "WordPress credentials configured.";
53
+ };
54
+ // ── Posts ────────────────────────────────────────────────────────────
55
+ const listPosts = async (args) => {
56
+ const opts = (typeof args[0] === "object" && args[0] !== null ? args[0] : {});
57
+ return wpApi(`/posts${buildQs(opts, ["per_page", "page", "status", "search", "categories", "tags", "orderby", "order", "author"])}`);
58
+ };
59
+ const getPost = async (args) => {
60
+ const postId = args[0];
61
+ if (!postId)
62
+ throw new Error("wordpress.getPost requires a postId.");
63
+ return wpApi(`/posts/${postId}`);
64
+ };
65
+ const createPost = async (args) => {
66
+ const post = args[0];
67
+ if (!post)
68
+ throw new Error("wordpress.createPost requires a post object.");
69
+ return wpApi("/posts", "POST", post);
70
+ };
71
+ const updatePost = async (args) => {
72
+ const postId = args[0];
73
+ const post = args[1];
74
+ if (!postId || !post)
75
+ throw new Error("wordpress.updatePost requires postId and post object.");
76
+ return wpApi(`/posts/${postId}`, "POST", post);
77
+ };
78
+ const deletePost = async (args) => {
79
+ const postId = args[0];
80
+ const force = args[1] ?? false;
81
+ if (!postId)
82
+ throw new Error("wordpress.deletePost requires a postId.");
83
+ return wpApi(`/posts/${postId}?force=${force}`, "DELETE");
84
+ };
85
+ // ── Pages ───────────────────────────────────────────────────────────
86
+ const listPages = async (args) => {
87
+ const opts = (typeof args[0] === "object" && args[0] !== null ? args[0] : {});
88
+ return wpApi(`/pages${buildQs(opts, ["per_page", "page", "status", "search", "parent", "orderby", "order"])}`);
89
+ };
90
+ const createPage = async (args) => {
91
+ const page = args[0];
92
+ if (!page)
93
+ throw new Error("wordpress.createPage requires a page object.");
94
+ return wpApi("/pages", "POST", page);
95
+ };
96
+ const updatePage = async (args) => {
97
+ const pageId = args[0];
98
+ const page = args[1];
99
+ if (!pageId || !page)
100
+ throw new Error("wordpress.updatePage requires pageId and page object.");
101
+ return wpApi(`/pages/${pageId}`, "POST", page);
102
+ };
103
+ const deletePage = async (args) => {
104
+ const pageId = args[0];
105
+ const force = args[1] ?? false;
106
+ if (!pageId)
107
+ throw new Error("wordpress.deletePage requires a pageId.");
108
+ return wpApi(`/pages/${pageId}?force=${force}`, "DELETE");
109
+ };
110
+ // ── Categories ──────────────────────────────────────────────────────
111
+ const listCategories = async (args) => {
112
+ const opts = (typeof args[0] === "object" && args[0] !== null ? args[0] : {});
113
+ return wpApi(`/categories${buildQs(opts, ["per_page", "page", "search", "parent", "orderby", "order"])}`);
114
+ };
115
+ const createCategory = async (args) => {
116
+ const name = args[0];
117
+ const opts = (typeof args[1] === "object" && args[1] !== null ? args[1] : {});
118
+ if (!name)
119
+ throw new Error("wordpress.createCategory requires a name.");
120
+ const payload = { name };
121
+ if (opts.description)
122
+ payload.description = opts.description;
123
+ if (opts.parent)
124
+ payload.parent = opts.parent;
125
+ if (opts.slug)
126
+ payload.slug = opts.slug;
127
+ return wpApi("/categories", "POST", payload);
128
+ };
129
+ const deleteCategory = async (args) => {
130
+ const categoryId = args[0];
131
+ if (!categoryId)
132
+ throw new Error("wordpress.deleteCategory requires a categoryId.");
133
+ return wpApi(`/categories/${categoryId}?force=true`, "DELETE");
134
+ };
135
+ // ── Tags ────────────────────────────────────────────────────────────
136
+ const listTags = async (args) => {
137
+ const opts = (typeof args[0] === "object" && args[0] !== null ? args[0] : {});
138
+ return wpApi(`/tags${buildQs(opts, ["per_page", "page", "search", "orderby", "order"])}`);
139
+ };
140
+ const createTag = async (args) => {
141
+ const name = args[0];
142
+ const opts = (typeof args[1] === "object" && args[1] !== null ? args[1] : {});
143
+ if (!name)
144
+ throw new Error("wordpress.createTag requires a name.");
145
+ const payload = { name };
146
+ if (opts.description)
147
+ payload.description = opts.description;
148
+ if (opts.slug)
149
+ payload.slug = opts.slug;
150
+ return wpApi("/tags", "POST", payload);
151
+ };
152
+ const deleteTag = async (args) => {
153
+ const tagId = args[0];
154
+ if (!tagId)
155
+ throw new Error("wordpress.deleteTag requires a tagId.");
156
+ return wpApi(`/tags/${tagId}?force=true`, "DELETE");
157
+ };
158
+ // ── Comments ────────────────────────────────────────────────────────
159
+ const listComments = async (args) => {
160
+ const opts = (typeof args[0] === "object" && args[0] !== null ? args[0] : {});
161
+ return wpApi(`/comments${buildQs(opts, ["per_page", "page", "post", "status", "search", "author", "orderby", "order"])}`);
162
+ };
163
+ const getComment = async (args) => {
164
+ const commentId = args[0];
165
+ if (!commentId)
166
+ throw new Error("wordpress.getComment requires a commentId.");
167
+ return wpApi(`/comments/${commentId}`);
168
+ };
169
+ const createComment = async (args) => {
170
+ const comment = args[0];
171
+ if (!comment)
172
+ throw new Error("wordpress.createComment requires a comment object.");
173
+ return wpApi("/comments", "POST", comment);
174
+ };
175
+ const updateComment = async (args) => {
176
+ const commentId = args[0];
177
+ const updates = args[1];
178
+ if (!commentId || !updates)
179
+ throw new Error("wordpress.updateComment requires commentId and updates.");
180
+ return wpApi(`/comments/${commentId}`, "POST", updates);
181
+ };
182
+ const deleteComment = async (args) => {
183
+ const commentId = args[0];
184
+ const force = args[1] ?? false;
185
+ if (!commentId)
186
+ throw new Error("wordpress.deleteComment requires a commentId.");
187
+ return wpApi(`/comments/${commentId}?force=${force}`, "DELETE");
188
+ };
189
+ const moderateComment = async (args) => {
190
+ const commentId = args[0];
191
+ const status = args[1];
192
+ if (!commentId || !status)
193
+ throw new Error("wordpress.moderateComment requires commentId and status (approved, hold, spam, trash).");
194
+ return wpApi(`/comments/${commentId}`, "POST", { status });
195
+ };
196
+ // ── Media ───────────────────────────────────────────────────────────
197
+ const listMedia = async (args) => {
198
+ const opts = (typeof args[0] === "object" && args[0] !== null ? args[0] : {});
199
+ return wpApi(`/media${buildQs(opts, ["per_page", "page", "search", "media_type", "mime_type", "orderby", "order"])}`);
200
+ };
201
+ const getMedia = async (args) => {
202
+ const mediaId = args[0];
203
+ if (!mediaId)
204
+ throw new Error("wordpress.getMedia requires a mediaId.");
205
+ return wpApi(`/media/${mediaId}`);
206
+ };
207
+ const uploadMedia = async (args) => {
208
+ const filename = args[0];
209
+ const content = args[1];
210
+ const mimeType = args[2] ?? "image/png";
211
+ if (!filename || content === undefined)
212
+ throw new Error("wordpress.uploadMedia requires filename and content.");
213
+ const res = await fetch(`${getBaseUrl()}/wp-json/wp/v2/media`, {
214
+ method: "POST",
215
+ headers: {
216
+ Authorization: `Basic ${getAuth()}`,
217
+ "Content-Type": mimeType,
218
+ "Content-Disposition": `attachment; filename="${filename}"`,
219
+ },
220
+ body: content,
221
+ });
222
+ if (!res.ok) {
223
+ const text = await res.text();
224
+ throw new Error(`WordPress media upload error (${res.status}): ${text}`);
225
+ }
226
+ return res.json();
227
+ };
228
+ const updateMedia = async (args) => {
229
+ const mediaId = args[0];
230
+ const updates = args[1];
231
+ if (!mediaId || !updates)
232
+ throw new Error("wordpress.updateMedia requires mediaId and updates.");
233
+ return wpApi(`/media/${mediaId}`, "POST", updates);
234
+ };
235
+ const deleteMedia = async (args) => {
236
+ const mediaId = args[0];
237
+ const force = args[1] ?? true;
238
+ if (!mediaId)
239
+ throw new Error("wordpress.deleteMedia requires a mediaId.");
240
+ return wpApi(`/media/${mediaId}?force=${force}`, "DELETE");
241
+ };
242
+ // ── Users ───────────────────────────────────────────────────────────
243
+ const listUsers = async (args) => {
244
+ const opts = (typeof args[0] === "object" && args[0] !== null ? args[0] : {});
245
+ return wpApi(`/users${buildQs(opts, ["per_page", "page", "search", "roles", "orderby", "order"])}`);
246
+ };
247
+ const getUser = async (args) => {
248
+ const userId = args[0];
249
+ if (!userId)
250
+ throw new Error("wordpress.getUser requires a userId.");
251
+ return wpApi(`/users/${userId}`);
252
+ };
253
+ const createUser = async (args) => {
254
+ const user = args[0];
255
+ if (!user)
256
+ throw new Error("wordpress.createUser requires a user object.");
257
+ if (!user.username || !user.email || !user.password)
258
+ throw new Error("wordpress.createUser requires username, email, and password.");
259
+ return wpApi("/users", "POST", user);
260
+ };
261
+ const updateUser = async (args) => {
262
+ const userId = args[0];
263
+ const updates = args[1];
264
+ if (!userId || !updates)
265
+ throw new Error("wordpress.updateUser requires userId and updates.");
266
+ return wpApi(`/users/${userId}`, "POST", updates);
267
+ };
268
+ const deleteUser = async (args) => {
269
+ const userId = args[0];
270
+ const reassignTo = args[1];
271
+ if (!userId)
272
+ throw new Error("wordpress.deleteUser requires a userId.");
273
+ if (!reassignTo)
274
+ throw new Error("wordpress.deleteUser requires a reassignTo userId (WordPress requires content reassignment).");
275
+ return wpApi(`/users/${userId}?force=true&reassign=${reassignTo}`, "DELETE");
276
+ };
277
+ // ── Post/Page Meta (Custom Fields) ─────────────────────────────────
278
+ const getMeta = async (args) => {
279
+ const postType = args[0] ?? "posts";
280
+ const postId = args[1];
281
+ if (!postId)
282
+ throw new Error("wordpress.getMeta requires postId.");
283
+ return wpApi(`/${postType}/${postId}?_fields=meta`);
284
+ };
285
+ const updateMeta = async (args) => {
286
+ const postType = args[0] ?? "posts";
287
+ const postId = args[1];
288
+ const meta = args[2];
289
+ if (!postId || !meta)
290
+ throw new Error("wordpress.updateMeta requires postId and meta object.");
291
+ return wpApi(`/${postType}/${postId}`, "POST", { meta });
292
+ };
293
+ const deleteMeta = async (args) => {
294
+ const postType = args[0] ?? "posts";
295
+ const postId = args[1];
296
+ const metaKey = args[2];
297
+ if (!postId || !metaKey)
298
+ throw new Error("wordpress.deleteMeta requires postId and metaKey.");
299
+ return wpApi(`/${postType}/${postId}`, "POST", { meta: { [metaKey]: null } });
300
+ };
301
+ // ── Revisions ───────────────────────────────────────────────────────
302
+ const listRevisions = async (args) => {
303
+ const postType = args[0] ?? "posts";
304
+ const postId = args[1];
305
+ if (!postId)
306
+ throw new Error("wordpress.listRevisions requires postId.");
307
+ return wpApi(`/${postType}/${postId}/revisions`);
308
+ };
309
+ const getRevision = async (args) => {
310
+ const postType = args[0] ?? "posts";
311
+ const postId = args[1];
312
+ const revisionId = args[2];
313
+ if (!postId || !revisionId)
314
+ throw new Error("wordpress.getRevision requires postId and revisionId.");
315
+ return wpApi(`/${postType}/${postId}/revisions/${revisionId}`);
316
+ };
317
+ const deleteRevision = async (args) => {
318
+ const postType = args[0] ?? "posts";
319
+ const postId = args[1];
320
+ const revisionId = args[2];
321
+ if (!postId || !revisionId)
322
+ throw new Error("wordpress.deleteRevision requires postId and revisionId.");
323
+ return wpApi(`/${postType}/${postId}/revisions/${revisionId}?force=true`, "DELETE");
324
+ };
325
+ // ── Taxonomies (Custom) ─────────────────────────────────────────────
326
+ const listTaxonomies = async () => {
327
+ return wpApi("/taxonomies");
328
+ };
329
+ const listTerms = async (args) => {
330
+ const taxonomy = args[0];
331
+ const opts = (typeof args[1] === "object" && args[1] !== null ? args[1] : {});
332
+ if (!taxonomy)
333
+ throw new Error("wordpress.listTerms requires a taxonomy slug.");
334
+ return wpApi(`/${taxonomy}${buildQs(opts, ["per_page", "page", "search", "parent", "orderby", "order"])}`);
335
+ };
336
+ const createTerm = async (args) => {
337
+ const taxonomy = args[0];
338
+ const name = args[1];
339
+ const opts = (typeof args[2] === "object" && args[2] !== null ? args[2] : {});
340
+ if (!taxonomy || !name)
341
+ throw new Error("wordpress.createTerm requires taxonomy and name.");
342
+ const payload = { name };
343
+ if (opts.description)
344
+ payload.description = opts.description;
345
+ if (opts.parent)
346
+ payload.parent = opts.parent;
347
+ if (opts.slug)
348
+ payload.slug = opts.slug;
349
+ return wpApi(`/${taxonomy}`, "POST", payload);
350
+ };
351
+ // ── Plugins (WP 5.5+) ──────────────────────────────────────────────
352
+ const listPlugins = async () => {
353
+ return wpApi("/plugins");
354
+ };
355
+ const activatePlugin = async (args) => {
356
+ const plugin = args[0];
357
+ if (!plugin)
358
+ throw new Error("wordpress.activatePlugin requires a plugin slug.");
359
+ return wpApi(`/plugins/${plugin}`, "POST", { status: "active" });
360
+ };
361
+ const deactivatePlugin = async (args) => {
362
+ const plugin = args[0];
363
+ if (!plugin)
364
+ throw new Error("wordpress.deactivatePlugin requires a plugin slug.");
365
+ return wpApi(`/plugins/${plugin}`, "POST", { status: "inactive" });
366
+ };
367
+ const installPlugin = async (args) => {
368
+ const slug = args[0];
369
+ const activate = args[1] ?? false;
370
+ if (!slug)
371
+ throw new Error("wordpress.installPlugin requires a plugin slug from wordpress.org.");
372
+ const result = await wpApi("/plugins", "POST", { slug, status: activate ? "active" : "inactive" });
373
+ return result;
374
+ };
375
+ const deletePlugin = async (args) => {
376
+ const plugin = args[0];
377
+ if (!plugin)
378
+ throw new Error("wordpress.deletePlugin requires a plugin slug.");
379
+ const res = await fetch(`${getBaseUrl()}/wp-json/wp/v2/plugins/${plugin}`, {
380
+ method: "DELETE",
381
+ headers: {
382
+ Authorization: `Basic ${getAuth()}`,
383
+ "Content-Type": "application/json",
384
+ },
385
+ });
386
+ if (!res.ok) {
387
+ const text = await res.text();
388
+ throw new Error(`WordPress plugin delete error (${res.status}): ${text}`);
389
+ }
390
+ if (res.status === 204)
391
+ return { success: true };
392
+ return res.json();
393
+ };
394
+ // ── Themes ──────────────────────────────────────────────────────────
395
+ const listThemes = async () => {
396
+ return wpApi("/themes");
397
+ };
398
+ const activateTheme = async (args) => {
399
+ const theme = args[0];
400
+ if (!theme)
401
+ throw new Error("wordpress.activateTheme requires a theme stylesheet slug.");
402
+ return wpApi(`/themes/${theme}`, "POST", { status: "active" });
403
+ };
404
+ // ── Site Settings ───────────────────────────────────────────────────
405
+ const getSettings = async () => {
406
+ return wpApi("/settings");
407
+ };
408
+ const updateSettings = async (args) => {
409
+ const settings = args[0];
410
+ if (!settings)
411
+ throw new Error("wordpress.updateSettings requires a settings object.");
412
+ return wpApi("/settings", "POST", settings);
413
+ };
414
+ // ── Search ──────────────────────────────────────────────────────────
415
+ const search = async (args) => {
416
+ const query = args[0];
417
+ const opts = (typeof args[1] === "object" && args[1] !== null ? args[1] : {});
418
+ if (!query)
419
+ throw new Error("wordpress.search requires a query.");
420
+ const allOpts = { ...opts, search: query };
421
+ return wpApi(`/search${buildQs(allOpts, ["search", "per_page", "page", "type", "subtype"])}`);
422
+ };
423
+ // ── Bulk Operations ─────────────────────────────────────────────────
424
+ const bulkUpdatePosts = async (args) => {
425
+ const postIds = args[0];
426
+ const updates = args[1];
427
+ if (!postIds?.length || !updates)
428
+ throw new Error("wordpress.bulkUpdatePosts requires postIds array and updates object.");
429
+ const results = [];
430
+ for (const id of postIds) {
431
+ results.push(await wpApi(`/posts/${id}`, "POST", updates));
432
+ }
433
+ return results;
434
+ };
435
+ const bulkDeletePosts = async (args) => {
436
+ const postIds = args[0];
437
+ const force = args[1] ?? false;
438
+ if (!postIds?.length)
439
+ throw new Error("wordpress.bulkDeletePosts requires a postIds array.");
440
+ const results = [];
441
+ for (const id of postIds) {
442
+ results.push(await wpApi(`/posts/${id}?force=${force}`, "DELETE"));
443
+ }
444
+ return results;
445
+ };
446
+ // ── Exports ─────────────────────────────────────────────────────────
447
+ export const WordpressFunctions = {
448
+ // Credentials
449
+ setCredentials,
450
+ // Posts
451
+ listPosts, getPost, createPost, updatePost, deletePost,
452
+ // Pages
453
+ listPages, createPage, updatePage, deletePage,
454
+ // Categories
455
+ listCategories, createCategory, deleteCategory,
456
+ // Tags
457
+ listTags, createTag, deleteTag,
458
+ // Comments
459
+ listComments, getComment, createComment, updateComment, deleteComment, moderateComment,
460
+ // Media
461
+ listMedia, getMedia, uploadMedia, updateMedia, deleteMedia,
462
+ // Users
463
+ listUsers, getUser, createUser, updateUser, deleteUser,
464
+ // Meta
465
+ getMeta, updateMeta, deleteMeta,
466
+ // Revisions
467
+ listRevisions, getRevision, deleteRevision,
468
+ // Taxonomies
469
+ listTaxonomies, listTerms, createTerm,
470
+ // Plugins
471
+ listPlugins, activatePlugin, deactivatePlugin, installPlugin, deletePlugin,
472
+ // Themes
473
+ listThemes, activateTheme,
474
+ // Settings
475
+ getSettings, updateSettings,
476
+ // Search
477
+ search,
478
+ // Bulk
479
+ bulkUpdatePosts, bulkDeletePosts,
480
+ };
481
+ export const WordpressFunctionMetadata = {
482
+ // ── Credentials ─────────────────────────────────────────────────
483
+ setCredentials: {
484
+ description: "Set WordPress site URL and Application Password credentials.",
485
+ parameters: [
486
+ { name: "siteUrl", dataType: "string", description: "WordPress site URL (e.g. https://mysite.com)", formInputType: "text", required: true },
487
+ { name: "username", dataType: "string", description: "WordPress username", formInputType: "text", required: true },
488
+ { name: "appPassword", dataType: "string", description: "Application Password (WP Admin > Users > Application Passwords)", formInputType: "text", required: true },
489
+ ],
490
+ returnType: "string",
491
+ returnDescription: "Confirmation message.",
492
+ example: 'wordpress.setCredentials "https://mysite.com" "admin" "xxxx xxxx xxxx xxxx"',
493
+ },
494
+ // ── Posts ────────────────────────────────────────────────────────
495
+ listPosts: {
496
+ description: "List posts with optional filters.",
497
+ parameters: [
498
+ { name: "options", dataType: "object", description: "Options: per_page, page, status, search, categories, tags, orderby, order, author", formInputType: "json", required: false },
499
+ ],
500
+ returnType: "array",
501
+ returnDescription: "Array of post objects.",
502
+ example: 'wordpress.listPosts {"per_page":5,"status":"publish"}',
503
+ },
504
+ getPost: {
505
+ description: "Get a single post by ID.",
506
+ parameters: [
507
+ { name: "postId", dataType: "string", description: "Post ID", formInputType: "text", required: true },
508
+ ],
509
+ returnType: "object",
510
+ returnDescription: "Post object.",
511
+ example: 'wordpress.getPost "123"',
512
+ },
513
+ createPost: {
514
+ description: "Create a new post.",
515
+ parameters: [
516
+ { name: "post", dataType: "object", description: "Post object (title, content, status, categories, tags, featured_media, etc.)", formInputType: "json", required: true },
517
+ ],
518
+ returnType: "object",
519
+ returnDescription: "Created post object.",
520
+ example: 'wordpress.createPost {"title":"My Post","content":"<p>Hello</p>","status":"draft"}',
521
+ },
522
+ updatePost: {
523
+ description: "Update an existing post.",
524
+ parameters: [
525
+ { name: "postId", dataType: "string", description: "Post ID", formInputType: "text", required: true },
526
+ { name: "post", dataType: "object", description: "Fields to update", formInputType: "json", required: true },
527
+ ],
528
+ returnType: "object",
529
+ returnDescription: "Updated post object.",
530
+ example: 'wordpress.updatePost "123" {"title":"Updated","status":"publish"}',
531
+ },
532
+ deletePost: {
533
+ description: "Delete a post (trash or force-delete).",
534
+ parameters: [
535
+ { name: "postId", dataType: "string", description: "Post ID", formInputType: "text", required: true },
536
+ { name: "force", dataType: "boolean", description: "Permanently delete (default: false = trash)", formInputType: "checkbox", required: false },
537
+ ],
538
+ returnType: "object",
539
+ returnDescription: "Deleted/trashed post object.",
540
+ example: 'wordpress.deletePost "123"',
541
+ },
542
+ // ── Pages ───────────────────────────────────────────────────────
543
+ listPages: {
544
+ description: "List pages with optional filters.",
545
+ parameters: [
546
+ { name: "options", dataType: "object", description: "Options: per_page, page, status, search, parent, orderby, order", formInputType: "json", required: false },
547
+ ],
548
+ returnType: "array",
549
+ returnDescription: "Array of page objects.",
550
+ example: 'wordpress.listPages {"per_page":10}',
551
+ },
552
+ createPage: {
553
+ description: "Create a new page.",
554
+ parameters: [
555
+ { name: "page", dataType: "object", description: "Page object (title, content, status, parent, etc.)", formInputType: "json", required: true },
556
+ ],
557
+ returnType: "object",
558
+ returnDescription: "Created page object.",
559
+ example: 'wordpress.createPage {"title":"About","content":"<p>About us</p>","status":"publish"}',
560
+ },
561
+ updatePage: {
562
+ description: "Update an existing page.",
563
+ parameters: [
564
+ { name: "pageId", dataType: "string", description: "Page ID", formInputType: "text", required: true },
565
+ { name: "page", dataType: "object", description: "Fields to update", formInputType: "json", required: true },
566
+ ],
567
+ returnType: "object",
568
+ returnDescription: "Updated page object.",
569
+ example: 'wordpress.updatePage "456" {"content":"<p>Updated</p>"}',
570
+ },
571
+ deletePage: {
572
+ description: "Delete a page (trash or force-delete).",
573
+ parameters: [
574
+ { name: "pageId", dataType: "string", description: "Page ID", formInputType: "text", required: true },
575
+ { name: "force", dataType: "boolean", description: "Permanently delete (default: false = trash)", formInputType: "checkbox", required: false },
576
+ ],
577
+ returnType: "object",
578
+ returnDescription: "Deleted/trashed page object.",
579
+ example: 'wordpress.deletePage "456" true',
580
+ },
581
+ // ── Categories ──────────────────────────────────────────────────
582
+ listCategories: {
583
+ description: "List post categories.",
584
+ parameters: [
585
+ { name: "options", dataType: "object", description: "Options: per_page, page, search, parent, orderby, order", formInputType: "json", required: false },
586
+ ],
587
+ returnType: "array",
588
+ returnDescription: "Array of category objects.",
589
+ example: "wordpress.listCategories",
590
+ },
591
+ createCategory: {
592
+ description: "Create a new category.",
593
+ parameters: [
594
+ { name: "name", dataType: "string", description: "Category name", formInputType: "text", required: true },
595
+ { name: "options", dataType: "object", description: "Options: description, parent, slug", formInputType: "json", required: false },
596
+ ],
597
+ returnType: "object",
598
+ returnDescription: "Created category object.",
599
+ example: 'wordpress.createCategory "Technology"',
600
+ },
601
+ deleteCategory: {
602
+ description: "Permanently delete a category.",
603
+ parameters: [
604
+ { name: "categoryId", dataType: "string", description: "Category ID", formInputType: "text", required: true },
605
+ ],
606
+ returnType: "object",
607
+ returnDescription: "Deletion confirmation.",
608
+ example: 'wordpress.deleteCategory "12"',
609
+ },
610
+ // ── Tags ────────────────────────────────────────────────────────
611
+ listTags: {
612
+ description: "List post tags.",
613
+ parameters: [
614
+ { name: "options", dataType: "object", description: "Options: per_page, page, search, orderby, order", formInputType: "json", required: false },
615
+ ],
616
+ returnType: "array",
617
+ returnDescription: "Array of tag objects.",
618
+ example: 'wordpress.listTags {"search":"javascript"}',
619
+ },
620
+ createTag: {
621
+ description: "Create a new tag.",
622
+ parameters: [
623
+ { name: "name", dataType: "string", description: "Tag name", formInputType: "text", required: true },
624
+ { name: "options", dataType: "object", description: "Options: description, slug", formInputType: "json", required: false },
625
+ ],
626
+ returnType: "object",
627
+ returnDescription: "Created tag object.",
628
+ example: 'wordpress.createTag "react"',
629
+ },
630
+ deleteTag: {
631
+ description: "Permanently delete a tag.",
632
+ parameters: [
633
+ { name: "tagId", dataType: "string", description: "Tag ID", formInputType: "text", required: true },
634
+ ],
635
+ returnType: "object",
636
+ returnDescription: "Deletion confirmation.",
637
+ example: 'wordpress.deleteTag "34"',
638
+ },
639
+ // ── Comments ────────────────────────────────────────────────────
640
+ listComments: {
641
+ description: "List comments with optional filters.",
642
+ parameters: [
643
+ { name: "options", dataType: "object", description: "Options: per_page, page, post, status (approved, hold, spam, trash), search, author, orderby, order", formInputType: "json", required: false },
644
+ ],
645
+ returnType: "array",
646
+ returnDescription: "Array of comment objects.",
647
+ example: 'wordpress.listComments {"post":"123","status":"approved"}',
648
+ },
649
+ getComment: {
650
+ description: "Get a single comment by ID.",
651
+ parameters: [
652
+ { name: "commentId", dataType: "string", description: "Comment ID", formInputType: "text", required: true },
653
+ ],
654
+ returnType: "object",
655
+ returnDescription: "Comment object.",
656
+ example: 'wordpress.getComment "456"',
657
+ },
658
+ createComment: {
659
+ description: "Create a new comment.",
660
+ parameters: [
661
+ { name: "comment", dataType: "object", description: "Comment object (post, content, author_name, author_email, parent, status)", formInputType: "json", required: true },
662
+ ],
663
+ returnType: "object",
664
+ returnDescription: "Created comment object.",
665
+ example: 'wordpress.createComment {"post":123,"content":"Great article!","author_name":"John"}',
666
+ },
667
+ updateComment: {
668
+ description: "Update an existing comment.",
669
+ parameters: [
670
+ { name: "commentId", dataType: "string", description: "Comment ID", formInputType: "text", required: true },
671
+ { name: "updates", dataType: "object", description: "Fields to update (content, status, etc.)", formInputType: "json", required: true },
672
+ ],
673
+ returnType: "object",
674
+ returnDescription: "Updated comment object.",
675
+ example: 'wordpress.updateComment "456" {"content":"Edited comment"}',
676
+ },
677
+ deleteComment: {
678
+ description: "Delete a comment (trash or force-delete).",
679
+ parameters: [
680
+ { name: "commentId", dataType: "string", description: "Comment ID", formInputType: "text", required: true },
681
+ { name: "force", dataType: "boolean", description: "Permanently delete (default: false = trash)", formInputType: "checkbox", required: false },
682
+ ],
683
+ returnType: "object",
684
+ returnDescription: "Deleted/trashed comment.",
685
+ example: 'wordpress.deleteComment "456"',
686
+ },
687
+ moderateComment: {
688
+ description: "Change a comment's moderation status.",
689
+ parameters: [
690
+ { name: "commentId", dataType: "string", description: "Comment ID", formInputType: "text", required: true },
691
+ { name: "status", dataType: "string", description: "New status: approved, hold, spam, trash", formInputType: "select", required: true },
692
+ ],
693
+ returnType: "object",
694
+ returnDescription: "Updated comment object.",
695
+ example: 'wordpress.moderateComment "456" "approved"',
696
+ },
697
+ // ── Media ───────────────────────────────────────────────────────
698
+ listMedia: {
699
+ description: "List media library items.",
700
+ parameters: [
701
+ { name: "options", dataType: "object", description: "Options: per_page, page, search, media_type (image, video, audio, application), mime_type, orderby, order", formInputType: "json", required: false },
702
+ ],
703
+ returnType: "array",
704
+ returnDescription: "Array of media objects.",
705
+ example: 'wordpress.listMedia {"media_type":"image","per_page":20}',
706
+ },
707
+ getMedia: {
708
+ description: "Get a media item by ID.",
709
+ parameters: [
710
+ { name: "mediaId", dataType: "string", description: "Media ID", formInputType: "text", required: true },
711
+ ],
712
+ returnType: "object",
713
+ returnDescription: "Media object with source_url, dimensions, etc.",
714
+ example: 'wordpress.getMedia "789"',
715
+ },
716
+ uploadMedia: {
717
+ description: "Upload a media file.",
718
+ parameters: [
719
+ { name: "filename", dataType: "string", description: "File name", formInputType: "text", required: true },
720
+ { name: "content", dataType: "string", description: "File content", formInputType: "textarea", required: true },
721
+ { name: "mimeType", dataType: "string", description: "MIME type (default: image/png)", formInputType: "text", required: false },
722
+ ],
723
+ returnType: "object",
724
+ returnDescription: "Uploaded media object with source_url.",
725
+ example: 'wordpress.uploadMedia "photo.png" content "image/png"',
726
+ },
727
+ updateMedia: {
728
+ description: "Update media metadata (title, alt_text, caption, description).",
729
+ parameters: [
730
+ { name: "mediaId", dataType: "string", description: "Media ID", formInputType: "text", required: true },
731
+ { name: "updates", dataType: "object", description: "Fields: title, alt_text, caption, description", formInputType: "json", required: true },
732
+ ],
733
+ returnType: "object",
734
+ returnDescription: "Updated media object.",
735
+ example: 'wordpress.updateMedia "789" {"alt_text":"Hero image","caption":"Homepage banner"}',
736
+ },
737
+ deleteMedia: {
738
+ description: "Permanently delete a media item.",
739
+ parameters: [
740
+ { name: "mediaId", dataType: "string", description: "Media ID", formInputType: "text", required: true },
741
+ { name: "force", dataType: "boolean", description: "Force permanent deletion (default: true)", formInputType: "checkbox", required: false },
742
+ ],
743
+ returnType: "object",
744
+ returnDescription: "Deletion confirmation.",
745
+ example: 'wordpress.deleteMedia "789"',
746
+ },
747
+ // ── Users ───────────────────────────────────────────────────────
748
+ listUsers: {
749
+ description: "List users on the site.",
750
+ parameters: [
751
+ { name: "options", dataType: "object", description: "Options: per_page, page, search, roles, orderby, order", formInputType: "json", required: false },
752
+ ],
753
+ returnType: "array",
754
+ returnDescription: "Array of user objects.",
755
+ example: 'wordpress.listUsers {"roles":"administrator"}',
756
+ },
757
+ getUser: {
758
+ description: "Get a user by ID.",
759
+ parameters: [
760
+ { name: "userId", dataType: "string", description: "User ID", formInputType: "text", required: true },
761
+ ],
762
+ returnType: "object",
763
+ returnDescription: "User object.",
764
+ example: 'wordpress.getUser "1"',
765
+ },
766
+ createUser: {
767
+ description: "Create a new user.",
768
+ parameters: [
769
+ { name: "user", dataType: "object", description: "User object (username, email, password required; also: first_name, last_name, roles, description)", formInputType: "json", required: true },
770
+ ],
771
+ returnType: "object",
772
+ returnDescription: "Created user object.",
773
+ example: 'wordpress.createUser {"username":"john","email":"john@example.com","password":"SecureP@ss","roles":["editor"]}',
774
+ },
775
+ updateUser: {
776
+ description: "Update a user's profile.",
777
+ parameters: [
778
+ { name: "userId", dataType: "string", description: "User ID", formInputType: "text", required: true },
779
+ { name: "updates", dataType: "object", description: "Fields to update (first_name, last_name, email, roles, description, etc.)", formInputType: "json", required: true },
780
+ ],
781
+ returnType: "object",
782
+ returnDescription: "Updated user object.",
783
+ example: 'wordpress.updateUser "2" {"roles":["administrator"],"first_name":"John"}',
784
+ },
785
+ deleteUser: {
786
+ description: "Delete a user and reassign their content.",
787
+ parameters: [
788
+ { name: "userId", dataType: "string", description: "User ID to delete", formInputType: "text", required: true },
789
+ { name: "reassignTo", dataType: "string", description: "User ID to reassign content to (required by WordPress)", formInputType: "text", required: true },
790
+ ],
791
+ returnType: "object",
792
+ returnDescription: "Deletion confirmation.",
793
+ example: 'wordpress.deleteUser "5" "1"',
794
+ },
795
+ // ── Meta ────────────────────────────────────────────────────────
796
+ getMeta: {
797
+ description: "Get custom fields/meta for a post or page.",
798
+ parameters: [
799
+ { name: "postType", dataType: "string", description: "Post type endpoint: 'posts' or 'pages' (default: posts)", formInputType: "text", required: false },
800
+ { name: "postId", dataType: "string", description: "Post/Page ID", formInputType: "text", required: true },
801
+ ],
802
+ returnType: "object",
803
+ returnDescription: "Object containing meta fields.",
804
+ example: 'wordpress.getMeta "posts" "123"',
805
+ },
806
+ updateMeta: {
807
+ description: "Update custom fields/meta on a post or page.",
808
+ parameters: [
809
+ { name: "postType", dataType: "string", description: "Post type endpoint: 'posts' or 'pages' (default: posts)", formInputType: "text", required: false },
810
+ { name: "postId", dataType: "string", description: "Post/Page ID", formInputType: "text", required: true },
811
+ { name: "meta", dataType: "object", description: "Meta key-value pairs to set", formInputType: "json", required: true },
812
+ ],
813
+ returnType: "object",
814
+ returnDescription: "Updated post/page object.",
815
+ example: 'wordpress.updateMeta "posts" "123" {"custom_field":"value","price":"29.99"}',
816
+ },
817
+ deleteMeta: {
818
+ description: "Remove a custom field/meta key from a post or page.",
819
+ parameters: [
820
+ { name: "postType", dataType: "string", description: "Post type endpoint: 'posts' or 'pages' (default: posts)", formInputType: "text", required: false },
821
+ { name: "postId", dataType: "string", description: "Post/Page ID", formInputType: "text", required: true },
822
+ { name: "metaKey", dataType: "string", description: "Meta key to remove", formInputType: "text", required: true },
823
+ ],
824
+ returnType: "object",
825
+ returnDescription: "Updated post/page object.",
826
+ example: 'wordpress.deleteMeta "posts" "123" "custom_field"',
827
+ },
828
+ // ── Revisions ───────────────────────────────────────────────────
829
+ listRevisions: {
830
+ description: "List revisions for a post or page.",
831
+ parameters: [
832
+ { name: "postType", dataType: "string", description: "Post type endpoint: 'posts' or 'pages' (default: posts)", formInputType: "text", required: false },
833
+ { name: "postId", dataType: "string", description: "Post/Page ID", formInputType: "text", required: true },
834
+ ],
835
+ returnType: "array",
836
+ returnDescription: "Array of revision objects.",
837
+ example: 'wordpress.listRevisions "posts" "123"',
838
+ },
839
+ getRevision: {
840
+ description: "Get a specific revision.",
841
+ parameters: [
842
+ { name: "postType", dataType: "string", description: "Post type endpoint (default: posts)", formInputType: "text", required: false },
843
+ { name: "postId", dataType: "string", description: "Post/Page ID", formInputType: "text", required: true },
844
+ { name: "revisionId", dataType: "string", description: "Revision ID", formInputType: "text", required: true },
845
+ ],
846
+ returnType: "object",
847
+ returnDescription: "Revision object with content diff.",
848
+ example: 'wordpress.getRevision "posts" "123" "456"',
849
+ },
850
+ deleteRevision: {
851
+ description: "Permanently delete a revision.",
852
+ parameters: [
853
+ { name: "postType", dataType: "string", description: "Post type endpoint (default: posts)", formInputType: "text", required: false },
854
+ { name: "postId", dataType: "string", description: "Post/Page ID", formInputType: "text", required: true },
855
+ { name: "revisionId", dataType: "string", description: "Revision ID", formInputType: "text", required: true },
856
+ ],
857
+ returnType: "object",
858
+ returnDescription: "Deletion confirmation.",
859
+ example: 'wordpress.deleteRevision "posts" "123" "456"',
860
+ },
861
+ // ── Taxonomies ──────────────────────────────────────────────────
862
+ listTaxonomies: {
863
+ description: "List all registered taxonomies.",
864
+ parameters: [],
865
+ returnType: "object",
866
+ returnDescription: "Object of taxonomy definitions.",
867
+ example: "wordpress.listTaxonomies",
868
+ },
869
+ listTerms: {
870
+ description: "List terms for any taxonomy.",
871
+ parameters: [
872
+ { name: "taxonomy", dataType: "string", description: "Taxonomy REST slug (e.g. 'categories', 'tags', or custom)", formInputType: "text", required: true },
873
+ { name: "options", dataType: "object", description: "Options: per_page, page, search, parent, orderby, order", formInputType: "json", required: false },
874
+ ],
875
+ returnType: "array",
876
+ returnDescription: "Array of term objects.",
877
+ example: 'wordpress.listTerms "categories" {"search":"tech"}',
878
+ },
879
+ createTerm: {
880
+ description: "Create a term in any taxonomy.",
881
+ parameters: [
882
+ { name: "taxonomy", dataType: "string", description: "Taxonomy REST slug", formInputType: "text", required: true },
883
+ { name: "name", dataType: "string", description: "Term name", formInputType: "text", required: true },
884
+ { name: "options", dataType: "object", description: "Options: description, parent, slug", formInputType: "json", required: false },
885
+ ],
886
+ returnType: "object",
887
+ returnDescription: "Created term object.",
888
+ example: 'wordpress.createTerm "categories" "DevOps" {"slug":"devops"}',
889
+ },
890
+ // ── Plugins ─────────────────────────────────────────────────────
891
+ listPlugins: {
892
+ description: "List all installed plugins with status.",
893
+ parameters: [],
894
+ returnType: "array",
895
+ returnDescription: "Array of plugin objects with name, status, version.",
896
+ example: "wordpress.listPlugins",
897
+ },
898
+ activatePlugin: {
899
+ description: "Activate a plugin.",
900
+ parameters: [
901
+ { name: "plugin", dataType: "string", description: "Plugin slug (e.g. 'akismet/akismet')", formInputType: "text", required: true },
902
+ ],
903
+ returnType: "object",
904
+ returnDescription: "Updated plugin object.",
905
+ example: 'wordpress.activatePlugin "akismet/akismet"',
906
+ },
907
+ deactivatePlugin: {
908
+ description: "Deactivate a plugin.",
909
+ parameters: [
910
+ { name: "plugin", dataType: "string", description: "Plugin slug (e.g. 'akismet/akismet')", formInputType: "text", required: true },
911
+ ],
912
+ returnType: "object",
913
+ returnDescription: "Updated plugin object.",
914
+ example: 'wordpress.deactivatePlugin "akismet/akismet"',
915
+ },
916
+ installPlugin: {
917
+ description: "Install a plugin from the WordPress.org marketplace.",
918
+ parameters: [
919
+ { name: "slug", dataType: "string", description: "Plugin slug from wordpress.org", formInputType: "text", required: true },
920
+ { name: "activate", dataType: "boolean", description: "Activate immediately after install (default: false)", formInputType: "checkbox", required: false },
921
+ ],
922
+ returnType: "object",
923
+ returnDescription: "Installed plugin object with name, version, status.",
924
+ example: 'wordpress.installPlugin "plugin-slug" true',
925
+ },
926
+ deletePlugin: {
927
+ description: "Delete (uninstall) a plugin. Plugin must be deactivated first.",
928
+ parameters: [
929
+ { name: "plugin", dataType: "string", description: "Plugin slug with folder (e.g. 'folder/plugin-file')", formInputType: "text", required: true },
930
+ ],
931
+ returnType: "object",
932
+ returnDescription: "Deletion confirmation.",
933
+ example: 'wordpress.deletePlugin "folder/plugin-file"',
934
+ },
935
+ // ── Themes ──────────────────────────────────────────────────────
936
+ listThemes: {
937
+ description: "List all installed themes.",
938
+ parameters: [],
939
+ returnType: "array",
940
+ returnDescription: "Array of theme objects.",
941
+ example: "wordpress.listThemes",
942
+ },
943
+ activateTheme: {
944
+ description: "Activate a theme.",
945
+ parameters: [
946
+ { name: "theme", dataType: "string", description: "Theme stylesheet slug (e.g. 'twentytwentyfour')", formInputType: "text", required: true },
947
+ ],
948
+ returnType: "object",
949
+ returnDescription: "Updated theme object.",
950
+ example: 'wordpress.activateTheme "twentytwentyfour"',
951
+ },
952
+ // ── Settings ────────────────────────────────────────────────────
953
+ getSettings: {
954
+ description: "Get site settings (title, description, timezone, etc.).",
955
+ parameters: [],
956
+ returnType: "object",
957
+ returnDescription: "Site settings object.",
958
+ example: "wordpress.getSettings",
959
+ },
960
+ updateSettings: {
961
+ description: "Update site settings.",
962
+ parameters: [
963
+ { name: "settings", dataType: "object", description: "Settings to update (title, description, timezone_string, date_format, etc.)", formInputType: "json", required: true },
964
+ ],
965
+ returnType: "object",
966
+ returnDescription: "Updated settings object.",
967
+ example: 'wordpress.updateSettings {"title":"My Enterprise Site","description":"The best site"}',
968
+ },
969
+ // ── Search ──────────────────────────────────────────────────────
970
+ search: {
971
+ description: "Global search across all content types.",
972
+ parameters: [
973
+ { name: "query", dataType: "string", description: "Search query", formInputType: "text", required: true },
974
+ { name: "options", dataType: "object", description: "Options: per_page, page, type (post, term, post-format), subtype", formInputType: "json", required: false },
975
+ ],
976
+ returnType: "array",
977
+ returnDescription: "Array of search result objects with title, url, type.",
978
+ example: 'wordpress.search "migration guide"',
979
+ },
980
+ // ── Bulk Operations ─────────────────────────────────────────────
981
+ bulkUpdatePosts: {
982
+ description: "Update multiple posts at once with the same changes.",
983
+ parameters: [
984
+ { name: "postIds", dataType: "array", description: "Array of post IDs to update", formInputType: "json", required: true },
985
+ { name: "updates", dataType: "object", description: "Fields to apply to all posts", formInputType: "json", required: true },
986
+ ],
987
+ returnType: "array",
988
+ returnDescription: "Array of updated post objects.",
989
+ example: 'wordpress.bulkUpdatePosts ["1","2","3"] {"status":"publish","categories":[5]}',
990
+ },
991
+ bulkDeletePosts: {
992
+ description: "Delete multiple posts at once.",
993
+ parameters: [
994
+ { name: "postIds", dataType: "array", description: "Array of post IDs to delete", formInputType: "json", required: true },
995
+ { name: "force", dataType: "boolean", description: "Permanently delete (default: false = trash)", formInputType: "checkbox", required: false },
996
+ ],
997
+ returnType: "array",
998
+ returnDescription: "Array of deletion results.",
999
+ example: 'wordpress.bulkDeletePosts ["10","11","12"]',
1000
+ },
1001
+ };
1002
+ export const WordpressModuleMetadata = {
1003
+ description: "Enterprise WordPress management — posts, pages, comments, media, users, categories, tags, custom fields, revisions, plugins, themes, settings, search, and bulk operations via the WordPress REST API v2.",
1004
+ methods: Object.keys(WordpressFunctions),
1005
+ category: "cms",
1006
+ };
1007
+ //# sourceMappingURL=wordpress.js.map