Skip to content

Commit 5f1b080

Browse files
[COMPONENTS] wordpress_com. Actions + sources (#16461)
* Initialization * Add [COMPONENTS] Wordpress.com * CodeRabbit change * update bnpm-lock.yaml * CodeRabbit change 2 * Lint: fix eslint errors in WordPress.com components * Fix keys * Minor fix * updates * doc link --------- Co-authored-by: michelle0927 <michellelbergero@hotmail.com>
1 parent 57f04ff commit 5f1b080

File tree

12 files changed

+1081
-6
lines changed

12 files changed

+1081
-6
lines changed

components/wordpress_com/README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,33 @@ The Wordpress.com API empowers developers to extend and integrate their website'
99
- **Comment Moderation Alerts**: Set up a Pipedream workflow that monitors Wordpress.com for new comments. When a comment is detected, analyze its content for specific keywords or sentiment using a service like Google's Natural Language API. If the comment requires attention (e.g., contains flagged words or negative sentiment), send an immediate alert to a Slack channel or via email to prompt review and moderation, keeping your community healthy and engaged.
1010

1111
- **User Synchronization and Engagement**: Create a workflow that triggers when a new user registers on your Wordpress.com site. This workflow can add the user to a CRM like HubSpot or Salesforce, subscribe them to a Mailchimp email list, and even send a personalized welcome email via SendGrid. This ensures your user data is consistent across platforms and kickstarts the user engagement process from the moment they sign up.
12+
13+
14+
# Available Event Sources
15+
16+
Trigger workflows automatically when specific Wordpress.com events occur:
17+
18+
New Post: Emit a new event when a post, page, or media attachment is published.
19+
Required props: site ID or URL. Optional: post type (post, page, attachment).
20+
21+
New Comment: Emit a new event when a comment is added to any post or page.
22+
Required props: site ID or URL. Optional: post ID to filter comments.
23+
24+
New Follower: Emit a new event when someone subscribes to the site's blog.
25+
Required props: site ID or URL.
26+
27+
Each source manages its own database cursor to ensure only new data is processed each time it runs — no duplicates, no missed updates.
28+
Available Actions
29+
30+
Perform direct operations on your Wordpress.com site:
31+
32+
Create Post: Create a new post on the site.
33+
Required props: site ID or URL, post title, post content.
34+
Optional props: post status (draft, published), categories, and tags.
35+
36+
Upload Media: Upload a media file (image, video, etc.) to the site's library.
37+
Required props: site ID or URL, media file (binary or URL).
38+
Optional props: media title and description.
39+
40+
Delete Post: Delete an existing post from the site.
41+
Required props: site ID or URL, post ID.
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
import wordpress from "../../wordpress_com.app.mjs";
2+
3+
export default {
4+
key: "wordpress_com-create-post",
5+
name: "Create New Post",
6+
description: "Creates a new post on a WordPress.com site. [See the documentation](https://developer.wordpress.com/docs/api/1.1/post/sites/%24site/posts/new/)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
wordpress,
11+
site: {
12+
propDefinition: [
13+
wordpress,
14+
"siteId",
15+
],
16+
},
17+
title: {
18+
type: "string",
19+
label: "Post Title",
20+
description: "The title of the post",
21+
},
22+
content: {
23+
type: "string",
24+
label: "Post Content",
25+
description: "The content of the post (HTML or text)",
26+
},
27+
status: {
28+
type: "string",
29+
label: "Status",
30+
description: "The status of the post",
31+
options: [
32+
"publish",
33+
"draft",
34+
"private",
35+
"pending",
36+
],
37+
default: "draft",
38+
optional: true,
39+
},
40+
type: {
41+
type: "string",
42+
label: "Post Type",
43+
description: "The type of the post (post or page). For attachments, use the 'Upload Media' action.",
44+
options: [
45+
{
46+
label: "Post",
47+
value: "post",
48+
},
49+
{
50+
label: "Page",
51+
value: "page",
52+
},
53+
],
54+
default: "post",
55+
optional: true,
56+
},
57+
},
58+
async run({ $ }) {
59+
const warnings = [];
60+
61+
const {
62+
site,
63+
wordpress,
64+
...fields
65+
} = this;
66+
67+
warnings.push(...wordpress.checkDomainOrId(site));
68+
69+
let response;
70+
71+
try {
72+
response = await wordpress.createWordpressPost({
73+
$,
74+
site,
75+
data: {
76+
...fields,
77+
},
78+
});
79+
} catch (error) {
80+
wordpress.throwCustomError("Could not create post", error, warnings);
81+
};
82+
83+
$.export("$summary", `Post successfully created. ID = ${response?.ID}` + "\n- " + warnings.join("\n- "));
84+
},
85+
};
86+
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import wordpress from "../../wordpress_com.app.mjs";
2+
3+
export default {
4+
key: "wordpress_com-delete-post",
5+
name: "Delete Post",
6+
description: "Deletes a post. [See the documentation](https://developer.wordpress.com/docs/api/1.1/post/sites/%24site/posts/%24post_ID/delete/)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
wordpress,
11+
site: {
12+
propDefinition: [
13+
wordpress,
14+
"siteId",
15+
],
16+
},
17+
postId: {
18+
propDefinition: [
19+
wordpress,
20+
"postId",
21+
(c) => ({
22+
site: c.site,
23+
}),
24+
],
25+
description: "The ID of the post you want to delete",
26+
},
27+
},
28+
async run({ $ }) {
29+
const warnings = [];
30+
31+
const {
32+
site,
33+
wordpress,
34+
postId,
35+
} = this;
36+
37+
warnings.push(...wordpress.checkDomainOrId(site));
38+
39+
let response;
40+
41+
try {
42+
response = await wordpress.deleteWordpressPost({
43+
$,
44+
site,
45+
postId,
46+
});
47+
} catch (error) {
48+
wordpress.throwCustomError("Could not delete post", error, warnings);
49+
};
50+
51+
$.export("$summary", `Post ID = ${response?.ID} successfully deleted.` + "\n- " + warnings.join("\n- "));
52+
},
53+
};
54+
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
import { prepareMediaUpload } from "../../common/utils.mjs";
2+
import wordpress from "../../wordpress_com.app.mjs";
3+
4+
export default {
5+
key: "wordpress_com-upload-media",
6+
name: "Upload Media",
7+
description: "Uploads a media file from a URL to the specified WordPress.com site. [See the documentation](https://developer.wordpress.com/docs/api/1.1/post/sites/%24site/media/new/)",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
wordpress,
12+
site: {
13+
propDefinition: [
14+
wordpress,
15+
"siteId",
16+
],
17+
},
18+
media: {
19+
type: "any",
20+
label: "Media URL",
21+
description: "A direct media URL, or a FormData object with the file attached under the field name 'media[]'.",
22+
},
23+
title: {
24+
type: "string",
25+
label: "Title",
26+
description: "Title of the media",
27+
optional: true,
28+
},
29+
caption: {
30+
type: "string",
31+
label: "Caption",
32+
description: "Optional caption text to associate with the uploaded media",
33+
optional: true,
34+
},
35+
description: {
36+
type: "string",
37+
label: "Description",
38+
description: "A description of the uploaded media",
39+
optional: true,
40+
},
41+
},
42+
async run({ $ }) {
43+
const warnings = [];
44+
45+
const
46+
{
47+
wordpress,
48+
site,
49+
media,
50+
...fields
51+
} = this;
52+
53+
warnings.push(...wordpress.checkDomainOrId(site));
54+
55+
let form;
56+
57+
// If not form data
58+
if (wordpress.isFormData(media)) {
59+
form = media;
60+
61+
} else {
62+
form = await prepareMediaUpload(media, fields, $);
63+
}
64+
65+
let response;
66+
67+
try {
68+
response = await wordpress.uploadWordpressMedia({
69+
$,
70+
contentType: form.getHeaders()["content-type"],
71+
site,
72+
data: form,
73+
});
74+
75+
const media = response.media[0];
76+
77+
$.export("$summary", `Media "${media.title}" uploaded successfully (ID: ${media.ID})` + "\n- " + warnings.join("\n- "));
78+
79+
console.log(response);
80+
return response;
81+
82+
} catch (error) {
83+
wordpress.throwCustomError("Failed to upload media", error, warnings);
84+
};
85+
},
86+
};
87+

0 commit comments

Comments
 (0)