PluginProbe ʕ •ᴥ•ʔ
Starter Sites & Templates by Neve / 1.4.1
Starter Sites & Templates by Neve v1.4.1
1.4.1 1.4.0 1.3.0 1.2.29 1.2.28 1.2.6 1.2.7 1.2.8 1.2.9 trunk 1.0.10 1.0.11 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.1.10 1.1.11 1.1.12 1.1.13 1.1.14 1.1.15 1.1.16 1.1.17 1.1.18 1.1.19 1.1.2 1.1.20 1.1.21 1.1.22 1.1.23 1.1.24 1.1.25 1.1.26 1.1.27 1.1.28 1.1.29 1.1.3 1.1.30 1.1.31 1.1.32 1.1.33 1.1.34 1.1.35 1.1.36 1.1.37 1.1.38 1.1.39 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.2.1 1.2.10 1.2.11 1.2.12 1.2.13 1.2.14 1.2.15 1.2.16 1.2.17 1.2.18 1.2.19 1.2.2 1.2.20 1.2.21 1.2.22 1.2.23 1.2.24 1.2.25 1.2.26 1.2.27 1.2.3 1.2.4 1.2.5
templates-patterns-collection / assets / src / utils / site-import.js
templates-patterns-collection / assets / src / utils Last commit date
common.js 2 years ago rest.js 3 years ago site-import.js 2 years ago
site-import.js
133 lines
1 /* global tiobDash */
2 const { onboarding } = tiobDash;
3 import { get, send } from './rest';
4 import { __ } from '@wordpress/i18n';
5
6 export const importWidgets = ( data ) => {
7 return send( onboarding.root + '/import_widgets', data );
8 };
9
10 export const importMods = ( data ) => {
11 return send( onboarding.root + '/import_theme_mods', data );
12 };
13
14 export const cleanupImport = ( data ) => {
15 return send( onboarding.root + '/cleanup', data );
16 };
17
18 export const installPlugins = ( pluginArray ) => {
19 return send( onboarding.root + '/install_plugins', pluginArray );
20 };
21
22 export const importContent = ( data ) => {
23 return send( onboarding.root + '/import_content', data );
24 };
25
26 export const importTemplates = async ( data ) => {
27 const plugins = {};
28
29 data.forEach( ( template ) => {
30 if ( 'elementor' === template.template_type ) {
31 plugins.elementor = true;
32 } else if ( 'beaver' === template.template_type ) {
33 plugins[ 'beaver-builder-lite-version' ] = true;
34 }
35 } );
36
37 if ( Object.keys( plugins ).length > 0 ) {
38 try {
39 await installPlugins( plugins );
40 } catch ( e ) {
41 return e;
42 }
43 }
44
45 return send( onboarding.root + '/import_single_templates', data );
46 };
47
48 /**
49 * Import FSE templates.
50 *
51 * @param {Object[]} data Array of templates to import.
52 *
53 * @return {Promise} Promise resolving to the import results.
54 */
55 export const importFseTemplate = async ( data ) => {
56 const url = tiobDash.siteUrl + 'wp-json/wp/v2/templates';
57 const requests = data.map( async ( template ) => {
58 const requestData = {
59 slug: 'wp-custom-template-' + template.template_id,
60 status: 'publish',
61 title: template.template_name,
62 content: template.content,
63 };
64
65 try {
66 const response = await send( url, requestData, true );
67 return {
68 success: true,
69 message: __(
70 'Import successful',
71 'templates-patterns-collection'
72 ),
73 response,
74 };
75 } catch ( fseError ) {
76 return {
77 success: false,
78 message: fseError.message,
79 error: fseError,
80 };
81 }
82 } );
83
84 try {
85 // Wait for all requests to complete before moving on
86 const results = await Promise.all( requests );
87
88 // Check if any request failed
89 const failedRequest = results.find( ( result ) => ! result.success );
90
91 if ( failedRequest ) {
92 // If any request failed, return the first failure
93 return failedRequest;
94 }
95
96 // If all requests succeeded, return success
97 return {
98 success: true,
99 message: __(
100 'All imports are successful',
101 'templates-patterns-collection'
102 ),
103 results,
104 };
105 } catch ( error ) {
106 throw error;
107 }
108 };
109
110 export const installTheme = (
111 slug = 'neve',
112 callbackSuccess,
113 callbackError
114 ) => {
115 wp.updates.installTheme( {
116 slug,
117 success: callbackSuccess,
118 error: callbackError,
119 } );
120 };
121
122 export const activateTheme = ( themeData, callbackSuccess, callbackError ) => {
123 const { themesURL } = tiobDash;
124 const url = `${ themesURL }?action=activate&stylesheet=${ themeData.slug }&_wpnonce=${ themeData.nonce }`;
125 get( url, true ).then( ( response ) => {
126 if ( response.status !== 200 ) {
127 callbackError( response );
128 return false;
129 }
130 callbackSuccess();
131 } );
132 };
133