mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-10 06:34:05 -08:00
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 * 🔨 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>
This commit is contained in:
parent
a8c16675d0
commit
02bc3da785
|
@ -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',
|
||||
},
|
||||
};
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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 ],
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
@ -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 ],
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
|
|
@ -11,6 +11,7 @@ export interface IPost {
|
|||
ping_status?: string;
|
||||
format?: string;
|
||||
sticky?: boolean;
|
||||
template?: string;
|
||||
categories?: number[];
|
||||
tags?: number[];
|
||||
}
|
||||
|
|
|
@ -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[];
|
||||
}
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 1.6 KiB |
1
packages/nodes-base/nodes/Wordpress/wordpress.svg
Normal file
1
packages/nodes-base/nodes/Wordpress/wordpress.svg
Normal file
|
@ -0,0 +1 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" width="2500" height="2500" viewBox="8.399 8.4 51.2 51.2"><path fill="#21759B" d="M34 59.6C19.813 59.6 8.293 48.293 8.4 34 8.507 19.707 19.28 8.4 34 8.4c14.721 0 25.6 11.52 25.6 25.6S48.187 59.6 34 59.6zm7.573-3.947l-7.253-19.52-6.827 19.947c5.014 1.174 8.427 1.493 14.08-.427zm-17.706-1.066l-10.88-29.76c-1.494 3.2-1.813 5.867-2.027 9.173.107 8.746 5.013 16.746 12.907 20.587zM56.934 34c.106-5.653-2.453-10.133-2.667-10.773.214 4.374-.427 6.613-1.173 9.067l-7.467 21.44C55.014 48.08 56.826 39.653 57.04 34h-.106zm-23.68-.96l-3.627-9.92-2.667-.213c-1.066-.747-.427-1.92.32-1.92 4.8.32 7.466.32 12.267 0 1.174 0 1.493 1.707.106 1.92l-2.56.213 8.319 24.533 3.946-13.44c.214-5.866-1.387-6.506-3.52-10.773-1.707-3.307.107-6.507 3.414-6.613-2.668-2.56-8.107-5.76-15.254-5.867s-14.72 3.52-19.2 10.347l7.894-.213c.96.427.533 1.813 0 1.92l-2.773.213 8.32 24.96 5.015-15.147z"/></svg>
|
After Width: | Height: | Size: 914 B |
Loading…
Reference in a new issue