Astra Starter Sites - Version 1.4.0

Version Description

Download this release

Release Info

Developer brainstormworg
Plugin Icon Astra Starter Sites
Version 1.4.0
Comparing to
See all releases

Code changes from version 1.3.21 to 1.4.0

astra-sites.php CHANGED
@@ -3,7 +3,7 @@
3
* Plugin Name: Astra Starter Sites
4
* Plugin URI: http://www.wpastra.com/pro/
5
* Description: Import free sites build with Astra theme.
6
- * Version: 1.3.21
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.21' );
23
}
24
25
if ( ! defined( 'ASTRA_SITES_FILE' ) ) {
3
* Plugin Name: Astra Starter Sites
4
* Plugin URI: http://www.wpastra.com/pro/
5
* Description: Import free sites build with Astra theme.
6
+ * Version: 1.4.0
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.4.0' );
23
}
24
25
if ( ! defined( 'ASTRA_SITES_FILE' ) ) {
inc/assets/images/beaver-builder.jpg ADDED
Binary file
inc/assets/js/install-theme.js CHANGED
@@ -38,7 +38,8 @@
38
url: AstraSitesInstallThemeVars.ajaxurl,
39
type: 'POST',
40
data: {
41
- 'action' : 'astra-sites-getting-started-notice'
42
},
43
})
44
.done(function (result) {
@@ -70,7 +71,8 @@
70
url: AstraSitesInstallThemeVars.ajaxurl,
71
type: 'POST',
72
data: {
73
- 'action' : 'astra-sites-activate-theme'
74
},
75
})
76
.done(function (result) {
38
url: AstraSitesInstallThemeVars.ajaxurl,
39
type: 'POST',
40
data: {
41
+ 'action' : 'astra-sites-getting-started-notice',
42
+ '_ajax_nonce' : AstraSitesInstallThemeVars._ajax_nonce,
43
},
44
})
45
.done(function (result) {
71
url: AstraSitesInstallThemeVars.ajaxurl,
72
type: 'POST',
73
data: {
74
+ 'action' : 'astra-sites-activate-theme',
75
+ '_ajax_nonce' : AstraSitesInstallThemeVars._ajax_nonce,
76
},
77
})
78
.done(function (result) {
inc/classes/class-astra-sites-importer.php CHANGED
@@ -133,7 +133,7 @@ if ( ! class_exists( 'Astra_Sites_Importer' ) ) :
133
134
if ( ! empty( $demo_api_uri ) ) {
135
136
- $demo_data = self::get_astra_single_demo( $demo_api_uri );
137
update_option( 'astra_sites_import_data', $demo_data );
138
139
if ( is_wp_error( $demo_data ) ) {
@@ -154,23 +154,97 @@ if ( ! class_exists( 'Astra_Sites_Importer' ) ) :
154
155
}
156
157
/**
158
* Import WP Forms
159
*
160
* @since 1.2.14
161
*
162
* @return void
163
*/
164
- function import_wpforms() {
165
166
- // Verify Nonce.
167
- check_ajax_referer( 'astra-sites', '_ajax_nonce' );
168
169
- if ( ! current_user_can( 'customize' ) ) {
170
- wp_send_json_error( __( 'You are not allowed to perform this action', 'astra-sites' ) );
171
}
172
173
- $wpforms_url = ( isset( $_REQUEST['wpforms_url'] ) ) ? urldecode( $_REQUEST['wpforms_url'] ) : '';
174
$ids_mapping = array();
175
176
if ( ! empty( $wpforms_url ) && function_exists( 'wpforms_encode' ) ) {
@@ -204,6 +278,10 @@ if ( ! class_exists( 'Astra_Sites_Importer' ) ) :
204
)
205
);
206
207
// Set meta for tracking the post.
208
update_post_meta( $new_id, '_astra_sites_imported_wp_forms', true );
209
Astra_Sites_Importer_Log::add( 'Inserted WP Form ' . $new_id );
@@ -231,25 +309,34 @@ if ( ! class_exists( 'Astra_Sites_Importer' ) ) :
231
232
update_option( 'astra_sites_wpforms_ids_mapping', $ids_mapping );
233
234
- wp_send_json_success( $ids_mapping );
235
}
236
237
/**
238
* Import Customizer Settings.
239
*
240
* @since 1.0.14
241
* @return void
242
*/
243
- function import_customizer_settings() {
244
245
- // Verify Nonce.
246
- check_ajax_referer( 'astra-sites', '_ajax_nonce' );
247
248
- if ( ! current_user_can( 'customize' ) ) {
249
- wp_send_json_error( __( 'You are not allowed to perform this action', 'astra-sites' ) );
250
}
251
252
- $customizer_data = ( isset( $_POST['customizer_data'] ) ) ? (array) json_decode( stripcslashes( $_POST['customizer_data'] ), 1 ) : array();
253
254
if ( ! empty( $customizer_data ) ) {
255
@@ -260,10 +347,17 @@ if ( ! class_exists( 'Astra_Sites_Importer' ) ) :
260
261
Astra_Customizer_Import::instance()->import( $customizer_data );
262
263
- wp_send_json_success( $customizer_data );
264
-
265
} else {
266
- wp_send_json_error( __( 'Customizer data is empty!', 'astra-sites' ) );
267
}
268
269
}
@@ -317,21 +411,25 @@ if ( ! class_exists( 'Astra_Sites_Importer' ) ) :
317
* Import Options.
318
*
319
* @since 1.0.14
320
* @return void
321
*/
322
- function import_options() {
323
324
- // Verify Nonce.
325
- check_ajax_referer( 'astra-sites', '_ajax_nonce' );
326
327
- if ( ! current_user_can( 'customize' ) ) {
328
- wp_send_json_error( __( 'You are not allowed to perform this action', 'astra-sites' ) );
329
}
330
331
- $options_data = ( isset( $_POST['options_data'] ) ) ? (array) json_decode( stripcslashes( $_POST['options_data'] ), 1 ) : '';
332
333
if ( ! empty( $options_data ) ) {
334
-
335
// Set meta for tracking the post.
336
if ( is_array( $options_data ) ) {
337
Astra_Sites_Importer_Log::add( 'Imported - Site Options ' . json_encode( $options_data ) );
@@ -340,9 +438,17 @@ if ( ! class_exists( 'Astra_Sites_Importer' ) ) :
340
341
$options_importer = Astra_Site_Options_Import::instance();
342
$options_importer->import_options( $options_data );
343
- wp_send_json_success( $options_data );
344
} else {
345
- wp_send_json_error( __( 'Site options are empty!', 'astra-sites' ) );
346
}
347
348
}
@@ -351,18 +457,23 @@ if ( ! class_exists( 'Astra_Sites_Importer' ) ) :
351
* Import Widgets.
352
*
353
* @since 1.0.14
354
* @return void
355
*/
356
- function import_widgets() {
357
358
- // Verify Nonce.
359
- check_ajax_referer( 'astra-sites', '_ajax_nonce' );
360
361
- if ( ! current_user_can( 'customize' ) ) {
362
- wp_send_json_error( __( 'You are not allowed to perform this action', 'astra-sites' ) );
363
}
364
365
- $widgets_data = ( isset( $_POST['widgets_data'] ) ) ? (object) json_decode( stripcslashes( $_POST['widgets_data'] ) ) : '';
366
367
Astra_Sites_Importer_Log::add( 'Imported - Widgets ' . json_encode( $widgets_data ) );
368
@@ -377,9 +488,17 @@ if ( ! class_exists( 'Astra_Sites_Importer' ) ) :
377
update_option( '_astra_sites_old_widgets_data', $widgets_data );
378
}
379
380
- wp_send_json_success( $widgets_data );
381
} else {
382
- wp_send_json_error( __( 'Widget data is empty!', 'astra-sites' ) );
383
}
384
385
}
@@ -392,17 +511,18 @@ if ( ! class_exists( 'Astra_Sites_Importer' ) ) :
392
*/
393
function import_end() {
394
395
- // Verify Nonce.
396
- check_ajax_referer( 'astra-sites', '_ajax_nonce' );
397
398
- if ( ! current_user_can( 'customize' ) ) {
399
- wp_send_json_error( __( 'You are not allowed to perform this action', 'astra-sites' ) );
400
}
401
402
do_action( 'astra_sites_import_complete' );
403
}
404
405
-
406
/**
407
* Get single demo.
408
*
@@ -412,7 +532,11 @@ if ( ! class_exists( 'Astra_Sites_Importer' ) ) :
412
*
413
* @return (Array) $astra_demo_data demo data for the demo.
414
*/
415
- public static function get_astra_single_demo( $demo_api_uri ) {
416
417
// default values.
418
$remote_args = array();
@@ -428,6 +552,8 @@ if ( ! class_exists( 'Astra_Sites_Importer' ) ) :
428
'astra-custom-404' => '',
429
'required-plugins' => '',
430
'astra-site-taxonomy-mapping' => '',
431
);
432
433
$api_args = apply_filters(
@@ -479,6 +605,8 @@ if ( ! class_exists( 'Astra_Sites_Importer' ) ) :
479
$remote_args['astra-custom-404'] = $data['astra-custom-404'];
480
$remote_args['required-plugins'] = $data['required-plugins'];
481
$remote_args['astra-site-taxonomy-mapping'] = $data['astra-site-taxonomy-mapping'];
482
}
483
484
// Merge remote demo and defaults.
@@ -491,6 +619,7 @@ if ( ! class_exists( 'Astra_Sites_Importer' ) ) :
491
* @since 1.0.9
492
*/
493
public function clear_cache() {
494
// Clear 'Elementor' file cache.
495
if ( class_exists( '\Elementor\Plugin' ) ) {
496
Elementor\Plugin::$instance->posts_css_manager->clear_cache();
@@ -517,18 +646,24 @@ if ( ! class_exists( 'Astra_Sites_Importer' ) ) :
517
*/
518
function reset_customizer_data() {
519
520
- // Verify Nonce.
521
- check_ajax_referer( 'astra-sites', '_ajax_nonce' );
522
523
- if ( ! current_user_can( 'customize' ) ) {
524
- wp_send_json_error( __( 'You are not allowed to perform this action', 'astra-sites' ) );
525
}
526
527
Astra_Sites_Importer_Log::add( 'Deleted customizer Settings ' . json_encode( get_option( 'astra-settings', array() ) ) );
528
529
delete_option( 'astra-settings' );
530
531
- wp_send_json_success();
532
}
533
534
/**
@@ -539,11 +674,13 @@ if ( ! class_exists( 'Astra_Sites_Importer' ) ) :
539
*/
540
function reset_site_options() {
541
542
- // Verify Nonce.
543
- check_ajax_referer( 'astra-sites', '_ajax_nonce' );
544
545
- if ( ! current_user_can( 'customize' ) ) {
546
- wp_send_json_error( __( 'You are not allowed to perform this action', 'astra-sites' ) );
547
}
548
549
$options = get_option( '_astra_sites_old_site_options', array() );
@@ -556,7 +693,11 @@ if ( ! class_exists( 'Astra_Sites_Importer' ) ) :
556
}
557
}
558
559
- wp_send_json_success();
560
}
561
562
/**
@@ -567,23 +708,26 @@ if ( ! class_exists( 'Astra_Sites_Importer' ) ) :
567
*/
568
function reset_widgets_data() {
569
570
- // Verify Nonce.
571
- check_ajax_referer( 'astra-sites', '_ajax_nonce' );
572
573
- if ( ! current_user_can( 'customize' ) ) {
574
- wp_send_json_error( __( 'You are not allowed to perform this action', 'astra-sites' ) );
575
}
576
577
- $old_widgets = get_option( '_astra_sites_old_widgets_data', array() );
578
579
- Astra_Sites_Importer_Log::add( 'DELETED - WIDGETS ' . json_encode( $old_widgets ) );
580
581
- if ( $old_widgets ) {
582
$sidebars_widgets = get_option( 'sidebars_widgets', array() );
583
584
foreach ( $old_widgets as $sidebar_id => $widgets ) {
585
586
- if ( $widgets ) {
587
foreach ( $widgets as $widget_key => $widget_data ) {
588
589
if ( isset( $sidebars_widgets['wp_inactive_widgets'] ) ) {
@@ -598,80 +742,110 @@ if ( ! class_exists( 'Astra_Sites_Importer' ) ) :
598
update_option( 'sidebars_widgets', $sidebars_widgets );
599
}
600
601
- wp_send_json_success();
602
}
603
604
/**
605
* Delete imported posts
606
*
607
* @since 1.3.0
608
* @return void
609
*/
610
- function delete_imported_posts() {
611
612
- // Verify Nonce.
613
- check_ajax_referer( 'astra-sites', '_ajax_nonce' );
614
615
- if ( ! current_user_can( 'customize' ) ) {
616
- wp_send_json_error( __( 'You are not allowed to perform this action', 'astra-sites' ) );
617
}
618
619
- $post_id = isset( $_REQUEST['post_id'] ) ? absint( $_REQUEST['post_id'] ) : '';
620
$message = 'Deleted - Post ID ' . $post_id . ' - ' . get_post_type( $post_id ) . ' - ' . get_the_title( $post_id );
621
622
- Astra_Sites_Importer_Log::add( $message );
623
- wp_delete_post( $post_id, true );
624
625
- /* translators: %s is the post ID */
626
- wp_send_json_success( $message );
627
}
628
629
/**
630
* Delete imported WP forms
631
*
632
* @since 1.3.0
633
* @return void
634
*/
635
- function delete_imported_wp_forms() {
636
637
- // Verify Nonce.
638
- check_ajax_referer( 'astra-sites', '_ajax_nonce' );
639
640
- if ( ! current_user_can( 'customize' ) ) {
641
- wp_send_json_error( __( 'You are not allowed to perform this action', 'astra-sites' ) );
642
}
643
644
- $post_id = isset( $_REQUEST['post_id'] ) ? absint( $_REQUEST['post_id'] ) : '';
645
-
646
- $message = 'Deleted - Form ID ' . $post_id . ' - ' . get_post_type( $post_id ) . ' - ' . get_the_title( $post_id );
647
-
648
- Astra_Sites_Importer_Log::add( $message );
649
650
- wp_delete_post( $post_id, true );
651
652
- /* translators: %s is the form ID */
653
- wp_send_json_success( $message );
654
}
655
656
/**
657
* Delete imported terms
658
*
659
* @since 1.3.0
660
* @return void
661
*/
662
- function delete_imported_terms() {
663
664
- // Verify Nonce.
665
- check_ajax_referer( 'astra-sites', '_ajax_nonce' );
666
-
667
- if ( ! current_user_can( 'customize' ) ) {
668
- wp_send_json_error( __( 'You are not allowed to perform this action', 'astra-sites' ) );
669
}
670
671
- $term_id = isset( $_REQUEST['term_id'] ) ? absint( $_REQUEST['term_id'] ) : '';
672
673
$message = '';
674
-
675
if ( $term_id ) {
676
$term = get_term( $term_id );
677
if ( $term ) {
@@ -681,8 +855,11 @@ if ( ! class_exists( 'Astra_Sites_Importer' ) ) :
681
}
682
}
683
684
- /* translators: %s is the term ID */
685
- wp_send_json_success( $message );
686
}
687
688
}
133
134
if ( ! empty( $demo_api_uri ) ) {
135
136
+ $demo_data = self::get_single_demo( $demo_api_uri );
137
update_option( 'astra_sites_import_data', $demo_data );
138
139
if ( is_wp_error( $demo_data ) ) {
154
155
}
156
157
+ /**
158
+ * Change flow status
159
+ *
160
+ * @since 1.4.0
161
+ *
162
+ * @param array $args Flow query args.
163
+ * @return array Flow query args.
164
+ */
165
+ function change_flow_status( $args ) {
166
+ $args['post_status'] = 'publish';
167
+ return $args;
168
+ }
169
+
170
+ /**
171
+ * Track Flow
172
+ *
173
+ * @since 1.4.0
174
+ *
175
+ * @param integer $flow_id Flow ID.
176
+ * @return void
177
+ */
178
+ function track_flows( $flow_id ) {
179
+ error_log( 'Flow ID ' . $flow_id );
180
+ Astra_WXR_Importer::instance()->track_post( $flow_id );
181
+ }
182
+
183
+ /**
184
+ * Import CartFlows
185
+ *
186
+ * @since 1.4.0
187
+ *
188
+ * @param string $url Cartflows JSON file URL.
189
+ * @return void
190
+ */
191
+ function import_cartflows( $url = '' ) {
192
+
193
+ // Make the flow publish.
194
+ add_action( 'cartflows_flow_importer_args', array( $this, 'change_flow_status' ) );
195
+ add_action( 'cartflows_flow_imported', array( $this, 'track_flows' ) );
196
+ add_action( 'cartflows_step_imported', array( $this, 'track_flows' ) );
197
+
198
+ $url = ( isset( $_REQUEST['cartflows_url'] ) ) ? urldecode( $_REQUEST['cartflows_url'] ) : urldecode( $url );
199
+ if ( ! empty( $url ) && is_callable( 'CartFlows_Importer::get_instance' ) ) {
200
+
201
+ // Download JSON file.
202
+ $file_path = Astra_Sites_Helper::download_file( $url );
203
+
204
+ if ( $file_path['success'] ) {
205
+ if ( isset( $file_path['data']['file'] ) ) {
206
+
207
+ $ext = strtolower( pathinfo( $file_path['data']['file'], PATHINFO_EXTENSION ) );
208
+
209
+ if ( 'json' === $ext ) {
210
+ $flows = json_decode( file_get_contents( $file_path['data']['file'] ), true );
211
+
212
+ if ( ! empty( $flows ) ) {
213
+ CartFlows_Importer::get_instance()->import_from_json_data( $flows );
214
+ }
215
+ }
216
+ }
217
+ }
218
+ }
219
+
220
+ if ( defined( 'WP_CLI' ) ) {
221
+ WP_CLI::line( 'Imported from ' . $url );
222
+ } else {
223
+ wp_send_json_success( $url );
224
+ }
225
+ }
226
+
227
/**
228
* Import WP Forms
229
*
230
* @since 1.2.14
231
+ * @since 1.4.0 The `$wpforms_url` was added.
232
*
233
+ * @param string $wpforms_url WP Forms JSON file URL.
234
* @return void
235
*/
236
+ function import_wpforms( $wpforms_url = '' ) {
237
238
+ if ( ! defined( 'WP_CLI' ) ) {
239
+ // Verify Nonce.
240
+ check_ajax_referer( 'astra-sites', '_ajax_nonce' );
241
242
+ if ( ! current_user_can( 'customize' ) ) {
243
+ wp_send_json_error( __( 'You are not allowed to perform this action', 'astra-sites' ) );
244
+ }
245
}
246
247
+ $wpforms_url = ( isset( $_REQUEST['wpforms_url'] ) ) ? urldecode( $_REQUEST['wpforms_url'] ) : $wpforms_url;
248
$ids_mapping = array();
249
250
if ( ! empty( $wpforms_url ) && function_exists( 'wpforms_encode' ) ) {
278
)
279
);
280
281
+ if ( defined( 'WP_CLI' ) ) {
282
+ WP_CLI::line( 'Imported Form ' . $title );
283
+ }
284
+
285
// Set meta for tracking the post.
286
update_post_meta( $new_id, '_astra_sites_imported_wp_forms', true );
287
Astra_Sites_Importer_Log::add( 'Inserted WP Form ' . $new_id );
309
310
update_option( 'astra_sites_wpforms_ids_mapping', $ids_mapping );
311
312
+ if ( defined( 'WP_CLI' ) ) {
313
+ WP_CLI::line( 'WP Forms Imported.' );
314
+ } else {
315
+ wp_send_json_success( $ids_mapping );
316
+ }
317
}
318
319
/**
320
* Import Customizer Settings.
321
*
322
* @since 1.0.14
323
+ * @since 1.4.0 The `$customizer_data` was added.
324
+ *
325
+ * @param array $customizer_data Customizer Data.
326
* @return void
327
*/
328
+ function import_customizer_settings( $customizer_data = array() ) {
329
330
+ if ( ! defined( 'WP_CLI' ) ) {
331
+ // Verify Nonce.
332
+ check_ajax_referer( 'astra-sites', '_ajax_nonce' );
333
334
+ if ( ! current_user_can( 'customize' ) ) {
335
+ wp_send_json_error( __( 'You are not allowed to perform this action', 'astra-sites' ) );
336
+ }
337
}
338
339
+ $customizer_data = ( isset( $_POST['customizer_data'] ) ) ? (array) json_decode( stripcslashes( $_POST['customizer_data'] ), 1 ) : $customizer_data;
340
341
if ( ! empty( $customizer_data ) ) {
342
347
348
Astra_Customizer_Import::instance()->import( $customizer_data );
349
350
+ if ( defined( 'WP_CLI' ) ) {
351
+ WP_CLI::line( 'Imported Customizer Settings!' );
352
+ } else {
353
+ wp_send_json_success( $customizer_data );
354
+ }
355
} else {
356
+ if ( defined( 'WP_CLI' ) ) {
357
+ WP_CLI::line( 'Customizer data is empty!' );
358
+ } else {
359
+ wp_send_json_error( __( 'Customizer data is empty!', 'astra-sites' ) );
360
+ }
361
}
362
363
}
411
* Import Options.
412
*
413
* @since 1.0.14
414
+ * @since 1.4.0 The `$options_data` was added.
415
+ *
416
+ * @param array $options_data Site Options.
417
* @return void
418
*/
419
+ function import_options( $options_data = array() ) {
420
421
+ if ( ! defined( 'WP_CLI' ) ) {
422
+ // Verify Nonce.
423
+ check_ajax_referer( 'astra-sites', '_ajax_nonce' );
424
425
+ if ( ! current_user_can( 'customize' ) ) {
426
+ wp_send_json_error( __( 'You are not allowed to perform this action', 'astra-sites' ) );
427
+ }
428
}
429
430
+ $options_data = ( isset( $_POST['options_data'] ) ) ? (array) json_decode( stripcslashes( $_POST['options_data'] ), 1 ) : $options_data;
431
432
if ( ! empty( $options_data ) ) {
433
// Set meta for tracking the post.
434
if ( is_array( $options_data ) ) {
435
Astra_Sites_Importer_Log::add( 'Imported - Site Options ' . json_encode( $options_data ) );
438
439
$options_importer = Astra_Site_Options_Import::instance();
440
$options_importer->import_options( $options_data );
441
+ if ( defined( 'WP_CLI' ) ) {
442
+ WP_CLI::line( 'Imported Site Options!' );
443
+ } else {
444
+ wp_send_json_success( $options_data );
445
+ }
446
} else {
447
+ if ( defined( 'WP_CLI' ) ) {
448
+ WP_CLI::line( 'Site options are empty!' );
449
+ } else {
450
+ wp_send_json_error( __( 'Site options are empty!', 'astra-sites' ) );
451
+ }
452
}
453
454
}
457
* Import Widgets.
458
*
459
* @since 1.0.14
460
+ * @since 1.4.0 The `$widgets_data` was added.
461
+ *
462
+ * @param string $widgets_data Widgets Data.
463
* @return void
464
*/
465
+ function import_widgets( $widgets_data = '' ) {
466
467
+ if ( ! defined( 'WP_CLI' ) ) {
468
+ // Verify Nonce.
469
+ check_ajax_referer( 'astra-sites', '_ajax_nonce' );
470
471
+ if ( ! current_user_can( 'customize' ) ) {
472
+ wp_send_json_error( __( 'You are not allowed to perform this action', 'astra-sites' ) );
473
+ }
474
}
475
476
+ $widgets_data = ( isset( $_POST['widgets_data'] ) ) ? (object) json_decode( stripslashes( $_POST['widgets_data'] ) ) : (object) $widgets_data;
477
478
Astra_Sites_Importer_Log::add( 'Imported - Widgets ' . json_encode( $widgets_data ) );
479
488
update_option( '_astra_sites_old_widgets_data', $widgets_data );
489
}
490
491
+ if ( defined( 'WP_CLI' ) ) {
492
+ WP_CLI::line( 'Widget Imported!' );
493
+ } else {
494
+ wp_send_json_success( $widgets_data );
495
+ }
496
} else {
497
+ if ( defined( 'WP_CLI' ) ) {
498
+ WP_CLI::line( 'Widget data is empty!' );
499
+ } else {
500
+ wp_send_json_error( __( 'Widget data is empty!', 'astra-sites' ) );
501
+ }
502
}
503
504
}
511
*/
512
function import_end() {
513
514
+ if ( ! defined( 'WP_CLI' ) ) {
515
+ // Verify Nonce.
516
+ check_ajax_referer( 'astra-sites', '_ajax_nonce' );
517
518
+ if ( ! current_user_can( 'customize' ) ) {
519
+ wp_send_json_error( __( 'You are not allowed to perform this action', 'astra-sites' ) );
520
+ }
521
}
522
523
do_action( 'astra_sites_import_complete' );
524
}
525
526
/**
527
* Get single demo.
528
*
532
*
533
* @return (Array) $astra_demo_data demo data for the demo.
534
*/
535
+ public static function get_single_demo( $demo_api_uri ) {
536
+
537
+ if ( is_int( $demo_api_uri ) ) {
538
+ $demo_api_uri = Astra_Sites::get_instance()->get_api_url() . 'astra-sites/' . $demo_api_uri;
539
+ }
540
541
// default values.
542
$remote_args = array();
552
'astra-custom-404' => '',
553
'required-plugins' => '',
554
'astra-site-taxonomy-mapping' => '',
555
+ 'license-status' => '',
556
+ 'site-type' => '',
557
);
558
559
$api_args = apply_filters(
605
$remote_args['astra-custom-404'] = $data['astra-custom-404'];
606
$remote_args['required-plugins'] = $data['required-plugins'];
607
$remote_args['astra-site-taxonomy-mapping'] = $data['astra-site-taxonomy-mapping'];
608
+ $remote_args['license-status'] = $data['license-status'];
609
+ $remote_args['site-type'] = $data['astra-site-type'];
610
}
611
612
// Merge remote demo and defaults.
619
* @since 1.0.9
620
*/
621
public function clear_cache() {
622
+
623
// Clear 'Elementor' file cache.
624
if ( class_exists( '\Elementor\Plugin' ) ) {
625
Elementor\Plugin::$instance->posts_css_manager->clear_cache();
646
*/
647
function reset_customizer_data() {
648
649
+ if ( ! defined( 'WP_CLI' ) ) {
650
+ // Verify Nonce.
651
+ check_ajax_referer( 'astra-sites', '_ajax_nonce' );
652
653
+ if ( ! current_user_can( 'customize' ) ) {
654
+ wp_send_json_error( __( 'You are not allowed to perform this action', 'astra-sites' ) );
655
+ }
656
}
657
658
Astra_Sites_Importer_Log::add( 'Deleted customizer Settings ' . json_encode( get_option( 'astra-settings', array() ) ) );
659
660
delete_option( 'astra-settings' );
661
662
+ if ( defined( 'WP_CLI' ) ) {
663
+ WP_CLI::line( 'Deleted Customizer Settings!' );
664
+ } else {
665
+ wp_send_json_success();
666
+ }
667
}
668
669
/**
674
*/
675
function reset_site_options() {
676
677
+ if ( ! defined( 'WP_CLI' ) ) {
678
+ // Verify Nonce.
679
+ check_ajax_referer( 'astra-sites', '_ajax_nonce' );
680
681
+ if ( ! current_user_can( 'customize' ) ) {
682
+ wp_send_json_error( __( 'You are not allowed to perform this action', 'astra-sites' ) );
683
+ }
684
}
685
686
$options = get_option( '_astra_sites_old_site_options', array() );
693
}
694
}
695
696
+ if ( defined( 'WP_CLI' ) ) {
697
+ WP_CLI::line( 'Deleted Site Options!' );
698
+ } else {
699
+ wp_send_json_success();
700
+ }
701
}
702
703
/**
708
*/
709
function reset_widgets_data() {
710
711
+ if ( ! defined( 'WP_CLI' ) ) {
712
+ // Verify Nonce.
713
+ check_ajax_referer( 'astra-sites', '_ajax_nonce' );
714
715
+ if ( ! current_user_can( 'customize' ) ) {
716
+ wp_send_json_error( __( 'You are not allowed to perform this action', 'astra-sites' ) );
717
+ }
718
}
719
720
+ $old_widgets = (array) get_option( '_astra_sites_old_widgets_data', array() );
721
722
+ if ( ! empty( $old_widgets ) ) {
723
+
724
+ Astra_Sites_Importer_Log::add( 'DELETED - WIDGETS ' . json_encode( $old_widgets ) );
725
726
$sidebars_widgets = get_option( 'sidebars_widgets', array() );
727
728
foreach ( $old_widgets as $sidebar_id => $widgets ) {
729
730
+ if ( ! empty( $widgets ) && is_array( $widgets ) ) {
731
foreach ( $widgets as $widget_key => $widget_data ) {
732
733
if ( isset( $sidebars_widgets['wp_inactive_widgets'] ) ) {
742
update_option( 'sidebars_widgets', $sidebars_widgets );
743
}
744
745
+ if ( defined( 'WP_CLI' ) ) {
746
+ WP_CLI::line( 'Deleted Widgets!' );
747
+ } else {
748
+ wp_send_json_success();
749
+ }
750
}
751
752
/**
753
* Delete imported posts
754
*
755
* @since 1.3.0
756
+ * @since 1.4.0 The `$post_id` was added.
757
+ *
758
+ * @param integer $post_id Post ID.
759
* @return void
760
*/
761
+ function delete_imported_posts( $post_id = 0 ) {
762
763
+ if ( ! defined( 'WP_CLI' ) ) {
764
+ // Verify Nonce.
765
+ check_ajax_referer( 'astra-sites', '_ajax_nonce' );
766
767
+ if ( ! current_user_can( 'customize' ) ) {
768
+ wp_send_json_error( __( 'You are not allowed to perform this action', 'astra-sites' ) );
769
+ }
770
}
771
772
+ $post_id = isset( $_REQUEST['post_id'] ) ? absint( $_REQUEST['post_id'] ) : $post_id;
773
+
774
$message = 'Deleted - Post ID ' . $post_id . ' - ' . get_post_type( $post_id ) . ' - ' . get_the_title( $post_id );
775
776
+ $message = '';
777
+ if ( $post_id ) {
778
+ $message = 'Deleted - Post ID ' . $post_id . ' - ' . get_post_type( $post_id ) . ' - ' . get_the_title( $post_id );
779
+
780
+ Astra_Sites_Importer_Log::add( $message );
781
+ wp_delete_post( $post_id, true );
782
+ }
783
784
+ if ( defined( 'WP_CLI' ) ) {
785
+ WP_CLI::line( $message );
786
+ } else {
787
+ wp_send_json_success( $message );
788
+ }
789
}
790
791
/**
792
* Delete imported WP forms
793
*
794
* @since 1.3.0
795
+ * @since 1.4.0 The `$post_id` was added.
796
+ *
797
+ * @param integer $post_id Post ID.
798
* @return void
799
*/
800
+ function delete_imported_wp_forms( $post_id = 0 ) {
801
802
+ if ( ! defined( 'WP_CLI' ) ) {
803
+ // Verify Nonce.
804
+ check_ajax_referer( 'astra-sites', '_ajax_nonce' );
805
806
+ if ( ! current_user_can( 'customize' ) ) {
807
+ wp_send_json_error( __( 'You are not allowed to perform this action', 'astra-sites' ) );
808
+ }
809
}
810
811
+ $post_id = isset( $_REQUEST['post_id'] ) ? absint( $_REQUEST['post_id'] ) : $post_id;
812
813
+ $message = '';
814
+ if ( $post_id ) {
815
+ $message = 'Deleted - Form ID ' . $post_id . ' - ' . get_post_type( $post_id ) . ' - ' . get_the_title( $post_id );
816
+ Astra_Sites_Importer_Log::add( $message );
817
+ wp_delete_post( $post_id, true );
818
+ }
819
820
+ if ( defined( 'WP_CLI' ) ) {
821
+ WP_CLI::line( $message );
822
+ } else {
823
+ wp_send_json_success( $message );
824
+ }
825
}
826
827
/**
828
* Delete imported terms
829
*
830
* @since 1.3.0
831
+ * @since 1.4.0 The `$post_id` was added.
832
+ *
833
+ * @param integer $term_id Term ID.
834
* @return void
835
*/
836
+ function delete_imported_terms( $term_id = 0 ) {
837
+ if ( ! defined( 'WP_CLI' ) ) {
838
+ // Verify Nonce.
839
+ check_ajax_referer( 'astra-sites', '_ajax_nonce' );
840
841
+ if ( ! current_user_can( 'customize' ) ) {
842
+ wp_send_json_error( __( 'You are not allowed to perform this action', 'astra-sites' ) );
843
+ }
844
}
845
846
+ $term_id = isset( $_REQUEST['term_id'] ) ? absint( $_REQUEST['term_id'] ) : $term_id;
847
848
$message = '';
849
if ( $term_id ) {
850
$term = get_term( $term_id );
851
if ( $term ) {
855
}
856
}
857
858
+ if ( defined( 'WP_CLI' ) ) {
859
+ WP_CLI::line( $message );
860
+ } else {
861
+ wp_send_json_success( $message );
862
+ }
863
}
864
865
}
inc/classes/class-astra-sites-page.php CHANGED
@@ -90,24 +90,32 @@ if ( ! class_exists( 'Astra_Sites_Page' ) ) {
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.
@@ -115,7 +123,9 @@ if ( ! class_exists( 'Astra_Sites_Page' ) ) {
115
116
// Update settings.
117
update_option( 'astra_sites_settings', $data );
118
119
wp_redirect( admin_url( '/themes.php?page=astra-sites' ) );
120
}
121
}
@@ -279,33 +289,15 @@ if ( ! class_exists( 'Astra_Sites_Page' ) ) {
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>
@@ -360,6 +352,37 @@ if ( ! class_exists( 'Astra_Sites_Page' ) ) {
360
}
361
}
362
363
/**
364
* Get and return page URL
365
*
90
/**
91
* Save Page Builder
92
*
93
+ * @since 1.4.0 The `$page_builder_slug` was added.
94
+ *
95
+ * @param string $page_builder_slug Page Builder Slug.
96
+ * @return mixed
97
*/
98
+ function save_page_builder( $page_builder_slug = '' ) {
99
100
// Only admins can save settings.
101
+ if ( ! defined( 'WP_CLI' ) && ! current_user_can( 'manage_options' ) ) {
102
return;
103
}
104
105
// Make sure we have a valid nonce.
106
+ if ( ! defined( 'WP_CLI' ) && ( ! isset( $_REQUEST['astra-sites-page-builder'] ) || ! wp_verify_nonce( $_REQUEST['astra-sites-page-builder'], 'astra-sites-welcome-screen' ) ) ) {
107
+ return;
108
+ }
109
+
110
+ // Stored Settings.
111
+ $stored_data = $this->get_settings();
112
113
+ $page_builder = isset( $_REQUEST['page_builder'] ) ? sanitize_key( $_REQUEST['page_builder'] ) : sanitize_key( $page_builder_slug );
114
115
+ if ( ! empty( $page_builder ) ) {
116
// New settings.
117
$new_data = array(
118
+ 'page_builder' => $page_builder,
119
);
120
121
// Merge settings.
123
124
// Update settings.
125
update_option( 'astra_sites_settings', $data );
126
+ }
127
128
+ if ( ! defined( 'WP_CLI' ) ) {
129
wp_redirect( admin_url( '/themes.php?page=astra-sites' ) );
130
}
131
}
289
<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>
290
<div class="fields">
291
<ul class="page-builders">
292
+ <?php foreach ( (array) $this->get_page_builders() as $key => $page_builder ) { ?>
293
+ <li>
294
+ <label>
295
+ <input type="radio" name="page_builder" value="<?php echo esc_attr( $page_builder['slug'] ); ?>">
296
+ <img src="<?php echo esc_url( $page_builder['image_url'] ); ?>" />
297
+ <div class="title"><?php echo esc_html( $page_builder['name'] ); ?></div>
298
+ </label>
299
</li>
300
+ <?php } ?>
301
</ul>
302
<div class="astra-sites-page-builder-notice" style="display: none;">
303
<p class="description"><?php _e( 'Please select your favorite page builder to continue..', 'astra-sites' ); ?></p>
352
}
353
}
354
355
+ /**
356
+ * Page Builder List
357
+ *
358
+ * @since 1.4.0
359
+ * @return array
360
+ */
361
+ function get_page_builders() {
362
+ return array(
363
+ 'gutenberg' => array(
364
+ 'slug' => 'gutenberg',
365
+ 'name' => __( 'Gutenberg', 'astra-sites' ),
366
+ 'image_url' => ASTRA_SITES_URI . 'inc/assets/images/gutenberg.jpg',
367
+ ),
368
+ 'elementor' => array(
369
+ 'slug' => 'elementor',
370
+ 'name' => __( 'Elementor', 'astra-sites' ),
371
+ 'image_url' => ASTRA_SITES_URI . 'inc/assets/images/elementor.jpg',
372
+ ),
373
+ 'beaver-builder' => array(
374
+ 'slug' => 'beaver-builder',
375
+ 'name' => __( 'Beaver Builder', 'astra-sites' ),
376
+ 'image_url' => ASTRA_SITES_URI . 'inc/assets/images/beaver-builder.jpg',
377
+ ),
378
+ 'brizy' => array(
379
+ 'slug' => 'brizy',
380
+ 'name' => __( 'Brizy', 'astra-sites' ),
381
+ 'image_url' => ASTRA_SITES_URI . 'inc/assets/images/brizy.jpg',
382
+ ),
383
+ );
384
+ }
385
+
386
/**
387
* Get and return page URL
388
*
inc/classes/class-astra-sites-wp-cli.php ADDED
@@ -0,0 +1,651 @@
1
+ <?php
2
+ /**
3
+ * Astra Sites WP CLI
4
+ *
5
+ * 1. Run `wp astra-sites list` List of all astra sites.
6
+ * 2. Run `wp astra-sites import <id>` Import site.
7
+ *
8
+ * @package Astra Sites
9
+ * @since 1.4.0
10
+ */
11
+
12
+ if ( class_exists( 'WP_CLI_Command' ) && ! class_exists( 'Astra_Sites_WP_CLI' ) ) :
13
+
14
+ /**
15
+ * Astra Sites
16
+ *
17
+ * @since 1.4.0
18
+ */
19
+ class Astra_Sites_WP_CLI extends WP_CLI_Command {
20
+
21
+ /**
22
+ * Site Data
23
+ *
24
+ * @var array
25
+ */
26
+ protected $current_site_data;
27
+
28
+ /**
29
+ * Generates the list of all Astra Sites.
30
+ *
31
+ * ## OPTIONS
32
+ *
33
+ * [--per-page=<number>]
34
+ * : No of sites to show in the list. Default its showing 10 sites.
35
+ *
36
+ * [--search=<text>]
37
+ * : Show the sites from particular search term.
38
+ *
39
+ * [--category=<text>]
40
+ * : Show the site from the specific category.
41
+ *
42
+ * [--page-builder=<text>]
43
+ * : List the sites from the particular page builder.
44
+ *
45
+ * [--type=<text>]
46
+ * : List the sites from the particular site type.
47
+ *
48
+ * ## EXAMPLES
49
+ *
50
+ * # List all the sites.
51
+ * $ wp astra-sites list
52
+ * +-------+-------------------+-----------------------------------------+---------+----------------+--------------+
53
+ * | id | title | url | type | categories | page-builder |
54
+ * +-------+-------------------+-----------------------------------------+---------+----------------+--------------+
55
+ * | 34184 | Nutritionist | //websitedemos.net/nutritionist-01 | free | Business, Free | Elementor |
56
+ * | 34055 | Law Firm | //websitedemos.net/law-firm-03 | premium | Business | Elementor |
57
+ * +-------+-------------------+-----------------------------------------+---------+----------------+--------------+
58
+ *
59
+ * @since 1.4.0
60
+ * @param array $args Arguments.
61
+ * @param array $assoc_args Associated Arguments.
62
+ */
63
+ public function list( $args, $assoc_args ) {
64
+
65
+ $per_page = isset( $assoc_args['per-page'] ) ? $assoc_args['per-page'] : 10;
66
+ $search = isset( $assoc_args['search'] ) ? $assoc_args['search'] : '';
67
+
68
+ $rest_args = array(
69
+ '_fields' => 'id,title,slug,astra-site-category,astra-site-page-builder,astra-sites-tag,astra-site-type,astra-site-url',
70
+ 'per_page' => $per_page,
71
+ );
72
+
73
+ if ( ! empty( $search ) ) {
74
+ $rest_args['search'] = $search;
75
+ }
76
+
77
+ $list = (array) $this->get_sites( 'astra-sites', $rest_args, true, $assoc_args );
78
+
79
+ // Modify the output.
80
+ foreach ( $list as $key => $item ) {
81
+ $list[ $key ]['categories'] = implode( ', ', $list[ $key ]['categories'] );
82
+ $list[ $key ]['page-builder'] = implode( ', ', $list[ $key ]['page_builders'] );
83
+ }
84
+
85
+ if ( ! empty( $list ) ) {
86
+ $display_fields = array(
87
+ 'id',
88
+ 'title',
89
+ 'url',
90
+ 'type',
91
+ 'categories',
92
+ 'page-builder',
93
+ );
94
+ $formatter = $this->get_formatter( $assoc_args, $display_fields );
95
+ $formatter->display_items( $list );
96
+ } else {
97
+ WP_CLI::error( __( 'No sites found! Try another query.', 'astra-sites' ) );
98
+ }
99
+ }
100
+
101
+ /**
102
+ * Import the site by site ID.
103
+ *
104
+ * ## OPTIONS
105
+ *
106
+ * <id>
107
+ * : Site id of the import site.
108
+ *
109
+ * [--reset]
110
+ * : Reset the recently imported site data. Including post, pages, customizer settings, widgets etc.
111
+ *
112
+ * [--yes]
113
+ * : Forcefully import the site without asking any prompt message.
114
+ *
115
+ * ## EXAMPLES
116
+ *
117
+ * # Import demo site.
118
+ * $ wp astra-sites import 34184 --reset --yes
119
+ * Activating Plugins..
120
+ * Reseting Posts..
121
+ * ..
122
+ *
123
+ * @since 1.4.0
124
+ * @param array $args Arguments.
125
+ * @param array $assoc_args Associated Arguments.
126
+ */
127
+ public function import( $args, $assoc_args ) {
128
+
129
+ // Force import.
130
+ $yes = isset( $assoc_args['yes'] ) ? true : false;
131
+ if ( ! $yes ) {
132
+ WP_CLI::confirm( __( 'Are you sure you want to import the site?', 'astra-sites' ) );
133
+ }
134
+
135
+ // Valid site ID?
136
+ $id = isset( $args[0] ) ? absint( $args[0] ) : 0;
137
+ if ( ! $id ) {
138
+ WP_CLI::error( __( 'Invalid Site ID,', 'astra-sites' ) );
139
+ }
140
+
141
+ $reset = isset( $assoc_args['reset'] ) ? true : false;
142
+ $site_url = get_site_url();
143
+ $demo_data = $this->get_site_data( $id );
144
+
145
+ // Invalid Site ID.
146
+ if ( is_wp_error( $demo_data ) ) {
147
+ /* Translators: %s is the error message. */
148
+ WP_CLI::error( sprintf( __( 'Site Import failed due to error: %s', 'astra-sites' ), $demo_data->get_error_message() ) );
149
+ }
150
+
151
+ // License Status.
152
+ $license_status = false;
153
+ if ( is_callable( 'BSF_License_Manager::bsf_is_active_license' ) ) {
154
+ $license_status = BSF_License_Manager::bsf_is_active_license( 'astra-pro-sites' );
155
+ }
156
+
157
+ if ( 'free' !== $demo_data['site-type'] && 'upgrade' === $demo_data['license-status'] && ! $license_status ) {
158
+
159
+ if ( ! defined( 'ASTRA_PRO_SITES_NAME' ) ) {
160
+ WP_CLI::line( __( 'This is Agency site. Please activate the "Astra Premium Sites" license!', 'astra-sites' ) );
161
+ WP_CLI::line( __( 'Use `wp plugin deactivate astra-sites` and then `wp plugin activate astra-pro-sites`', 'astra-sites' ) );
162
+ }
163
+
164
+ /* translators: %s is the activate plugin license link. */
165
+ WP_CLI::error( __( 'Use CLI command `wp brainstormforce license activate astra-pro-sites {YOUR_LICENSE_KEY}`', 'astra-sites' ) );
166
+ }
167
+
168
+ /**
169
+ * Install & Activate Required Plugins.
170
+ */
171
+ if ( isset( $demo_data['required-plugins'] ) ) {
172
+ $plugins = (array) $demo_data['required-plugins'];
173
+ if ( ! empty( $plugins ) ) {
174
+ $plugin_status = Astra_Sites::get_instance()->required_plugin( $plugins );
175
+
176
+ // Install Plugins.
177
+ if ( ! empty( $plugin_status['required_plugins']['notinstalled'] ) ) {
178
+ WP_CLI::line( __( 'Installing Plugins..', 'astra-sites' ) );
179
+ foreach ( $plugin_status['required_plugins']['notinstalled'] as $key => $plugin ) {
180
+ if ( isset( $plugin['slug'] ) ) {
181
+ WP_CLI::runcommand( 'plugin install ' . $plugin['slug'] . ' --activate' );
182
+ }
183
+ }
184
+ }
185
+
186
+ // Activate Plugins.
187
+ if ( ! empty( $plugin_status['required_plugins']['inactive'] ) ) {
188
+ WP_CLI::line( __( 'Activating Plugins..', 'astra-sites' ) );
189
+ foreach ( $plugin_status['required_plugins']['inactive'] as $key => $plugin ) {
190
+ if ( isset( $plugin['init'] ) ) {
191
+ Astra_Sites::get_instance()->required_plugin_activate( $plugin['init'], $demo_data['astra-site-options-data'], $demo_data['astra-enabled-extensions'] );
192
+ }
193
+ }
194
+ }
195
+ }
196
+ }
197
+
198
+ /**
199
+ * Backup Customizer Settings
200
+ */
201
+ Astra_Sites::get_instance()->backup_settings();
202
+
203
+ /**
204
+ * Reset Site Data
205
+ */
206
+ if ( $reset ) {
207
+ WP_CLI::runcommand( 'astra-sites reset --yes' );
208
+ }
209
+
210
+ /**
211
+ * Import Flows & Steps for CartFlows.
212
+ */
213
+ if ( isset( $demo_data['astra-site-cartflows-path'] ) && ! empty( $demo_data['astra-site-cartflows-path'] ) ) {
214
+ Astra_Sites_Importer::get_instance()->import_cartflows( $demo_data['astra-site-cartflows-path'] );
215
+ }
216
+
217
+ /**
218
+ * Import WP Forms.
219
+ */
220
+ if ( isset( $demo_data['astra-site-wpforms-path'] ) && ! empty( $demo_data['astra-site-wpforms-path'] ) ) {
221
+ Astra_Sites_Importer::get_instance()->import_wpforms( $demo_data['astra-site-wpforms-path'] );
222
+ }
223
+
224
+ /**
225
+ * Import Customizer Settings.
226
+ */
227
+ WP_CLI::runcommand( 'astra-sites import_customizer_settings ' . $id );
228
+
229
+ /**
230
+ * Import Content from XML/WXR.
231
+ */
232
+ if ( isset( $demo_data['astra-site-wxr-path'] ) && ! empty( $demo_data['astra-site-wxr-path'] ) ) {
233
+
234
+ // Download XML file.
235
+ /* translators: %s is the XML file URL. */
236
+ WP_CLI::line( sprintf( __( 'Downloading %s', 'astra-sites' ), $demo_data['astra-site-wxr-path'] ) );
237
+ $xml_path = Astra_Sites_Helper::download_file( $demo_data['astra-site-wxr-path'] );
238
+
239
+ if ( $xml_path['success'] && isset( $xml_path['data']['file'] ) ) {
240
+ WP_CLI::line( __( 'Importing WXR..', 'astra-sites' ) );
241
+ Astra_WXR_Importer::instance()->sse_import( $xml_path['data']['file'] );
242
+ } else {
243
+ /* translators: %s is error message. */
244
+ WP_CLI::line( printf( __( 'WXR file Download Failed. Error %s', 'astra-sites' ), $xml_path['data'] ) );
245
+ }
246
+ }
247
+
248
+ /**
249
+ * Import Site Options.
250
+ */
251
+ if ( isset( $demo_data['astra-site-options-data'] ) && ! empty( $demo_data['astra-site-options-data'] ) ) {
252
+ WP_CLI::line( __( 'Importing Site Options..', 'astra-sites' ) );
253
+ Astra_Sites_Importer::get_instance()->import_options( $demo_data['astra-site-options-data'] );
254
+ }
255
+
256
+ /**
257
+ * Import Widgets.
258
+ */
259
+ if ( isset( $demo_data['astra-site-widgets-data'] ) && ! empty( $demo_data['astra-site-widgets-data'] ) ) {
260
+ WP_CLI::line( __( 'Importing Widgets..', 'astra-sites' ) );
261
+ Astra_Sites_Importer::get_instance()->import_widgets( $demo_data['astra-site-widgets-data'] );
262
+ }
263
+
264
+ /**
265
+ * Import End.
266
+ */
267
+ Astra_Sites_Importer::get_instance()->import_end();
268
+
269
+ /* translators: %s is the site URL. */
270
+ WP_CLI::line( sprintf( __( "Site Imported Successfully!\nVisit: %s", 'astra-sites' ), $site_url ) );
271
+ }
272
+
273
+ /**
274
+ * Reset
275
+ *
276
+ * Delete all pages, post, custom post type, customizer settings and site options.
277
+ *
278
+ * Use: `wp astra-sites reset`
279
+ *
280
+ * @since 1.4.0
281
+ * @param array $args Arguments.
282
+ * @param array $assoc_args Associated Arguments.
283
+ * @return void.
284
+ */
285
+ public function reset( $args = array(), $assoc_args = array() ) {
286
+
287
+ $yes = isset( $assoc_args['yes'] ) ? true : false;
288
+ if ( ! $yes ) {
289
+ WP_CLI::confirm( __( 'Are you sure you want to delete imported site data?', 'astra-sites' ) );
290
+ }
291
+
292
+ // Get tracked data.
293
+ $reset_data = Astra_Sites::get_instance()->get_reset_data();
294
+
295
+ // Delete tracked posts.
296
+ if ( isset( $reset_data['reset_posts'] ) && ! empty( $reset_data['reset_posts'] ) ) {
297
+ WP_CLI::line( __( 'Reseting Posts..', 'astra-sites' ) );
298
+ foreach ( $reset_data['reset_posts'] as $key => $post_id ) {
299
+ Astra_Sites_Importer::get_instance()->delete_imported_posts( $post_id );
300
+ }
301
+ }
302
+ // Delete tracked terms.
303
+ if ( isset( $reset_data['reset_terms'] ) && ! empty( $reset_data['reset_terms'] ) ) {
304
+ WP_CLI::line( __( 'Reseting Terms..', 'astra-sites' ) );
305
+ foreach ( $reset_data['reset_terms'] as $key => $post_id ) {
306
+ Astra_Sites_Importer::get_instance()->delete_imported_terms( $post_id );
307
+ }
308
+ }
309
+ // Delete tracked WP forms.
310
+ if ( isset( $reset_data['reset_wp_forms'] ) && ! empty( $reset_data['reset_wp_forms'] ) ) {
311
+ WP_CLI::line( __( 'Resting WP Forms...', 'astra-sites' ) );
312
+ foreach ( $reset_data['reset_wp_forms'] as $key => $post_id ) {
313
+ Astra_Sites_Importer::get_instance()->delete_imported_wp_forms( $post_id );
314
+ }
315
+ }
316
+
317
+ // Delete Customizer Data.
318
+ Astra_Sites_Importer::get_instance()->reset_customizer_data();
319
+
320
+ // Delete Site Options.
321
+ Astra_Sites_Importer::get_instance()->reset_site_options();
322
+
323
+ // Delete Widgets Data.
324
+ Astra_Sites_Importer::get_instance()->reset_widgets_data();
325
+ }
326
+
327
+ /**
328
+ * Import Customizer Settings
329
+ *
330
+ * @since 1.4.0
331
+ *
332
+ * Example: `wp astra-sites import_customizer_settings <id>`
333
+ *
334
+ * @param array $args Arguments.
335
+ * @param array $assoc_args Associated Arguments.
336
+ * @return void
337
+ */
338
+ public function import_customizer_settings( $args, $assoc_args ) {
339
+
340
+ // Valid site ID?
341
+ $id = isset( $args[0] ) ? absint( $args[0] ) : 0;
342
+ if ( ! $id ) {
343
+ WP_CLI::error( __( 'Invalid Site ID,', 'astra-sites' ) );
344
+ }
345
+
346
+ $demo_data = $this->get_site_data( $id );
347
+
348
+ WP_CLI::line( __( 'Importing customizer settings..', 'astra-sites' ) );
349
+ Astra_Sites_Importer::get_instance()->import_customizer_settings( $demo_data['astra-site-customizer-data'] );
350
+ }
351
+
352
+ /**
353
+ * Page Builders
354
+ *
355
+ * ### EXAMPLES
356
+ *
357
+ * # List all the page builders.
358
+ * λ wp astra-sites page_builder list
359
+ * +----------------+----------------+
360
+ * | slug | name |
361
+ * +----------------+----------------+
362
+ * | gutenberg | Gutenberg |
363
+ * | elementor | Elementor |
364
+ * | beaver-builder | Beaver Builder |
365
+ * | brizy | Brizy |
366
+ * +----------------+----------------+
367
+ *
368
+ * # Set `Elementor` as default page builder.
369
+ * λ wp astra-sites page_builder set elementor
370
+ * "Elementor" is set as default page builder.
371
+ *
372
+ * # Set `Beaver Builder` as default page builder.
373
+ * λ wp astra-sites page_builder set beaver-builder
374
+ * "Beaver Builder" is set as default page builder.
375
+ *
376
+ * @since 1.4.0
377
+ * @param array $args Arguments.
378
+ * @param array $assoc_args Associated Arguments.
379
+ */
380
+ public function page_builder( $args, $assoc_args ) {
381
+ $action = isset( $args[0] ) ? $args[0] : '';
382
+
383
+ if ( empty( $action ) ) {
384
+ WP_CLI::error( __( 'Please add valid parameter.', 'astra-sites' ) );
385
+ }
386
+
387
+ $page_builders = Astra_Sites_Page::get_instance()->get_page_builders();
388
+
389
+ if ( 'list' === $action ) {
390
+ $display_fields = array(
391
+ 'slug',
392
+ 'name',
393
+ );
394
+ $formatter = $this->get_formatter( $assoc_args, $display_fields );
395
+ $formatter->display_items( $page_builders );
396
+
397
+ $default_page_builder = isset( $page_builders[ Astra_Sites_Page::get_instance()->get_setting( 'page_builder' ) ] ) ? $page_builders[ Astra_Sites_Page::get_instance()->get_setting( 'page_builder' ) ]['name'] : '';
398
+
399
+ if ( ! empty( $default_page_builder ) ) {
400
+ /* translators: %s is the current page builder name. */
401
+ WP_CLI::line( sprintf( __( 'Default page builder is "%s".', 'astra-sites' ), $default_page_builder ) );
402
+ }
403
+ } elseif ( 'set' === $action ) {
404
+ $page_builder_slugs = array_keys( $page_builders );
405
+ $page_builder_slug = isset( $args[1] ) ? $args[1] : '';
406
+ if ( in_array( $page_builder_slug, $page_builder_slugs, true ) ) {
407
+ Astra_Sites_Page::get_instance()->save_page_builder( $page_builder_slug );
408
+ /* translators: %s is the page builder name. */
409
+ WP_CLI::line( sprintf( __( '"%s" is set as default page builder.', 'astra-sites' ), $page_builders[ $page_builder_slug ]['name'] ) );
410
+
411
+ } else {
412
+ WP_CLI::error( __( "Invalid page builder slug. \nCheck all page builder slugs with command `wp astra-sites page_builder list`", 'astra-sites' ) );
413
+ }
414
+ } else {
415
+ WP_CLI::error( __( "Invalid parameter! \nPlease use `list` or `set` parameter.", 'astra-sites' ) );
416
+ }
417
+ }
418
+
419
+ /**
420
+ * Get Formatter
421
+ *
422
+ * @since 1.4.0
423
+ * @param array $assoc_args Associate arguments.
424
+ * @param string $fields Fields.
425
+ * @param string $prefix Prefix.
426
+ * @return object Class object.
427
+ */
428
+ protected function get_formatter( &$assoc_args, $fields = '', $prefix = '' ) {
429
+ return new \WP_CLI\Formatter( $assoc_args, $fields, $prefix );
430
+ }
431
+
432
+ /**
433
+ * Get Site Data by Site ID
434
+ *
435
+ * @since 1.4.0
436
+ *
437
+ * @param int $id Site ID.
438
+ * @return array
439
+ */
440
+ private function get_site_data( $id ) {
441
+ if ( empty( $this->current_site_data ) ) {
442
+ $this->current_site_data = Astra_Sites_Importer::get_instance()->get_single_demo( $id );
443
+ }
444
+
445
+ return $this->current_site_data;
446
+ }
447
+
448
+ /**
449
+ * Get Sites
450
+ *
451
+ * @since 1.4.0
452
+ *
453
+ * @param string $post_slug Post slug.
454
+ * @param array $args Post query arguments.
455
+ * @param boolean $force Force import.
456
+ * @param array $assoc_args Associate arguments.
457
+ * @return array
458
+ */
459
+ private function get_sites( $post_slug = '', $args = array(), $force = false, $assoc_args = array() ) {
460
+
461
+ // Add page builders.
462
+ $page_builder = isset( $assoc_args['page-builder'] ) ? $assoc_args['page-builder'] : Astra_Sites_Page::get_instance()->get_setting( 'page_builder' );
463
+ $response = $this->get_term_ids( 'astra-site-page-builder', $page_builder, $args );
464
+ $args = $response['args'];
465
+ $page_builders = $response['terms'];
466
+
467
+ // Add type.
468
+ $type = isset( $assoc_args['type'] ) ? $assoc_args['type'] : '';
469
+ $response = $this->get_term_ids( 'astra-sites-type', $type, $args );
470
+ $args = $response['args'];
471
+ $types = $response['terms'];
472
+
473
+ // Add categories.
474
+ $category = isset( $assoc_args['category'] ) ? $assoc_args['category'] : '';
475
+ $response = $this->get_term_ids( 'astra-site-category', $category, $args );
476
+ $args = $response['args'];
477
+ $categories = $response['terms'];
478
+
479
+ // Site list.
480
+ $sites = (array) $this->get_posts( 'astra-sites', $args, $force );
481
+
482
+ $list = array();
483
+ if ( $sites['success'] ) {
484
+ foreach ( $sites['data'] as $key => $site ) {
485
+ $single_site = array(
486
+ 'id' => $site['id'],
487
+ 'slug' => $site['slug'],
488
+ 'title' => $site['title']['rendered'],
489
+ 'url' => $site['astra-site-url'],
490
+ 'type' => ( 'premium' === $site['astra-site-type'] ) ? 'Agency' : ucwords( $site['astra-site-type'] ),
491
+ 'categories' => array(),
492
+ 'page_builders' => array(),
493
+ );
494
+
495
+ if ( isset( $site['astra-site-category'] ) && ! empty( $categories['data'] ) ) {
496
+ foreach ( $site['astra-site-category'] as $category_key => $category_id ) {
497
+ if ( isset( $categories['data'][ $category_id ] ) ) {
498
+ $single_site['categories'][ $category_id ] = $categories['data'][ $category_id ];
499
+ }
500
+ }
501
+ }
502
+
503
+ if ( isset( $site['astra-site-page-builder'] ) && ! empty( $page_builders['data'] ) ) {
504
+ foreach ( $site['astra-site-page-builder'] as $page_builder_key => $page_builder_id ) {
505
+ if ( isset( $page_builders['data'][ $page_builder_id ] ) ) {
506
+ $single_site['page_builders'][ $page_builder_id ] = $page_builders['data'][ $page_builder_id ];
507
+ }
508
+ }
509
+ }
510
+
511
+ $list[] = $single_site;
512
+ }
513
+ }
514
+
515
+ return $list;
516
+ }
517
+
518
+
519
+ /**
520
+ * Get Term IDs
521
+ *
522
+ * @since 1.4.0
523
+ *
524
+ * @param string $term_slug Term slug.
525
+ * @param string $search_term Search term.
526
+ * @param array $args Term query arguments.
527
+ * @return array Term response.
528
+ */
529
+ private function get_term_ids( $term_slug = '', $search_term = '', $args = array() ) {
530
+ $term_args = array();
531
+
532
+ if ( ! empty( $search_term ) ) {
533
+ $term_args = array(
534
+ 'search' => $search_term,
535
+ );
536
+ }
537
+
538
+ $term_response = (array) $this->get_terms( $term_slug, $term_args, true );
539
+
540
+ if ( ! empty( $search_term ) ) {
541
+ if ( ! empty( $term_response ) && is_array( $term_response['data'] ) ) {
542
+ $args[ $term_slug ] = implode( ',', array_keys( $term_response['data'] ) );
543
+ }
544
+ }
545
+
546
+ return array(
547
+ 'args' => $args,
548
+ 'terms' => $term_response,
549
+ );
550
+ }
551
+
552
+ /**
553
+ * Get Terms
554
+ *
555
+ * @since 1.0.0
556
+ *
557
+ * @param array $term_slug Term Slug.
558
+ * @param array $args For selecting the demos (Search terms, pagination etc).
559
+ * @param string $force Force import.
560
+ * @return $array Term response.
561
+ */
562
+ private function get_terms( $term_slug = '', $args = array(), $force = false ) {
563
+
564
+ $defaults = array(
565
+ '_fields' => 'id,name,slug,count',
566
+ );
567
+ $args = wp_parse_args( (array) $args, $defaults );
568
+
569
+ $terms_data = get_transient( 'astra-sites-term-' . $term_slug );
570
+
571
+ if ( empty( $terms_data ) || $force ) {
572
+ $url = add_query_arg( $args, Astra_Sites::get_instance()->get_api_url() . $term_slug );
573
+
574
+ $api_args = array(
575
+ 'timeout' => 60,
576
+ );
577
+
578
+ $success = false;
579
+ $response = wp_remote_get( $url, $api_args );
580
+ if ( ! is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) === 200 ) {
581
+ $request_term_data = json_decode( wp_remote_retrieve_body( $response ), true );
582
+
583
+ if ( ! isset( $request_term_data['code'] ) ) {
584
+ $success = true;
585
+ $new_terms_data = array();
586
+ foreach ( $request_term_data as $key => $request_term ) {
587
+ $new_terms_data[ $request_term['id'] ] = $request_term['name'];
588
+ }
589
+ set_transient( 'astra-sites-term-' . $term_slug, $new_terms_data, WEEK_IN_SECONDS );
590
+ }
591
+ }
592
+ } else {
593
+ $success = true;
594
+ }
595
+
596
+ return array(
597
+ 'success' => $success,
598
+ 'data' => $terms_data,
599
+ );
600
+ }
601
+
602
+ /**
603
+ * Get Posts
604
+ *
605
+ * @since 1.4.0
606
+ *
607
+ * @param string $post_slug Post slug.
608
+ * @param array $args Post query arguments.
609
+ * @param boolean $force Force import.
610
+ * @return array
611
+ */
612
+ private function get_posts( $post_slug = '', $args = array(), $force = false ) {
613
+
614
+ $args = wp_parse_args( (array) $args, array() );
615
+
616
+ $all_posts = get_transient( 'astra-sites-post-' . $post_slug );
617
+
618
+ if ( empty( $all_posts ) || $force ) {
619
+ $url = add_query_arg( $args, Astra_Sites::get_instance()->get_api_url() . $post_slug );
620
+
621
+ $api_args = array(
622
+ 'timeout' => 60,
623
+ );
624
+
625
+ $success = false;
626
+ $response = wp_remote_get( $url, $api_args );
627
+ if ( ! is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) === 200 ) {
628
+ $all_posts = json_decode( wp_remote_retrieve_body( $response ), true );
629
+
630
+ if ( ! isset( $all_posts['code'] ) ) {
631
+ $success = true;
632
+ set_transient( 'astra-sites-post-' . $post_slug, $all_posts, WEEK_IN_SECONDS );
633
+ }
634
+ }
635
+ } else {
636
+ $success = true;
637
+ }
638
+
639
+ return array(
640
+ 'success' => $success,
641
+ 'data' => $all_posts,
642
+ );
643
+ }
644
+ }
645
+
646
+ /**
647
+ * Add Command
648
+ */
649
+ WP_CLI::add_command( 'astra-sites', 'Astra_Sites_WP_CLI' );
650
+
651
+ endif;
inc/classes/class-astra-sites.php CHANGED
@@ -66,7 +66,7 @@ if ( ! class_exists( 'Astra_Sites' ) ) :
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
}
@@ -117,12 +117,14 @@ if ( ! class_exists( 'Astra_Sites' ) ) :
117
/**
118
* Set reset data
119
*/
120
- function set_reset_data() {
121
122
- check_ajax_referer( 'astra-sites', '_ajax_nonce' );
123
124
- if ( ! current_user_can( 'manage_options' ) ) {
125
- return;
126
}
127
128
global $wpdb;
@@ -131,13 +133,18 @@ if ( ! class_exists( 'Astra_Sites' ) ) :
131
$form_ids = $wpdb->get_col( "SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key='_astra_sites_imported_wp_forms'" );
132
$term_ids = $wpdb->get_col( "SELECT term_id FROM {$wpdb->termmeta} WHERE meta_key='_astra_sites_imported_term'" );
133
134
- wp_send_json_success(
135
- array(
136
- 'reset_posts' => $post_ids,
137
- 'reset_wp_forms' => $form_ids,
138
- 'reset_terms' => $term_ids,
139
- )
140
);
141
}
142
143
/**
@@ -145,10 +152,12 @@ if ( ! class_exists( 'Astra_Sites' ) ) :
145
*/
146
function backup_settings() {
147
148
- check_ajax_referer( 'astra-sites', '_ajax_nonce' );
149
150
- if ( ! current_user_can( 'manage_options' ) ) {
151
- return;
152
}
153
154
$file_name = 'astra-sites-backup-' . date( 'd-M-Y-h-i-s' ) . '.json';
@@ -163,7 +172,11 @@ if ( ! class_exists( 'Astra_Sites' ) ) :
163
update_option( 'astra_sites_' . $file_name, $old_settings );
164
}
165
166
- wp_send_json_success();
167
}
168
169
/**
@@ -257,7 +270,15 @@ if ( ! class_exists( 'Astra_Sites' ) ) :
257
*/
258
public static function set_api_url() {
259
self::$api_url = apply_filters( 'astra_sites_api_url', 'https://websitedemos.net/wp-json/wp/v2/' );
260
261
}
262
263
/**
@@ -279,11 +300,12 @@ if ( ! class_exists( 'Astra_Sites' ) ) :
279
$data = apply_filters(
280
'astra_sites_install_theme_localize_vars',
281
array(
282
- 'installed' => __( 'Installed! Activating..', 'astra-sites' ),
283
- 'activating' => __( 'Activating..', 'astra-sites' ),
284
- 'activated' => __( 'Activated! Reloading..', 'astra-sites' ),
285
- 'installing' => __( 'Installing..', 'astra-sites' ),
286
- 'ajaxurl' => esc_url( admin_url( 'admin-ajax.php' ) ),
287
)
288
);
289
wp_localize_script( 'astra-sites-install-theme', 'AstraSitesInstallThemeVars', $data );
@@ -443,66 +465,86 @@ if ( ! class_exists( 'Astra_Sites' ) ) :
443
require_once ASTRA_SITES_DIR . 'inc/classes/class-astra-sites-page.php';
444
require_once ASTRA_SITES_DIR . 'inc/classes/compatibility/class-astra-sites-compatibility.php';
445
require_once ASTRA_SITES_DIR . 'inc/classes/class-astra-sites-importer.php';
446
}
447
448
/**
449
* Required Plugin Activate
450
*
451
* @since 1.0.0
452
*/
453
- public function required_plugin_activate() {
454
-
455
- check_ajax_referer( 'astra-sites', '_ajax_nonce' );
456
-
457
- if ( ! current_user_can( 'install_plugins' ) || ! isset( $_POST['init'] ) || ! $_POST['init'] ) {
458
- wp_send_json_error(
459
- array(
460
- 'success' => false,
461
- 'message' => __( 'No plugin specified', 'astra-sites' ),
462
- )
463
- );
464
}
465
466
- $data = array();
467
- $plugin_init = ( isset( $_POST['init'] ) ) ? esc_attr( $_POST['init'] ) : '';
468
- $astra_site_options = ( isset( $_POST['options'] ) ) ? json_decode( stripslashes( $_POST['options'] ) ) : '';
469
- $enabled_extensions = ( isset( $_POST['enabledExtensions'] ) ) ? json_decode( stripslashes( $_POST['enabledExtensions'] ) ) : '';
470
471
- $data['astra_site_options'] = $astra_site_options;
472
- $data['enabled_extensions'] = $enabled_extensions;
473
474
$activate = activate_plugin( $plugin_init, '', false, true );
475
476
if ( is_wp_error( $activate ) ) {
477
- wp_send_json_error(
478
- array(
479
- 'success' => false,
480
- 'message' => $activate->get_error_message(),
481
- )
482
- );
483
}
484
485
do_action( 'astra_sites_after_plugin_activation', $plugin_init, $data );
486
487
- wp_send_json_success(
488
- array(
489
- 'success' => true,
490
- 'message' => __( 'Plugin Activated', 'astra-sites' ),
491
- )
492
- );
493
-
494
}
495
496
/**
497
- * Required Plugin
498
*
499
- * @since 1.0.0
500
- * @return void
501
*/
502
- public function required_plugin() {
503
504
// Verify Nonce.
505
- check_ajax_referer( 'astra-sites', '_ajax_nonce' );
506
507
$response = array(
508
'active' => array(),
@@ -510,11 +552,11 @@ if ( ! class_exists( 'Astra_Sites' ) ) :
510
'notinstalled' => array(),
511
);
512
513
- if ( ! current_user_can( 'customize' ) ) {
514
wp_send_json_error( $response );
515
}
516
517
- $required_plugins = ( isset( $_POST['required_plugins'] ) ) ? $_POST['required_plugins'] : array();
518
$third_party_required_plugins = array();
519
$third_party_plugins = array(
520
'learndash-course-grid' => array(
@@ -542,7 +584,7 @@ if ( ! class_exists( 'Astra_Sites' ) ) :
542
* And
543
* Is Pro Version Installed?
544
*/
545
- $plugin_pro = self::pro_plugin_exist( $plugin['init'] );
546
if ( $plugin_pro ) {
547
548
// Pro - Active.
@@ -578,13 +620,18 @@ if ( ! class_exists( 'Astra_Sites' ) ) :
578
}
579
}
580
581
- // Send response.
582
- wp_send_json_success(
583
- array(
584
- 'required_plugins' => $response,
585
- 'third_party_required_plugins' => $third_party_required_plugins,
586
- )
587
);
588
}
589
590
/**
@@ -604,7 +651,7 @@ if ( ! class_exists( 'Astra_Sites' ) ) :
604
* @return mixed Return false if not installed or not supported by us
605
* else return 'Pro' version details.
606
*/
607
- public static function pro_plugin_exist( $lite_version = '' ) {
608
609
// Lite init => Pro init.
610
$plugins = apply_filters(
@@ -639,7 +686,6 @@ if ( ! class_exists( 'Astra_Sites' ) ) :
639
640
return false;
641
}
642
-
643
}
644
645
/**
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, 'get_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
}
117
/**
118
* Set reset data
119
*/
120
+ function get_reset_data() {
121
122
+ if ( ! defined( 'WP_CLI' ) ) {
123
+ check_ajax_referer( 'astra-sites', '_ajax_nonce' );
124
125
+ if ( ! current_user_can( 'manage_options' ) ) {
126
+ return;
127
+ }
128
}
129
130
global $wpdb;
133
$form_ids = $wpdb->get_col( "SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key='_astra_sites_imported_wp_forms'" );
134
$term_ids = $wpdb->get_col( "SELECT term_id FROM {$wpdb->termmeta} WHERE meta_key='_astra_sites_imported_term'" );
135
136
+ $data = array(
137
+ 'reset_posts' => $post_ids,
138
+ 'reset_wp_forms' => $form_ids,
139
+ 'reset_terms' => $term_ids,
140
);
141
+
142
+ if ( defined( 'WP_CLI' ) ) {
143
+ return $data;
144
+ } else {
145
+ wp_send_json_success( $data );
146
+ }
147
+
148
}
149
150
/**
152
*/
153
function backup_settings() {
154
155
+ if ( ! defined( 'WP_CLI' ) ) {
156
+ check_ajax_referer( 'astra-sites', '_ajax_nonce' );
157
158
+ if ( ! current_user_can( 'manage_options' ) ) {
159
+ wp_send_json_error( __( 'User not have permission!', 'astra-sites' ) );
160
+ }
161
}
162
163
$file_name = 'astra-sites-backup-' . date( 'd-M-Y-h-i-s' ) . '.json';
172
update_option( 'astra_sites_' . $file_name, $old_settings );
173
}
174
175
+ if ( defined( 'WP_CLI' ) ) {
176
+ WP_CLI::line( 'File generated at ' . $log_file );
177
+ } else {
178
+ wp_send_json_success();
179
+ }
180
}
181
182
/**
270
*/
271
public static function set_api_url() {
272
self::$api_url = apply_filters( 'astra_sites_api_url', 'https://websitedemos.net/wp-json/wp/v2/' );
273
+ }
274
275
+ /**
276
+ * Getter for $api_url
277
+ *
278
+ * @since 1.0.0
279
+ */
280
+ public function get_api_url() {
281
+ return self::$api_url;
282
}
283
284
/**
300
$data = apply_filters(
301
'astra_sites_install_theme_localize_vars',
302
array(
303
+ 'installed' => __( 'Installed! Activating..', 'astra-sites' ),
304
+ 'activating' => __( 'Activating..', 'astra-sites' ),
305
+ 'activated' => __( 'Activated! Reloading..', 'astra-sites' ),
306
+ 'installing' => __( 'Installing..', 'astra-sites' ),
307
+ 'ajaxurl' => esc_url( admin_url( 'admin-ajax.php' ) ),
308
+ '_ajax_nonce' => wp_create_nonce( 'astra-sites' ),
309
)
310
);
311
wp_localize_script( 'astra-sites-install-theme', 'AstraSitesInstallThemeVars', $data );
465
require_once ASTRA_SITES_DIR . 'inc/classes/class-astra-sites-page.php';
466
require_once ASTRA_SITES_DIR . 'inc/classes/compatibility/class-astra-sites-compatibility.php';
467
require_once ASTRA_SITES_DIR . 'inc/classes/class-astra-sites-importer.php';
468
+ require_once ASTRA_SITES_DIR . 'inc/classes/class-astra-sites-wp-cli.php';
469
}
470
471
/**
472
* Required Plugin Activate
473
*
474
+ * @since 2.0.0 Added parameters $init, $options & $enabled_extensions to add the WP CLI support.
475
* @since 1.0.0
476
+ * @param string $init Plugin init file.
477
+ * @param array $options Site options.
478
+ * @param array $enabled_extensions Enabled extensions.
479
+ * @return void
480
*/
481
+ public function required_plugin_activate( $init = '', $options = array(), $enabled_extensions = array() ) {
482
+
483
+ if ( ! defined( 'WP_CLI' ) ) {
484
+ check_ajax_referer( 'astra-sites', '_ajax_nonce' );
485
+
486
+ if ( ! current_user_can( 'install_plugins' ) || ! isset( $_POST['init'] ) || ! $_POST['init'] ) {
487
+ wp_send_json_error(
488
+ array(
489
+ 'success' => false,
490
+ 'message' => __( 'User have not plugin install permissions.', 'astra-sites' ),
491
+ )
492
+ );
493
+ }
494
}
495
496
+ $plugin_init = ( isset( $_POST['init'] ) ) ? esc_attr( $_POST['init'] ) : $init;
497
+ $astra_site_options = ( isset( $_POST['options'] ) ) ? json_decode( stripslashes( $_POST['options'] ) ) : $options;
498
+ $enabled_extensions = ( isset( $_POST['enabledExtensions'] ) ) ? json_decode( stripslashes( $_POST['enabledExtensions'] ) ) : $enabled_extensions;
499
500
+ $data = array(
501
+ 'astra_site_options' => $astra_site_options,
502
+ 'enabled_extensions' => $enabled_extensions,
503
+ );
504
505
$activate = activate_plugin( $plugin_init, '', false, true );
506
507
if ( is_wp_error( $activate ) ) {
508
+ if ( defined( 'WP_CLI' ) ) {
509
+ WP_CLI::line( 'Plugin Activation Error: ' . $activate->get_error_message() );
510
+ } else {
511
+ wp_send_json_error(
512
+ array(
513
+ 'success' => false,
514
+ 'message' => $activate->get_error_message(),
515
+ )
516
+ );
517
+ }
518
}
519
520
do_action( 'astra_sites_after_plugin_activation', $plugin_init, $data );
521
522
+ if ( defined( 'WP_CLI' ) ) {
523
+ WP_CLI::line( 'Plugin Activated!' );
524
+ } else {
525
+ wp_send_json_success(
526
+ array(
527
+ 'success' => true,
528
+ 'message' => __( 'Plugin Activated', 'astra-sites' ),
529
+ )
530
+ );
531
+ }
532
}
533
534
/**
535
+ * Required Plugins
536
*
537
+ * @since 2.0.0
538
+ *
539
+ * @param array $required_plugins Required Plugins.
540
+ * @return mixed
541
*/
542
+ public function required_plugin( $required_plugins = array() ) {
543
544
// Verify Nonce.
545
+ if ( ! defined( 'WP_CLI' ) ) {
546
+ check_ajax_referer( 'astra-sites', '_ajax_nonce' );
547
+ }
548
549
$response = array(
550
'active' => array(),
552
'notinstalled' => array(),
553
);
554
555
+ if ( ! defined( 'WP_CLI' ) && ! current_user_can( 'customize' ) ) {
556
wp_send_json_error( $response );
557
}
558
559
+ $required_plugins = ( isset( $_POST['required_plugins'] ) ) ? $_POST['required_plugins'] : $required_plugins;
560
$third_party_required_plugins = array();
561
$third_party_plugins = array(
562
'learndash-course-grid' => array(
584
* And
585
* Is Pro Version Installed?
586
*/
587
+ $plugin_pro = $this->pro_plugin_exist( $plugin['init'] );
588
if ( $plugin_pro ) {
589
590
// Pro - Active.
620
}
621
}
622
623
+ $data = array(
624
+ 'required_plugins' => $response,
625
+ 'third_party_required_plugins' => $third_party_required_plugins,
626
);
627
+
628
+ if ( defined( 'WP_CLI' ) ) {
629
+ return $data;
630
+ } else {
631
+ // Send response.
632
+ wp_send_json_success( $data );
633
+ }
634
+
635
}
636
637
/**
651
* @return mixed Return false if not installed or not supported by us
652
* else return 'Pro' version details.
653
*/
654
+ public function pro_plugin_exist( $lite_version = '' ) {
655
656
// Lite init => Pro init.
657
$plugins = apply_filters(
686
687
return false;
688
}
689
}
690
691
/**
inc/importers/batch-processing/class-astra-sites-batch-processing-elementor.php CHANGED
@@ -17,13 +17,12 @@ if ( ! class_exists( '\Elementor\Plugin' ) ) {
17
}
18
19
use Elementor\Core\Base\Document;
20
use Elementor\DB;
21
- use Elementor\Core\Settings\Page\Manager as PageSettingsManager;
22
use Elementor\Core\Settings\Manager as SettingsManager;
23
use Elementor\Core\Settings\Page\Model;
24
- use Elementor\Editor;
25
use Elementor\Plugin;
26
- use Elementor\Settings;
27
use Elementor\Utils;
28
29
/**
@@ -89,8 +88,14 @@ class Astra_Sites_Batch_Processing_Elementor extends Source_Local {
89
}
90
}
91
92
- $data = add_magic_quotes( $data );
93
- $data = json_decode( $data, true );
94
95
// Import the data.
96
$data = $this->process_export_import_content( $data, 'on_import' );
@@ -100,7 +105,7 @@ class Astra_Sites_Batch_Processing_Elementor extends Source_Local {
100
update_metadata( 'post', $post_id, '_astra_sites_hotlink_imported', true );
101
102
// !important, Clear the cache after images import.
103
- Plugin::$instance->posts_css_manager->clear_cache();
104
105
}
106
}
17
}
18
19
use Elementor\Core\Base\Document;
20
+ use Elementor\Core\Editor\Editor;
21
use Elementor\DB;
22
use Elementor\Core\Settings\Manager as SettingsManager;
23
use Elementor\Core\Settings\Page\Model;
24
+ use Elementor\Modules\Library\Documents\Library_Document;
25
use Elementor\Plugin;
26
use Elementor\Utils;
27
28
/**
88
}
89
}
90
91
+ if ( ! is_array( $data ) ) {
92
+ $data = json_decode( $data, true );
93
+ }
94
+
95
+ $document = Plugin::$instance->documents->get( $post_id );
96
+ if ( $document ) {
97
+ $data = $document->get_elements_raw_data( $data, true );
98
+ }
99
100
// Import the data.
101
$data = $this->process_export_import_content( $data, 'on_import' );
105
update_metadata( 'post', $post_id, '_astra_sites_hotlink_imported', true );
106
107
// !important, Clear the cache after images import.
108
+ Plugin::$instance->files_manager->clear_cache();
109
110
}
111
}
inc/importers/batch-processing/class-astra-sites-batch-processing.php CHANGED
@@ -145,7 +145,11 @@ if ( ! class_exists( 'Astra_Sites_Batch_Processing' ) ) :
145
// @todo Remove required `allow_url_fopen` support.
146
if ( ini_get( 'allow_url_fopen' ) ) {
147
if ( is_plugin_active( 'elementor/elementor.php' ) ) {
148
- $import = new \Elementor\TemplateLibrary\Astra_Sites_Batch_Processing_Elementor();
149
self::$process_all->push_to_queue( $import );
150
}
151
} else {
145
// @todo Remove required `allow_url_fopen` support.
146
if ( ini_get( 'allow_url_fopen' ) ) {
147
if ( is_plugin_active( 'elementor/elementor.php' ) ) {
148
+ if ( defined( 'WP_CLI' ) ) {
149
+ $import = new Elementor\TemplateLibrary\Astra_Sites_Batch_Processing_Elementor();
150
+ } else {
151
+ $import = new \Elementor\TemplateLibrary\Astra_Sites_Batch_Processing_Elementor();
152
+ }
153
self::$process_all->push_to_queue( $import );
154
}
155
} else {
inc/importers/class-astra-sites-helper.php CHANGED
@@ -275,8 +275,8 @@ if ( ! class_exists( 'Astra_Sites_Helper' ) ) :
275
$data->attachment_id = $id;
276
$data->url = wp_get_attachment_url( $id );
277
$data->thumbnail_url = wp_get_attachment_thumb_url( $id );
278
- $data->height = $meta['height'];
279
- $data->width = $meta['width'];
280
}
281
282
return $data;
275
$data->attachment_id = $id;
276
$data->url = wp_get_attachment_url( $id );
277
$data->thumbnail_url = wp_get_attachment_thumb_url( $id );
278
+ $data->height = isset( $meta['height'] ) ? $meta['height'] : '';
279
+ $data->width = isset( $meta['width'] ) ? $meta['width'] : '';
280
}
281
282
return $data;
inc/importers/wxr-importer/class-astra-wxr-importer.php CHANGED
@@ -179,46 +179,50 @@ class Astra_WXR_Importer {
179
* Constructor.
180
*
181
* @since 1.1.0
182
*/
183
- function sse_import() {
184
185
- // Verify Nonce.
186
- check_ajax_referer( 'astra-sites', '_ajax_nonce' );
187
188
- if ( ! current_user_can( 'customize' ) ) {
189
- wp_send_json_error( __( 'You are not allowed to perform this action', 'astra-sites' ) );
190
- }
191
192
- // Start the event stream.
193
- header( 'Content-Type: text/event-stream, charset=UTF-8' );
194
195
- // Turn off PHP output compression.
196
- $previous = error_reporting( error_reporting() ^ E_WARNING );
197
- ini_set( 'output_buffering', 'off' );
198
- ini_set( 'zlib.output_compression', false );
199
- error_reporting( $previous );
200
201
- if ( $GLOBALS['is_nginx'] ) {
202
- // Setting this header instructs Nginx to disable fastcgi_buffering
203
- // and disable gzip for this request.
204
- header( 'X-Accel-Buffering: no' );
205
- header( 'Content-Encoding: none' );
206
}
207
208
- $xml_url = urldecode( $_REQUEST['xml_url'] );
209
if ( empty( $xml_url ) ) {
210
exit;
211
}
212
213
- // 2KB padding for IE
214
- echo ':' . str_repeat( ' ', 2048 ) . "\n\n";
215
216
- // Time to run the import!
217
- set_time_limit( 0 );
218
-
219
- // Ensure we're not buffered.
220
- wp_ob_end_flush_all();
221
- flush();
222
223
// Are we allowed to create users?
224
add_filter( 'wxr_importer.pre_process.user', '__return_null' );
@@ -256,7 +260,9 @@ class Astra_WXR_Importer {
256
}
257
258
$this->emit_sse_message( $complete );
259
- exit;
260
}
261
262
/**
@@ -439,11 +445,14 @@ class Astra_WXR_Importer {
439
* @param mixed $data Data to be JSON-encoded and sent in the message.
440
*/
441
public function emit_sse_message( $data ) {
442
- echo "event: message\n";
443
- echo 'data: ' . wp_json_encode( $data ) . "\n\n";
444
445
- // Extra padding.
446
- echo ':' . str_repeat( ' ', 2048 ) . "\n\n";
447
448
flush();
449
}
179
* Constructor.
180
*
181
* @since 1.1.0
182
+ * @since 1.4.0 The `$xml_url` was added.
183
+ *
184
+ * @param string $xml_url XML file URL.
185
*/
186
+ function sse_import( $xml_url = '' ) {
187
188
+ if ( ! defined( 'WP_CLI' ) ) {
189
190
+ // Verify Nonce.
191
+ check_ajax_referer( 'astra-sites', '_ajax_nonce' );
192
+
193
+ // Start the event stream.
194
+ header( 'Content-Type: text/event-stream, charset=UTF-8' );
195
196
+ // Turn off PHP output compression.
197
+ $previous = error_reporting( error_reporting() ^ E_WARNING );
198
+ ini_set( 'output_buffering', 'off' );
199
+ ini_set( 'zlib.output_compression', false );
200
+ error_reporting( $previous );
201
202
+ if ( $GLOBALS['is_nginx'] ) {
203
+ // Setting this header instructs Nginx to disable fastcgi_buffering
204
+ // and disable gzip for this request.
205
+ header( 'X-Accel-Buffering: no' );
206
+ header( 'Content-Encoding: none' );
207
+ }
208
209
+ // 2KB padding for IE
210
+ echo ':' . str_repeat( ' ', 2048 ) . "\n\n";
211
}
212
213
+ $xml_url = isset( $_REQUEST['xml_url'] ) ? urldecode( $_REQUEST['xml_url'] ) : urldecode( $xml_url );
214
if ( empty( $xml_url ) ) {
215
exit;
216
}
217
218
+ if ( ! defined( 'WP_CLI' ) ) {
219
+ // Time to run the import!
220
+ set_time_limit( 0 );
221
222
+ // Ensure we're not buffered.
223
+ wp_ob_end_flush_all();
224
+ flush();
225
+ }
226
227
// Are we allowed to create users?
228
add_filter( 'wxr_importer.pre_process.user', '__return_null' );
260
}
261
262
$this->emit_sse_message( $complete );
263
+ if ( ! defined( 'WP_CLI' ) ) {
264
+ exit;
265
+ }
266
}
267
268
/**
445
* @param mixed $data Data to be JSON-encoded and sent in the message.
446
*/
447
public function emit_sse_message( $data ) {
448
449
+ if ( ! defined( 'WP_CLI' ) ) {
450
+ echo "event: message\n";
451
+ echo 'data: ' . wp_json_encode( $data ) . "\n\n";
452
+
453
+ // Extra padding.
454
+ echo ':' . str_repeat( ' ', 2048 ) . "\n\n";
455
+ }
456
457
flush();
458
}
inc/importers/wxr-importer/class-wp-importer-logger-serversentevents.php CHANGED
@@ -24,15 +24,31 @@ if ( ! class_exists( 'WP_Importer_Logger_ServerSentEvents' ) && class_exists( 'W
24
case 'warning':
25
case 'notice':
26
case 'info':
27
- echo "event: log\n";
28
- echo 'data: ' . wp_json_encode( $data ) . "\n\n";
29
flush();
30
break;
31
32
case 'debug':
33
if ( defined( 'IMPORT_DEBUG' ) && IMPORT_DEBUG ) {
34
- echo "event: log\n";
35
- echo 'data: ' . wp_json_encode( $data ) . "\n\n";
36
flush();
37
break;
38
}
24
case 'warning':
25
case 'notice':
26
case 'info':
27
+ if( defined( 'WP_CLI' ) ) {
28
+ if( isset( $data['message'] ) && ! empty( $data['message'] ) ) {
29
+ WP_CLI::line( $data['message'] );
30
+ } else {
31
+ WP_CLI::line( wp_json_encode( $data ) );
32
+ }
33
+ } else {
34
+ echo "event: log\n";
35
+ echo 'data: ' . wp_json_encode( $data ) . "\n\n";
36
+ }
37
flush();
38
break;
39
40
case 'debug':
41
if ( defined( 'IMPORT_DEBUG' ) && IMPORT_DEBUG ) {
42
+ if( defined( 'WP_CLI' ) ) {
43
+ if( isset( $data['message'] ) && ! empty( $data['message'] ) ) {
44
+ WP_CLI::line( $data['message'] );
45
+ } else {
46
+ WP_CLI::line( wp_json_encode( $data ) );
47
+ }
48
+ } else {
49
+ echo "event: log\n";
50
+ echo 'data: ' . wp_json_encode( $data ) . "\n\n";
51
+ }
52
flush();
53
break;
54
}
languages/astra-sites.pot CHANGED
@@ -2,9 +2,9 @@
2
# This file is distributed under the same license as the Astra Starter Sites package.
3
msgid ""
4
msgstr ""
5
- "Project-Id-Version: Astra Starter Sites 1.3.19\n"
6
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/astra-sites\n"
7
- "POT-Creation-Date: 2019-09-12 06:35:36+00:00\n"
8
"MIME-Version: 1.0\n"
9
"Content-Type: text/plain; charset=utf-8\n"
10
"Content-Transfer-Encoding: 8bit\n"
@@ -46,38 +46,51 @@ msgstr ""
46
msgid "No"
47
msgstr ""
48
49
- #: inc/classes/class-astra-sites-importer.php:126
50
- msgid "You have not \"customize\" access to import the Astra site."
51
- msgstr ""
52
-
53
- #: inc/classes/class-astra-sites-importer.php:149
54
msgid "Request site API URL is empty. Try again!"
55
msgstr ""
56
57
- #: inc/classes/class-astra-sites-importer.php:249
58
msgid "Customizer data is empty!"
59
msgstr ""
60
61
- #: inc/classes/class-astra-sites-importer.php:263
62
msgid ""
63
"If XMLReader is not available, it imports all other settings and only skips "
64
"XML import. This creates an incomplete website. We should bail early and "
65
"not import anything if this is not present."
66
msgstr ""
67