From 02bc3da78545de4771edf6fdc68720b0e7d596b9 Mon Sep 17 00:00:00 2001 From: Zapfmeister Date: Mon, 4 Jul 2022 09:39:56 +0200 Subject: [PATCH] feat(Wordpress Node): Add post template option (#3139) * Add wordpress post template option * Fix: Add UI components and fix typo * Add elementor template options * Add Standard option * :hammer: ability to use non elementor template, credential test, linter fixes * :hammer: removed commented code * :zap: Improvements Co-authored-by: Michael Kret Co-authored-by: ricardo --- .../credentials/WordpressApi.credentials.ts | 18 +++ .../nodes/Wordpress/GenericFunctions.ts | 7 +- .../nodes/Wordpress/PostDescription.ts | 132 ++++++++++++++++++ .../nodes/Wordpress/PostInterface.ts | 1 + .../nodes/Wordpress/Wordpress.node.ts | 9 +- .../nodes-base/nodes/Wordpress/wordpress.png | Bin 1678 -> 0 bytes .../nodes-base/nodes/Wordpress/wordpress.svg | 1 + 7 files changed, 161 insertions(+), 7 deletions(-) delete mode 100644 packages/nodes-base/nodes/Wordpress/wordpress.png create mode 100644 packages/nodes-base/nodes/Wordpress/wordpress.svg diff --git a/packages/nodes-base/credentials/WordpressApi.credentials.ts b/packages/nodes-base/credentials/WordpressApi.credentials.ts index 5d8e4174ee..ade71b8582 100644 --- a/packages/nodes-base/credentials/WordpressApi.credentials.ts +++ b/packages/nodes-base/credentials/WordpressApi.credentials.ts @@ -1,4 +1,6 @@ import { + IAuthenticateGeneric, + ICredentialTestRequest, ICredentialType, INodeProperties, } from 'n8n-workflow'; @@ -31,4 +33,20 @@ export class WordpressApi implements ICredentialType { placeholder: 'https://example.com', }, ]; + authenticate: IAuthenticateGeneric = { + type: 'generic', + properties: { + auth: { + username: '={{$credentials.username}}', + password: '={{$credentials.password}}', + }, + }, +}; + test: ICredentialTestRequest = { + request: { + baseURL: '={{$credentials?.url}}/wp-json/wp/v2', + url: '/users', + method: 'GET', + }, + }; } diff --git a/packages/nodes-base/nodes/Wordpress/GenericFunctions.ts b/packages/nodes-base/nodes/Wordpress/GenericFunctions.ts index ad74683126..145e482247 100644 --- a/packages/nodes-base/nodes/Wordpress/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Wordpress/GenericFunctions.ts @@ -21,10 +21,6 @@ export async function wordpressApiRequest(this: IExecuteFunctions | IExecuteSing 'Content-Type': 'application/json', 'User-Agent': 'n8n', }, - auth: { - user: credentials!.username as string, - password: credentials!.password as string, - }, method, qs, body, @@ -36,7 +32,8 @@ export async function wordpressApiRequest(this: IExecuteFunctions | IExecuteSing delete options.body; } try { - return await this.helpers.request!(options); + const credentialType = 'wordpressApi'; + return this.helpers.requestWithAuthentication.call(this, credentialType, options); } catch (error) { throw new NodeApiError(this.getNode(), error); } diff --git a/packages/nodes-base/nodes/Wordpress/PostDescription.ts b/packages/nodes-base/nodes/Wordpress/PostDescription.ts index 3b48b92b10..2a9fee87d2 100644 --- a/packages/nodes-base/nodes/Wordpress/PostDescription.ts +++ b/packages/nodes-base/nodes/Wordpress/PostDescription.ts @@ -257,6 +257,72 @@ export const postFields: INodeProperties[] = [ default: [], description: 'The terms assigned to the object in the post_tag taxonomy. Choose from the list, or specify IDs using an expression.', }, + { + displayName: 'Template', + name: 'postTemplate', + type: 'fixedCollection', + default: {}, + typeOptions: { + multipleValues: false, + }, + options: [ + { + displayName: 'Values', + name: 'values', + values: [ + { + displayName: 'Elementor Template', + name: 'elementor', + type: 'boolean', + default: true, + description: 'Whether site uses elementor page builder', + }, + { + displayName: 'Template', + name: 'template', + type: 'string', + default: '', + description: 'The theme file to use', + displayOptions: { + show: { + elementor: [ false ], + }, + }, + }, + { + displayName: 'Template', + name: 'template', + type: 'options', + options: [ + { + name: 'Standard', + value: '', + }, + { + name: 'Elementor Canvas', + value: 'elementor_canvas', + }, + { + name: 'Elementor Header Footer', + value: 'elementor_header_footer', + }, + { + name: 'Elementor Theme', + value: 'elementor_theme', + }, + ], + default: '', + description: 'The Elementor template to use', + displayOptions: { + show: { + elementor: [ true ], + }, + }, + }, + ], + }, + ], + }, ], }, /* -------------------------------------------------------------------------- */ @@ -477,6 +543,72 @@ export const postFields: INodeProperties[] = [ default: [], description: 'The terms assigned to the object in the post_tag taxonomy. Choose from the list, or specify IDs using an expression.', }, + { + displayName: 'Template', + name: 'postTemplate', + type: 'fixedCollection', + default: {}, + typeOptions: { + multipleValues: false, + }, + options: [ + { + displayName: 'Values', + name: 'values', + values: [ + { + displayName: 'Elementor Template', + name: 'elementor', + type: 'boolean', + default: true, + description: 'Whether site uses elementor page builder', + }, + { + displayName: 'Template', + name: 'template', + type: 'string', + default: '', + description: 'The theme file to use', + displayOptions: { + show: { + elementor: [ false ], + }, + }, + }, + { + displayName: 'Template', + name: 'template', + type: 'options', + options: [ + { + name: 'Standard', + value: '', + }, + { + name: 'Elementor Canvas', + value: 'elementor_canvas', + }, + { + name: 'Elementor Header Footer', + value: 'elementor_header_footer', + }, + { + name: 'Elementor Theme', + value: 'elementor_theme', + }, + ], + default: '', + description: 'The Elementor template to use', + displayOptions: { + show: { + elementor: [ true ], + }, + }, + }, + ], + }, + ], + }, ], }, /* -------------------------------------------------------------------------- */ diff --git a/packages/nodes-base/nodes/Wordpress/PostInterface.ts b/packages/nodes-base/nodes/Wordpress/PostInterface.ts index e810c11cf8..995ed6aec6 100644 --- a/packages/nodes-base/nodes/Wordpress/PostInterface.ts +++ b/packages/nodes-base/nodes/Wordpress/PostInterface.ts @@ -11,6 +11,7 @@ export interface IPost { ping_status?: string; format?: string; sticky?: boolean; + template?: string; categories?: number[]; tags?: number[]; } diff --git a/packages/nodes-base/nodes/Wordpress/Wordpress.node.ts b/packages/nodes-base/nodes/Wordpress/Wordpress.node.ts index 691847d986..a9fb305b50 100644 --- a/packages/nodes-base/nodes/Wordpress/Wordpress.node.ts +++ b/packages/nodes-base/nodes/Wordpress/Wordpress.node.ts @@ -32,8 +32,7 @@ export class Wordpress implements INodeType { description: INodeTypeDescription = { displayName: 'Wordpress', name: 'wordpress', - // eslint-disable-next-line n8n-nodes-base/node-class-description-icon-not-svg - icon: 'file:wordpress.png', + icon: 'file:wordpress.svg', group: ['output'], version: 1, subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}', @@ -170,6 +169,9 @@ export class Wordpress implements INodeType { if (additionalFields.sticky) { body.sticky = additionalFields.sticky as boolean; } + if (additionalFields.postTemplate) { + body.template = this.getNodeParameter('additionalFields.postTemplate.values.template', i, '') as string; + } if (additionalFields.categories) { body.categories = additionalFields.categories as number[]; } @@ -215,6 +217,9 @@ export class Wordpress implements INodeType { if (updateFields.sticky) { body.sticky = updateFields.sticky as boolean; } + if (updateFields.postTemplate) { + body.template = this.getNodeParameter('updateFields.postTemplate.values.template', i, '') as string; + } if (updateFields.categories) { body.categories = updateFields.categories as number[]; } diff --git a/packages/nodes-base/nodes/Wordpress/wordpress.png b/packages/nodes-base/nodes/Wordpress/wordpress.png deleted file mode 100644 index 3da800932da6554949d0a3e67b42a838832e7a47..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1678 zcmaJ>X)qfI6iz8isH*9@uWqTfT2e=g(w2lI;)o-bM%-FjBGk1))!J1`Xp=bNES5^e zrmBues1nf|)hHo0)i&bFE>g!*UEQ78+1Z`hH}l>%-+SLT@BMl?NH^#npe7Ii0PKOo zAf7vD`z7V1zjVGia&8BzkS^YiI|zY5oc;_)N5>rmgTa5%|F3_E|6lXp>5l7fY ziyNOmw^f7}@8@vX-IfedP0O(-``T6erP`_poBZ&4@3sXuPD@wcG|UzRb=}LSnuQ&I z^xH#^5%GZ!*9#g3^)#{tu!;m5N>OU){b`EMc7NIg9C-vCBOBhSuA~-eJw`K^!U$v1 zFG6prtIB$#6jg`0q))ezx64B0=nsF;c^w9ed3A0{wS2@VdJk7xki_^kxqa4D>V#nN zMNQ0Og=I+ zuAX+Rdq$%cCO>+x>?+1$eGR*Ft{HMc!pE?WYD|J9^nN{`kL8w)KJD&p(l4~^LRHT6 zm_={0hDk+H&(U%fBr}eR){K9LO3aI5)Um7nkE1y=`NoBwyj1eakJ7ad$`kTJXs62V zoC#K_0{PwnFH^wa+Uw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es/Wordpress/wordpress.svg new file mode 100644 index 0000000000..1ec64c05f7 --- /dev/null +++ b/packages/nodes-base/nodes/Wordpress/wordpress.svg @@ -0,0 +1 @@ + \ No newline at end of file