PluginProbe
Extendify / 0.9.3
Extendify v0.9.3
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 / api / WPApi.js

WPApi.js in Extendify 0.9.3, at src/Onboarding/api/WPApi.js

99 lines 3.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { __, sprintf } from '@wordpress/i18n'
2 import { Axios as api } from './axios'
3
4 export const parseThemeJson = (themeJson) =>
5 api.post('onboarding/parse-theme-json', { themeJson })
6
7 export const updateOption = (option, value) =>
8 api.post('onboarding/options', { option, value })
9
10 export const getOption = async (option) => {
11 const { data } = await api.get('onboarding/options', {
12 params: { option },
13 })
14 return data
15 }
16
17 export const createPage = (pageData) =>
18 api.post(`${window.extOnbData.wpRoot}wp/v2/pages`, pageData)
19
20 export const trashPost = (postId, postType) =>
21 api.delete(`${window.extOnbData.wpRoot}wp/v2/${postType}s/${postId}`)
22
23 export const getPost = (postSlug, type = 'post') =>
24 api.get(`${window.extOnbData.wpRoot}wp/v2/${type}s?slug=${postSlug}`)
25
26 export const installPlugin = async (plugin) => {
27 // Fail silently if no slug is provided
28 if (!plugin?.wordpressSlug) return
29
30 try {
31 // Install plugin and try to activate it.
32 const response = await api.post(
33 `${window.extOnbData.wpRoot}wp/v2/plugins`,
34 {
35 slug: plugin.wordpressSlug,
36 status: 'active',
37 },
38 )
39 if (!response.ok) return response
40 } catch (e) {
41 // Fail gracefully for now
42 }
43
44 try {
45 // Try and activate it if the above fails
46 return await activatePlugin(plugin)
47 } catch (e) {
48 // Fail gracefully for now
49 }
50 }
51
52 export const activatePlugin = async (plugin) => {
53 const endpoint = `${window.extOnbData.wpRoot}wp/v2/plugins`
54 const response = await api.get(`${endpoint}?search=${plugin.wordpressSlug}`)
55 const pluginSlug = response?.[0]?.plugin
56 if (!pluginSlug) {
57 throw new Error('Plugin not found')
58 }
59 // Attempt to activate the plugin with the slug we found
60 return await api.post(`${endpoint}/${pluginSlug}`, { status: 'active' })
61 }
62
63 export const updateTemplatePart = (part, content) =>
64 api.post(`${window.extOnbData.wpRoot}wp/v2/template-parts/${part}`, {
65 slug: `${part}`,
66 theme: 'extendable',
67 type: 'wp_template_part',
68 status: 'publish',
69 description: sprintf(
70 __('Added by %s', 'extendify'),
71 'Extendify Launch',
72 ),
73 content,
74 })
75
76 export const getHeadersAndFooters = async () => {
77 let patterns = await getTemplateParts()
78 patterns = patterns?.filter((p) => p.theme === 'extendable')
79 const headers = patterns?.filter((p) => p?.slug?.includes('header'))
80 const footers = patterns?.filter((p) => p?.slug?.includes('footer'))
81 return { headers, footers }
82 }
83
84 const getTemplateParts = () =>
85 api.get(window.extOnbData.wpRoot + 'wp/v2/template-parts')
86
87 export const getThemeVariations = () =>
88 api.get(
89 window.extOnbData.wpRoot +
90 'wp/v2/global-styles/themes/extendable/variations',
91 )
92
93 export const updateThemeVariation = (id, variation) =>
94 api.post(`${window.extOnbData.wpRoot}wp/v2/global-styles/${id}`, {
95 id,
96 settings: variation.settings,
97 styles: variation.styles,
98 })
99