Version Description
Download this release
Release Info
Developer | vrundakansara |
Plugin | |
Version | 1.3.8 |
Comparing to | |
See all releases |
Code changes from version 1.3.7 to 1.3.8
- astra-sites.php +2 -2
- inc/assets/js/admin-page.js +1 -1
- inc/assets/js/astra-sites-api.js +28 -26
- inc/classes/class-astra-sites-importer.php +597 -572
- inc/classes/class-astra-sites-page.php +434 -434
- inc/classes/class-astra-sites.php +600 -600
- inc/classes/compatibility/class-astra-sites-compatibility.php +66 -66
- inc/importers/batch-processing/class-astra-sites-batch-processing-beaver-builder.php +261 -261
- inc/importers/batch-processing/class-astra-sites-batch-processing-brizy.php +125 -125
- inc/importers/batch-processing/class-astra-sites-batch-processing-gutenberg.php +165 -165
- inc/importers/batch-processing/helpers/class-astra-sites-image-importer.php +243 -243
- inc/importers/wxr-importer/class-astra-wxr-importer.php +446 -446
- inc/includes/admin-page.php +420 -420
- languages/astra-sites.pot +3 -3
- readme.txt +5 -1
astra-sites.php
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
* Plugin Name: Astra Starter Sites – Elementor, Beaver Builder & Gutenberg Templates
|
4 |
* Plugin URI: http://www.wpastra.com/pro/
|
5 |
* Description: Import free sites build with Astra theme.
|
6 |
-
* Version: 1.3.
|
7 |
* Author: Brainstorm Force
|
8 |
* Author URI: http://www.brainstormforce.com
|
9 |
* Text Domain: astra-sites
|
@@ -19,7 +19,7 @@ if ( ! defined( 'ASTRA_SITES_NAME' ) ) {
|
|
19 |
}
|
20 |
|
21 |
if ( ! defined( 'ASTRA_SITES_VER' ) ) {
|
22 |
-
define( 'ASTRA_SITES_VER', '1.3.
|
23 |
}
|
24 |
|
25 |
if ( ! defined( 'ASTRA_SITES_FILE' ) ) {
|
3 |
* Plugin Name: Astra Starter Sites – Elementor, Beaver Builder & Gutenberg Templates
|
4 |
* Plugin URI: http://www.wpastra.com/pro/
|
5 |
* Description: Import free sites build with Astra theme.
|
6 |
+
* Version: 1.3.8
|
7 |
* Author: Brainstorm Force
|
8 |
* Author URI: http://www.brainstormforce.com
|
9 |
* Text Domain: astra-sites
|
19 |
}
|
20 |
|
21 |
if ( ! defined( 'ASTRA_SITES_VER' ) ) {
|
22 |
+
define( 'ASTRA_SITES_VER', '1.3.8' );
|
23 |
}
|
24 |
|
25 |
if ( ! defined( 'ASTRA_SITES_FILE' ) ) {
|
inc/assets/js/admin-page.js
CHANGED
@@ -294,7 +294,7 @@ var AstraSitesAjaxQueue = (function() {
|
|
294 |
}
|
295 |
},
|
296 |
|
297 |
-
_reset_customizer_data() {
|
298 |
$.ajax({
|
299 |
url : astraSitesAdmin.ajaxurl,
|
300 |
type : 'POST',
|
294 |
}
|
295 |
},
|
296 |
|
297 |
+
_reset_customizer_data: function() {
|
298 |
$.ajax({
|
299 |
url : astraSitesAdmin.ajaxurl,
|
300 |
type : 'POST',
|
inc/assets/js/astra-sites-api.js
CHANGED
@@ -14,45 +14,47 @@
|
|
14 |
*/
|
15 |
_api_request: function( args, callback ) {
|
16 |
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
};
|
21 |
|
22 |
if( astraRenderGrid.headers ) {
|
23 |
-
|
24 |
}
|
25 |
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
} else {
|
34 |
-
$(document).trigger( 'astra-sites-api-request-error' );
|
35 |
-
return response.json();
|
36 |
-
}
|
37 |
-
})
|
38 |
-
.then(data => {
|
39 |
-
if( 'object' === typeof data ) {
|
40 |
-
data['args'] = args;
|
41 |
-
if( data.args.id ) {
|
42 |
-
AstraSitesAPI._stored_data[ args.id ] = $.merge( AstraSitesAPI._stored_data[ data.args.id ], data.items );
|
43 |
}
|
44 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
if( 'undefined' !== typeof args.trigger && '' !== args.trigger ) {
|
46 |
$(document).trigger( args.trigger, [data] );
|
47 |
}
|
48 |
-
|
49 |
-
|
50 |
-
callback( data );
|
51 |
-
}
|
52 |
}
|
53 |
|
|
|
|
|
|
|
|
|
54 |
|
55 |
-
|
|
|
|
|
|
|
56 |
|
57 |
},
|
58 |
|
14 |
*/
|
15 |
_api_request: function( args, callback ) {
|
16 |
|
17 |
+
// Set API Request Data.
|
18 |
+
var data = {
|
19 |
+
url: AstraSitesAPI._api_url + args.slug,
|
20 |
};
|
21 |
|
22 |
if( astraRenderGrid.headers ) {
|
23 |
+
data.headers = astraRenderGrid.headers;
|
24 |
}
|
25 |
|
26 |
+
$.ajax( data )
|
27 |
+
.done(function( items, status, XHR ) {
|
28 |
+
|
29 |
+
if( 'success' === status && XHR.getResponseHeader('x-wp-total') ) {
|
30 |
+
|
31 |
+
if( args.id ) {
|
32 |
+
AstraSitesAPI._stored_data[ args.id ] = $.merge( AstraSitesAPI._stored_data[ args.id ], items );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
}
|
34 |
|
35 |
+
var data = {
|
36 |
+
args : args,
|
37 |
+
items : items,
|
38 |
+
items_count : XHR.getResponseHeader('x-wp-total') || 0,
|
39 |
+
item_pages : XHR.getResponseHeader('x-wp-totalpages') || 0,
|
40 |
+
};
|
41 |
+
|
42 |
if( 'undefined' !== typeof args.trigger && '' !== args.trigger ) {
|
43 |
$(document).trigger( args.trigger, [data] );
|
44 |
}
|
45 |
+
} else {
|
46 |
+
$(document).trigger( 'astra-sites-api-request-error' );
|
|
|
|
|
47 |
}
|
48 |
|
49 |
+
})
|
50 |
+
.fail(function( jqXHR, textStatus ) {
|
51 |
+
|
52 |
+
$(document).trigger( 'astra-sites-api-request-fail', [jqXHR, textStatus, args] );
|
53 |
|
54 |
+
})
|
55 |
+
.always(function() {
|
56 |
+
$(document).trigger( 'astra-sites-api-request-always' );
|
57 |
+
});
|
58 |
|
59 |
},
|
60 |
|
inc/classes/class-astra-sites-importer.php
CHANGED
@@ -1,572 +1,597 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* Astra Sites Importer
|
4 |
-
*
|
5 |
-
* @since 1.0.0
|
6 |
-
* @package Astra Sites
|
7 |
-
*/
|
8 |
-
|
9 |
-
defined( 'ABSPATH' ) or exit;
|
10 |
-
|
11 |
-
if ( ! class_exists( 'Astra_Sites_Importer' ) ) :
|
12 |
-
|
13 |
-
/**
|
14 |
-
* Astra Sites Importer
|
15 |
-
*/
|
16 |
-
class Astra_Sites_Importer {
|
17 |
-
|
18 |
-
/**
|
19 |
-
* Instance
|
20 |
-
*
|
21 |
-
* @since 1.0.0
|
22 |
-
* @var (Object) Class object
|
23 |
-
*/
|
24 |
-
public static $_instance = null;
|
25 |
-
|
26 |
-
/**
|
27 |
-
* Set Instance
|
28 |
-
*
|
29 |
-
* @since 1.0.0
|
30 |
-
*
|
31 |
-
* @return object Class object.
|
32 |
-
*/
|
33 |
-
public static function get_instance() {
|
34 |
-
if ( ! isset( self::$_instance ) ) {
|
35 |
-
self::$_instance = new self;
|
36 |
-
}
|
37 |
-
|
38 |
-
return self::$_instance;
|
39 |
-
}
|
40 |
-
|
41 |
-
/**
|
42 |
-
* Constructor.
|
43 |
-
*
|
44 |
-
* @since 1.0.0
|
45 |
-
*/
|
46 |
-
public function __construct() {
|
47 |
-
|
48 |
-
require_once ASTRA_SITES_DIR . 'inc/classes/class-astra-sites-importer-log.php';
|
49 |
-
require_once ASTRA_SITES_DIR . 'inc/importers/class-astra-sites-helper.php';
|
50 |
-
require_once ASTRA_SITES_DIR . 'inc/importers/class-widgets-importer.php';
|
51 |
-
require_once ASTRA_SITES_DIR . 'inc/importers/class-astra-customizer-import.php';
|
52 |
-
require_once ASTRA_SITES_DIR . 'inc/importers/class-astra-site-options-import.php';
|
53 |
-
|
54 |
-
// Import AJAX.
|
55 |
-
add_action( 'wp_ajax_astra-sites-import-set-site-data', array( $this, 'import_start' ) );
|
56 |
-
add_action( 'wp_ajax_astra-sites-import-wpforms', array( $this, 'import_wpforms' ) );
|
57 |
-
add_action( 'wp_ajax_astra-sites-import-customizer-settings', array( $this, 'import_customizer_settings' ) );
|
58 |
-
add_action( 'wp_ajax_astra-sites-import-prepare-xml', array( $this, 'prepare_xml_data' ) );
|
59 |
-
add_action( 'wp_ajax_astra-sites-import-options', array( $this, 'import_options' ) );
|
60 |
-
add_action( 'wp_ajax_astra-sites-import-widgets', array( $this, 'import_widgets' ) );
|
61 |
-
add_action( 'wp_ajax_astra-sites-import-end', array( $this, 'import_end' ) );
|
62 |
-
|
63 |
-
// Hooks in AJAX.
|
64 |
-
add_action( 'astra_sites_import_complete', array( $this, 'clear_cache' ) );
|
65 |
-
add_action( 'init', array( $this, 'load_importer' ) );
|
66 |
-
|
67 |
-
require_once ASTRA_SITES_DIR . 'inc/importers/batch-processing/class-astra-sites-batch-processing.php';
|
68 |
-
|
69 |
-
add_action( 'astra_sites_image_import_complete', array( $this, 'clear_cache' ) );
|
70 |
-
|
71 |
-
// Reset Customizer Data.
|
72 |
-
add_action( 'wp_ajax_astra-sites-reset-customizer-data', array( $this, 'reset_customizer_data' ) );
|
73 |
-
add_action( 'wp_ajax_astra-sites-reset-site-options', array( $this, 'reset_site_options' ) );
|
74 |
-
add_action( 'wp_ajax_astra-sites-reset-widgets-data', array( $this, 'reset_widgets_data' ) );
|
75 |
-
|
76 |
-
// Reset Post & Terms.
|
77 |
-
add_action( 'wp_ajax_astra-sites-delete-posts', array( $this, 'delete_imported_posts' ) );
|
78 |
-
add_action( 'wp_ajax_astra-sites-delete-wp-forms', array( $this, 'delete_imported_wp_forms' ) );
|
79 |
-
add_action( 'wp_ajax_astra-sites-delete-terms', array( $this, 'delete_imported_terms' ) );
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
*
|
91 |
-
*
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
*
|
229 |
-
*
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
if ( !
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
}
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
}
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
*
|
294 |
-
*
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
if (
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
}
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
|
435 |
-
|
436 |
-
|
437 |
-
*
|
438 |
-
*
|
439 |
-
* @
|
440 |
-
*/
|
441 |
-
function
|
442 |
-
|
443 |
-
|
444 |
-
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
|
452 |
-
|
453 |
-
|
454 |
-
|
455 |
-
|
456 |
-
|
457 |
-
|
458 |
-
|
459 |
-
|
460 |
-
|
461 |
-
|
462 |
-
|
463 |
-
|
464 |
-
|
465 |
-
|
466 |
-
|
467 |
-
|
468 |
-
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
-
|
473 |
-
|
474 |
-
|
475 |
-
|
476 |
-
|
477 |
-
|
478 |
-
|
479 |
-
|
480 |
-
|
481 |
-
|
482 |
-
|
483 |
-
|
484 |
-
|
485 |
-
|
486 |
-
|
487 |
-
|
488 |
-
|
489 |
-
|
490 |
-
|
491 |
-
|
492 |
-
|
493 |
-
|
494 |
-
|
495 |
-
|
496 |
-
|
497 |
-
|
498 |
-
|
499 |
-
|
500 |
-
|
501 |
-
|
502 |
-
|
503 |
-
|
504 |
-
|
505 |
-
|
506 |
-
|
507 |
-
|
508 |
-
|
509 |
-
|
510 |
-
|
511 |
-
|
512 |
-
|
513 |
-
|
514 |
-
|
515 |
-
|
516 |
-
|
517 |
-
|
518 |
-
|
519 |
-
|
520 |
-
|
521 |
-
|
522 |
-
|
523 |
-
|
524 |
-
|
525 |
-
|
526 |
-
|
527 |
-
|
528 |
-
|
529 |
-
|
530 |
-
|
531 |
-
|
532 |
-
|
533 |
-
|
534 |
-
|
535 |
-
|
536 |
-
|
537 |
-
|
538 |
-
|
539 |
-
|
540 |
-
|
541 |
-
|
542 |
-
|
543 |
-
|
544 |
-
|
545 |
-
|
546 |
-
|
547 |
-
|
548 |
-
|
549 |
-
|
550 |
-
|
551 |
-
|
552 |
-
|
553 |
-
|
554 |
-
|
555 |
-
|
556 |
-
|
557 |
-
|
558 |
-
|
559 |
-
|
560 |
-
|
561 |
-
/* translators: %s is the
|
562 |
-
wp_send_json_success( $message );
|
563 |
-
}
|
564 |
-
|
565 |
-
|
566 |
-
|
567 |
-
|
568 |
-
|
569 |
-
|
570 |
-
|
571 |
-
|
572 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Astra Sites Importer
|
4 |
+
*
|
5 |
+
* @since 1.0.0
|
6 |
+
* @package Astra Sites
|
7 |
+
*/
|
8 |
+
|
9 |
+
defined( 'ABSPATH' ) or exit;
|
10 |
+
|
11 |
+
if ( ! class_exists( 'Astra_Sites_Importer' ) ) :
|
12 |
+
|
13 |
+
/**
|
14 |
+
* Astra Sites Importer
|
15 |
+
*/
|
16 |
+
class Astra_Sites_Importer {
|
17 |
+
|
18 |
+
/**
|
19 |
+
* Instance
|
20 |
+
*
|
21 |
+
* @since 1.0.0
|
22 |
+
* @var (Object) Class object
|
23 |
+
*/
|
24 |
+
public static $_instance = null;
|
25 |
+
|
26 |
+
/**
|
27 |
+
* Set Instance
|
28 |
+
*
|
29 |
+
* @since 1.0.0
|
30 |
+
*
|
31 |
+
* @return object Class object.
|
32 |
+
*/
|
33 |
+
public static function get_instance() {
|
34 |
+
if ( ! isset( self::$_instance ) ) {
|
35 |
+
self::$_instance = new self;
|
36 |
+
}
|
37 |
+
|
38 |
+
return self::$_instance;
|
39 |
+
}
|
40 |
+
|
41 |
+
/**
|
42 |
+
* Constructor.
|
43 |
+
*
|
44 |
+
* @since 1.0.0
|
45 |
+
*/
|
46 |
+
public function __construct() {
|
47 |
+
|
48 |
+
require_once ASTRA_SITES_DIR . 'inc/classes/class-astra-sites-importer-log.php';
|
49 |
+
require_once ASTRA_SITES_DIR . 'inc/importers/class-astra-sites-helper.php';
|
50 |
+
require_once ASTRA_SITES_DIR . 'inc/importers/class-widgets-importer.php';
|
51 |
+
require_once ASTRA_SITES_DIR . 'inc/importers/class-astra-customizer-import.php';
|
52 |
+
require_once ASTRA_SITES_DIR . 'inc/importers/class-astra-site-options-import.php';
|
53 |
+
|
54 |
+
// Import AJAX.
|
55 |
+
add_action( 'wp_ajax_astra-sites-import-set-site-data', array( $this, 'import_start' ) );
|
56 |
+
add_action( 'wp_ajax_astra-sites-import-wpforms', array( $this, 'import_wpforms' ) );
|
57 |
+
add_action( 'wp_ajax_astra-sites-import-customizer-settings', array( $this, 'import_customizer_settings' ) );
|
58 |
+
add_action( 'wp_ajax_astra-sites-import-prepare-xml', array( $this, 'prepare_xml_data' ) );
|
59 |
+
add_action( 'wp_ajax_astra-sites-import-options', array( $this, 'import_options' ) );
|
60 |
+
add_action( 'wp_ajax_astra-sites-import-widgets', array( $this, 'import_widgets' ) );
|
61 |
+
add_action( 'wp_ajax_astra-sites-import-end', array( $this, 'import_end' ) );
|
62 |
+
|
63 |
+
// Hooks in AJAX.
|
64 |
+
add_action( 'astra_sites_import_complete', array( $this, 'clear_cache' ) );
|
65 |
+
add_action( 'init', array( $this, 'load_importer' ) );
|
66 |
+
|
67 |
+
require_once ASTRA_SITES_DIR . 'inc/importers/batch-processing/class-astra-sites-batch-processing.php';
|
68 |
+
|
69 |
+
add_action( 'astra_sites_image_import_complete', array( $this, 'clear_cache' ) );
|
70 |
+
|
71 |
+
// Reset Customizer Data.
|
72 |
+
add_action( 'wp_ajax_astra-sites-reset-customizer-data', array( $this, 'reset_customizer_data' ) );
|
73 |
+
add_action( 'wp_ajax_astra-sites-reset-site-options', array( $this, 'reset_site_options' ) );
|
74 |
+
add_action( 'wp_ajax_astra-sites-reset-widgets-data', array( $this, 'reset_widgets_data' ) );
|
75 |
+
|
76 |
+
// Reset Post & Terms.
|
77 |
+
add_action( 'wp_ajax_astra-sites-delete-posts', array( $this, 'delete_imported_posts' ) );
|
78 |
+
add_action( 'wp_ajax_astra-sites-delete-wp-forms', array( $this, 'delete_imported_wp_forms' ) );
|
79 |
+
add_action( 'wp_ajax_astra-sites-delete-terms', array( $this, 'delete_imported_terms' ) );
|
80 |
+
add_filter( 'http_request_timeout', array( $this, 'set_timeout_for_images' ), 10, 2 );
|
81 |
+
}
|
82 |
+
|
83 |
+
/**
|
84 |
+
* Set the timeout for the HTTP request by request URL.
|
85 |
+
*
|
86 |
+
* E.g. If URL is images (jpg|png|gif|jpeg) are from the domain `https://websitedemos.net` then we have set the timeout by 30 seconds. Default 5 seconds.
|
87 |
+
*
|
88 |
+
* @since 1.3.8
|
89 |
+
*
|
90 |
+
* @param int $timeout_value Time in seconds until a request times out. Default 5.
|
91 |
+
* @param string $url The request URL.
|
92 |
+
*/
|
93 |
+
function set_timeout_for_images( $timeout_value, $url ) {
|
94 |
+
|
95 |
+
// URL not contain `https://websitedemos.net` then return $timeout_value.
|
96 |
+
if ( strpos( $url, 'https://websitedemos.net' ) === false ) {
|
97 |
+
return $timeout_value;
|
98 |
+
}
|
99 |
+
|
100 |
+
// Check is image URL of type jpg|png|gif|jpeg.
|
101 |
+
if ( preg_match( '/^((https?:\/\/)|(www\.))([a-z0-9-].?)+(:[0-9]+)?\/[\w\-]+\.(jpg|png|gif|jpeg)\/?#x2F;i', $url ) ) {
|
102 |
+
$timeout_value = 30;
|
103 |
+
}
|
104 |
+
return $timeout_value;
|
105 |
+
}
|
106 |
+
|
107 |
+
/**
|
108 |
+
* Load WordPress WXR importer.
|
109 |
+
*/
|
110 |
+
public function load_importer() {
|
111 |
+
require_once ASTRA_SITES_DIR . 'inc/importers/wxr-importer/class-astra-wxr-importer.php';
|
112 |
+
}
|
113 |
+
|
114 |
+
/**
|
115 |
+
* Start Site Import
|
116 |
+
*
|
117 |
+
* @since 1.1.0
|
118 |
+
* @return void
|
119 |
+
*/
|
120 |
+
function import_start() {
|
121 |
+
|
122 |
+
if ( ! current_user_can( 'customize' ) ) {
|
123 |
+
wp_send_json_error( __( 'You have not "customize" access to import the Astra site.', 'astra-sites' ) );
|
124 |
+
}
|
125 |
+
|
126 |
+
$demo_api_uri = isset( $_POST['api_url'] ) ? esc_url( $_POST['api_url'] ) : '';
|
127 |
+
|
128 |
+
if ( ! empty( $demo_api_uri ) ) {
|
129 |
+
|
130 |
+
$demo_data = self::get_astra_single_demo( $demo_api_uri );
|
131 |
+
|
132 |
+
update_option( 'astra_sites_import_data', $demo_data );
|
133 |
+
|
134 |
+
if ( is_wp_error( $demo_data ) ) {
|
135 |
+
wp_send_json_error( $demo_data->get_error_message() );
|
136 |
+
} else {
|
137 |
+
$log_file = Astra_Sites_Importer_Log::add_log_file_url();
|
138 |
+
if ( isset( $log_file['url'] ) && ! empty( $log_file['url'] ) ) {
|
139 |
+
$demo_data['log_file'] = $log_file['url'];
|
140 |
+
}
|
141 |
+
do_action( 'astra_sites_import_start', $demo_data, $demo_api_uri );
|
142 |
+
}
|
143 |
+
|
144 |
+
wp_send_json_success( $demo_data );
|
145 |
+
|
146 |
+
} else {
|
147 |
+
wp_send_json_error( __( 'Request site API URL is empty. Try again!', 'astra-sites' ) );
|
148 |
+
}
|
149 |
+
|
150 |
+
}
|
151 |
+
|
152 |
+
/**
|
153 |
+
* Import WP Forms
|
154 |
+
*
|
155 |
+
* @since 1.2.14
|
156 |
+
*
|
157 |
+
* @return void
|
158 |
+
*/
|
159 |
+
function import_wpforms() {
|
160 |
+
|
161 |
+
$wpforms_url = ( isset( $_REQUEST['wpforms_url'] ) ) ? urldecode( $_REQUEST['wpforms_url'] ) : '';
|
162 |
+
$ids_mapping = array();
|
163 |
+
|
164 |
+
if ( ! empty( $wpforms_url ) && function_exists( 'wpforms_encode' ) ) {
|
165 |
+
|
166 |
+
// Download XML file.
|
167 |
+
$xml_path = Astra_Sites_Helper::download_file( $wpforms_url );
|
168 |
+
|
169 |
+
if ( $xml_path['success'] ) {
|
170 |
+
if ( isset( $xml_path['data']['file'] ) ) {
|
171 |
+
|
172 |
+
$ext = strtolower( pathinfo( $xml_path['data']['file'], PATHINFO_EXTENSION ) );
|
173 |
+
|
174 |
+
if ( 'json' === $ext ) {
|
175 |
+
$forms = json_decode( file_get_contents( $xml_path['data']['file'] ), true );
|
176 |
+
|
177 |
+
if ( ! empty( $forms ) ) {
|
178 |
+
|
179 |
+
foreach ( $forms as $form ) {
|
180 |
+
$title = ! empty( $form['settings']['form_title'] ) ? $form['settings']['form_title'] : '';
|
181 |
+
$desc = ! empty( $form['settings']['form_desc'] ) ? $form['settings']['form_desc'] : '';
|
182 |
+
|
183 |
+
$new_id = post_exists( $title );
|
184 |
+
|
185 |
+
if ( ! $new_id ) {
|
186 |
+
$new_id = wp_insert_post(
|
187 |
+
array(
|
188 |
+
'post_title' => $title,
|
189 |
+
'post_status' => 'publish',
|
190 |
+
'post_type' => 'wpforms',
|
191 |
+
'post_excerpt' => $desc,
|
192 |
+
)
|
193 |
+
);
|
194 |
+
|
195 |
+
// Set meta for tracking the post.
|
196 |
+
update_post_meta( $new_id, '_astra_sites_imported_wp_forms', true );
|
197 |
+
Astra_Sites_Importer_Log::add( 'Inserted WP Form ' . $new_id );
|
198 |
+
}
|
199 |
+
|
200 |
+
if ( $new_id ) {
|
201 |
+
|
202 |
+
// ID mapping.
|
203 |
+
$ids_mapping[ $form['id'] ] = $new_id;
|
204 |
+
|
205 |
+
$form['id'] = $new_id;
|
206 |
+
wp_update_post(
|
207 |
+
array(
|
208 |
+
'ID' => $new_id,
|
209 |
+
'post_content' => wpforms_encode( $form ),
|
210 |
+
)
|
211 |
+
);
|
212 |
+
}
|
213 |
+
}
|
214 |
+
}
|
215 |
+
}
|
216 |
+
}
|
217 |
+
}
|
218 |
+
}
|
219 |
+
|
220 |
+
update_option( 'astra_sites_wpforms_ids_mapping', $ids_mapping );
|
221 |
+
|
222 |
+
wp_send_json_success( $ids_mapping );
|
223 |
+
}
|
224 |
+
|
225 |
+
/**
|
226 |
+
* Import Customizer Settings.
|
227 |
+
*
|
228 |
+
* @since 1.0.14
|
229 |
+
* @return void
|
230 |
+
*/
|
231 |
+
function import_customizer_settings() {
|
232 |
+
|
233 |
+
$customizer_data = ( isset( $_POST['customizer_data'] ) ) ? (array) json_decode( stripcslashes( $_POST['customizer_data'] ), 1 ) : array();
|
234 |
+
|
235 |
+
if ( ! empty( $customizer_data ) ) {
|
236 |
+
|
237 |
+
Astra_Sites_Importer_Log::add( 'Imported Customizer Settings ' . json_encode( $customizer_data ) );
|
238 |
+
|
239 |
+
// Set meta for tracking the post.
|
240 |
+
update_option( '_astra_sites_old_customizer_data', $customizer_data );
|
241 |
+
|
242 |
+
Astra_Customizer_Import::instance()->import( $customizer_data );
|
243 |
+
|
244 |
+
wp_send_json_success( $customizer_data );
|
245 |
+
|
246 |
+
} else {
|
247 |
+
wp_send_json_error( __( 'Customizer data is empty!', 'astra-sites' ) );
|
248 |
+
}
|
249 |
+
|
250 |
+
}
|
251 |
+
|
252 |
+
/**
|
253 |
+
* Prepare XML Data.
|
254 |
+
*
|
255 |
+
* @since 1.1.0
|
256 |
+
* @return void
|
257 |
+
*/
|
258 |
+
function prepare_xml_data() {
|
259 |
+
|
260 |
+
if ( ! class_exists( 'XMLReader' ) ) {
|
261 |
+
wp_send_json_error( __( 'If XMLReader is not available, it imports all other settings and only skips XML import. This creates an incomplete website. We should bail early and not import anything if this is not present.', 'astra-sites' ) );
|
262 |
+
}
|
263 |
+
|
264 |
+
$wxr_url = ( isset( $_REQUEST['wxr_url'] ) ) ? urldecode( $_REQUEST['wxr_url'] ) : '';
|
265 |
+
|
266 |
+
if ( isset( $wxr_url ) ) {
|
267 |
+
|
268 |
+
Astra_Sites_Importer_Log::add( 'Importing from XML ' . $wxr_url );
|
269 |
+
|
270 |
+
// Download XML file.
|
271 |
+
$xml_path = Astra_Sites_Helper::download_file( $wxr_url );
|
272 |
+
|
273 |
+
if ( $xml_path['success'] ) {
|
274 |
+
if ( isset( $xml_path['data']['file'] ) ) {
|
275 |
+
$data = Astra_WXR_Importer::instance()->get_xml_data( $xml_path['data']['file'] );
|
276 |
+
$data['xml'] = $xml_path['data'];
|
277 |
+
wp_send_json_success( $data );
|
278 |
+
} else {
|
279 |
+
wp_send_json_error( __( 'There was an error downloading the XML file.', 'astra-sites' ) );
|
280 |
+
}
|
281 |
+
} else {
|
282 |
+
wp_send_json_error( $xml_path['data'] );
|
283 |
+
}
|
284 |
+
} else {
|
285 |
+
wp_send_json_error( __( 'Invalid site XML file!', 'astra-sites' ) );
|
286 |
+
}
|
287 |
+
|
288 |
+
}
|
289 |
+
|
290 |
+
/**
|
291 |
+
* Import Options.
|
292 |
+
*
|
293 |
+
* @since 1.0.14
|
294 |
+
* @return void
|
295 |
+
*/
|
296 |
+
function import_options() {
|
297 |
+
|
298 |
+
$options_data = ( isset( $_POST['options_data'] ) ) ? (array) json_decode( stripcslashes( $_POST['options_data'] ), 1 ) : '';
|
299 |
+
|
300 |
+
if ( ! empty( $options_data ) ) {
|
301 |
+
|
302 |
+
// Set meta for tracking the post.
|
303 |
+
if ( is_array( $options_data ) ) {
|
304 |
+
Astra_Sites_Importer_Log::add( 'Imported - Site Options ' . json_encode( $options_data ) );
|
305 |
+
update_option( '_astra_sites_old_site_options', $options_data );
|
306 |
+
}
|
307 |
+
|
308 |
+
$options_importer = Astra_Site_Options_Import::instance();
|
309 |
+
$options_importer->import_options( $options_data );
|
310 |
+
wp_send_json_success( $options_data );
|
311 |
+
} else {
|
312 |
+
wp_send_json_error( __( 'Site options are empty!', 'astra-sites' ) );
|
313 |
+
}
|
314 |
+
|
315 |
+
}
|
316 |
+
|
317 |
+
/**
|
318 |
+
* Import Widgets.
|
319 |
+
*
|
320 |
+
* @since 1.0.14
|
321 |
+
* @return void
|
322 |
+
*/
|
323 |
+
function import_widgets() {
|
324 |
+
|
325 |
+
$widgets_data = ( isset( $_POST['widgets_data'] ) ) ? (object) json_decode( stripcslashes( $_POST['widgets_data'] ) ) : '';
|
326 |
+
|
327 |
+
Astra_Sites_Importer_Log::add( 'Imported - Widgets ' . json_encode( $widgets_data ) );
|
328 |
+
|
329 |
+
if ( ! empty( $widgets_data ) ) {
|
330 |
+
|
331 |
+
$widgets_importer = Astra_Widget_Importer::instance();
|
332 |
+
$status = $widgets_importer->import_widgets_data( $widgets_data );
|
333 |
+
|
334 |
+
// Set meta for tracking the post.
|
335 |
+
if ( is_object( $widgets_data ) ) {
|
336 |
+
$widgets_data = (array) $widgets_data;
|
337 |
+
update_option( '_astra_sites_old_widgets_data', $widgets_data );
|
338 |
+
}
|
339 |
+
|
340 |
+
wp_send_json_success( $widgets_data );
|
341 |
+
} else {
|
342 |
+
wp_send_json_error( __( 'Widget data is empty!', 'astra-sites' ) );
|
343 |
+
}
|
344 |
+
|
345 |
+
}
|
346 |
+
|
347 |
+
/**
|
348 |
+
* Import End.
|
349 |
+
*
|
350 |
+
* @since 1.0.14
|
351 |
+
* @return void
|
352 |
+
*/
|
353 |
+
function import_end() {
|
354 |
+
do_action( 'astra_sites_import_complete' );
|
355 |
+
}
|
356 |
+
|
357 |
+
|
358 |
+
/**
|
359 |
+
* Get single demo.
|
360 |
+
*
|
361 |
+
* @since 1.0.0
|
362 |
+
*
|
363 |
+
* @param (String) $demo_api_uri API URL of a demo.
|
364 |
+
*
|
365 |
+
* @return (Array) $astra_demo_data demo data for the demo.
|
366 |
+
*/
|
367 |
+
public static function get_astra_single_demo( $demo_api_uri ) {
|
368 |
+
|
369 |
+
// default values.
|
370 |
+
$remote_args = array();
|
371 |
+
$defaults = array(
|
372 |
+
'id' => '',
|
373 |
+
'astra-site-widgets-data' => '',
|
374 |
+
'astra-site-customizer-data' => '',
|
375 |
+
'astra-site-options-data' => '',
|
376 |
+
'astra-post-data-mapping' => '',
|
377 |
+
'astra-site-wxr-path' => '',
|
378 |
+
'astra-site-wpforms-path' => '',
|
379 |
+
'astra-enabled-extensions' => '',
|
380 |
+
'astra-custom-404' => '',
|
381 |
+
'required-plugins' => '',
|
382 |
+
'astra-site-taxonomy-mapping' => '',
|
383 |
+
);
|
384 |
+
|
385 |
+
$api_args = apply_filters(
|
386 |
+
'astra_sites_api_args',
|
387 |
+
array(
|
388 |
+
'timeout' => 15,
|
389 |
+
)
|
390 |
+
);
|
391 |
+
|
392 |
+
// Use this for premium demos.
|
393 |
+
$request_params = apply_filters(
|
394 |
+
'astra_sites_api_params',
|
395 |
+
array(
|
396 |
+
'purchase_key' => '',
|
397 |
+
'site_url' => '',
|
398 |
+
)
|
399 |
+
);
|
400 |
+
|
401 |
+
$demo_api_uri = add_query_arg( $request_params, $demo_api_uri );
|
402 |
+
|
403 |
+
// API Call.
|
404 |
+
$response = wp_remote_get( $demo_api_uri, $api_args );
|
405 |
+
|
406 |
+
if ( is_wp_error( $response ) || ( isset( $response->status ) && 0 === $response->status ) ) {
|
407 |
+
if ( isset( $response->status ) ) {
|
408 |
+
$data = json_decode( $response, true );
|
409 |
+
} else {
|
410 |
+
return new WP_Error( 'api_invalid_response_code', $response->get_error_message() );
|
411 |
+
}
|
412 |
+
} else {
|
413 |
+
$data = json_decode( wp_remote_retrieve_body( $response ), true );
|
414 |
+
}
|
415 |
+
|
416 |
+
$data = json_decode( wp_remote_retrieve_body( $response ), true );
|
417 |
+
|
418 |
+
if ( ! isset( $data['code'] ) ) {
|
419 |
+
$remote_args['id'] = $data['id'];
|
420 |
+
$remote_args['astra-site-widgets-data'] = json_decode( $data['astra-site-widgets-data'] );
|
421 |
+
$remote_args['astra-site-customizer-data'] = $data['astra-site-customizer-data'];
|
422 |
+
$remote_args['astra-site-options-data'] = $data['astra-site-options-data'];
|
423 |
+
$remote_args['astra-post-data-mapping'] = $data['astra-post-data-mapping'];
|
424 |
+
$remote_args['astra-site-wxr-path'] = $data['astra-site-wxr-path'];
|
425 |
+
$remote_args['astra-site-wpforms-path'] = $data['astra-site-wpforms-path'];
|
426 |
+
$remote_args['astra-enabled-extensions'] = $data['astra-enabled-extensions'];
|
427 |
+
$remote_args['astra-custom-404'] = $data['astra-custom-404'];
|
428 |
+
$remote_args['required-plugins'] = $data['required-plugins'];
|
429 |
+
$remote_args['astra-site-taxonomy-mapping'] = $data['astra-site-taxonomy-mapping'];
|
430 |
+
}
|
431 |
+
|
432 |
+
// Merge remote demo and defaults.
|
433 |
+
return wp_parse_args( $remote_args, $defaults );
|
434 |
+
}
|
435 |
+
|
436 |
+
/**
|
437 |
+
* Clear Cache.
|
438 |
+
*
|
439 |
+
* @since 1.0.9
|
440 |
+
*/
|
441 |
+
public function clear_cache() {
|
442 |
+
// Clear 'Elementor' file cache.
|
443 |
+
if ( class_exists( '\Elementor\Plugin' ) ) {
|
444 |
+
Elementor\Plugin::$instance->posts_css_manager->clear_cache();
|
445 |
+
}
|
446 |
+
|
447 |
+
// Clear 'Builder Builder' cache.
|
448 |
+
if ( is_callable( 'FLBuilderModel::delete_asset_cache_for_all_posts' ) ) {
|
449 |
+
FLBuilderModel::delete_asset_cache_for_all_posts();
|
450 |
+
}
|
451 |
+
|
452 |
+
// Clear 'Astra Addon' cache.
|
453 |
+
if ( is_callable( 'Astra_Minify::refresh_assets' ) ) {
|
454 |
+
Astra_Minify::refresh_assets();
|
455 |
+
}
|
456 |
+
|
457 |
+
Astra_Sites_Importer_Log::add( 'Complete ' );
|
458 |
+
}
|
459 |
+
|
460 |
+
/**
|
461 |
+
* Reset customizer data
|
462 |
+
*
|
463 |
+
* @since 1.3.0
|
464 |
+
* @return void
|
465 |
+
*/
|
466 |
+
function reset_customizer_data() {
|
467 |
+
Astra_Sites_Importer_Log::add( 'Deleted customizer Settings ' . json_encode( get_option( 'astra-settings', array() ) ) );
|
468 |
+
|
469 |
+
delete_option( 'astra-settings' );
|
470 |
+
|
471 |
+
wp_send_json_success();
|
472 |
+
}
|
473 |
+
|
474 |
+
/**
|
475 |
+
* Reset site options
|
476 |
+
*
|
477 |
+
* @since 1.3.0
|
478 |
+
* @return void
|
479 |
+
*/
|
480 |
+
function reset_site_options() {
|
481 |
+
|
482 |
+
$options = get_option( '_astra_sites_old_site_options', array() );
|
483 |
+
|
484 |
+
Astra_Sites_Importer_Log::add( 'Deleted - Site Options ' . json_encode( $options ) );
|
485 |
+
|
486 |
+
if ( $options ) {
|
487 |
+
foreach ( $options as $option_key => $option_value ) {
|
488 |
+
delete_option( $option_key );
|
489 |
+
}
|
490 |
+
}
|
491 |
+
|
492 |
+
wp_send_json_success();
|
493 |
+
}
|
494 |
+
|
495 |
+
/**
|
496 |
+
* Reset widgets data
|
497 |
+
*
|
498 |
+
* @since 1.3.0
|
499 |
+
* @return void
|
500 |
+
*/
|
501 |
+
function reset_widgets_data() {
|
502 |
+
$old_widgets = get_option( '_astra_sites_old_widgets_data', array() );
|
503 |
+
|
504 |
+
Astra_Sites_Importer_Log::add( 'DELETED - WIDGETS ' . json_encode( $old_widgets ) );
|
505 |
+
|
506 |
+
if ( $old_widgets ) {
|
507 |
+
$sidebars_widgets = get_option( 'sidebars_widgets', array() );
|
508 |
+
|
509 |
+
foreach ( $old_widgets as $sidebar_id => $widgets ) {
|
510 |
+
|
511 |
+
if ( $widgets ) {
|
512 |
+
foreach ( $widgets as $widget_key => $widget_data ) {
|
513 |
+
|
514 |
+
if ( isset( $sidebars_widgets['wp_inactive_widgets'] ) ) {
|
515 |
+
if ( ! in_array( $widget_key, $sidebars_widgets['wp_inactive_widgets'], true ) ) {
|
516 |
+
$sidebars_widgets['wp_inactive_widgets'][] = $widget_key;
|
517 |
+
}
|
518 |
+
}
|
519 |
+
}
|
520 |
+
}
|
521 |
+
}
|
522 |
+
|
523 |
+
update_option( 'sidebars_widgets', $sidebars_widgets );
|
524 |
+
}
|
525 |
+
|
526 |
+
wp_send_json_success();
|
527 |
+
}
|
528 |
+
|
529 |
+
/**
|
530 |
+
* Delete imported posts
|
531 |
+
*
|
532 |
+
* @since 1.3.0
|
533 |
+
* @return void
|
534 |
+
*/
|
535 |
+
function delete_imported_posts() {
|
536 |
+
$post_id = isset( $_REQUEST['post_id'] ) ? absint( $_REQUEST['post_id'] ) : '';
|
537 |
+
$message = 'Deleted - Post ID ' . $post_id . ' - ' . get_post_type( $post_id ) . ' - ' . get_the_title( $post_id );
|
538 |
+
|
539 |
+
Astra_Sites_Importer_Log::add( $message );
|
540 |
+
wp_delete_post( $post_id, true );
|
541 |
+
|
542 |
+
/* translators: %s is the post ID */
|
543 |
+
wp_send_json_success( $message );
|
544 |
+
}
|
545 |
+
|
546 |
+
/**
|
547 |
+
* Delete imported WP forms
|
548 |
+
*
|
549 |
+
* @since 1.3.0
|
550 |
+
* @return void
|
551 |
+
*/
|
552 |
+
function delete_imported_wp_forms() {
|
553 |
+
$post_id = isset( $_REQUEST['post_id'] ) ? absint( $_REQUEST['post_id'] ) : '';
|
554 |
+
|
555 |
+
$message = 'Deleted - Form ID ' . $post_id . ' - ' . get_post_type( $post_id ) . ' - ' . get_the_title( $post_id );
|
556 |
+
|
557 |
+
Astra_Sites_Importer_Log::add( $message );
|
558 |
+
|
559 |
+
wp_delete_post( $post_id, true );
|
560 |
+
|
561 |
+
/* translators: %s is the form ID */
|
562 |
+
wp_send_json_success( $message );
|
563 |
+
}
|
564 |
+
|
565 |
+
/**
|
566 |
+
* Delete imported terms
|
567 |
+
*
|
568 |
+
* @since 1.3.0
|
569 |
+
* @return void
|
570 |
+
*/
|
571 |
+
function delete_imported_terms() {
|
572 |
+
|
573 |
+
$term_id = isset( $_REQUEST['term_id'] ) ? absint( $_REQUEST['term_id'] ) : '';
|
574 |
+
|
575 |
+
$message = '';
|
576 |
+
|
577 |
+
if ( $term_id ) {
|
578 |
+
$term = get_term( $term_id );
|
579 |
+
if ( $term ) {
|
580 |
+
$message = 'Deleted - Term ' . $term_id . ' - ' . $term->name . ' ' . $term->taxonomy;
|
581 |
+
Astra_Sites_Importer_Log::add( $message );
|
582 |
+
wp_delete_term( $term_id, $term->taxonomy );
|
583 |
+
}
|
584 |
+
}
|
585 |
+
|
586 |
+
/* translators: %s is the term ID */
|
587 |
+
wp_send_json_success( $message );
|
588 |
+
}
|
589 |
+
|
590 |
+
}
|
591 |
+
|
592 |
+
/**
|
593 |
+
* Kicking this off by calling 'get_instance()' method
|
594 |
+
*/
|
595 |
+
Astra_Sites_Importer::get_instance();
|
596 |
+
|
597 |
+
endif;
|
inc/classes/class-astra-sites-page.php
CHANGED
@@ -1,434 +1,434 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* Astra Sites Page
|
4 |
-
*
|
5 |
-
* @since 1.0.6
|
6 |
-
* @package Astra Sites
|
7 |
-
*/
|
8 |
-
|
9 |
-
if ( ! defined( 'ABSPATH' ) ) {
|
10 |
-
exit;
|
11 |
-
}
|
12 |
-
|
13 |
-
if ( ! class_exists( 'Astra_Sites_Page' ) ) {
|
14 |
-
|
15 |
-
/**
|
16 |
-
* Astra Admin Settings
|
17 |
-
*/
|
18 |
-
class Astra_Sites_Page {
|
19 |
-
|
20 |
-
/**
|
21 |
-
* View all actions
|
22 |
-
*
|
23 |
-
* @since 1.0.6
|
24 |
-
* @var array $view_actions
|
25 |
-
*/
|
26 |
-
public $view_actions = array();
|
27 |
-
|
28 |
-
/**
|
29 |
-
* Member Variable
|
30 |
-
*
|
31 |
-
* @var instance
|
32 |
-
*/
|
33 |
-
private static $instance;
|
34 |
-
|
35 |
-
/**
|
36 |
-
* Initiator
|
37 |
-
*
|
38 |
-
* @since 1.3.0
|
39 |
-
*/
|
40 |
-
public static function get_instance() {
|
41 |
-
if ( ! isset( self::$instance ) ) {
|
42 |
-
self::$instance = new self;
|
43 |
-
}
|
44 |
-
return self::$instance;
|
45 |
-
}
|
46 |
-
|
47 |
-
/**
|
48 |
-
* Constructor
|
49 |
-
*
|
50 |
-
* @since 1.3.0
|
51 |
-
*/
|
52 |
-
public function __construct() {
|
53 |
-
|
54 |
-
if ( ! is_admin() ) {
|
55 |
-
return;
|
56 |
-
}
|
57 |
-
|
58 |
-
add_action( 'after_setup_theme', array( $this, 'init_admin_settings' ), 99 );
|
59 |
-
add_action( 'admin_init', array( $this, 'save_page_builder' ) );
|
60 |
-
add_action( 'admin_notices', array( $this, 'getting_started' ) );
|
61 |
-
}
|
62 |
-
|
63 |
-
/**
|
64 |
-
* Admin notice
|
65 |
-
*
|
66 |
-
* @since 1.3.5
|
67 |
-
*
|
68 |
-
* @return void
|
69 |
-
*/
|
70 |
-
function getting_started() {
|
71 |
-
if ( 'plugins' !== get_current_screen()->base ) {
|
72 |
-
return;
|
73 |
-
}
|
74 |
-
|
75 |
-
$processed = get_user_meta( get_current_user_id(), '_astra_sites_gettings_started', true );
|
76 |
-
$product_name = Astra_Sites_White_Label::get_instance()->page_title( 'Astra' );
|
77 |
-
|
78 |
-
if ( $processed ) {
|
79 |
-
return;
|
80 |
-
}
|
81 |
-
|
82 |
-
?>
|
83 |
-
<div class="notice notice-info is-dismissible astra-sites-getting-started-notice">
|
84 |
-
<?php /* translators: %1$s is the admin page URL, %2$s is product name. */ ?>
|
85 |
-
<p><?php printf( __( 'Thank you for choosing %1$s! Check the library of <a class="astra-sites-getting-started-btn" href="%2$s">ready starter sites here »</a>', 'astra-sites' ), $product_name, admin_url( 'themes.php?page=astra-sites' ) ); ?></p>
|
86 |
-
</div>
|
87 |
-
<?php
|
88 |
-
}
|
89 |
-
|
90 |
-
/**
|
91 |
-
* Save Page Builder
|
92 |
-
*
|
93 |
-
* @return void
|
94 |
-
*/
|
95 |
-
function save_page_builder() {
|
96 |
-
|
97 |
-
// Only admins can save settings.
|
98 |
-
if ( ! current_user_can( 'manage_options' ) ) {
|
99 |
-
return;
|
100 |
-
}
|
101 |
-
|
102 |
-
// Make sure we have a valid nonce.
|
103 |
-
if ( isset( $_REQUEST['astra-sites-page-builder'] ) && wp_verify_nonce( $_REQUEST['astra-sites-page-builder'], 'astra-sites-welcome-screen' ) ) {
|
104 |
-
|
105 |
-
// Stored Settings.
|
106 |
-
$stored_data = $this->get_settings();
|
107 |
-
|
108 |
-
// New settings.
|
109 |
-
$new_data = array(
|
110 |
-
'page_builder' => ( isset( $_REQUEST['page_builder'] ) ) ? sanitize_key( $_REQUEST['page_builder'] ) : '',
|
111 |
-
);
|
112 |
-
|
113 |
-
// Merge settings.
|
114 |
-
$data = wp_parse_args( $new_data, $stored_data );
|
115 |
-
|
116 |
-
// Update settings.
|
117 |
-
update_option( 'astra_sites_settings', $data );
|
118 |
-
|
119 |
-
wp_redirect( admin_url( '/themes.php?page=astra-sites' ) );
|
120 |
-
}
|
121 |
-
}
|
122 |
-
|
123 |
-
/**
|
124 |
-
* Get single setting value
|
125 |
-
*
|
126 |
-
* @param string $key Setting key.
|
127 |
-
* @param mixed $defaults Setting value.
|
128 |
-
* @return mixed Stored setting value.
|
129 |
-
*/
|
130 |
-
function get_setting( $key = '', $defaults = '' ) {
|
131 |
-
|
132 |
-
$settings = $this->get_settings();
|
133 |
-
|
134 |
-
if ( empty( $settings ) ) {
|
135 |
-
return $defaults;
|
136 |
-
}
|
137 |
-
|
138 |
-
if ( array_key_exists( $key, $settings ) ) {
|
139 |
-
return $settings[ $key ];
|
140 |
-
}
|
141 |
-
|
142 |
-
return $defaults;
|
143 |
-
}
|
144 |
-
|
145 |
-
/**
|
146 |
-
* Get Settings
|
147 |
-
*
|
148 |
-
* @return array Stored settings.
|
149 |
-
*/
|
150 |
-
function get_settings() {
|
151 |
-
|
152 |
-
$defaults = array(
|
153 |
-
'page_builder' => '',
|
154 |
-
);
|
155 |
-
|
156 |
-
$stored_data = get_option( 'astra_sites_settings', $defaults );
|
157 |
-
|
158 |
-
return wp_parse_args( $stored_data, $defaults );
|
159 |
-
}
|
160 |
-
|
161 |
-
/**
|
162 |
-
* Admin settings init
|
163 |
-
*/
|
164 |
-
public function init_admin_settings() {
|
165 |
-
add_action( 'admin_menu', array( $this, 'add_admin_menu' ), 100 );
|
166 |
-
add_action( 'admin_notices', array( $this, 'notices' ) );
|
167 |
-
add_action( 'astra_sites_menu_general_action', array( $this, 'general_page' ) );
|
168 |
-
}
|
169 |
-
|
170 |
-
/**
|
171 |
-
* Admin notice
|
172 |
-
*
|
173 |
-
* @since 1.2.8
|
174 |
-
*/
|
175 |
-
public function notices() {
|
176 |
-
|
177 |
-
if ( 'appearance_page_astra-sites' !== get_current_screen()->id ) {
|
178 |
-
return;
|
179 |
-
}
|
180 |
-
|
181 |
-
if ( ! class_exists( 'XMLReader' ) ) {
|
182 |
-
?>
|
183 |
-
<div class="notice astra-sites-xml-notice notice-error">
|
184 |
-
<p><b><?php _e( 'Required XMLReader PHP extension is missing on your server!', 'astra-sites' ); ?></b></p>
|
185 |
-
<?php /* translators: %s is the white label name. */ ?>
|
186 |
-
<p><?php printf( __( '%s import requires XMLReader extension to be installed. Please contact your web hosting provider and ask them to install and activate the XMLReader PHP extension.', 'astra-sites' ), ASTRA_SITES_NAME ); ?></p>
|
187 |
-
</div>
|
188 |
-
<?php
|
189 |
-
}
|
190 |
-
}
|
191 |
-
|
192 |
-
/**
|
193 |
-
* Init Nav Menu
|
194 |
-
*
|
195 |
-
* @param mixed $action Action name.
|
196 |
-
* @since 1.0.6
|
197 |
-
*/
|
198 |
-
public function init_nav_menu( $action = '' ) {
|
199 |
-
|
200 |
-
if ( '' !== $action ) {
|
201 |
-
$this->render_tab_menu( $action );
|
202 |
-
}
|
203 |
-
}
|
204 |
-
|
205 |
-
/**
|
206 |
-
* Render tab menu
|
207 |
-
*
|
208 |
-
* @param mixed $action Action name.
|
209 |
-
* @since 1.0.6
|
210 |
-
*/
|
211 |
-
public function render_tab_menu( $action = '' ) {
|
212 |
-
?>
|
213 |
-
<div id="astra-sites-menu-page">
|
214 |
-
<?php $this->render( $action ); ?>
|
215 |
-
</div>
|
216 |
-
<?php
|
217 |
-
}
|
218 |
-
|
219 |
-
/**
|
220 |
-
* View actions
|
221 |
-
*
|
222 |
-
* @since 1.0.11
|
223 |
-
*/
|
224 |
-
public function get_view_actions() {
|
225 |
-
|
226 |
-
if ( empty( $this->view_actions ) ) {
|
227 |
-
|
228 |
-
$this->view_actions = apply_filters(
|
229 |
-
'astra_sites_menu_item',
|
230 |
-
array()
|
231 |
-
);
|
232 |
-
}
|
233 |
-
|
234 |
-
return $this->view_actions;
|
235 |
-
}
|
236 |
-
|
237 |
-
/**
|
238 |
-
* Prints HTML content for tabs
|
239 |
-
*
|
240 |
-
* @param mixed $action Action name.
|
241 |
-
* @since 1.0.6
|
242 |
-
*/
|
243 |
-
public function render( $action ) {
|
244 |
-
|
245 |
-
// Settings update message.
|
246 |
-
if ( isset( $_REQUEST['message'] ) && ( 'saved' === $_REQUEST['message'] || 'saved_ext' === $_REQUEST['message'] ) ) {
|
247 |
-
?>
|
248 |
-
<span id="message" class="notice notice-success is-dismissive"><p> <?php esc_html_e( 'Settings saved successfully.', 'astra-sites' ); ?> </p></span>
|
249 |
-
<?php
|
250 |
-
}
|
251 |
-
|
252 |
-
$default_page_builder = $this->get_setting( 'page_builder' );
|
253 |
-
|
254 |
-
if ( empty( $default_page_builder ) || isset( $_GET['change-page-builder'] ) ) {
|
255 |
-
|
256 |
-
$plugins = get_option( 'active_plugins', array() );
|
257 |
-
$page_builders = array();
|
258 |
-
if ( $plugins ) {
|
259 |
-
foreach ( $plugins as $key => $plugin_init ) {
|
260 |
-
if ( false !== strpos( $plugin_init, 'elementor' ) ) {
|
261 |
-
$page_builders[] = 'elementor';
|
262 |
-
}
|
263 |
-
if ( false !== strpos( $plugin_init, 'beaver-builder' ) ) {
|
264 |
-
$page_builders[] = 'beaver-builder';
|
265 |
-
}
|
266 |
-
if ( false !== strpos( $plugin_init, 'brizy' ) ) {
|
267 |
-
$page_builders[] = 'brizy';
|
268 |
-
}
|
269 |
-
}
|
270 |
-
}
|
271 |
-
$page_builders = array_unique( $page_builders );
|
272 |
-
$page_builders[] = 'gutenberg';
|
273 |
-
$page_builders = implode( ',', $page_builders );
|
274 |
-
?>
|
275 |
-
<div class="astra-sites-welcome" data-plugins="<?php echo esc_attr( $page_builders ); ?>">
|
276 |
-
<div class="inner">
|
277 |
-
<form id="astra-sites-welcome-form" enctype="multipart/form-data" method="post">
|
278 |
-
<h1><?php _e( 'Select Page Builder', 'astra-sites' ); ?></h1>
|
279 |
-
<p><?php _e( 'Astra offers starter sites that can be imported in one click. These templates are available in few different page builders. Please choose your preferred page builder from the list below.', 'astra-sites' ); ?></p>
|
280 |
-
<div class="fields">
|
281 |
-
<ul class="page-builders">
|
282 |
-
<li>
|
283 |
-
<label>
|
284 |
-
<input type="radio" name="page_builder" value="gutenberg">
|
285 |
-
<img src="<?php echo esc_url( ASTRA_SITES_URI . 'inc/assets/images/gutenberg.jpg' ); ?>" />
|
286 |
-
<div class="title"><?php _e( 'Gutenberg', 'astra-sites' ); ?></div>
|
287 |
-
</label>
|
288 |
-
</li>
|
289 |
-
<li>
|
290 |
-
<label>
|
291 |
-
<input type="radio" name="page_builder" value="elementor">
|
292 |
-
<img src="<?php echo esc_url( ASTRA_SITES_URI . 'inc/assets/images/elementor.jpg' ); ?>" />
|
293 |
-
<div class="title"><?php _e( 'Elementor', 'astra-sites' ); ?></div>
|
294 |
-
</label>
|
295 |
-
</li>
|
296 |
-
<li>
|
297 |
-
<label>
|
298 |
-
<input type="radio" name="page_builder" value="beaver-builder">
|
299 |
-
<img src="<?php echo esc_url( ASTRA_SITES_URI . 'inc/assets/images/beaver-builder.png' ); ?>" />
|
300 |
-
<div class="title"><?php _e( 'Beaver Builder', 'astra-sites' ); ?></div>
|
301 |
-
</li>
|
302 |
-
<li>
|
303 |
-
<label>
|
304 |
-
<input type="radio" name="page_builder" value="brizy">
|
305 |
-
<img src="<?php echo esc_url( ASTRA_SITES_URI . 'inc/assets/images/brizy.jpg' ); ?>" />
|
306 |
-
<div class="title"><?php _e( 'Brizy', 'astra-sites' ); ?></div>
|
307 |
-
</label>
|
308 |
-
</li>
|
309 |
-
</ul>
|
310 |
-
<div class="astra-sites-page-builder-notice" style="display: none;">
|
311 |
-
<p class="description"><?php _e( 'Please select your favorite page builder to continue..', 'astra-sites' ); ?></p>
|
312 |
-
</div>
|
313 |
-
<?php submit_button( __( 'Next', 'astra-sites' ), 'primary button-hero disabled' ); ?>
|
314 |
-
</div>
|
315 |
-
|
316 |
-
<input type="hidden" name="message" value="saved" />
|
317 |
-
<?php wp_nonce_field( 'astra-sites-welcome-screen', 'astra-sites-page-builder' ); ?>
|
318 |
-
</form>
|
319 |
-
</div>
|
320 |
-
</div>
|
321 |
-
<?php } else { ?>
|
322 |
-
<?php
|
323 |
-
$page_title = apply_filters( 'astra_sites_page_title', __( 'Astra Starter Sites - Your Library of 100+ Ready Templates!', 'astra-sites' ) );
|
324 |
-
?>
|
325 |
-
<div class="nav-tab-wrapper">
|
326 |
-
<h1 class='astra-sites-title'> <?php echo esc_html( $page_title ); ?> </h1>
|
327 |
-
<form id="astra-sites-welcome-form-inline" enctype="multipart/form-data" method="post">
|
328 |
-
<div class="fields">
|
329 |
-
<select name="page_builder" required="required">
|
330 |
-
<option value="gutenberg" <?php selected( $default_page_builder, 'gutenberg' ); ?>><?php _e( 'Block Editor (Gutenberg)', 'astra-sites' ); ?></option>
|
331 |
-
<option value="elementor" <?php selected( $default_page_builder, 'elementor' ); ?>><?php _e( 'Elementor', 'astra-sites' ); ?></option>
|
332 |
-
<option value="beaver-builder" <?php selected( $default_page_builder, 'beaver-builder' ); ?>><?php _e( 'Beaver Builder', 'astra-sites' ); ?></option>
|
333 |
-
<option value="brizy" <?php selected( $default_page_builder, 'brizy' ); ?>><?php _e( 'Brizy', 'astra-sites' ); ?></option>
|
334 |
-
</select>
|
335 |
-
</div>
|
336 |
-
<input type="hidden" name="message" value="saved" />
|
337 |
-
<?php wp_nonce_field( 'astra-sites-welcome-screen', 'astra-sites-page-builder' ); ?>
|
338 |
-
</form>
|
339 |
-
<?php
|
340 |
-
$view_actions = $this->get_view_actions();
|
341 |
-
|
342 |
-
foreach ( $view_actions as $slug => $data ) {
|
343 |
-
|
344 |
-
if ( ! $data['show'] ) {
|
345 |
-
continue;
|
346 |
-
}
|
347 |
-
|
348 |
-
$url = $this->get_page_url( $slug );
|
349 |
-
|
350 |
-
if ( 'general' === $slug ) {
|
351 |
-
update_option( 'astra_parent_page_url', $url );
|
352 |
-
}
|
353 |
-
|
354 |
-
$active = ( $slug === $action ) ? 'nav-tab-active' : '';
|
355 |
-
?>
|
356 |
-
<a class='nav-tab <?php echo esc_attr( $active ); ?>' href='<?php echo esc_url( $url ); ?>'> <?php echo esc_html( $data['label'] ); ?> </a>
|
357 |
-
<?php } ?>
|
358 |
-
</div><!-- .nav-tab-wrapper -->
|
359 |
-
<?php
|
360 |
-
}
|
361 |
-
}
|
362 |
-
|
363 |
-
/**
|
364 |
-
* Get and return page URL
|
365 |
-
*
|
366 |
-
* @param string $menu_slug Menu name.
|
367 |
-
* @since 1.0.6
|
368 |
-
* @return string page url
|
369 |
-
*/
|
370 |
-
public function get_page_url( $menu_slug ) {
|
371 |
-
|
372 |
-
$parent_page = 'themes.php';
|
373 |
-
|
374 |
-
if ( strpos( $parent_page, '?' ) !== false ) {
|
375 |
-
$query_var = '&page=astra-sites';
|
376 |
-
} else {
|
377 |
-
$query_var = '?page=astra-sites';
|
378 |
-
}
|
379 |
-
|
380 |
-
$parent_page_url = admin_url( $parent_page . $query_var );
|
381 |
-
|
382 |
-
$url = $parent_page_url . '&action=' . $menu_slug;
|
383 |
-
|
384 |
-
return esc_url( $url );
|
385 |
-
}
|
386 |
-
|
387 |
-
/**
|
388 |
-
* Add main menu
|
389 |
-
*
|
390 |
-
* @since 1.0.6
|
391 |
-
*/
|
392 |
-
public function add_admin_menu() {
|
393 |
-
$page_title = apply_filters( 'astra_sites_menu_page_title', __( 'Astra Starter Sites', 'astra-sites' ) );
|
394 |
-
|
395 |
-
$page = add_theme_page( $page_title, $page_title, 'manage_options', 'astra-sites', array( $this, 'menu_callback' ) );
|
396 |
-
}
|
397 |
-
|
398 |
-
/**
|
399 |
-
* Menu callback
|
400 |
-
*
|
401 |
-
* @since 1.0.6
|
402 |
-
*/
|
403 |
-
public function menu_callback() {
|
404 |
-
|
405 |
-
$current_slug = isset( $_GET['action'] ) ? esc_attr( $_GET['action'] ) : 'general';
|
406 |
-
|
407 |
-
$active_tab = str_replace( '_', '-', $current_slug );
|
408 |
-
$current_slug = str_replace( '-', '_', $current_slug );
|
409 |
-
|
410 |
-
?>
|
411 |
-
<div class="astra-sites-menu-page-wrapper">
|
412 |
-
<?php $this->init_nav_menu( $active_tab ); ?>
|
413 |
-
<?php do_action( 'astra_sites_menu_' . esc_attr( $current_slug ) . '_action' ); ?>
|
414 |
-
</div>
|
415 |
-
<?php
|
416 |
-
}
|
417 |
-
|
418 |
-
/**
|
419 |
-
* Include general page
|
420 |
-
*
|
421 |
-
* @since 1.0.6
|
422 |
-
*/
|
423 |
-
public function general_page() {
|
424 |
-
$default_page_builder = $this->get_setting( 'page_builder' );
|
425 |
-
if ( empty( $default_page_builder ) || isset( $_GET['change-page-builder'] ) ) {
|
426 |
-
return;
|
427 |
-
}
|
428 |
-
require_once ASTRA_SITES_DIR . 'inc/includes/admin-page.php';
|
429 |
-
}
|
430 |
-
}
|
431 |
-
|
432 |
-
Astra_Sites_Page::get_instance();
|
433 |
-
|
434 |
-
}// End if.
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Astra Sites Page
|
4 |
+
*
|
5 |
+
* @since 1.0.6
|
6 |
+
* @package Astra Sites
|
7 |
+
*/
|
8 |
+
|
9 |
+
if ( ! defined( 'ABSPATH' ) ) {
|
10 |
+
exit;
|
11 |
+
}
|
12 |
+
|
13 |
+
if ( ! class_exists( 'Astra_Sites_Page' ) ) {
|
14 |
+
|
15 |
+
/**
|
16 |
+
* Astra Admin Settings
|
17 |
+
*/
|
18 |
+
class Astra_Sites_Page {
|
19 |
+
|
20 |
+
/**
|
21 |
+
* View all actions
|
22 |
+
*
|
23 |
+
* @since 1.0.6
|
24 |
+
* @var array $view_actions
|
25 |
+
*/
|
26 |
+
public $view_actions = array();
|
27 |
+
|
28 |
+
/**
|
29 |
+
* Member Variable
|
30 |
+
*
|
31 |
+
* @var instance
|
32 |
+
*/
|
33 |
+
private static $instance;
|
34 |
+
|
35 |
+
/**
|
36 |
+
* Initiator
|
37 |
+
*
|
38 |
+
* @since 1.3.0
|
39 |
+
*/
|
40 |
+
public static function get_instance() {
|
41 |
+
if ( ! isset( self::$instance ) ) {
|
42 |
+
self::$instance = new self;
|
43 |
+
}
|
44 |
+
return self::$instance;
|
45 |
+
}
|
46 |
+
|
47 |
+
/**
|
48 |
+
* Constructor
|
49 |
+
*
|
50 |
+
* @since 1.3.0
|
51 |
+
*/
|
52 |
+
public function __construct() {
|
53 |
+
|
54 |
+
if ( ! is_admin() ) {
|
55 |
+
return;
|
56 |
+
}
|
57 |
+
|
58 |
+
add_action( 'after_setup_theme', array( $this, 'init_admin_settings' ), 99 );
|
59 |
+
add_action( 'admin_init', array( $this, 'save_page_builder' ) );
|
60 |
+
add_action( 'admin_notices', array( $this, 'getting_started' ) );
|
61 |
+
}
|
62 |
+
|
63 |
+
/**
|
64 |
+
* Admin notice
|
65 |
+
*
|
66 |
+
* @since 1.3.5
|
67 |
+
*
|
68 |
+
* @return void
|
69 |
+
*/
|
70 |
+
function getting_started() {
|
71 |
+
if ( 'plugins' !== get_current_screen()->base ) {
|
72 |
+
return;
|
73 |
+
}
|
74 |
+
|
75 |
+
$processed = get_user_meta( get_current_user_id(), '_astra_sites_gettings_started', true );
|
76 |
+
$product_name = Astra_Sites_White_Label::get_instance()->page_title( 'Astra' );
|
77 |
+
|
78 |
+
if ( $processed ) {
|
79 |
+
return;
|
80 |
+
}
|
81 |
+
|
82 |
+
?>
|
83 |
+
<div class="notice notice-info is-dismissible astra-sites-getting-started-notice">
|
84 |
+
<?php /* translators: %1$s is the admin page URL, %2$s is product name. */ ?>
|
85 |
+
<p><?php printf( __( 'Thank you for choosing %1$s! Check the library of <a class="astra-sites-getting-started-btn" href="%2$s">ready starter sites here »</a>', 'astra-sites' ), $product_name, admin_url( 'themes.php?page=astra-sites' ) ); ?></p>
|
86 |
+
</div>
|
87 |
+
<?php
|
88 |
+
}
|
89 |
+
|
90 |
+
/**
|
91 |
+
* Save Page Builder
|
92 |
+
*
|
93 |
+
* @return void
|
94 |
+
*/
|
95 |
+
function save_page_builder() {
|
96 |
+
|
97 |
+
// Only admins can save settings.
|
98 |
+
if ( ! current_user_can( 'manage_options' ) ) {
|
99 |
+
return;
|
100 |
+
}
|
101 |
+
|
102 |
+
// Make sure we have a valid nonce.
|
103 |
+
if ( isset( $_REQUEST['astra-sites-page-builder'] ) && wp_verify_nonce( $_REQUEST['astra-sites-page-builder'], 'astra-sites-welcome-screen' ) ) {
|
104 |
+
|
105 |
+
// Stored Settings.
|
106 |
+
$stored_data = $this->get_settings();
|
107 |
+
|
108 |
+
// New settings.
|
109 |
+
$new_data = array(
|
110 |
+
'page_builder' => ( isset( $_REQUEST['page_builder'] ) ) ? sanitize_key( $_REQUEST['page_builder'] ) : '',
|
111 |
+
);
|
112 |
+
|
113 |
+
// Merge settings.
|
114 |
+
$data = wp_parse_args( $new_data, $stored_data );
|
115 |
+
|
116 |
+
// Update settings.
|
117 |
+
update_option( 'astra_sites_settings', $data );
|
118 |
+
|
119 |
+
wp_redirect( admin_url( '/themes.php?page=astra-sites' ) );
|
120 |
+
}
|
121 |
+
}
|
122 |
+
|
123 |
+
/**
|
124 |
+
* Get single setting value
|
125 |
+
*
|
126 |
+
* @param string $key Setting key.
|
127 |
+
* @param mixed $defaults Setting value.
|
128 |
+
* @return mixed Stored setting value.
|
129 |
+
*/
|
130 |
+
function get_setting( $key = '', $defaults = '' ) {
|
131 |
+
|
132 |
+
$settings = $this->get_settings();
|
133 |
+
|
134 |
+
if ( empty( $settings ) ) {
|
135 |
+
return $defaults;
|
136 |
+
}
|
137 |
+
|
138 |
+
if ( array_key_exists( $key, $settings ) ) {
|
139 |
+
return $settings[ $key ];
|
140 |
+
}
|
141 |
+
|
142 |
+
return $defaults;
|
143 |
+
}
|
144 |
+
|
145 |
+
/**
|
146 |
+
* Get Settings
|
147 |
+
*
|
148 |
+
* @return array Stored settings.
|
149 |
+
*/
|
150 |
+
function get_settings() {
|
151 |
+
|
152 |
+
$defaults = array(
|
153 |
+
'page_builder' => '',
|
154 |
+
);
|
155 |
+
|
156 |
+
$stored_data = get_option( 'astra_sites_settings', $defaults );
|
157 |
+
|
158 |
+
return wp_parse_args( $stored_data, $defaults );
|
159 |
+
}
|
160 |
+
|
161 |
+
/**
|
162 |
+
* Admin settings init
|
163 |
+
*/
|
164 |
+
public function init_admin_settings() {
|
165 |
+
add_action( 'admin_menu', array( $this, 'add_admin_menu' ), 100 );
|
166 |
+
add_action( 'admin_notices', array( $this, 'notices' ) );
|
167 |
+
add_action( 'astra_sites_menu_general_action', array( $this, 'general_page' ) );
|
168 |
+
}
|
169 |
+
|
170 |
+
/**
|
171 |
+
* Admin notice
|
172 |
+
*
|
173 |
+
* @since 1.2.8
|
174 |
+
*/
|
175 |
+
public function notices() {
|
176 |
+
|
177 |
+
if ( 'appearance_page_astra-sites' !== get_current_screen()->id ) {
|
178 |
+
return;
|
179 |
+
}
|
180 |
+
|
181 |
+
if ( ! class_exists( 'XMLReader' ) ) {
|
182 |
+
?>
|
183 |
+
<div class="notice astra-sites-xml-notice notice-error">
|
184 |
+
<p><b><?php _e( 'Required XMLReader PHP extension is missing on your server!', 'astra-sites' ); ?></b></p>
|
185 |
+
<?php /* translators: %s is the white label name. */ ?>
|
186 |
+
<p><?php printf( __( '%s import requires XMLReader extension to be installed. Please contact your web hosting provider and ask them to install and activate the XMLReader PHP extension.', 'astra-sites' ), ASTRA_SITES_NAME ); ?></p>
|
187 |
+
</div>
|
188 |
+
<?php
|
189 |
+
}
|
190 |
+
}
|
191 |
+
|
192 |
+
/**
|
193 |
+
* Init Nav Menu
|
194 |
+
*
|
195 |
+
* @param mixed $action Action name.
|
196 |
+
* @since 1.0.6
|
197 |
+
*/
|
198 |
+
public function init_nav_menu( $action = '' ) {
|
199 |
+
|
200 |
+
if ( '' !== $action ) {
|
201 |
+
$this->render_tab_menu( $action );
|
202 |
+
}
|
203 |
+
}
|
204 |
+
|
205 |
+
/**
|
206 |
+
* Render tab menu
|
207 |
+
*
|
208 |
+
* @param mixed $action Action name.
|
209 |
+
* @since 1.0.6
|
210 |
+
*/
|
211 |
+
public function render_tab_menu( $action = '' ) {
|
212 |
+
?>
|
213 |
+
<div id="astra-sites-menu-page">
|
214 |
+
<?php $this->render( $action ); ?>
|
215 |
+
</div>
|
216 |
+
<?php
|
217 |
+
}
|
218 |
+
|
219 |
+
/**
|
220 |
+
* View actions
|
221 |
+
*
|
222 |
+
* @since 1.0.11
|
223 |
+
*/
|
224 |
+
public function get_view_actions() {
|
225 |
+
|
226 |
+
if ( empty( $this->view_actions ) ) {
|
227 |
+
|
228 |
+
$this->view_actions = apply_filters(
|
229 |
+
'astra_sites_menu_item',
|
230 |
+
array()
|
231 |
+
);
|
232 |
+
}
|
233 |
+
|
234 |
+
return $this->view_actions;
|
235 |
+
}
|
236 |
+
|
237 |
+
/**
|
238 |
+
* Prints HTML content for tabs
|
239 |
+
*
|
240 |
+
* @param mixed $action Action name.
|
241 |
+
* @since 1.0.6
|
242 |
+
*/
|
243 |
+
public function render( $action ) {
|
244 |
+
|
245 |
+
// Settings update message.
|
246 |
+
if ( isset( $_REQUEST['message'] ) && ( 'saved' === $_REQUEST['message'] || 'saved_ext' === $_REQUEST['message'] ) ) {
|
247 |
+
?>
|
248 |
+
<span id="message" class="notice notice-success is-dismissive"><p> <?php esc_html_e( 'Settings saved successfully.', 'astra-sites' ); ?> </p></span>
|
249 |
+
<?php
|
250 |
+
}
|
251 |
+
|
252 |
+
$default_page_builder = $this->get_setting( 'page_builder' );
|
253 |
+
|
254 |
+
if ( empty( $default_page_builder ) || isset( $_GET['change-page-builder'] ) ) {
|
255 |
+
|
256 |
+
$plugins = get_option( 'active_plugins', array() );
|
257 |
+
$page_builders = array();
|
258 |
+
if ( $plugins ) {
|
259 |
+
foreach ( $plugins as $key => $plugin_init ) {
|
260 |
+
if ( false !== strpos( $plugin_init, 'elementor' ) ) {
|
261 |
+
$page_builders[] = 'elementor';
|
262 |
+
}
|
263 |
+
if ( false !== strpos( $plugin_init, 'beaver-builder' ) ) {
|
264 |
+
$page_builders[] = 'beaver-builder';
|
265 |
+
}
|
266 |
+
if ( false !== strpos( $plugin_init, 'brizy' ) ) {
|
267 |
+
$page_builders[] = 'brizy';
|
268 |
+
}
|
269 |
+
}
|
270 |
+
}
|
271 |
+
$page_builders = array_unique( $page_builders );
|
272 |
+
$page_builders[] = 'gutenberg';
|
273 |
+
$page_builders = implode( ',', $page_builders );
|
274 |
+
?>
|
275 |
+
<div class="astra-sites-welcome" data-plugins="<?php echo esc_attr( $page_builders ); ?>">
|
276 |
+
<div class="inner">
|
277 |
+
<form id="astra-sites-welcome-form" enctype="multipart/form-data" method="post">
|
278 |
+
<h1><?php _e( 'Select Page Builder', 'astra-sites' ); ?></h1>
|
279 |
+
<p><?php _e( 'Astra offers starter sites that can be imported in one click. These templates are available in few different page builders. Please choose your preferred page builder from the list below.', 'astra-sites' ); ?></p>
|
280 |
+
<div class="fields">
|
281 |
+
<ul class="page-builders">
|
282 |
+
<li>
|
283 |
+
<label>
|
284 |
+
<input type="radio" name="page_builder" value="gutenberg">
|
285 |
+
<img src="<?php echo esc_url( ASTRA_SITES_URI . 'inc/assets/images/gutenberg.jpg' ); ?>" />
|
286 |
+
<div class="title"><?php _e( 'Gutenberg', 'astra-sites' ); ?></div>
|
287 |
+
</label>
|
288 |
+
</li>
|
289 |
+
<li>
|
290 |
+
<label>
|
291 |
+
<input type="radio" name="page_builder" value="elementor">
|
292 |
+
<img src="<?php echo esc_url( ASTRA_SITES_URI . 'inc/assets/images/elementor.jpg' ); ?>" />
|
293 |
+
<div class="title"><?php _e( 'Elementor', 'astra-sites' ); ?></div>
|
294 |
+
</label>
|
295 |
+
</li>
|
296 |
+
<li>
|
297 |
+
<label>
|
298 |
+
<input type="radio" name="page_builder" value="beaver-builder">
|
299 |
+
<img src="<?php echo esc_url( ASTRA_SITES_URI . 'inc/assets/images/beaver-builder.png' ); ?>" />
|
300 |
+
<div class="title"><?php _e( 'Beaver Builder', 'astra-sites' ); ?></div>
|
301 |
+
</li>
|
302 |
+
<li>
|
303 |
+
<label>
|
304 |
+
<input type="radio" name="page_builder" value="brizy">
|
305 |
+
<img src="<?php echo esc_url( ASTRA_SITES_URI . 'inc/assets/images/brizy.jpg' ); ?>" />
|
306 |
+
<div class="title"><?php _e( 'Brizy', 'astra-sites' ); ?></div>
|
307 |
+
</label>
|
308 |
+
</li>
|
309 |
+
</ul>
|
310 |
+
<div class="astra-sites-page-builder-notice" style="display: none;">
|
311 |
+
<p class="description"><?php _e( 'Please select your favorite page builder to continue..', 'astra-sites' ); ?></p>
|
312 |
+
</div>
|
313 |
+
<?php submit_button( __( 'Next', 'astra-sites' ), 'primary button-hero disabled' ); ?>
|
314 |
+
</div>
|
315 |
+
|
316 |
+
<input type="hidden" name="message" value="saved" />
|
317 |
+
<?php wp_nonce_field( 'astra-sites-welcome-screen', 'astra-sites-page-builder' ); ?>
|
318 |
+
</form>
|
319 |
+
</div>
|
320 |
+
</div>
|
321 |
+
<?php } else { ?>
|
322 |
+
<?php
|
323 |
+
$page_title = apply_filters( 'astra_sites_page_title', __( 'Astra Starter Sites - Your Library of 100+ Ready Templates!', 'astra-sites' ) );
|
324 |
+
?>
|
325 |
+
<div class="nav-tab-wrapper">
|
326 |
+
<h1 class='astra-sites-title'> <?php echo esc_html( $page_title ); ?> </h1>
|
327 |
+
<form id="astra-sites-welcome-form-inline" enctype="multipart/form-data" method="post">
|
328 |
+
<div class="fields">
|
329 |
+
<select name="page_builder" required="required">
|
330 |
+
<option value="gutenberg" <?php selected( $default_page_builder, 'gutenberg' ); ?>><?php _e( 'Block Editor (Gutenberg)', 'astra-sites' ); ?></option>
|
331 |
+
<option value="elementor" <?php selected( $default_page_builder, 'elementor' ); ?>><?php _e( 'Elementor', 'astra-sites' ); ?></option>
|
332 |
+
<option value="beaver-builder" <?php selected( $default_page_builder, 'beaver-builder' ); ?>><?php _e( 'Beaver Builder', 'astra-sites' ); ?></option>
|
333 |
+
<option value="brizy" <?php selected( $default_page_builder, 'brizy' ); ?>><?php _e( 'Brizy', 'astra-sites' ); ?></option>
|
334 |
+
</select>
|
335 |
+
</div>
|
336 |
+
<input type="hidden" name="message" value="saved" />
|
337 |
+
<?php wp_nonce_field( 'astra-sites-welcome-screen', 'astra-sites-page-builder' ); ?>
|
338 |
+
</form>
|
339 |
+
<?php
|
340 |
+
$view_actions = $this->get_view_actions();
|
341 |
+
|
342 |
+
foreach ( $view_actions as $slug => $data ) {
|
343 |
+
|
344 |
+
if ( ! $data['show'] ) {
|
345 |
+
continue;
|
346 |
+
}
|
347 |
+
|
348 |
+
$url = $this->get_page_url( $slug );
|
349 |
+
|
350 |
+
if ( 'general' === $slug ) {
|
351 |
+
update_option( 'astra_parent_page_url', $url );
|
352 |
+
}
|
353 |
+
|
354 |
+
$active = ( $slug === $action ) ? 'nav-tab-active' : '';
|
355 |
+
?>
|
356 |
+
<a class='nav-tab <?php echo esc_attr( $active ); ?>' href='<?php echo esc_url( $url ); ?>'> <?php echo esc_html( $data['label'] ); ?> </a>
|
357 |
+
<?php } ?>
|
358 |
+
</div><!-- .nav-tab-wrapper -->
|
359 |
+
<?php
|
360 |
+
}
|
361 |
+
}
|
362 |
+
|
363 |
+
/**
|
364 |
+
* Get and return page URL
|
365 |
+
*
|
366 |
+
* @param string $menu_slug Menu name.
|
367 |
+
* @since 1.0.6
|
368 |
+
* @return string page url
|
369 |
+
*/
|
370 |
+
public function get_page_url( $menu_slug ) {
|
371 |
+
|
372 |
+
$parent_page = 'themes.php';
|
373 |
+
|
374 |
+
if ( strpos( $parent_page, '?' ) !== false ) {
|
375 |
+
$query_var = '&page=astra-sites';
|
376 |
+
} else {
|
377 |
+
$query_var = '?page=astra-sites';
|
378 |
+
}
|
379 |
+
|
380 |
+
$parent_page_url = admin_url( $parent_page . $query_var );
|
381 |
+
|
382 |
+
$url = $parent_page_url . '&action=' . $menu_slug;
|
383 |
+
|
384 |
+
return esc_url( $url );
|
385 |
+
}
|
386 |
+
|
387 |
+
/**
|
388 |
+
* Add main menu
|
389 |
+
*
|
390 |
+
* @since 1.0.6
|
391 |
+
*/
|
392 |
+
public function add_admin_menu() {
|
393 |
+
$page_title = apply_filters( 'astra_sites_menu_page_title', __( 'Astra Starter Sites', 'astra-sites' ) );
|
394 |
+
|
395 |
+
$page = add_theme_page( $page_title, $page_title, 'manage_options', 'astra-sites', array( $this, 'menu_callback' ) );
|
396 |
+
}
|
397 |
+
|
398 |
+
/**
|
399 |
+
* Menu callback
|
400 |
+
*
|
401 |
+
* @since 1.0.6
|
402 |
+
*/
|
403 |
+
public function menu_callback() {
|
404 |
+
|
405 |
+
$current_slug = isset( $_GET['action'] ) ? esc_attr( $_GET['action'] ) : 'general';
|
406 |
+
|
407 |
+
$active_tab = str_replace( '_', '-', $current_slug );
|
408 |
+
$current_slug = str_replace( '-', '_', $current_slug );
|
409 |
+
|
410 |
+
?>
|
411 |
+
<div class="astra-sites-menu-page-wrapper">
|
412 |
+
<?php $this->init_nav_menu( $active_tab ); ?>
|
413 |
+
<?php do_action( 'astra_sites_menu_' . esc_attr( $current_slug ) . '_action' ); ?>
|
414 |
+
</div>
|
415 |
+
<?php
|
416 |
+
}
|
417 |
+
|
418 |
+
/**
|
419 |
+
* Include general page
|
420 |
+
*
|
421 |
+
* @since 1.0.6
|
422 |
+
*/
|
423 |
+
public function general_page() {
|
424 |
+
$default_page_builder = $this->get_setting( 'page_builder' );
|
425 |
+
if ( empty( $default_page_builder ) || isset( $_GET['change-page-builder'] ) ) {
|
426 |
+
return;
|
427 |
+
}
|
428 |
+
require_once ASTRA_SITES_DIR . 'inc/includes/admin-page.php';
|
429 |
+
}
|
430 |
+
}
|
431 |
+
|
432 |
+
Astra_Sites_Page::get_instance();
|
433 |
+
|
434 |
+
}// End if.
|
inc/classes/class-astra-sites.php
CHANGED
@@ -1,600 +1,600 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* Astra Sites
|
4 |
-
*
|
5 |
-
* @since 1.0.0
|
6 |
-
* @package Astra Sites
|
7 |
-
*/
|
8 |
-
|
9 |
-
defined( 'ABSPATH' ) or exit;
|
10 |
-
|
11 |
-
if ( ! class_exists( 'Astra_Sites' ) ) :
|
12 |
-
|
13 |
-
/**
|
14 |
-
* Astra_Sites
|
15 |
-
*/
|
16 |
-
class Astra_Sites {
|
17 |
-
|
18 |
-
/**
|
19 |
-
* API URL which is used to get the response from.
|
20 |
-
*
|
21 |
-
* @since 1.0.0
|
22 |
-
* @var (String) URL
|
23 |
-
*/
|
24 |
-
public static $api_url;
|
25 |
-
|
26 |
-
/**
|
27 |
-
* Instance of Astra_Sites
|
28 |
-
*
|
29 |
-
* @since 1.0.0
|
30 |
-
* @var (Object) Astra_Sites
|
31 |
-
*/
|
32 |
-
private static $_instance = null;
|
33 |
-
|
34 |
-
/**
|
35 |
-
* Instance of Astra_Sites.
|
36 |
-
*
|
37 |
-
* @since 1.0.0
|
38 |
-
*
|
39 |
-
* @return object Class object.
|
40 |
-
*/
|
41 |
-
public static function get_instance() {
|
42 |
-
if ( ! isset( self::$_instance ) ) {
|
43 |
-
self::$_instance = new self;
|
44 |
-
}
|
45 |
-
|
46 |
-
return self::$_instance;
|
47 |
-
}
|
48 |
-
|
49 |
-
/**
|
50 |
-
* Constructor.
|
51 |
-
*
|
52 |
-
* @since 1.0.0
|
53 |
-
*/
|
54 |
-
private function __construct() {
|
55 |
-
|
56 |
-
self::set_api_url();
|
57 |
-
|
58 |
-
$this->includes();
|
59 |
-
|
60 |
-
add_action( 'admin_notices', array( $this, 'add_notice' ), 1 );
|
61 |
-
add_action( 'admin_notices', array( $this, 'admin_notices' ) );
|
62 |
-
add_action( 'plugins_loaded', array( $this, 'load_textdomain' ) );
|
63 |
-
add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue' ) );
|
64 |
-
|
65 |
-
// AJAX.
|
66 |
-
add_action( 'wp_ajax_astra-required-plugins', array( $this, 'required_plugin' ) );
|
67 |
-
add_action( 'wp_ajax_astra-required-plugin-activate', array( $this, 'required_plugin_activate' ) );
|
68 |
-
add_action( 'wp_ajax_astra-sites-backup-settings', array( $this, 'backup_settings' ) );
|
69 |
-
add_action( 'wp_ajax_astra-sites-set-reset-data', array( $this, 'set_reset_data' ) );
|
70 |
-
add_action( 'wp_ajax_astra-sites-activate-theme', array( $this, 'activate_theme' ) );
|
71 |
-
add_action( 'wp_ajax_astra-sites-getting-started-notice', array( $this, 'getting_started_notice' ) );
|
72 |
-
}
|
73 |
-
|
74 |
-
/**
|
75 |
-
* Close getting started notice for current user
|
76 |
-
*
|
77 |
-
* @since 1.3.5
|
78 |
-
* @return void
|
79 |
-
*/
|
80 |
-
function getting_started_notice() {
|
81 |
-
update_user_meta( get_current_user_id(), '_astra_sites_gettings_started', true );
|
82 |
-
wp_send_json_success();
|
83 |
-
}
|
84 |
-
|
85 |
-
/**
|
86 |
-
* Activate theme
|
87 |
-
*
|
88 |
-
* @since 1.3.2
|
89 |
-
* @return void
|
90 |
-
*/
|
91 |
-
function activate_theme() {
|
92 |
-
|
93 |
-
switch_theme( 'astra' );
|
94 |
-
|
95 |
-
wp_send_json_success(
|
96 |
-
array(
|
97 |
-
'success' => true,
|
98 |
-
'message' => __( 'Theme Activated', 'astra-sites' ),
|
99 |
-
)
|
100 |
-
);
|
101 |
-
}
|
102 |
-
|
103 |
-
/**
|
104 |
-
* Set reset data
|
105 |
-
*/
|
106 |
-
function set_reset_data() {
|
107 |
-
if ( ! current_user_can( 'manage_options' ) ) {
|
108 |
-
return;
|
109 |
-
}
|
110 |
-
|
111 |
-
global $wpdb;
|
112 |
-
|
113 |
-
$post_ids = $wpdb->get_col( "SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key='_astra_sites_imported_post'" );
|
114 |
-
$form_ids = $wpdb->get_col( "SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key='_astra_sites_imported_wp_forms'" );
|
115 |
-
$term_ids = $wpdb->get_col( "SELECT term_id FROM {$wpdb->termmeta} WHERE meta_key='_astra_sites_imported_term'" );
|
116 |
-
|
117 |
-
wp_send_json_success(
|
118 |
-
array(
|
119 |
-
'reset_posts' => $post_ids,
|
120 |
-
'reset_wp_forms' => $form_ids,
|
121 |
-
'reset_terms' => $term_ids,
|
122 |
-
)
|
123 |
-
);
|
124 |
-
}
|
125 |
-
|
126 |
-
/**
|
127 |
-
* Backup our existing settings.
|
128 |
-
*/
|
129 |
-
function backup_settings() {
|
130 |
-
if ( ! current_user_can( 'manage_options' ) ) {
|
131 |
-
return;
|
132 |
-
}
|
133 |
-
|
134 |
-
$file_name = 'astra-sites-backup-' . date( 'd-M-Y-h-i-s' ) . '.json';
|
135 |
-
$old_settings = get_option( 'astra-settings', array() );
|
136 |
-
$upload_dir = Astra_Sites_Importer_Log::get_instance()->log_dir();
|
137 |
-
$upload_path = trailingslashit( $upload_dir['path'] );
|
138 |
-
$log_file = $upload_path . $file_name;
|
139 |
-
$file_system = Astra_Sites_Importer_Log::get_instance()->get_filesystem();
|
140 |
-
|
141 |
-
// If file system fails? Then take a backup in site option.
|
142 |
-
if ( false === $file_system->put_contents( $log_file, json_encode( $old_settings ), FS_CHMOD_FILE ) ) {
|
143 |
-
update_option( 'astra_sites_' . $file_name, $old_settings );
|
144 |
-
}
|
145 |
-
|
146 |
-
wp_send_json_success();
|
147 |
-
}
|
148 |
-
|
149 |
-
/**
|
150 |
-
* Add Admin Notice.
|
151 |
-
*/
|
152 |
-
function add_notice() {
|
153 |
-
|
154 |
-
$theme_status = 'astra-sites-theme-' . $this->get_theme_status();
|
155 |
-
|
156 |
-
Astra_Notices::add_notice(
|
157 |
-
array(
|
158 |
-
'id' => 'astra-theme-activation-nag',
|
159 |
-
'type' => 'error',
|
160 |
-
'show_if' => ( ! defined( 'ASTRA_THEME_SETTINGS' ) ) ? true : false,
|
161 |
-
/* translators: 1: theme.php file*/
|
162 |
-
'message' => sprintf( __( '<p>Astra Theme needs to be active for you to use currently installed "%1$s" plugin. <a href="#" class="%3$s" data-theme-slug="astra">Install & Activate Now</a></p>', 'astra-sites' ), ASTRA_SITES_NAME, esc_url( admin_url( 'themes.php?theme=astra' ) ), $theme_status ),
|
163 |
-
'dismissible' => true,
|
164 |
-
'dismissible-time' => WEEK_IN_SECONDS,
|
165 |
-
)
|
166 |
-
);
|
167 |
-
}
|
168 |
-
|
169 |
-
/**
|
170 |
-
* Get theme install, active or inactive status.
|
171 |
-
*
|
172 |
-
* @since 1.3.2
|
173 |
-
*
|
174 |
-
* @return string Theme status
|
175 |
-
*/
|
176 |
-
function get_theme_status() {
|
177 |
-
|
178 |
-
$theme = wp_get_theme();
|
179 |
-
|
180 |
-
// Theme installed and activate.
|
181 |
-
if ( 'Astra' === $theme->name || 'Astra' === $theme->parent_theme ) {
|
182 |
-
return 'installed-and-active';
|
183 |
-
}
|
184 |
-
|
185 |
-
// Theme installed but not activate.
|
186 |
-
foreach ( (array) wp_get_themes() as $theme_dir => $theme ) {
|
187 |
-
if ( 'Astra' === $theme->name || 'Astra' === $theme->parent_theme ) {
|
188 |
-
return 'installed-but-inactive';
|
189 |
-
}
|
190 |
-
}
|
191 |
-
|
192 |
-
return 'not-installed';
|
193 |
-
}
|
194 |
-
|
195 |
-
/**
|
196 |
-
* Loads textdomain for the plugin.
|
197 |
-
*
|
198 |
-
* @since 1.0.1
|
199 |
-
*/
|
200 |
-
function load_textdomain() {
|
201 |
-
load_plugin_textdomain( 'astra-sites' );
|
202 |
-
}
|
203 |
-
|
204 |
-
/**
|
205 |
-
* Admin Notices
|
206 |
-
*
|
207 |
-
* @since 1.0.5
|
208 |
-
* @return void
|
209 |
-
*/
|
210 |
-
function admin_notices() {
|
211 |
-
|
212 |
-
if ( ! defined( 'ASTRA_THEME_SETTINGS' ) ) {
|
213 |
-
return;
|
214 |
-
}
|
215 |
-
|
216 |
-
add_action( 'plugin_action_links_' . ASTRA_SITES_BASE, array( $this, 'action_links' ) );
|
217 |
-
}
|
218 |
-
|
219 |
-
/**
|
220 |
-
* Show action links on the plugin screen.
|
221 |
-
*
|
222 |
-
* @param mixed $links Plugin Action links.
|
223 |
-
* @return array
|
224 |
-
*/
|
225 |
-
function action_links( $links ) {
|
226 |
-
$action_links = array(
|
227 |
-
'settings' => '<a href="' . admin_url( 'themes.php?page=astra-sites' ) . '" aria-label="' . esc_attr__( 'See Library', 'astra-sites' ) . '">' . esc_html__( 'See Library', 'astra-sites' ) . '</a>',
|
228 |
-
);
|
229 |
-
|
230 |
-
return array_merge( $action_links, $links );
|
231 |
-
}
|
232 |
-
|
233 |
-
/**
|
234 |
-
* Setter for $api_url
|
235 |
-
*
|
236 |
-
* @since 1.0.0
|
237 |
-
*/
|
238 |
-
public static function set_api_url() {
|
239 |
-
self::$api_url = apply_filters( 'astra_sites_api_url', 'https://websitedemos.net/wp-json/wp/v2/' );
|
240 |
-
|
241 |
-
}
|
242 |
-
|
243 |
-
/**
|
244 |
-
* Enqueue admin scripts.
|
245 |
-
*
|
246 |
-
* @since 1.3.2 Added 'install-theme.js' to install and activate theme.
|
247 |
-
* @since 1.0.5 Added 'getUpgradeText' and 'getUpgradeURL' localize variables.
|
248 |
-
*
|
249 |
-
* @since 1.0.0
|
250 |
-
*
|
251 |
-
* @param string $hook Current hook name.
|
252 |
-
* @return void
|
253 |
-
*/
|
254 |
-
public function admin_enqueue( $hook = '' ) {
|
255 |
-
|
256 |
-
wp_enqueue_script( 'astra-sites-install-theme', ASTRA_SITES_URI . 'inc/assets/js/install-theme.js', array( 'jquery', 'updates' ), ASTRA_SITES_VER, true );
|
257 |
-
wp_enqueue_style( 'astra-sites-install-theme', ASTRA_SITES_URI . 'inc/assets/css/install-theme.css', null, ASTRA_SITES_VER, 'all' );
|
258 |
-
|
259 |
-
$data = apply_filters(
|
260 |
-
'astra_sites_install_theme_localize_vars',
|
261 |
-
array(
|
262 |
-
'installed' => __( 'Installed! Activating..', 'astra-sites' ),
|
263 |
-
'activating' => __( 'Activating..', 'astra-sites' ),
|
264 |
-
'activated' => __( 'Activated! Reloading..', 'astra-sites' ),
|
265 |
-
'installing' => __( 'Installing..', 'astra-sites' ),
|
266 |
-
'ajaxurl' => esc_url( admin_url( 'admin-ajax.php' ) ),
|
267 |
-
)
|
268 |
-
);
|
269 |
-
wp_localize_script( 'astra-sites-install-theme', 'AstraSitesInstallThemeVars', $data );
|
270 |
-
|
271 |
-
if ( 'appearance_page_astra-sites' !== $hook ) {
|
272 |
-
return;
|
273 |
-
}
|
274 |
-
|
275 |
-
global $is_IE, $is_edge;
|
276 |
-
|
277 |
-
if ( $is_IE || $is_edge ) {
|
278 |
-
wp_enqueue_script( 'astra-sites-eventsource', ASTRA_SITES_URI . 'inc/assets/js/eventsource.min.js', array( 'jquery', 'wp-util', 'updates' ), ASTRA_SITES_VER, true );
|
279 |
-
}
|
280 |
-
|
281 |
-
// Fetch.
|
282 |
-
wp_register_script( 'astra-sites-fetch', ASTRA_SITES_URI . 'inc/assets/js/fetch.umd.js', array( 'jquery' ), ASTRA_SITES_VER, true );
|
283 |
-
|
284 |
-
// API.
|
285 |
-
wp_register_script( 'astra-sites-api', ASTRA_SITES_URI . 'inc/assets/js/astra-sites-api.js', array( 'jquery', 'astra-sites-fetch' ), ASTRA_SITES_VER, true );
|
286 |
-
|
287 |
-
// Admin Page.
|
288 |
-
wp_enqueue_style( 'astra-sites-admin', ASTRA_SITES_URI . 'inc/assets/css/admin.css', ASTRA_SITES_VER, true );
|
289 |
-
wp_enqueue_script( 'astra-sites-admin-page', ASTRA_SITES_URI . 'inc/assets/js/admin-page.js', array( 'jquery', 'wp-util', 'updates' ), ASTRA_SITES_VER, true );
|
290 |
-
wp_enqueue_script( 'astra-sites-render-grid', ASTRA_SITES_URI . 'inc/assets/js/render-grid.js', array( 'wp-util', 'astra-sites-api', 'imagesloaded', 'jquery' ), ASTRA_SITES_VER, true );
|
291 |
-
|
292 |
-
$data = apply_filters(
|
293 |
-
'astra_sites_localize_vars',
|
294 |
-
array(
|
295 |
-
'ApiURL' => self::$api_url,
|
296 |
-
'filters' => array(
|
297 |
-
'page_builder' => array(
|
298 |
-
'title' => __( 'Page Builder', 'astra-sites' ),
|
299 |
-
'slug' => 'astra-site-page-builder',
|
300 |
-
'trigger' => 'astra-api-category-loaded',
|
301 |
-
),
|
302 |
-
'categories' => array(
|
303 |
-
'title' => __( 'Categories', 'astra-sites' ),
|
304 |
-
'slug' => 'astra-site-category',
|
305 |
-
'trigger' => 'astra-api-category-loaded',
|
306 |
-
),
|
307 |
-
),
|
308 |
-
)
|
309 |
-
);
|
310 |
-
wp_localize_script( 'astra-sites-api', 'astraSitesApi', $data );
|
311 |
-
|
312 |
-
// Use this for premium demos.
|
313 |
-
$request_params = apply_filters(
|
314 |
-
'astra_sites_api_params',
|
315 |
-
array(
|
316 |
-
'purchase_key' => '',
|
317 |
-
'site_url' => '',
|
318 |
-
'par-page' => 30,
|
319 |
-
)
|
320 |
-
);
|
321 |
-
|
322 |
-
$data = apply_filters(
|
323 |
-
'astra_sites_render_localize_vars',
|
324 |
-
array(
|
325 |
-
'sites' => $request_params,
|
326 |
-
'page-builders' => array(),
|
327 |
-
'categories' => array(),
|
328 |
-
'settings' => array(),
|
329 |
-
'default_page_builder' => Astra_Sites_Page::get_instance()->get_setting( 'page_builder' ),
|
330 |
-
)
|
331 |
-
);
|
332 |
-
|
333 |
-
wp_localize_script( 'astra-sites-render-grid', 'astraRenderGrid', $data );
|
334 |
-
|
335 |
-
$data = apply_filters(
|
336 |
-
'astra_sites_localize_vars',
|
337 |
-
array(
|
338 |
-
'debug' => ( ( defined( 'WP_DEBUG' ) && WP_DEBUG ) || isset( $_GET['debug'] ) ) ? true : false,
|
339 |
-
'isPro' => defined( 'ASTRA_PRO_SITES_NAME' ) ? true : false,
|
340 |
-
'isWhiteLabeled' => Astra_Sites_White_Label::get_instance()->is_white_labeled(),
|
341 |
-
'ajaxurl' => esc_url( admin_url( 'admin-ajax.php' ) ),
|
342 |
-
'siteURL' => site_url(),
|
343 |
-
'docUrl' => 'https://wpastra.com/',
|
344 |
-
'getProText' => __( 'Get Agency Bundle', 'astra-sites' ),
|
345 |
-
'getProURL' => esc_url( 'https://wpastra.com/agency/?utm_source=demo-import-panel&utm_campaign=astra-sites&utm_medium=wp-dashboard' ),
|
346 |
-
'getUpgradeText' => __( 'Upgrade', 'astra-sites' ),
|
347 |
-
'getUpgradeURL' => esc_url( 'https://wpastra.com/agency/?utm_source=demo-import-panel&utm_campaign=astra-sites&utm_medium=wp-dashboard' ),
|
348 |
-
'_ajax_nonce' => wp_create_nonce( 'astra-sites' ),
|
349 |
-
'requiredPlugins' => array(),
|
350 |
-
'XMLReaderDisabled' => ! class_exists( 'XMLReader' ) ? true : false,
|
351 |
-
'strings' => array(
|
352 |
-
/* translators: %s are HTML tags. */
|
353 |
-
'warningXMLReader' => sprintf( __( '%1$sRequired XMLReader PHP extension is missing on your server!%2$sAstra Sites import requires XMLReader extension to be installed. Please contact your web hosting provider and ask them to install and activate the XMLReader PHP extension.', 'astra-sites' ), '<div class="notice astra-sites-xml-notice notice-error"><p><b>', '</b></p><p>', '</p></div>' ),
|
354 |
-
'warningBeforeCloseWindow' => __( 'Warning! Astra Site Import process is not complete. Don\'t close the window until import process complete. Do you still want to leave the window?', 'astra-sites' ),
|
355 |
-
'importFailedBtnSmall' => __( 'Error!', 'astra-sites' ),
|
356 |
-
'importFailedBtnLarge' => __( 'Error! Read Possibilities.', 'astra-sites' ),
|
357 |
-
'importFailedURL' => esc_url( 'https://wpastra.com/docs/?p=1314&utm_source=demo-import-panel&utm_campaign=astra-sites&utm_medium=import-failed' ),
|
358 |
-
'viewSite' => __( 'Done! View Site', 'astra-sites' ),
|
359 |
-
'btnActivating' => __( 'Activating', 'astra-sites' ) . '…',
|
360 |
-
'btnActive' => __( 'Active', 'astra-sites' ),
|
361 |
-
'importFailBtn' => __( 'Import failed.', 'astra-sites' ),
|
362 |
-
'importFailBtnLarge' => __( 'Import failed. See error log.', 'astra-sites' ),
|
363 |
-
'importDemo' => __( 'Import This Site', 'astra-sites' ),
|
364 |
-
'importingDemo' => __( 'Importing..', 'astra-sites' ),
|
365 |
-
'DescExpand' => __( 'Read more', 'astra-sites' ) . '…',
|
366 |
-
'DescCollapse' => __( 'Hide', 'astra-sites' ),
|
367 |
-
'responseError' => __( 'There was a problem receiving a response from server.', 'astra-sites' ),
|
368 |
-
'searchNoFound' => __( 'No Demos found, Try a different search.', 'astra-sites' ),
|
369 |
-
),
|
370 |
-
'log' => array(
|
371 |
-
'installingPlugin' => __( 'Installing plugin ', 'astra-sites' ),
|
372 |
-
'installed' => __( 'Plugin installed!', 'astra-sites' ),
|
373 |
-
'activating' => __( 'Activating plugin ', 'astra-sites' ),
|
374 |
-
'activated' => __( 'Plugin activated ', 'astra-sites' ),
|
375 |
-
'bulkActivation' => __( 'Bulk plugin activation...', 'astra-sites' ),
|
376 |
-
'activate' => __( 'Plugin activate - ', 'astra-sites' ),
|
377 |
-
'activationError' => __( 'Error! While activating plugin - ', 'astra-sites' ),
|
378 |
-
'bulkInstall' => __( 'Bulk plugin installation...', 'astra-sites' ),
|
379 |
-
'api' => __( 'Site API ', 'astra-sites' ),
|
380 |
-
'importing' => __( 'Importing..', 'astra-sites' ),
|
381 |
-
'processingRequest' => __( 'Processing requests...', 'astra-sites' ),
|
382 |
-
'importCustomizer' => __( 'Importing "Customizer Settings"...', 'astra-sites' ),
|
383 |
-
'importCustomizerSuccess' => __( 'Imported customizer settings!', 'astra-sites' ),
|
384 |
-
'importWPForms' => __( 'Importing "Contact Forms"...', 'astra-sites' ),
|
385 |
-
'importWPFormsSuccess' => __( 'Imported Contact Forms!', 'astra-sites' ),
|
386 |
-
'importXMLPrepare' => __( 'Preparing "XML" Data...', 'astra-sites' ),
|
387 |
-
'importXMLPrepareSuccess' => __( 'Set XML data!', 'astra-sites' ),
|
388 |
-
'importXML' => __( 'Importing "XML"...', 'astra-sites' ),
|
389 |
-
'importXMLSuccess' => __( 'Imported XML!', 'astra-sites' ),
|
390 |
-
'importOptions' => __( 'Importing "Options"...', 'astra-sites' ),
|
391 |
-
'importOptionsSuccess' => __( 'Imported Options!', 'astra-sites' ),
|
392 |
-
'importWidgets' => __( 'Importing "Widgets"...', 'astra-sites' ),
|
393 |
-
'importWidgetsSuccess' => __( 'Imported Widgets!', 'astra-sites' ),
|
394 |
-
'serverConfiguration' => esc_url( 'https://wpastra.com/docs/?p=1314&utm_source=demo-import-panel&utm_campaign=import-error&utm_medium=wp-dashboard' ),
|
395 |
-
'success' => __( 'View site: ', 'astra-sites' ),
|
396 |
-
'gettingData' => __( 'Getting Site Information..', 'astra-sites' ),
|
397 |
-
'importingCustomizer' => __( 'Importing Customizer Settings..', 'astra-sites' ),
|
398 |
-
'importingWPForms' => __( 'Importing Contact Forms..', 'astra-sites' ),
|
399 |
-
'importXMLPreparing' => __( 'Setting up import data..', 'astra-sites' ),
|
400 |
-
'importingXML' => __( 'Importing Content..', 'astra-sites' ),
|
401 |
-
'importingOptions' => __( 'Importing Site Options..', 'astra-sites' ),
|
402 |
-
'importingWidgets' => __( 'Importing Widgets..', 'astra-sites' ),
|
403 |
-
'importComplete' => __( 'Import Complete..', 'astra-sites' ),
|
404 |
-
'preview' => __( 'Previewing ', 'astra-sites' ),
|
405 |
-
'importLogText' => __( 'See Error Log →', 'astra-sites' ),
|
406 |
-
),
|
407 |
-
)
|
408 |
-
);
|
409 |
-
|
410 |
-
wp_localize_script( 'astra-sites-admin-page', 'astraSitesAdmin', $data );
|
411 |
-
|
412 |
-
}
|
413 |
-
|
414 |
-
/**
|
415 |
-
* Load all the required files in the importer.
|
416 |
-
*
|
417 |
-
* @since 1.0.0
|
418 |
-
*/
|
419 |
-
private function includes() {
|
420 |
-
|
421 |
-
require_once ASTRA_SITES_DIR . 'inc/lib/astra-notices/class-astra-notices.php';
|
422 |
-
require_once ASTRA_SITES_DIR . 'inc/classes/class-astra-sites-white-label.php';
|
423 |
-
require_once ASTRA_SITES_DIR . 'inc/classes/class-astra-sites-page.php';
|
424 |
-
require_once ASTRA_SITES_DIR . 'inc/classes/compatibility/class-astra-sites-compatibility.php';
|
425 |
-
require_once ASTRA_SITES_DIR . 'inc/classes/class-astra-sites-importer.php';
|
426 |
-
}
|
427 |
-
|
428 |
-
/**
|
429 |
-
* Required Plugin Activate
|
430 |
-
*
|
431 |
-
* @since 1.0.0
|
432 |
-
*/
|
433 |
-
public function required_plugin_activate() {
|
434 |
-
|
435 |
-
if ( ! current_user_can( 'install_plugins' ) || ! isset( $_POST['init'] ) || ! $_POST['init'] ) {
|
436 |
-
wp_send_json_error(
|
437 |
-
array(
|
438 |
-
'success' => false,
|
439 |
-
'message' => __( 'No plugin specified', 'astra-sites' ),
|
440 |
-
)
|
441 |
-
);
|
442 |
-
}
|
443 |
-
|
444 |
-
$data = array();
|
445 |
-
$plugin_init = ( isset( $_POST['init'] ) ) ? esc_attr( $_POST['init'] ) : '';
|
446 |
-
$astra_site_options = ( isset( $_POST['options'] ) ) ? json_decode( stripslashes( $_POST['options'] ) ) : '';
|
447 |
-
$enabled_extensions = ( isset( $_POST['enabledExtensions'] ) ) ? json_decode( stripslashes( $_POST['enabledExtensions'] ) ) : '';
|
448 |
-
|
449 |
-
$data['astra_site_options'] = $astra_site_options;
|
450 |
-
$data['enabled_extensions'] = $enabled_extensions;
|
451 |
-
|
452 |
-
$activate = activate_plugin( $plugin_init, '', false, true );
|
453 |
-
|
454 |
-
if ( is_wp_error( $activate ) ) {
|
455 |
-
wp_send_json_error(
|
456 |
-
array(
|
457 |
-
'success' => false,
|
458 |
-
'message' => $activate->get_error_message(),
|
459 |
-
)
|
460 |
-
);
|
461 |
-
}
|
462 |
-
|
463 |
-
do_action( 'astra_sites_after_plugin_activation', $plugin_init, $data );
|
464 |
-
|
465 |
-
wp_send_json_success(
|
466 |
-
array(
|
467 |
-
'success' => true,
|
468 |
-
'message' => __( 'Plugin Activated', 'astra-sites' ),
|
469 |
-
)
|
470 |
-
);
|
471 |
-
|
472 |
-
}
|
473 |
-
|
474 |
-
/**
|
475 |
-
* Required Plugin
|
476 |
-
*
|
477 |
-
* @since 1.0.0
|
478 |
-
* @return void
|
479 |
-
*/
|
480 |
-
public function required_plugin() {
|
481 |
-
|
482 |
-
// Verify Nonce.
|
483 |
-
check_ajax_referer( 'astra-sites', '_ajax_nonce' );
|
484 |
-
|
485 |
-
$response = array(
|
486 |
-
'active' => array(),
|
487 |
-
'inactive' => array(),
|
488 |
-
'notinstalled' => array(),
|
489 |
-
);
|
490 |
-
|
491 |
-
if ( ! current_user_can( 'customize' ) ) {
|
492 |
-
wp_send_json_error( $response );
|
493 |
-
}
|
494 |
-
|
495 |
-
$required_plugins = ( isset( $_POST['required_plugins'] ) ) ? $_POST['required_plugins'] : array();
|
496 |
-
|
497 |
-
if ( count( $required_plugins ) > 0 ) {
|
498 |
-
foreach ( $required_plugins as $key => $plugin ) {
|
499 |
-
|
500 |
-
/**
|
501 |
-
* Has Pro Version Support?
|
502 |
-
* And
|
503 |
-
* Is Pro Version Installed?
|
504 |
-
*/
|
505 |
-
$plugin_pro = self::pro_plugin_exist( $plugin['init'] );
|
506 |
-
if ( $plugin_pro ) {
|
507 |
-
|
508 |
-
// Pro - Active.
|
509 |
-
if ( is_plugin_active( $plugin_pro['init'] ) ) {
|
510 |
-
$response['active'][] = $plugin_pro;
|
511 |
-
|
512 |
-
// Pro - Inactive.
|
513 |
-
} else {
|
514 |
-
$response['inactive'][] = $plugin_pro;
|
515 |
-
}
|
516 |
-
} else {
|
517 |
-
|
518 |
-
// Lite - Installed but Inactive.
|
519 |
-
if ( file_exists( WP_PLUGIN_DIR . '/' . $plugin['init'] ) && is_plugin_inactive( $plugin['init'] ) ) {
|
520 |
-
|
521 |
-
$response['inactive'][] = $plugin;
|
522 |
-
|
523 |
-
// Lite - Not Installed.
|
524 |
-
} elseif ( ! file_exists( WP_PLUGIN_DIR . '/' . $plugin['init'] ) ) {
|
525 |
-
|
526 |
-
$response['notinstalled'][] = $plugin;
|
527 |
-
|
528 |
-
// Lite - Active.
|
529 |
-
} else {
|
530 |
-
$response['active'][] = $plugin;
|
531 |
-
}
|
532 |
-
}
|
533 |
-
}
|
534 |
-
}
|
535 |
-
|
536 |
-
// Send response.
|
537 |
-
wp_send_json_success( $response );
|
538 |
-
}
|
539 |
-
|
540 |
-
/**
|
541 |
-
* Has Pro Version Support?
|
542 |
-
* And
|
543 |
-
* Is Pro Version Installed?
|
544 |
-
*
|
545 |
-
* Check Pro plugin version exist of requested plugin lite version.
|
546 |
-
*
|
547 |
-
* Eg. If plugin 'BB Lite Version' required to import demo. Then we check the 'BB Agency Version' is exist?
|
548 |
-
* If yes then we only 'Activate' Agency Version. [We couldn't install agency version.]
|
549 |
-
* Else we 'Activate' or 'Install' Lite Version.
|
550 |
-
*
|
551 |
-
* @since 1.0.1
|
552 |
-
*
|
553 |
-
* @param string $lite_version Lite version init file.
|
554 |
-
* @return mixed Return false if not installed or not supported by us
|
555 |
-
* else return 'Pro' version details.
|
556 |
-
*/
|
557 |
-
public static function pro_plugin_exist( $lite_version = '' ) {
|
558 |
-
|
559 |
-
// Lite init => Pro init.
|
560 |
-
$plugins = apply_filters(
|
561 |
-
'astra_sites_pro_plugin_exist',
|
562 |
-
array(
|
563 |
-
'beaver-builder-lite-version/fl-builder.php' => array(
|
564 |
-
'slug' => 'bb-plugin',
|
565 |
-
'init' => 'bb-plugin/fl-builder.php',
|
566 |
-
'name' => 'Beaver Builder Plugin',
|
567 |
-
),
|
568 |
-
'ultimate-addons-for-beaver-builder-lite/bb-ultimate-addon.php' => array(
|
569 |
-
'slug' => 'bb-ultimate-addon',
|
570 |
-
'init' => 'bb-ultimate-addon/bb-ultimate-addon.php',
|
571 |
-
'name' => 'Ultimate Addon for Beaver Builder',
|
572 |
-
),
|
573 |
-
'wpforms-lite/wpforms.php' => array(
|
574 |
-
'slug' => 'wpforms',
|
575 |
-
'init' => 'wpforms/wpforms.php',
|
576 |
-
'name' => 'WPForms',
|
577 |
-
),
|
578 |
-
),
|
579 |
-
$lite_version
|
580 |
-
);
|
581 |
-
|
582 |
-
if ( isset( $plugins[ $lite_version ] ) ) {
|
583 |
-
|
584 |
-
// Pro plugin directory exist?
|
585 |
-
if ( file_exists( WP_PLUGIN_DIR . '/' . $plugins[ $lite_version ]['init'] ) ) {
|
586 |
-
return $plugins[ $lite_version ];
|
587 |
-
}
|
588 |
-
}
|
589 |
-
|
590 |
-
return false;
|
591 |
-
}
|
592 |
-
|
593 |
-
}
|
594 |
-
|
595 |
-
/**
|
596 |
-
* Kicking this off by calling 'get_instance()' method
|
597 |
-
*/
|
598 |
-
Astra_Sites::get_instance();
|
599 |
-
|
600 |
-
endif;
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Astra Sites
|
4 |
+
*
|
5 |
+
* @since 1.0.0
|
6 |
+
* @package Astra Sites
|
7 |
+
*/
|
8 |
+
|
9 |
+
defined( 'ABSPATH' ) or exit;
|
10 |
+
|
11 |
+
if ( ! class_exists( 'Astra_Sites' ) ) :
|
12 |
+
|
13 |
+
/**
|
14 |
+
* Astra_Sites
|
15 |
+
*/
|
16 |
+
class Astra_Sites {
|
17 |
+
|
18 |
+
/**
|
19 |
+
* API URL which is used to get the response from.
|
20 |
+
*
|
21 |
+
* @since 1.0.0
|
22 |
+
* @var (String) URL
|
23 |
+
*/
|
24 |
+
public static $api_url;
|
25 |
+
|
26 |
+
/**
|
27 |
+
* Instance of Astra_Sites
|
28 |
+
*
|
29 |
+
* @since 1.0.0
|
30 |
+
* @var (Object) Astra_Sites
|
31 |
+
*/
|
32 |
+
private static $_instance = null;
|
33 |
+
|
34 |
+
/**
|
35 |
+
* Instance of Astra_Sites.
|
36 |
+
*
|
37 |
+
* @since 1.0.0
|
38 |
+
*
|
39 |
+
* @return object Class object.
|
40 |
+
*/
|
41 |
+
public static function get_instance() {
|
42 |
+
if ( ! isset( self::$_instance ) ) {
|
43 |
+
self::$_instance = new self;
|
44 |
+
}
|
45 |
+
|
46 |
+
return self::$_instance;
|
47 |
+
}
|
48 |
+
|
49 |
+
/**
|
50 |
+
* Constructor.
|
51 |
+
*
|
52 |
+
* @since 1.0.0
|
53 |
+
*/
|
54 |
+
private function __construct() {
|
55 |
+
|
56 |
+
self::set_api_url();
|
57 |
+
|
58 |
+
$this->includes();
|
59 |
+
|
60 |
+
add_action( 'admin_notices', array( $this, 'add_notice' ), 1 );
|
61 |
+
add_action( 'admin_notices', array( $this, 'admin_notices' ) );
|
62 |
+
add_action( 'plugins_loaded', array( $this, 'load_textdomain' ) );
|
63 |
+
add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue' ) );
|
64 |
+
|
65 |
+
// AJAX.
|
66 |
+
add_action( 'wp_ajax_astra-required-plugins', array( $this, 'required_plugin' ) );
|
67 |
+
add_action( 'wp_ajax_astra-required-plugin-activate', array( $this, 'required_plugin_activate' ) );
|
68 |
+
add_action( 'wp_ajax_astra-sites-backup-settings', array( $this, 'backup_settings' ) );
|
69 |
+
add_action( 'wp_ajax_astra-sites-set-reset-data', array( $this, 'set_reset_data' ) );
|
70 |
+
add_action( 'wp_ajax_astra-sites-activate-theme', array( $this, 'activate_theme' ) );
|
71 |
+
add_action( 'wp_ajax_astra-sites-getting-started-notice', array( $this, 'getting_started_notice' ) );
|
72 |
+
}
|
73 |
+
|
74 |
+
/**
|
75 |
+
* Close getting started notice for current user
|
76 |
+
*
|
77 |
+
* @since 1.3.5
|
78 |
+
* @return void
|
79 |
+
*/
|
80 |
+
function getting_started_notice() {
|
81 |
+
update_user_meta( get_current_user_id(), '_astra_sites_gettings_started', true );
|
82 |
+
wp_send_json_success();
|
83 |
+
}
|
84 |
+
|
85 |
+
/**
|
86 |
+
* Activate theme
|
87 |
+
*
|
88 |
+
* @since 1.3.2
|
89 |
+
* @return void
|
90 |
+
*/
|
91 |
+
function activate_theme() {
|
92 |
+
|
93 |
+
switch_theme( 'astra' );
|
94 |
+
|
95 |
+
wp_send_json_success(
|
96 |
+
array(
|
97 |
+
'success' => true,
|
98 |
+
'message' => __( 'Theme Activated', 'astra-sites' ),
|
99 |
+
)
|
100 |
+
);
|
101 |
+
}
|
102 |
+
|
103 |
+
/**
|
104 |
+
* Set reset data
|
105 |
+
*/
|
106 |
+
function set_reset_data() {
|
107 |
+
if ( ! current_user_can( 'manage_options' ) ) {
|
108 |
+
return;
|
109 |
+
}
|
110 |
+
|
111 |
+
global $wpdb;
|
112 |
+
|
113 |
+
$post_ids = $wpdb->get_col( "SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key='_astra_sites_imported_post'" );
|
114 |
+
$form_ids = $wpdb->get_col( "SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key='_astra_sites_imported_wp_forms'" );
|
115 |
+
$term_ids = $wpdb->get_col( "SELECT term_id FROM {$wpdb->termmeta} WHERE meta_key='_astra_sites_imported_term'" );
|
116 |
+
|
117 |
+
wp_send_json_success(
|
118 |
+
array(
|
119 |
+
'reset_posts' => $post_ids,
|
120 |
+
'reset_wp_forms' => $form_ids,
|
121 |
+
'reset_terms' => $term_ids,
|
122 |
+
)
|
123 |
+
);
|
124 |
+
}
|
125 |
+
|
126 |
+
/**
|
127 |
+
* Backup our existing settings.
|
128 |
+
*/
|
129 |
+
function backup_settings() {
|
130 |
+
if ( ! current_user_can( 'manage_options' ) ) {
|
131 |
+
return;
|
132 |
+
}
|
133 |
+
|
134 |
+
$file_name = 'astra-sites-backup-' . date( 'd-M-Y-h-i-s' ) . '.json';
|
135 |
+
$old_settings = get_option( 'astra-settings', array() );
|
136 |
+
$upload_dir = Astra_Sites_Importer_Log::get_instance()->log_dir();
|
137 |
+
$upload_path = trailingslashit( $upload_dir['path'] );
|
138 |
+
$log_file = $upload_path . $file_name;
|
139 |
+
$file_system = Astra_Sites_Importer_Log::get_instance()->get_filesystem();
|
140 |
+
|
141 |
+
// If file system fails? Then take a backup in site option.
|
142 |
+
if ( false === $file_system->put_contents( $log_file, json_encode( $old_settings ), FS_CHMOD_FILE ) ) {
|
143 |
+
update_option( 'astra_sites_' . $file_name, $old_settings );
|
144 |
+
}
|
145 |
+
|
146 |
+
wp_send_json_success();
|
147 |
+
}
|
148 |
+
|
149 |
+
/**
|
150 |
+
* Add Admin Notice.
|
151 |
+
*/
|
152 |
+
function add_notice() {
|
153 |
+
|
154 |
+
$theme_status = 'astra-sites-theme-' . $this->get_theme_status();
|
155 |
+
|
156 |
+
Astra_Notices::add_notice(
|
157 |
+
array(
|
158 |
+
'id' => 'astra-theme-activation-nag',
|
159 |
+
'type' => 'error',
|
160 |
+
'show_if' => ( ! defined( 'ASTRA_THEME_SETTINGS' ) ) ? true : false,
|
161 |
+
/* translators: 1: theme.php file*/
|
162 |
+
'message' => sprintf( __( '<p>Astra Theme needs to be active for you to use currently installed "%1$s" plugin. <a href="#" class="%3$s" data-theme-slug="astra">Install & Activate Now</a></p>', 'astra-sites' ), ASTRA_SITES_NAME, esc_url( admin_url( 'themes.php?theme=astra' ) ), $theme_status ),
|
163 |
+
'dismissible' => true,
|
164 |
+
'dismissible-time' => WEEK_IN_SECONDS,
|
165 |
+
)
|
166 |
+
);
|
167 |
+
}
|
168 |
+
|
169 |
+
/**
|
170 |
+
* Get theme install, active or inactive status.
|
171 |
+
*
|
172 |
+
* @since 1.3.2
|
173 |
+
*
|
174 |
+
* @return string Theme status
|
175 |
+
*/
|
176 |
+
function get_theme_status() {
|
177 |
+
|
178 |
+
$theme = wp_get_theme();
|
179 |
+
|
180 |
+
// Theme installed and activate.
|
181 |
+
if ( 'Astra' === $theme->name || 'Astra' === $theme->parent_theme ) {
|
182 |
+
return 'installed-and-active';
|
183 |
+
}
|
184 |
+
|
185 |
+
// Theme installed but not activate.
|
186 |
+
foreach ( (array) wp_get_themes() as $theme_dir => $theme ) {
|
187 |
+
if ( 'Astra' === $theme->name || 'Astra' === $theme->parent_theme ) {
|
188 |
+
return 'installed-but-inactive';
|
189 |
+
}
|
190 |
+
}
|
191 |
+
|
192 |
+
return 'not-installed';
|
193 |
+
}
|
194 |
+
|
195 |
+
/**
|
196 |
+
* Loads textdomain for the plugin.
|
197 |
+
*
|
198 |
+
* @since 1.0.1
|
199 |
+
*/
|
200 |
+
function load_textdomain() {
|
201 |
+
load_plugin_textdomain( 'astra-sites' );
|
202 |
+
}
|
203 |
+
|
204 |
+
/**
|
205 |
+
* Admin Notices
|
206 |
+
*
|
207 |
+
* @since 1.0.5
|
208 |
+
* @return void
|
209 |
+
*/
|
210 |
+
function admin_notices() {
|
211 |
+
|
212 |
+
if ( ! defined( 'ASTRA_THEME_SETTINGS' ) ) {
|
213 |
+
return;
|
214 |
+
}
|
215 |
+
|
216 |
+
add_action( 'plugin_action_links_' . ASTRA_SITES_BASE, array( $this, 'action_links' ) );
|
217 |
+
}
|
218 |
+
|
219 |
+
/**
|
220 |
+
* Show action links on the plugin screen.
|
221 |
+
*
|
222 |
+
* @param mixed $links Plugin Action links.
|
223 |
+
* @return array
|
224 |
+
*/
|
225 |
+
function action_links( $links ) {
|
226 |
+
$action_links = array(
|
227 |
+
'settings' => '<a href="' . admin_url( 'themes.php?page=astra-sites' ) . '" aria-label="' . esc_attr__( 'See Library', 'astra-sites' ) . '">' . esc_html__( 'See Library', 'astra-sites' ) . '</a>',
|
228 |
+
);
|
229 |
+
|
230 |
+
return array_merge( $action_links, $links );
|
231 |
+
}
|
232 |
+
|
233 |
+
/**
|
234 |
+
* Setter for $api_url
|
235 |
+
*
|
236 |
+
* @since 1.0.0
|
237 |
+
*/
|
238 |
+
public static function set_api_url() {
|
239 |
+
self::$api_url = apply_filters( 'astra_sites_api_url', 'https://websitedemos.net/wp-json/wp/v2/' );
|
240 |
+
|
241 |
+
}
|
242 |
+
|
243 |
+
/**
|
244 |
+
* Enqueue admin scripts.
|
245 |
+
*
|
246 |
+
* @since 1.3.2 Added 'install-theme.js' to install and activate theme.
|
247 |
+
* @since 1.0.5 Added 'getUpgradeText' and 'getUpgradeURL' localize variables.
|
248 |
+
*
|
249 |
+
* @since 1.0.0
|
250 |
+
*
|
251 |
+
* @param string $hook Current hook name.
|
252 |
+
* @return void
|
253 |