PluginProbe
Extendify / 2.2.0
Extendify v2.2.0
3.2.0 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.6 3.0.5 3.0.4 trunk 0.1.0 0.10.0 0.10.1 0.10.2 0.11.0 0.11.1 0.2.0 0.3.0 0.3.1 0.4.0 0.5.0 0.6.0 0.7.0 All 126 releases
extendify / src / Agent / workflows / content / tools / update-post-strings.js

update-post-strings.js in Extendify 2.2.0, at src/Agent/workflows/content/tools/update-post-strings.js

24 lines 782 B
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import apiFetch from '@wordpress/api-fetch';
2
3 // TODO: check for post_lock and error that someone is editing
4 export default async ({ postId, postType, replacements }) => {
5 const type = postType === 'page' ? 'pages' : 'posts';
6 const response = await apiFetch({
7 path: `/wp/v2/${type}/${postId}?context=edit`,
8 });
9 let content = response.content.raw;
10 let title = response.title.raw;
11 const escapeRegExp = (str) => str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
12 for (const { original, updated } of replacements) {
13 const regex = new RegExp(escapeRegExp(original), 'g');
14 content = content.replace(regex, updated);
15 title = title.split(original).join(updated);
16 }
17
18 return await apiFetch({
19 path: `/wp/v2/${type}/${postId}`,
20 method: 'POST',
21 data: { content, title },
22 });
23 };
24