Skip to content

AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents

fix(wordpress): keep categories and tags on update post when the field is empty (#16622)

Talal Jaberc7b6dfef7e17
diff --git a/bun.lock b/bun.lock
index 470792b8dca..7aa8d67bfd9 100644
--- a/bun.lock
+++ b/bun.lock
@@ -10084,7 +10084,7 @@
},
"packages/pieces/community/wordpress": {
"name": "@activepieces/piece-wordpress",
- "version": "0.8.0",
+ "version": "0.9.0",
"dependencies": {
"@activepieces/core-piece-types": "workspace:*",
"@activepieces/core-utils": "workspace:*",
@@ -10095,6 +10095,7 @@
},
"devDependencies": {
"tslib": "2.6.2",
+ "vitest": "3.2.6",
},
},
"packages/pieces/community/workable": {
diff --git a/docs/install/reference/breaking-changes-unreleased.mdx b/docs/install/reference/breaking-changes-unreleased.mdx
index 93dff07bb9c..faf1bc21169 100644
--- a/docs/install/reference/breaking-changes-unreleased.mdx
+++ b/docs/install/reference/breaking-changes-unreleased.mdx
@@ -8,6 +8,14 @@ Entries here move to [Breaking Changes](/install/reference/breaking-changes) aut
## What has changed?
+#### WordPress Update Post keeps a post's categories and tags when those fields are empty
+
+Update Post used to send an empty list when **Categories** or **Tags** was cleared or mapped to an empty list. WordPress then reset the post to the default category and removed all of its tags. From WordPress 0.9.0, an empty Categories or Tags field leaves the post's current categories and tags as they are, like every other empty field on the form. Steps keep running on the version they were built with until you upgrade them.
+
+#### What you need to do
+
+Nothing for most flows. If a flow cleared a post's tags or categories by sending an empty list, it no longer does: pick the categories to keep instead, or use the Custom API Call with `POST /posts/<id>` and `{"tags": []}` in the body.
+
#### Background migrations need a dedicated Postgres role when a `statement_timeout` applies
The app's background migration track (slow data backfills, `CREATE INDEX CONCURRENTLY`, `DROP INDEX CONCURRENTLY`) runs through whichever database connection the app itself uses. When a `statement_timeout` applies to that connection, every long DDL statement a background migration issues is cancelled at that cap and never completes. The retry loop leaves `INVALID` index artifacts behind that an `IF NOT EXISTS` on the next deploy silently skips.
diff --git a/packages/pieces/community/wordpress/package.json b/packages/pieces/community/wordpress/package.json
index 86494d64d92..b3f288354d4 100644
--- a/packages/pieces/community/wordpress/package.json
+++ b/packages/pieces/community/wordpress/package.json
@@ -1,12 +1,13 @@
{
"name": "@activepieces/piece-wordpress",
- "version": "0.8.0",
+ "version": "0.9.0",
"main": "./dist/src/index.js",
"types": "./dist/src/index.d.ts",
"scripts": {
"build": "tsc -p tsconfig.lib.json && cp package.json dist/",
"bundle": "node ../../../../dist/packages/cli/src/index.js pieces bundle",
- "lint": "eslint 'src/**/*.ts'"
+ "lint": "eslint 'src/**/*.ts'",
+ "test": "vitest run"
},
"dependencies": {
"@activepieces/pieces-common": "workspace:*",
@@ -17,6 +18,7 @@
"@activepieces/core-utils": "workspace:*"
},
"devDependencies": {
- "tslib": "2.6.2"
+ "tslib": "2.6.2",
+ "vitest": "3.2.6"
}
}
diff --git a/packages/pieces/community/wordpress/src/lib/actions/update-post.action.ts b/packages/pieces/community/wordpress/src/lib/actions/update-post.action.ts
index d2058065309..02ac9928acc 100644
--- a/packages/pieces/community/wordpress/src/lib/actions/update-post.action.ts
+++ b/packages/pieces/community/wordpress/src/lib/actions/update-post.action.ts
@@ -141,7 +141,7 @@ export const updateWordPressPost = createAction({
? 'open'
: 'closed';
}
- if (context.propsValue.categories) {
+ if (context.propsValue.categories?.length) {
requestBody['categories'] = context.propsValue.categories;
}
if (context.propsValue.slug) {
@@ -150,7 +150,7 @@ export const updateWordPressPost = createAction({
if (context.propsValue.excerpt) {
requestBody['excerpt'] = context.propsValue.excerpt;
}
- if (context.propsValue.tags) {
+ if (context.propsValue.tags?.length) {
requestBody['tags'] = context.propsValue.tags;
}
if (context.propsValue.ping_status) {
diff --git a/packages/pieces/community/wordpress/test/update-post.test.ts b/packages/pieces/community/wordpress/test/update-post.test.ts
new file mode 100644
index 00000000000..b3a395fe864
--- /dev/null
+++ b/packages/pieces/community/wordpress/test/update-post.test.ts
@@ -0,0 +1,86 @@
+import { HttpRequest, HttpResponse, httpClient } from '@activepieces/pieces-common';
+import { AppConnectionType, createMockActionContext } from '@activepieces/pieces-framework';
+import { afterEach, describe, expect, it, vi } from 'vitest';
+import '../src';
+import { updateWordPressPost } from '../src/lib/actions/update-post.action';
+
+afterEach(() => {
+ vi.restoreAllMocks();
+});
+
+describe('update_post categories and tags', () => {
+ it('keeps the current categories and tags when both dropdowns were cleared', async () => {
+ const sent = mockWordPress();
+
+ await runUpdatePost({ changes: { categories: [], tags: [] } });
+
+ expect(postUpdate({ sent })).toEqual({});
+ });
+
+ it('keeps the current categories and tags when both dropdowns were left untouched', async () => {
+ const sent = mockWordPress();
+
+ await runUpdatePost({ changes: { title: 'New title' } });
+
+ expect(postUpdate({ sent })).toEqual({ title: 'New title' });
+ });
+
+ it('sends the categories and tags that were picked', async () => {
+ const sent = mockWordPress();
+
+ await runUpdatePost({ changes: { categories: ['3'], tags: ['5', '8'] } });
+
+ expect(postUpdate({ sent })).toEqual({ categories: ['3'], tags: ['5', '8'] });
+ });
+});
+
+function mockWordPress(): HttpRequest[] {
+ const sent: HttpRequest[] = [];
+ vi.spyOn(httpClient, 'sendRequest').mockImplementation(async (request: HttpRequest): Promise<HttpResponse> => {
+ sent.push(request);
+ return { status: 200, headers: {}, body: {} };
+ });
+ return sent;
+}
+
+function postUpdate({ sent }: { sent: HttpRequest[] }): unknown {
+ const update = sent.find((request) => request.url === `${SITE}/wp-json/wp/v2/posts/${POST_ID}`);
+ return update?.body;
+}
+
+function runUpdatePost({ changes }: { changes: Partial<UpdatePostPropsValue> }): Promise<unknown> {
+ const propsValue: UpdatePostPropsValue = { ...UNTOUCHED_FORM, ...changes };
+ return updateWordPressPost.run({
+ ...createMockActionContext<UpdatePostProps>({ propsValue }),
+ auth: {
+ type: AppConnectionType.CUSTOM_AUTH,
+ props: { username: 'editor', password: 'app-password', website_url: SITE },
+ },
+ });
+}
+
+const SITE = 'https://blog.example.com';
+
+const POST_ID = 7;
+
+const UNTOUCHED_FORM: UpdatePostPropsValue = {
+ post: POST_ID,
+ empty_fields_info: undefined,
+ title: undefined,
+ content: undefined,
+ status: undefined,
+ categories: undefined,
+ tags: undefined,
+ featured_media: undefined,
+ featured_media_file: undefined,
+ excerpt: undefined,
+ date: undefined,
+ slug: undefined,
+ acfFields: undefined,
+ comment_status: undefined,
+ ping_status: undefined,
+};
+
+type UpdatePostProps = typeof updateWordPressPost.props;
+
+type UpdatePostPropsValue = Parameters<typeof createMockActionContext<UpdatePostProps>>[0]['propsValue'];
diff --git a/packages/pieces/community/wordpress/vitest.config.ts b/packages/pieces/community/wordpress/vitest.config.ts
new file mode 100644
index 00000000000..79c97261904
--- /dev/null
+++ b/packages/pieces/community/wordpress/vitest.config.ts
@@ -0,0 +1,19 @@
+import path from 'path'
+import { defineConfig } from 'vitest/config'
+
+const repoRoot = path.resolve(__dirname, '../../../..')
+
+export default defineConfig({
+ root: __dirname,
+ test: {
+ globals: true,
+ environment: 'node',
+ include: ['test/**/*.test.ts'],
+ },
+ resolve: {
+ alias: {
+ '@activepieces/pieces-framework': path.resolve(repoRoot, 'packages/pieces/framework/src/index.ts'),
+ '@activepieces/pieces-common': path.resolve(repoRoot, 'packages/pieces/common/src/index.ts'),
+ },
+ },
+})