mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-18 02:21:13 +00:00
feat(Wordpress Node): Support WordPress pages (#8852)
Signed-off-by: Ludwig Gerdes <gerdesludwig@gmail.com>
This commit is contained in:
@@ -9,8 +9,11 @@ import type {
|
||||
} from 'n8n-workflow';
|
||||
import { wordpressApiRequest, wordpressApiRequestAllItems } from './GenericFunctions';
|
||||
import { postFields, postOperations } from './PostDescription';
|
||||
import { pageFields, pageOperations } from './PageDescription';
|
||||
import { userFields, userOperations } from './UserDescription';
|
||||
|
||||
import type { IPost } from './PostInterface';
|
||||
import type { IPage } from './PageInterface';
|
||||
import type { IUser } from './UserInterface';
|
||||
|
||||
export class Wordpress implements INodeType {
|
||||
@@ -44,6 +47,10 @@ export class Wordpress implements INodeType {
|
||||
name: 'Post',
|
||||
value: 'post',
|
||||
},
|
||||
{
|
||||
name: 'Page',
|
||||
value: 'page',
|
||||
},
|
||||
{
|
||||
name: 'User',
|
||||
value: 'user',
|
||||
@@ -53,6 +60,8 @@ export class Wordpress implements INodeType {
|
||||
},
|
||||
...postOperations,
|
||||
...postFields,
|
||||
...pageOperations,
|
||||
...pageFields,
|
||||
...userOperations,
|
||||
...userFields,
|
||||
],
|
||||
@@ -305,6 +314,171 @@ export class Wordpress implements INodeType {
|
||||
);
|
||||
}
|
||||
}
|
||||
if (resource === 'page') {
|
||||
//https://developer.wordpress.org/rest-api/reference/pages/#create-a-page
|
||||
if (operation === 'create') {
|
||||
const title = this.getNodeParameter('title', i) as string;
|
||||
const additionalFields = this.getNodeParameter('additionalFields', i);
|
||||
const body: IPage = {
|
||||
title,
|
||||
};
|
||||
if (additionalFields.authorId) {
|
||||
body.author = additionalFields.authorId as number;
|
||||
}
|
||||
if (additionalFields.content) {
|
||||
body.content = additionalFields.content as string;
|
||||
}
|
||||
if (additionalFields.slug) {
|
||||
body.slug = additionalFields.slug as string;
|
||||
}
|
||||
if (additionalFields.password) {
|
||||
body.password = additionalFields.password as string;
|
||||
}
|
||||
if (additionalFields.status) {
|
||||
body.status = additionalFields.status as string;
|
||||
}
|
||||
if (additionalFields.commentStatus) {
|
||||
body.comment_status = additionalFields.commentStatus as string;
|
||||
}
|
||||
if (additionalFields.pingStatus) {
|
||||
body.ping_status = additionalFields.pingStatus as string;
|
||||
}
|
||||
if (additionalFields.pageTemplate) {
|
||||
body.template = this.getNodeParameter(
|
||||
'additionalFields.pageTemplate.values.template',
|
||||
i,
|
||||
'',
|
||||
) as string;
|
||||
}
|
||||
if (additionalFields.menuOrder) {
|
||||
body.menu_order = additionalFields.menuOrder as number;
|
||||
}
|
||||
if (additionalFields.parent) {
|
||||
body.parent = additionalFields.parent as number;
|
||||
}
|
||||
if (additionalFields.featuredMediaId) {
|
||||
body.featured_media = additionalFields.featuredMediaId as number;
|
||||
}
|
||||
responseData = await wordpressApiRequest.call(this, 'POST', '/pages', body);
|
||||
}
|
||||
//https://developer.wordpress.org/rest-api/reference/pages/#update-a-page
|
||||
if (operation === 'update') {
|
||||
const pageId = this.getNodeParameter('pageId', i) as string;
|
||||
const updateFields = this.getNodeParameter('updateFields', i);
|
||||
const body: IPage = {
|
||||
id: parseInt(pageId, 10),
|
||||
};
|
||||
if (updateFields.authorId) {
|
||||
body.author = updateFields.authorId as number;
|
||||
}
|
||||
if (updateFields.title) {
|
||||
body.title = updateFields.title as string;
|
||||
}
|
||||
if (updateFields.content) {
|
||||
body.content = updateFields.content as string;
|
||||
}
|
||||
if (updateFields.slug) {
|
||||
body.slug = updateFields.slug as string;
|
||||
}
|
||||
if (updateFields.password) {
|
||||
body.password = updateFields.password as string;
|
||||
}
|
||||
if (updateFields.status) {
|
||||
body.status = updateFields.status as string;
|
||||
}
|
||||
if (updateFields.commentStatus) {
|
||||
body.comment_status = updateFields.commentStatus as string;
|
||||
}
|
||||
if (updateFields.pingStatus) {
|
||||
body.ping_status = updateFields.pingStatus as string;
|
||||
}
|
||||
if (updateFields.pageTemplate) {
|
||||
body.template = this.getNodeParameter(
|
||||
'updateFields.pageTemplate.values.template',
|
||||
i,
|
||||
'',
|
||||
) as string;
|
||||
}
|
||||
if (updateFields.menuOrder) {
|
||||
body.menu_order = updateFields.menuOrder as number;
|
||||
}
|
||||
if (updateFields.parent) {
|
||||
body.parent = updateFields.parent as number;
|
||||
}
|
||||
if (updateFields.featuredMediaId) {
|
||||
body.featured_media = updateFields.featuredMediaId as number;
|
||||
}
|
||||
responseData = await wordpressApiRequest.call(this, 'POST', `/pages/${pageId}`, body);
|
||||
}
|
||||
//https://developer.wordpress.org/rest-api/reference/pages/#retrieve-a-page
|
||||
if (operation === 'get') {
|
||||
const pageId = this.getNodeParameter('pageId', i) as string;
|
||||
const options = this.getNodeParameter('options', i);
|
||||
if (options.password) {
|
||||
qs.password = options.password as string;
|
||||
}
|
||||
if (options.context) {
|
||||
qs.context = options.context as string;
|
||||
}
|
||||
responseData = await wordpressApiRequest.call(this, 'GET', `/pages/${pageId}`, {}, qs);
|
||||
}
|
||||
//https://developer.wordpress.org/rest-api/reference/pages/#list-pages
|
||||
if (operation === 'getAll') {
|
||||
const returnAll = this.getNodeParameter('returnAll', i);
|
||||
const options = this.getNodeParameter('options', i);
|
||||
if (options.context) {
|
||||
qs.context = options.context as string;
|
||||
}
|
||||
if (options.orderBy) {
|
||||
qs.orderby = options.orderBy as string;
|
||||
}
|
||||
if (options.order) {
|
||||
qs.order = options.order as string;
|
||||
}
|
||||
if (options.search) {
|
||||
qs.search = options.search as string;
|
||||
}
|
||||
if (options.after) {
|
||||
qs.after = options.after as string;
|
||||
}
|
||||
if (options.author) {
|
||||
qs.author = options.author as number[];
|
||||
}
|
||||
if (options.parent) {
|
||||
qs.parent = options.parent as number;
|
||||
}
|
||||
if (options.menuOrder) {
|
||||
qs.menu_order = options.menuOrder as number;
|
||||
}
|
||||
if (options.status) {
|
||||
qs.status = options.status as string;
|
||||
}
|
||||
if (options.page) {
|
||||
qs.page = options.page as number;
|
||||
}
|
||||
if (returnAll) {
|
||||
responseData = await wordpressApiRequestAllItems.call(this, 'GET', '/pages', {}, qs);
|
||||
} else {
|
||||
qs.per_page = this.getNodeParameter('limit', i);
|
||||
responseData = await wordpressApiRequest.call(this, 'GET', '/pages', {}, qs);
|
||||
}
|
||||
}
|
||||
//https://developer.wordpress.org/rest-api/reference/pages/#delete-a-page
|
||||
if (operation === 'delete') {
|
||||
const pageId = this.getNodeParameter('pageId', i) as string;
|
||||
const options = this.getNodeParameter('options', i);
|
||||
if (options.force) {
|
||||
qs.force = options.force as boolean;
|
||||
}
|
||||
responseData = await wordpressApiRequest.call(
|
||||
this,
|
||||
'DELETE',
|
||||
`/pages/${pageId}`,
|
||||
{},
|
||||
qs,
|
||||
);
|
||||
}
|
||||
}
|
||||
if (resource === 'user') {
|
||||
//https://developer.wordpress.org/rest-api/reference/users/#create-a-user
|
||||
if (operation === 'create') {
|
||||
|
||||
Reference in New Issue
Block a user