# extendify/3.2.1/src/Agent/workflows/content/tools/update-post-strings.js

Extendify, version 3.2.1. 26 lines.

- Page: https://pluginprobe.com/plugins/extendify/3.2.1/code/src/Agent/workflows/content/tools/update-post-strings.js
- Raw: https://pluginprobe.com/plugins/extendify/3.2.1/raw/src/Agent/workflows/content/tools/update-post-strings.js
- Modified: 2026-09-09T18:23:40+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/extendify/3.2.1/code/src/Agent/workflows/content/tools/update-post-strings.js#L10-L20`.

```javascript
import apiFetch from '@wordpress/api-fetch';

// TODO: check for post_lock and error that someone is editing
export default async ({ postId, postType, replacements }) => {
	const type = postType === 'page' ? 'pages' : 'posts';
	const response = await apiFetch({
		path: `/wp/v2/${type}/${postId}?context=edit`,
	});
	let content = response.content.raw;
	let title = response.title.raw;
	const escapeRegExp = (str) => str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
	for (const { original, updated } of replacements) {
		const regex = new RegExp(escapeRegExp(original), 'g');
		content = content.replace(regex, updated);
		title = title.split(original).join(updated);
	}

	const postResult = await apiFetch({
		path: `/wp/v2/${type}/${postId}`,
		method: 'POST',
		data: { content, title },
	});

	return postResult;
};

```
