Skip to content

Commit

Permalink
feat(Wordpress Node): Add post template option (#3139)
Browse files Browse the repository at this point in the history
* Add wordpress post template option

* Fix: Add UI components and fix typo

* Add elementor template options

* Add Standard option

* 🔨 ability to use non elementor template, credential test, linter fixes

* 🔨 removed commented code

* ⚡ Improvements

Co-authored-by: Michael Kret <michael.k@radency.com>
Co-authored-by: ricardo <ricardoespinoza105@gmail.com>
  • Loading branch information
3 people authored Jul 4, 2022
1 parent a8c1667 commit 02bc3da
Show file tree
Hide file tree
Showing 7 changed files with 161 additions and 7 deletions.
18 changes: 18 additions & 0 deletions packages/nodes-base/credentials/WordpressApi.credentials.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import {
IAuthenticateGeneric,
ICredentialTestRequest,
ICredentialType,
INodeProperties,
} from 'n8n-workflow';
Expand Down Expand Up @@ -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',
},
};
}
7 changes: 2 additions & 5 deletions packages/nodes-base/nodes/Wordpress/GenericFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
}
Expand Down
132 changes: 132 additions & 0 deletions packages/nodes-base/nodes/Wordpress/PostDescription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 <a href="https://docs.n8n.io/nodes/expressions.html#expressions">expression</a>.',
},
{
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 ],
},
},
},
],
},
],
},
],
},
/* -------------------------------------------------------------------------- */
Expand Down Expand Up @@ -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 <a href="https://docs.n8n.io/nodes/expressions.html#expressions">expression</a>.',
},
{
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 ],
},
},
},
],
},
],
},
],
},
/* -------------------------------------------------------------------------- */
Expand Down
1 change: 1 addition & 0 deletions packages/nodes-base/nodes/Wordpress/PostInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export interface IPost {
ping_status?: string;
format?: string;
sticky?: boolean;
template?: string;
categories?: number[];
tags?: number[];
}
9 changes: 7 additions & 2 deletions packages/nodes-base/nodes/Wordpress/Wordpress.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"]}}',
Expand Down Expand Up @@ -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[];
}
Expand Down Expand Up @@ -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[];
}
Expand Down
Binary file removed packages/nodes-base/nodes/Wordpress/wordpress.png
Binary file not shown.
1 change: 1 addition & 0 deletions packages/nodes-base/nodes/Wordpress/wordpress.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 02bc3da

Please sign in to comment.