PluginProbe
Extendify / 0.11.1
Extendify v0.11.1
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.11.1, at src/Onboarding/lib/wp.js

72 lines 2.2 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:
17 page.slug === 'home'
18 ? siteType.slug.startsWith('blog')
19 ? style?.blogBaseLayout
20 : style?.homeBaseLayout
21 : null,
22 kit: page.slug !== 'home' ? style?.kit : null,
23 })
24 let content = ''
25 if (template?.data) {
26 content = [template?.data?.code, template?.data?.code2]
27 .filter(Boolean)
28 .join('')
29 }
30
31 const name = page.slug
32 // Get content
33 const result = await createPage({
34 title: page.title,
35 name,
36 status: 'publish',
37 content: content,
38 template: 'no-title',
39 meta: { made_with_extendify_launch: true },
40 })
41 pageIds[name] = { id: result.id, title: page.title }
42 }
43 // When we have home and blog, set reading setting
44 if (pageIds?.home) {
45 await updateOption('show_on_front', 'page')
46 await updateOption('page_on_front', pageIds.home.id)
47 if (pageIds?.blog) await updateOption('page_for_posts', pageIds.blog)
48 }
49
50 // If we've created pages, consider the onboarding in a completed state
51 await updateOption(
52 'extendify_onboarding_completed',
53 new Date().toISOString(),
54 )
55 return pageIds
56 }
57
58 export const trashWordpressPages = (posts) => {
59 posts.forEach(async (el) => {
60 // Try and retrieve posts via slug.
61 const post = await getPost(el.slug, el.type)
62
63 // If post exists (but not trashed) then send it to trash.
64 if (post?.length && post[0].status !== 'trash') {
65 await trashPost(post[0].id, el.type)
66 }
67 })
68 }
69
70 export const updateGlobalStyleVariant = (variation) =>
71 updateThemeVariation(window.extOnbData.globalStylesPostID, variation)
72