PluginProbe
Extendify / 0.10.0
Extendify v0.10.0
3.2.1 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 All 127 releases
extendify / src / Onboarding / lib / wp.js

wp.js in Extendify 0.10.0, at src/Onboarding/lib/wp.js

67 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { getTemplate } from '@onboarding/api/DataApi'
2 import {
3 updateOption,
4 createPage,
5 trashPost,
6 getPost,
7 updateThemeVariation,
8 } from '@onboarding/api/WPApi'
9
10 export const createWordpressPages = async (pages, siteType, style) => {
11 const pageIds = {}
12 for (const page of pages) {
13 const template = await getTemplate({
14 siteType: siteType.slug,
15 layoutType: page.slug,
16 baseLayout: page.slug === 'home' ? style?.homeBaseLayout : null,
17 kit: page.slug !== 'home' ? style?.kit : null,
18 })
19 let content = ''
20 if (template?.data) {
21 content = [template?.data?.code, template?.data?.code2]
22 .filter(Boolean)
23 .join('')
24 }
25
26 const name = page.slug
27 // Get content
28 const result = await createPage({
29 title: page.title,
30 name,
31 status: 'publish',
32 content: content,
33 template: 'no-title',
34 meta: { made_with_extendify_launch: true },
35 })
36 pageIds[name] = { id: result.id, title: page.title }
37 }
38 // When we have home and blog, set reading setting
39 if (pageIds?.home) {
40 await updateOption('show_on_front', 'page')
41 await updateOption('page_on_front', pageIds.home.id)
42 if (pageIds?.blog) await updateOption('page_for_posts', pageIds.blog)
43 }
44
45 // If we've created pages, consider the onboarding in a completed state
46 await updateOption(
47 'extendify_onboarding_completed',
48 new Date().toISOString(),
49 )
50 return pageIds
51 }
52
53 export const trashWordpressPages = (posts) => {
54 posts.forEach(async (el) => {
55 // Try and retrieve posts via slug.
56 const post = await getPost(el.slug, el.type)
57
58 // If post exists (but not trashed) then send it to trash.
59 if (post?.length && post[0].status !== 'trash') {
60 await trashPost(post[0].id, el.type)
61 }
62 })
63 }
64
65 export const updateGlobalStyleVariant = (variation) =>
66 updateThemeVariation(window.extOnbData.globalStylesPostID, variation)
67