Astra Starter Sites - Version 1.3.18

Version Description

Download this release

Release Info

Developer vrundakansara
Plugin Icon Astra Starter Sites
Version 1.3.18
Comparing to
See all releases

Code changes from version 1.3.17 to 1.3.18

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.17
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.17' );
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.3.18
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.18' );
23
  }
24
 
25
  if ( ! defined( 'ASTRA_SITES_FILE' ) ) {
inc/assets/js/admin-page.js CHANGED
@@ -930,7 +930,7 @@ var AstraSitesAjaxQueue = (function() {
930
  *
931
  * @param {string} data Error message.
932
  */
933
- _importFailMessage: function( message, from ) {
934
 
935
  $('.astra-demo-import')
936
  .addClass('go-pro button-primary')
@@ -940,40 +940,10 @@ var AstraSitesAjaxQueue = (function() {
940
  .append('<i class="dashicons dashicons-external"></i>')
941
  .removeClass('astra-demo-import');
942
 
943
- // Add the doc link due to import log file not generated.
944
- if( 'undefined' === from ) {
945
 
946
- $('.wp-full-overlay-header .go-pro').text( astraSitesAdmin.strings.importFailedBtnSmall );
947
- $('.wp-full-overlay-footer .go-pro').text( astraSitesAdmin.strings.importFailedBtnLarge );
948
- $('.go-pro').attr('href', astraSitesAdmin.log.serverConfiguration );
949
-
950
- // Add the import log file link.
951
- } else {
952
-
953
- $('.wp-full-overlay-header .go-pro').text( astraSitesAdmin.strings.importFailBtn );
954
- $('.wp-full-overlay-footer .go-pro').text( astraSitesAdmin.strings.importFailBtnLarge )
955
-
956
- // Add the import log file link.
957
- if( 'undefined' !== AstraSitesAdmin.log_file_url ) {
958
- $('.go-pro').attr('href', AstraSitesAdmin.log_file_url );
959
- } else {
960
- $('.go-pro').attr('href', astraSitesAdmin.log.serverConfiguration );
961
- }
962
- }
963
-
964
- var output = '<div class="astra-api-error notice notice-error notice-alt is-dismissible">';
965
- output += ' <p>'+message+'</p>';
966
- output += ' <button type="button" class="notice-dismiss">';
967
- output += ' <span class="screen-reader-text">'+commonL10n.dismiss+'</span>';
968
- output += ' </button>';
969
- output += '</div>';
970
-
971
- // Fail Notice.
972
- $('.install-theme-info').append( output );
973
-
974
- // !important to add trigger.
975
- // Which reinitialize the dismiss error message events.
976
- $(document).trigger('wp-updates-notice-added');
977
  },
978
 
979
 
@@ -1376,8 +1346,7 @@ var AstraSitesAjaxQueue = (function() {
1376
 
1377
  // 1. Fail - Request Site Import
1378
  if( false === demo_data.success ) {
1379
-
1380
-
1381
  } else {
1382
 
1383
  // Set log file URL.
930
  *
931
  * @param {string} data Error message.
932
  */
933
+ _importFailMessage: function( message ) {
934
 
935
  $('.astra-demo-import')
936
  .addClass('go-pro button-primary')
940
  .append('<i class="dashicons dashicons-external"></i>')
941
  .removeClass('astra-demo-import');
942
 
943
+ AstraSitesAdmin._log_title( message );
 
944
 
945
+ $('.wp-full-overlay-header .go-pro').text( astraSitesAdmin.strings.importFailBtn );
946
+ $('.wp-full-overlay-footer .go-pro').text( astraSitesAdmin.strings.importFailBtnLarge )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
947
  },
948
 
949
 
1346
 
1347
  // 1. Fail - Request Site Import
1348
  if( false === demo_data.success ) {
1349
+ AstraSitesAdmin._importFailMessage( demo_data.data );
 
1350
  } else {
1351
 
1352
  // Set log file URL.
inc/classes/class-astra-sites-importer.php CHANGED
@@ -1,602 +1,605 @@
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
- if ( version_compare( get_bloginfo( 'version' ), '5.1.0', '>=' ) ) {
82
- add_filter( 'http_request_timeout', array( $this, 'set_timeout_for_images' ), 10, 2 );
83
- }
84
- }
85
-
86
- /**
87
- * Set the timeout for the HTTP request by request URL.
88
- *
89
- * 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.
90
- *
91
- * @since 1.3.8
92
- *
93
- * @param int $timeout_value Time in seconds until a request times out. Default 5.
94
- * @param string $url The request URL.
95
- */
96
- function set_timeout_for_images( $timeout_value, $url ) {
97
-
98
- // URL not contain `https://websitedemos.net` then return $timeout_value.
99
- if ( strpos( $url, 'https://websitedemos.net' ) === false ) {
100
- return $timeout_value;
101
- }
102
-
103
- // Check is image URL of type jpg|png|gif|jpeg.
104
- if ( Astra_Sites_Image_Importer::get_instance()->is_image_url( $url ) ) {
105
- $timeout_value = 30;
106
- }
107
- return $timeout_value;
108
- }
109
-
110
- /**
111
- * Load WordPress WXR importer.
112
- */
113
- public function load_importer() {
114
- require_once ASTRA_SITES_DIR . 'inc/importers/wxr-importer/class-astra-wxr-importer.php';
115
- }
116
-
117
- /**
118
- * Start Site Import
119
- *
120
- * @since 1.1.0
121
- * @return void
122
- */
123
- function import_start() {
124
-
125
- if ( ! current_user_can( 'customize' ) ) {
126
- wp_send_json_error( __( 'You have not "customize" access to import the Astra site.', 'astra-sites' ) );
127
- }
128
-
129
- $demo_api_uri = isset( $_POST['api_url'] ) ? esc_url( $_POST['api_url'] ) : '';
130
-
131
- if ( ! empty( $demo_api_uri ) ) {
132
-
133
- $demo_data = self::get_astra_single_demo( $demo_api_uri );
134
-
135
- update_option( 'astra_sites_import_data', $demo_data );
136
-
137
- if ( is_wp_error( $demo_data ) ) {
138
- wp_send_json_error( $demo_data->get_error_message() );
139
- } else {
140
- $log_file = Astra_Sites_Importer_Log::add_log_file_url();
141
- if ( isset( $log_file['url'] ) && ! empty( $log_file['url'] ) ) {
142
- $demo_data['log_file'] = $log_file['url'];
143
- }
144
- do_action( 'astra_sites_import_start', $demo_data, $demo_api_uri );
145
- }
146
-
147
- wp_send_json_success( $demo_data );
148
-
149
- } else {
150
- wp_send_json_error( __( 'Request site API URL is empty. Try again!', 'astra-sites' ) );
151
- }
152
-
153
- }
154
-
155
- /**
156
- * Import WP Forms
157
- *
158
- * @since 1.2.14
159
- *
160
- * @return void
161
- */
162
- function import_wpforms() {
163
-
164
- $wpforms_url = ( isset( $_REQUEST['wpforms_url'] ) ) ? urldecode( $_REQUEST['wpforms_url'] ) : '';
165
- $ids_mapping = array();
166
-
167
- if ( ! empty( $wpforms_url ) && function_exists( 'wpforms_encode' ) ) {
168
-
169
- // Download XML file.
170
- $xml_path = Astra_Sites_Helper::download_file( $wpforms_url );
171
-
172
- if ( $xml_path['success'] ) {
173
- if ( isset( $xml_path['data']['file'] ) ) {
174
-
175
- $ext = strtolower( pathinfo( $xml_path['data']['file'], PATHINFO_EXTENSION ) );
176
-
177
- if ( 'json' === $ext ) {
178
- $forms = json_decode( file_get_contents( $xml_path['data']['file'] ), true );
179
-
180
- if ( ! empty( $forms ) ) {
181
-
182
- foreach ( $forms as $form ) {
183
- $title = ! empty( $form['settings']['form_title'] ) ? $form['settings']['form_title'] : '';
184
- $desc = ! empty( $form['settings']['form_desc'] ) ? $form['settings']['form_desc'] : '';
185
-
186
- $new_id = post_exists( $title );
187
-
188
- if ( ! $new_id ) {
189
- $new_id = wp_insert_post(
190
- array(
191
- 'post_title' => $title,
192
- 'post_status' => 'publish',
193
- 'post_type' => 'wpforms',
194
- 'post_excerpt' => $desc,
195
- )
196
- );
197
-
198
- // Set meta for tracking the post.
199
- update_post_meta( $new_id, '_astra_sites_imported_wp_forms', true );
200
- Astra_Sites_Importer_Log::add( 'Inserted WP Form ' . $new_id );
201
- }
202
-
203
- if ( $new_id ) {
204
-
205
- // ID mapping.
206
- $ids_mapping[ $form['id'] ] = $new_id;
207
-
208
- $form['id'] = $new_id;
209
- wp_update_post(
210
- array(
211
- 'ID' => $new_id,
212
- 'post_content' => wpforms_encode( $form ),
213
- )
214
- );
215
- }
216
- }
217
- }
218
- }
219
- }
220
- }
221
- }
222
-
223
- update_option( 'astra_sites_wpforms_ids_mapping', $ids_mapping );
224
-
225
- wp_send_json_success( $ids_mapping );
226
- }
227
-
228
- /**
229
- * Import Customizer Settings.
230
- *
231
- * @since 1.0.14
232
- * @return void
233
- */
234
- function import_customizer_settings() {
235
-
236
- $customizer_data = ( isset( $_POST['customizer_data'] ) ) ? (array) json_decode( stripcslashes( $_POST['customizer_data'] ), 1 ) : array();
237
-
238
- if ( ! empty( $customizer_data ) ) {
239
-
240
- Astra_Sites_Importer_Log::add( 'Imported Customizer Settings ' . json_encode( $customizer_data ) );
241
-
242
- // Set meta for tracking the post.
243
- update_option( '_astra_sites_old_customizer_data', $customizer_data );
244
-
245
- Astra_Customizer_Import::instance()->import( $customizer_data );
246
-
247
- wp_send_json_success( $customizer_data );
248
-
249
- } else {
250
- wp_send_json_error( __( 'Customizer data is empty!', 'astra-sites' ) );
251
- }
252
-
253
- }
254
-
255
- /**
256
- * Prepare XML Data.
257
- *
258
- * @since 1.1.0
259
- * @return void
260
- */
261
- function prepare_xml_data() {
262
-
263
- if ( ! class_exists( 'XMLReader' ) ) {
264
- 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' ) );
265
- }
266
-
267
- $wxr_url = ( isset( $_REQUEST['wxr_url'] ) ) ? urldecode( $_REQUEST['wxr_url'] ) : '';
268
-
269
- if ( isset( $wxr_url ) ) {
270
-
271
- Astra_Sites_Importer_Log::add( 'Importing from XML ' . $wxr_url );
272
-
273
- // Download XML file.
274
- $xml_path = Astra_Sites_Helper::download_file( $wxr_url );
275
-
276
- if ( $xml_path['success'] ) {
277
- if ( isset( $xml_path['data']['file'] ) ) {
278
- $data = Astra_WXR_Importer::instance()->get_xml_data( $xml_path['data']['file'] );
279
- $data['xml'] = $xml_path['data'];
280
- wp_send_json_success( $data );
281
- } else {
282
- wp_send_json_error( __( 'There was an error downloading the XML file.', 'astra-sites' ) );
283
- }
284
- } else {
285
- wp_send_json_error( $xml_path['data'] );
286
- }
287
- } else {
288
- wp_send_json_error( __( 'Invalid site XML file!', 'astra-sites' ) );
289
- }
290
-
291
- }
292
-
293
- /**
294
- * Import Options.
295
- *
296
- * @since 1.0.14
297
- * @return void
298
- */
299
- function import_options() {
300
-
301
- $options_data = ( isset( $_POST['options_data'] ) ) ? (array) json_decode( stripcslashes( $_POST['options_data'] ), 1 ) : '';
302
-
303
- if ( ! empty( $options_data ) ) {
304
-
305
- // Set meta for tracking the post.
306
- if ( is_array( $options_data ) ) {
307
- Astra_Sites_Importer_Log::add( 'Imported - Site Options ' . json_encode( $options_data ) );
308
- update_option( '_astra_sites_old_site_options', $options_data );
309
- }
310
-
311
- $options_importer = Astra_Site_Options_Import::instance();
312
- $options_importer->import_options( $options_data );
313
- wp_send_json_success( $options_data );
314
- } else {
315
- wp_send_json_error( __( 'Site options are empty!', 'astra-sites' ) );
316
- }
317
-
318
- }
319
-
320
- /**
321
- * Import Widgets.
322
- *
323
- * @since 1.0.14
324
- * @return void
325
- */
326
- function import_widgets() {
327
-
328
- $widgets_data = ( isset( $_POST['widgets_data'] ) ) ? (object) json_decode( stripcslashes( $_POST['widgets_data'] ) ) : '';
329
-
330
- Astra_Sites_Importer_Log::add( 'Imported - Widgets ' . json_encode( $widgets_data ) );
331
-
332
- if ( ! empty( $widgets_data ) ) {
333
-
334
- $widgets_importer = Astra_Widget_Importer::instance();
335
- $status = $widgets_importer->import_widgets_data( $widgets_data );
336
-
337
- // Set meta for tracking the post.
338
- if ( is_object( $widgets_data ) ) {
339
- $widgets_data = (array) $widgets_data;
340
- update_option( '_astra_sites_old_widgets_data', $widgets_data );
341
- }
342
-
343
- wp_send_json_success( $widgets_data );
344
- } else {
345
- wp_send_json_error( __( 'Widget data is empty!', 'astra-sites' ) );
346
- }
347
-
348
- }
349
-
350
- /**
351
- * Import End.
352
- *
353
- * @since 1.0.14
354
- * @return void
355
- */
356
- function import_end() {
357
- do_action( 'astra_sites_import_complete' );
358
- }
359
-
360
-
361
- /**
362
- * Get single demo.
363
- *
364
- * @since 1.0.0
365
- *
366
- * @param (String) $demo_api_uri API URL of a demo.
367
- *
368
- * @return (Array) $astra_demo_data demo data for the demo.
369
- */
370
- public static function get_astra_single_demo( $demo_api_uri ) {
371
-
372
- // default values.
373
- $remote_args = array();
374
- $defaults = array(
375
- 'id' => '',
376
- 'astra-site-widgets-data' => '',
377
- 'astra-site-customizer-data' => '',
378
- 'astra-site-options-data' => '',
379
- 'astra-post-data-mapping' => '',
380
- 'astra-site-wxr-path' => '',
381
- 'astra-site-wpforms-path' => '',
382
- 'astra-enabled-extensions' => '',
383
- 'astra-custom-404' => '',
384
- 'required-plugins' => '',
385
- 'astra-site-taxonomy-mapping' => '',
386
- );
387
-
388
- $api_args = apply_filters(
389
- 'astra_sites_api_args',
390
- array(
391
- 'timeout' => 15,
392
- )
393
- );
394
-
395
- // Use this for premium demos.
396
- $request_params = apply_filters(
397
- 'astra_sites_api_params',
398
- array(
399
- 'purchase_key' => '',
400
- 'site_url' => '',
401
- )
402
- );
403
-
404
- $demo_api_uri = add_query_arg( $request_params, $demo_api_uri );
405
-
406
- // API Call.
407
- $response = wp_remote_get( $demo_api_uri, $api_args );
408
-
409
- if ( is_wp_error( $response ) || ( isset( $response->status ) && 0 === $response->status ) ) {
410
- if ( isset( $response->status ) ) {
411
- $data = json_decode( $response, true );
412
- } else {
413
- return new WP_Error( 'api_invalid_response_code', $response->get_error_message() );
414
- }
415
- } else {
416
- $data = json_decode( wp_remote_retrieve_body( $response ), true );
417
- }
418
-
419
- $data = json_decode( wp_remote_retrieve_body( $response ), true );
420
-
421
- if ( ! isset( $data['code'] ) ) {
422
- $remote_args['id'] = $data['id'];
423
- $remote_args['astra-site-widgets-data'] = json_decode( $data['astra-site-widgets-data'] );
424
- $remote_args['astra-site-customizer-data'] = $data['astra-site-customizer-data'];
425
- $remote_args['astra-site-options-data'] = $data['astra-site-options-data'];
426
- $remote_args['astra-post-data-mapping'] = $data['astra-post-data-mapping'];
427
- $remote_args['astra-site-wxr-path'] = $data['astra-site-wxr-path'];
428
- $remote_args['astra-site-wpforms-path'] = $data['astra-site-wpforms-path'];
429
- $remote_args['astra-enabled-extensions'] = $data['astra-enabled-extensions'];
430
- $remote_args['astra-custom-404'] = $data['astra-custom-404'];
431
- $remote_args['required-plugins'] = $data['required-plugins'];
432
- $remote_args['astra-site-taxonomy-mapping'] = $data['astra-site-taxonomy-mapping'];
433
- }
434
-
435
- // Merge remote demo and defaults.
436
- return wp_parse_args( $remote_args, $defaults );
437
- }
438
-
439
- /**
440
- * Clear Cache.
441
- *
442
- * @since 1.0.9
443
- */
444
- public function clear_cache() {
445
- // Clear 'Elementor' file cache.
446
- if ( class_exists( '\Elementor\Plugin' ) ) {
447
- Elementor\Plugin::$instance->posts_css_manager->clear_cache();
448
- }
449
-
450
- // Clear 'Builder Builder' cache.
451
- if ( is_callable( 'FLBuilderModel::delete_asset_cache_for_all_posts' ) ) {
452
- FLBuilderModel::delete_asset_cache_for_all_posts();
453
- }
454
-
455
- // Clear 'Astra Addon' cache.
456
- if ( is_callable( 'Astra_Minify::refresh_assets' ) ) {
457
- Astra_Minify::refresh_assets();
458
- }
459
-
460
- Astra_Sites_Importer_Log::add( 'Complete ' );
461
- }
462
-
463
- /**
464
- * Reset customizer data
465
- *
466
- * @since 1.3.0
467
- * @return void
468
- */
469
- function reset_customizer_data() {
470
- Astra_Sites_Importer_Log::add( 'Deleted customizer Settings ' . json_encode( get_option( 'astra-settings', array() ) ) );
471
-
472
- delete_option( 'astra-settings' );
473
-
474
- wp_send_json_success();
475
- }
476
-
477
- /**
478
- * Reset site options
479
- *
480
- * @since 1.3.0
481
- * @return void
482
- */
483
- function reset_site_options() {
484
-
485
- $options = get_option( '_astra_sites_old_site_options', array() );
486
-
487
- Astra_Sites_Importer_Log::add( 'Deleted - Site Options ' . json_encode( $options ) );
488
-
489
- if ( $options ) {
490
- foreach ( $options as $option_key => $option_value ) {
491
- delete_option( $option_key );
492
- }
493
- }
494
-
495
- wp_send_json_success();
496
- }
497
-
498
- /**
499
- * Reset widgets data
500
- *
501
- * @since 1.3.0
502
- * @return void
503
- */
504
- function reset_widgets_data() {
505
- $old_widgets = get_option( '_astra_sites_old_widgets_data', array() );
506
-
507
- Astra_Sites_Importer_Log::add( 'DELETED - WIDGETS ' . json_encode( $old_widgets ) );
508
-
509
- if ( $old_widgets ) {
510
- $sidebars_widgets = get_option( 'sidebars_widgets', array() );
511
-
512
- foreach ( $old_widgets as $sidebar_id => $widgets ) {
513
-
514
- if ( $widgets ) {
515
- foreach ( $widgets as $widget_key => $widget_data ) {
516
-
517
- if ( isset( $sidebars_widgets['wp_inactive_widgets'] ) ) {
518
- if ( ! in_array( $widget_key, $sidebars_widgets['wp_inactive_widgets'], true ) ) {
519
- $sidebars_widgets['wp_inactive_widgets'][] = $widget_key;
520
- }
521
- }
522
- }
523
- }
524
- }
525
-
526
- update_option( 'sidebars_widgets', $sidebars_widgets );
527
- }
528
-
529
- wp_send_json_success();
530
- }
531
-
532
- /**
533
- * Delete imported posts
534
- *
535
- * @since 1.3.0
536
- * @return void
537
- */
538
- function delete_imported_posts() {
539
- $post_id = isset( $_REQUEST['post_id'] ) ? absint( $_REQUEST['post_id'] ) : '';
540
- $message = 'Deleted - Post ID ' . $post_id . ' - ' . get_post_type( $post_id ) . ' - ' . get_the_title( $post_id );
541
-
542
- Astra_Sites_Importer_Log::add( $message );
543
- wp_delete_post( $post_id, true );
544
-
545
- /* translators: %s is the post ID */
546
- wp_send_json_success( $message );
547
- }
548
-
549
- /**
550
- * Delete imported WP forms
551
- *
552
- * @since 1.3.0
553
- * @return void
554
- */
555
- function delete_imported_wp_forms() {
556
- $post_id = isset( $_REQUEST['post_id'] ) ? absint( $_REQUEST['post_id'] ) : '';
557
-
558
- $message = 'Deleted - Form ID ' . $post_id . ' - ' . get_post_type( $post_id ) . ' - ' . get_the_title( $post_id );
559
-
560
- Astra_Sites_Importer_Log::add( $message );
561
-
562
- wp_delete_post( $post_id, true );
563
-
564
- /* translators: %s is the form ID */
565
- wp_send_json_success( $message );
566
- }
567
-
568
- /**
569
- * Delete imported terms
570
- *
571
- * @since 1.3.0
572
- * @return void
573
- */
574
- function delete_imported_terms() {
575
-
576
- $term_id = isset( $_REQUEST['term_id'] ) ? absint( $_REQUEST['term_id'] ) : '';
577
-
578
- $message = '';
579
-
580
- if ( $term_id ) {
581
- $term = get_term( $term_id );
582
- if ( $term ) {
583
- $message = 'Deleted - Term ' . $term_id . ' - ' . $term->name . ' ' . $term->taxonomy;
584
- Astra_Sites_Importer_Log::add( $message );
585
- wp_delete_term( $term_id, $term->taxonomy );
586
- }
587
- }
588
-
589
- /* translators: %s is the term ID */
590
- wp_send_json_success( $message );
591
- }
592
-
593
- }
594
-
595
- /**
596
- * Kicking this off by calling 'get_instance()' method
597
- */
598
- Astra_Sites_Importer::get_instance();
599
-
600
- endif;
601
-
602
-
 
 
 
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
+ if ( version_compare( get_bloginfo( 'version' ), '5.1.0', '>=' ) ) {
82
+ add_filter( 'http_request_timeout', array( $this, 'set_timeout_for_images' ), 10, 2 );
83
+ }
84
+ }
85
+
86
+ /**
87
+ * Set the timeout for the HTTP request by request URL.
88
+ *
89
+ * 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.
90
+ *
91
+ * @since 1.3.8
92
+ *
93
+ * @param int $timeout_value Time in seconds until a request times out. Default 5.
94
+ * @param string $url The request URL.
95
+ */
96
+ function set_timeout_for_images( $timeout_value, $url ) {
97
+
98
+ // URL not contain `https://websitedemos.net` then return $timeout_value.
99
+ if ( strpos( $url, 'https://websitedemos.net' ) === false ) {
100
+ return $timeout_value;
101
+ }
102
+
103
+ // Check is image URL of type jpg|png|gif|jpeg.
104
+ if ( Astra_Sites_Image_Importer::get_instance()->is_image_url( $url ) ) {
105
+ $timeout_value = 30;
106
+ }
107
+ return $timeout_value;
108
+ }
109
+
110
+ /**
111
+ * Load WordPress WXR importer.
112
+ */
113
+ public function load_importer() {
114
+ require_once ASTRA_SITES_DIR . 'inc/importers/wxr-importer/class-astra-wxr-importer.php';
115
+ }
116
+
117
+ /**
118
+ * Start Site Import
119
+ *
120
+ * @since 1.1.0
121
+ * @return void
122
+ */
123
+ function import_start() {
124
+
125
+ if ( ! current_user_can( 'customize' ) ) {
126
+ wp_send_json_error( __( 'You have not "customize" access to import the Astra site.', 'astra-sites' ) );
127
+ }
128
+
129
+ $demo_api_uri = isset( $_POST['api_url'] ) ? esc_url( $_POST['api_url'] ) : '';
130
+
131
+ if ( ! empty( $demo_api_uri ) ) {
132
+
133
+ $demo_data = self::get_astra_single_demo( $demo_api_uri );
134
+ update_option( 'astra_sites_import_data', $demo_data );
135
+
136
+ if ( is_wp_error( $demo_data ) ) {
137
+ wp_send_json_error( $demo_data->get_error_message() );
138
+ } else {
139
+ $log_file = Astra_Sites_Importer_Log::add_log_file_url();
140
+ if ( isset( $log_file['url'] ) && ! empty( $log_file['url'] ) ) {
141
+ $demo_data['log_file'] = $log_file['url'];
142
+ }
143
+ do_action( 'astra_sites_import_start', $demo_data, $demo_api_uri );
144
+ }
145
+
146
+ wp_send_json_success( $demo_data );
147
+
148
+ } else {
149
+ wp_send_json_error( __( 'Request site API URL is empty. Try again!', 'astra-sites' ) );
150
+ }
151
+
152
+ }
153
+
154
+ /**
155
+ * Import WP Forms
156
+ *
157
+ * @since 1.2.14
158
+ *
159
+ * @return void
160
+ */
161
+ function import_wpforms() {
162
+
163
+ $wpforms_url = ( isset( $_REQUEST['wpforms_url'] ) ) ? urldecode( $_REQUEST['wpforms_url'] ) : '';
164
+ $ids_mapping = array();
165
+
166
+ if ( ! empty( $wpforms_url ) && function_exists( 'wpforms_encode' ) ) {
167
+
168
+ // Download XML file.
169
+ $xml_path = Astra_Sites_Helper::download_file( $wpforms_url );
170
+
171
+ if ( $xml_path['success'] ) {
172
+ if ( isset( $xml_path['data']['file'] ) ) {
173
+
174
+ $ext = strtolower( pathinfo( $xml_path['data']['file'], PATHINFO_EXTENSION ) );
175
+
176
+ if ( 'json' === $ext ) {
177
+ $forms = json_decode( file_get_contents( $xml_path['data']['file'] ), true );
178
+
179
+ if ( ! empty( $forms ) ) {
180
+
181
+ foreach ( $forms as $form ) {
182
+ $title = ! empty( $form['settings']['form_title'] ) ? $form['settings']['form_title'] : '';
183
+ $desc = ! empty( $form['settings']['form_desc'] ) ? $form['settings']['form_desc'] : '';
184
+
185
+ $new_id = post_exists( $title );
186
+
187
+ if ( ! $new_id ) {
188
+ $new_id = wp_insert_post(
189
+ array(
190
+ 'post_title' => $title,
191
+ 'post_status' => 'publish',
192
+ 'post_type' => 'wpforms',
193
+ 'post_excerpt' => $desc,
194
+ )
195
+ );
196
+
197
+ // Set meta for tracking the post.
198
+ update_post_meta( $new_id, '_astra_sites_imported_wp_forms', true );
199
+ Astra_Sites_Importer_Log::add( 'Inserted WP Form ' . $new_id );
200
+ }
201
+
202
+ if ( $new_id ) {
203
+
204
+ // ID mapping.
205
+ $ids_mapping[ $form['id'] ] = $new_id;
206
+
207
+ $form['id'] = $new_id;
208
+ wp_update_post(
209
+ array(
210
+ 'ID' => $new_id,
211
+ 'post_content' => wpforms_encode( $form ),
212
+ )
213
+ );
214
+ }
215
+ }
216
+ }
217
+ }
218
+ }
219
+ }
220
+ }
221
+
222
+ update_option( 'astra_sites_wpforms_ids_mapping', $ids_mapping );
223
+
224
+ wp_send_json_success( $ids_mapping );
225
+ }
226
+
227
+ /**
228
+ * Import Customizer Settings.
229
+ *
230
+ * @since 1.0.14
231
+ * @return void
232
+ */
233
+ function import_customizer_settings() {
234
+
235
+ $customizer_data = ( isset( $_POST['customizer_data'] ) ) ? (array) json_decode( stripcslashes( $_POST['customizer_data'] ), 1 ) : array();
236
+
237
+ if ( ! empty( $customizer_data ) ) {
238
+
239
+ Astra_Sites_Importer_Log::add( 'Imported Customizer Settings ' . json_encode( $customizer_data ) );
240
+
241
+ // Set meta for tracking the post.
242
+ update_option( '_astra_sites_old_customizer_data', $customizer_data );
243
+
244
+ Astra_Customizer_Import::instance()->import( $customizer_data );
245
+
246
+ wp_send_json_success( $customizer_data );
247
+
248
+ } else {
249
+ wp_send_json_error( __( 'Customizer data is empty!', 'astra-sites' ) );
250
+ }
251
+
252
+ }
253
+
254
+ /**
255
+ * Prepare XML Data.
256
+ *
257
+ * @since 1.1.0
258
+ * @return void
259
+ */
260
+ function prepare_xml_data() {
261
+
262
+ if ( ! class_exists( 'XMLReader' ) ) {
263
+ 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' ) );
264
+ }
265
+
266
+ $wxr_url = ( isset( $_REQUEST['wxr_url'] ) ) ? urldecode( $_REQUEST['wxr_url'] ) : '';
267
+
268
+ if ( isset( $wxr_url ) ) {
269
+
270
+ Astra_Sites_Importer_Log::add( 'Importing from XML ' . $wxr_url );
271
+
272
+ // Download XML file.
273
+ $xml_path = Astra_Sites_Helper::download_file( $wxr_url );
274
+
275
+ if ( $xml_path['success'] ) {
276
+ if ( isset( $xml_path['data']['file'] ) ) {
277
+ $data = Astra_WXR_Importer::instance()->get_xml_data( $xml_path['data']['file'] );
278
+ $data['xml'] = $xml_path['data'];
279
+ wp_send_json_success( $data );
280
+ } else {
281
+ wp_send_json_error( __( 'There was an error downloading the XML file.', 'astra-sites' ) );
282
+ }
283
+ } else {
284
+ wp_send_json_error( $xml_path['data'] );
285
+ }
286
+ } else {
287
+ wp_send_json_error( __( 'Invalid site XML file!', 'astra-sites' ) );
288
+ }
289
+
290
+ }
291
+
292
+ /**
293
+ * Import Options.
294
+ *
295
+ * @since 1.0.14
296
+ * @return void
297
+ */
298
+ function import_options() {
299
+
300
+ $options_data = ( isset( $_POST['options_data'] ) ) ? (array) json_decode( stripcslashes( $_POST['options_data'] ), 1 ) : '';
301
+
302
+ if ( ! empty( $options_data ) ) {
303
+
304
+ // Set meta for tracking the post.
305
+ if ( is_array( $options_data ) ) {
306
+ Astra_Sites_Importer_Log::add( 'Imported - Site Options ' . json_encode( $options_data ) );
307
+ update_option( '_astra_sites_old_site_options', $options_data );
308
+ }
309
+
310
+ $options_importer = Astra_Site_Options_Import::instance();
311
+ $options_importer->import_options( $options_data );
312
+ wp_send_json_success( $options_data );
313
+ } else {
314
+ wp_send_json_error( __( 'Site options are empty!', 'astra-sites' ) );
315
+ }
316
+
317
+ }
318
+
319
+ /**
320
+ * Import Widgets.
321
+ *
322
+ * @since 1.0.14
323
+ * @return void
324
+ */
325
+ function import_widgets() {
326
+
327
+ $widgets_data = ( isset( $_POST['widgets_data'] ) ) ? (object) json_decode( stripcslashes( $_POST['widgets_data'] ) ) : '';
328
+
329
+ Astra_Sites_Importer_Log::add( 'Imported - Widgets ' . json_encode( $widgets_data ) );
330
+
331
+ if ( ! empty( $widgets_data ) ) {
332
+
333
+ $widgets_importer = Astra_Widget_Importer::instance();
334
+ $status = $widgets_importer->import_widgets_data( $widgets_data );
335
+
336
+ // Set meta for tracking the post.
337
+ if ( is_object( $widgets_data ) ) {
338
+ $widgets_data = (array) $widgets_data;
339
+ update_option( '_astra_sites_old_widgets_data', $widgets_data );
340
+ }
341
+
342
+ wp_send_json_success( $widgets_data );
343
+ } else {
344
+ wp_send_json_error( __( 'Widget data is empty!', 'astra-sites' ) );
345
+ }
346
+
347
+ }
348
+
349
+ /**
350
+ * Import End.
351
+ *
352
+ * @since 1.0.14
353
+ * @return void
354
+ */
355
+ function import_end() {
356
+ do_action( 'astra_sites_import_complete' );
357
+ }
358
+
359
+
360
+ /**
361
+ * Get single demo.
362
+ *
363
+ * @since 1.0.0
364
+ *
365
+ * @param (String) $demo_api_uri API URL of a demo.
366
+ *
367
+ * @return (Array) $astra_demo_data demo data for the demo.
368
+ */
369
+ public static function get_astra_single_demo( $demo_api_uri ) {
370
+
371
+ // default values.
372
+ $remote_args = array();
373
+ $defaults = array(
374
+ 'id' => '',
375
+ 'astra-site-widgets-data' => '',
376
+ 'astra-site-customizer-data' => '',
377
+ 'astra-site-options-data' => '',
378
+ 'astra-post-data-mapping' => '',
379
+ 'astra-site-wxr-path' => '',
380
+ 'astra-site-wpforms-path' => '',
381
+ 'astra-enabled-extensions' => '',
382
+ 'astra-custom-404' => '',
383
+ 'required-plugins' => '',
384
+ 'astra-site-taxonomy-mapping' => '',
385
+ );
386
+
387
+ $api_args = apply_filters(
388
+ 'astra_sites_api_args',
389
+ array(
390
+ 'timeout' => 15,
391
+ )
392
+ );
393
+
394
+ // Use this for premium demos.
395
+ $request_params = apply_filters(
396
+ 'astra_sites_api_params',
397
+ array(
398
+ 'purchase_key' => '',
399
+ 'site_url' => '',
400
+ )
401
+ );
402
+
403
+ $demo_api_uri = add_query_arg( $request_params, $demo_api_uri );
404
+
405
+ // API Call.
406
+ $response = wp_remote_get( $demo_api_uri, $api_args );
407
+
408
+ if ( is_wp_error( $response ) || ( isset( $response->status ) && 0 === $response->status ) ) {
409
+ if ( isset( $response->status ) ) {
410
+ $data = json_decode( $response, true );
411
+ } else {
412
+ return new WP_Error( 'api_invalid_response_code', $response->get_error_message() );
413
+ }
414
+ }
415
+
416
+ if ( wp_remote_retrieve_response_code( $response ) !== 200 ) {
417
+ return new WP_Error( 'api_invalid_response_code', wp_remote_retrieve_body( $response ) );
418
+ } else {
419
+ $data = json_decode( wp_remote_retrieve_body( $response ), true );
420
+ }
421
+
422
+ $data = json_decode( wp_remote_retrieve_body( $response ), true );
423
+
424
+ if ( ! isset( $data['code'] ) ) {
425
+ $remote_args['id'] = $data['id'];
426
+ $remote_args['astra-site-widgets-data'] = json_decode( $data['astra-site-widgets-data'] );
427
+ $remote_args['astra-site-customizer-data'] = $data['astra-site-customizer-data'];
428
+ $remote_args['astra-site-options-data'] = $data['astra-site-options-data'];
429
+ $remote_args['astra-post-data-mapping'] = $data['astra-post-data-mapping'];
430
+ $remote_args['astra-site-wxr-path'] = $data['astra-site-wxr-path'];
431
+ $remote_args['astra-site-wpforms-path'] = $data['astra-site-wpforms-path'];
432
+ $remote_args['astra-enabled-extensions'] = $data['astra-enabled-extensions'];
433
+ $remote_args['astra-custom-404'] = $data['astra-custom-404'];
434
+ $remote_args['required-plugins'] = $data['required-plugins'];
435
+ $remote_args['astra-site-taxonomy-mapping'] = $data['astra-site-taxonomy-mapping'];
436
+ }
437
+
438
+ // Merge remote demo and defaults.
439
+ return wp_parse_args( $remote_args, $defaults );
440
+ }
441
+
442
+ /**
443
+ * Clear Cache.
444
+ *
445
+ * @since 1.0.9
446
+ */
447
+ public function clear_cache() {
448
+ // Clear 'Elementor' file cache.
449
+ if ( class_exists( '\Elementor\Plugin' ) ) {
450
+ Elementor\Plugin::$instance->posts_css_manager->clear_cache();
451
+ }
452
+
453
+ // Clear 'Builder Builder' cache.
454
+ if ( is_callable( 'FLBuilderModel::delete_asset_cache_for_all_posts' ) ) {
455
+ FLBuilderModel::delete_asset_cache_for_all_posts();
456
+ }
457
+
458
+ // Clear 'Astra Addon' cache.
459
+ if ( is_callable( 'Astra_Minify::refresh_assets' ) ) {
460
+ Astra_Minify::refresh_assets();
461
+ }
462
+
463
+ Astra_Sites_Importer_Log::add( 'Complete ' );
464
+ }
465
+
466
+ /**
467
+ * Reset customizer data
468
+ *
469
+ * @since 1.3.0
470
+ * @return void
471
+ */
472
+ function reset_customizer_data() {
473
+ Astra_Sites_Importer_Log::add( 'Deleted customizer Settings ' . json_encode( get_option( 'astra-settings', array() ) ) );
474
+
475
+ delete_option( 'astra-settings' );
476
+
477
+ wp_send_json_success();
478
+ }
479
+
480
+ /**
481
+ * Reset site options
482
+ *
483
+ * @since 1.3.0
484
+ * @return void
485
+ */
486
+ function reset_site_options() {
487
+
488
+ $options = get_option( '_astra_sites_old_site_options', array() );
489
+
490
+ Astra_Sites_Importer_Log::add( 'Deleted - Site Options ' . json_encode( $options ) );
491
+
492
+ if ( $options ) {
493
+ foreach ( $options as $option_key => $option_value ) {
494
+ delete_option( $option_key );
495
+ }
496
+ }
497
+
498
+ wp_send_json_success();
499
+ }
500
+
501
+ /**
502
+ * Reset widgets data
503
+ *
504
+ * @since 1.3.0
505
+ * @return void
506
+ */
507
+ function reset_widgets_data() {
508
+ $old_widgets = get_option( '_astra_sites_old_widgets_data', array() );
509
+
510
+ Astra_Sites_Importer_Log::add( 'DELETED - WIDGETS ' . json_encode( $old_widgets ) );
511
+
512
+ if ( $old_widgets ) {
513
+ $sidebars_widgets = get_option( 'sidebars_widgets', array() );
514
+
515
+ foreach ( $old_widgets as $sidebar_id => $widgets ) {
516
+
517
+ if ( $widgets ) {
518
+ foreach ( $widgets as $widget_key => $widget_data ) {
519
+
520
+ if ( isset( $sidebars_widgets['wp_inactive_widgets'] ) ) {
521
+ if ( ! in_array( $widget_key, $sidebars_widgets['wp_inactive_widgets'], true ) ) {
522
+ $sidebars_widgets['wp_inactive_widgets'][] = $widget_key;
523
+ }
524
+ }
525
+ }
526
+ }
527
+ }
528
+
529
+ update_option( 'sidebars_widgets', $sidebars_widgets );
530
+ }
531
+
532
+ wp_send_json_success();
533
+ }
534
+
535
+ /**
536
+ * Delete imported posts
537
+ *
538
+ * @since 1.3.0
539
+ * @return void
540
+ */
541
+ function delete_imported_posts() {
542
+ $post_id = isset( $_REQUEST['post_id'] ) ? absint( $_REQUEST['post_id'] ) : '';
543
+ $message = 'Deleted - Post ID ' . $post_id . ' - ' . get_post_type( $post_id ) . ' - ' . get_the_title( $post_id );
544
+
545
+ Astra_Sites_Importer_Log::add( $message );
546
+ wp_delete_post( $post_id, true );
547
+
548
+ /* translators: %s is the post ID */
549
+ wp_send_json_success( $message );
550
+ }
551
+
552
+ /**
553
+ * Delete imported WP forms
554
+ *
555
+ * @since 1.3.0
556
+ * @return void
557
+ */
558
+ function delete_imported_wp_forms() {
559
+ $post_id = isset( $_REQUEST['post_id'] ) ? absint( $_REQUEST['post_id'] ) : '';
560
+
561
+ $message = 'Deleted - Form ID ' . $post_id . ' - ' . get_post_type( $post_id ) . ' - ' . get_the_title( $post_id );
562
+
563
+ Astra_Sites_Importer_Log::add( $message );
564
+
565
+ wp_delete_post( $post_id, true );
566
+
567
+ /* translators: %s is the form ID */
568
+ wp_send_json_success( $message );
569
+ }
570
+
571
+ /**
572
+ * Delete imported terms
573
+ *
574
+ * @since 1.3.0
575
+ * @return void
576
+ */
577
+ function delete_imported_terms() {
578
+
579
+ $term_id = isset( $_REQUEST['term_id'] ) ? absint( $_REQUEST['term_id'] ) : '';
580
+
581
+ $message = '';
582
+
583
+ if ( $term_id ) {
584
+ $term = get_term( $term_id );
585
+ if ( $term ) {
586
+ $message = 'Deleted - Term ' . $term_id . ' - ' . $term->name . ' ' . $term->taxonomy;
587
+ Astra_Sites_Importer_Log::add( $message );
588
+ wp_delete_term( $term_id, $term->taxonomy );
589
+ }
590
+ }
591
+
592
+ /* translators: %s is the term ID */
593
+ wp_send_json_success( $message );
594
+ }
595
+
596
+ }
597
+
598
+ /**
599
+ * Kicking this off by calling 'get_instance()' method
600
+ */
601
+ Astra_Sites_Importer::get_instance();
602
+
603
+ endif;
604
+
605
+
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-white-label.php CHANGED
@@ -1,239 +1,239 @@
1
- <?php
2
- /**
3
- * Astra Sites White Label
4
- *
5
- * @package Astra Sites
6
- * @since 1.0.12
7
- */
8
-
9
- if ( ! class_exists( 'Astra_Sites_White_Label' ) ) :
10
-
11
- /**
12
- * Astra_Sites_White_Label
13
- *
14
- * @since 1.0.12
15
- */
16
- class Astra_Sites_White_Label {
17
-
18
- /**
19
- * Instance
20
- *
21
- * @since 1.0.12
22
- *
23
- * @var object Class Object.
24
- * @access private
25
- */
26
- private static $instance;
27
-
28
- /**
29
- * Member Variable
30
- *
31
- * @since 1.0.12
32
- *
33
- * @var array branding
34
- * @access private
35
- */
36
- private static $branding;
37
-
38
- /**
39
- * Settings
40
- *
41
- * @since 1.2.11
42
- *
43
- * @var array settings
44
- *
45
- * @access private
46
- */
47
- private $settings;
48
-
49
- /**
50
- * Initiator
51
- *
52
- * @since 1.0.12
53
- *
54
- * @return object initialized object of class.
55
- */
56
- public static function get_instance() {
57
- if ( ! isset( self::$instance ) ) {
58
- self::$instance = new self;
59
- }
60
- return self::$instance;
61
- }
62
-
63
- /**
64
- * Constructor
65
- *
66
- * @since 1.0.12
67
- */
68
- public function __construct() {
69
- add_filter( 'all_plugins', array( $this, 'plugins_page' ) );
70
- add_filter( 'astra_addon_branding_options', __CLASS__ . '::settings' );
71
- add_action( 'astra_pro_white_label_add_form', __CLASS__ . '::add_white_lavel_form' );
72
- add_filter( 'astra_sites_menu_page_title', array( $this, 'page_title' ) );
73
- add_filter( 'astra_sites_page_title', array( $this, 'page_title' ) );
74
-
75
- // Display the link with the plugin meta.
76
- if ( is_admin() ) {
77
- add_filter( 'plugin_row_meta', array( $this, 'plugin_links' ), 10, 4 );
78
- }
79
- }
80
-
81
- /**
82
- * White labels the plugins page.
83
- *
84
- * @since 1.0.12
85
- *
86
- * @param array $plugins Plugins Array.
87
- * @return array
88
- */
89
- function plugins_page( $plugins ) {
90
-
91
- if ( ! is_callable( 'Astra_Ext_White_Label_Markup::get_whitelabel_string' ) ) {
92
- return $plugins;
93
- }
94
-
95
- if ( ! isset( $plugins[ ASTRA_SITES_BASE ] ) ) {
96
- return $plugins;
97
- }
98
-
99
- // Set White Labels.
100
- $name = Astra_Ext_White_Label_Markup::get_whitelabel_string( 'astra-sites', 'name' );
101
- $description = Astra_Ext_White_Label_Markup::get_whitelabel_string( 'astra-sites', 'description' );
102
- $author = Astra_Ext_White_Label_Markup::get_whitelabel_string( 'astra-agency', 'author' );
103
- $author_uri = Astra_Ext_White_Label_Markup::get_whitelabel_string( 'astra-agency', 'author_url' );
104
-
105
- if ( ! empty( $name ) ) {
106
- $plugins[ ASTRA_SITES_BASE ]['Name'] = $name;
107
-
108
- // Remove Plugin URI if Agency White Label name is set.
109
- $plugins[ ASTRA_SITES_BASE ]['PluginURI'] = '';
110
- }
111
-
112
- if ( ! empty( $description ) ) {
113
- $plugins[ ASTRA_SITES_BASE ]['Description'] = $description;
114
- }
115
-
116
- if ( ! empty( $author ) ) {
117
- $plugins[ ASTRA_SITES_BASE ]['Author'] = $author;
118
- }
119
-
120
- if ( ! empty( $author_uri ) ) {
121
- $plugins[ ASTRA_SITES_BASE ]['AuthorURI'] = $author_uri;
122
- }
123
-
124
- return $plugins;
125
- }
126
-
127
- /**
128
- * Remove a "view details" link from the plugin list table
129
- *
130
- * @since 1.0.12
131
- *
132
- * @param array $plugin_meta List of links.
133
- * @param string $plugin_file Relative path to the main plugin file from the plugins directory.
134
- * @param array $plugin_data Data from the plugin headers.
135
- * @return array
136
- */
137
- public function plugin_links( $plugin_meta, $plugin_file, $plugin_data ) {
138
-
139
- if ( ! is_callable( 'Astra_Ext_White_Label_Markup::get_whitelabel_string' ) ) {
140
- return $plugin_meta;
141
- }
142
-
143
- // Set White Labels.
144
- if ( ASTRA_SITES_BASE === $plugin_file ) {
145
-
146
- $name = Astra_Ext_White_Label_Markup::get_whitelabel_string( 'astra-sites', 'name' );
147
- $description = Astra_Ext_White_Label_Markup::get_whitelabel_string( 'astra-sites', 'description' );
148
-
149
- // Remove Plugin URI if Agency White Label name is set.
150
- if ( ! empty( $name ) ) {
151
- unset( $plugin_meta[2] );
152
- }
153
- }
154
-
155
- return $plugin_meta;
156
- }
157
-
158
- /**
159
- * Add White Label setting's
160
- *
161
- * @since 1.0.12
162
- *
163
- * @param array $settings White label setting.
164
- * @return array
165
- */
166
- public static function settings( $settings = array() ) {
167
-
168
- $settings['astra-sites'] = array(
169
- 'name' => '',
170
- 'description' => '',
171
- );
172
-
173
- return $settings;
174
- }
175
-
176
- /**
177
- * Add White Label form
178
- *
179
- * @since 1.0.12
180
- *
181
- * @param array $settings White label setting.
182
- * @return void
183
- */
184
- public static function add_white_lavel_form( $settings = array() ) {
185
-
186
- /* translators: %1$s product name */
187
- $plugin_name = sprintf( __( '%1$s Branding', 'astra-sites' ), ASTRA_SITES_NAME );
188
-
189
- require_once ASTRA_SITES_DIR . 'inc/includes/white-label.php';
190
- }
191
-
192
- /**
193
- * Page Title
194
- *
195
- * @since 1.0.12
196
- *
197
- * @param string $title Page Title.
198
- * @return string Filtered Page Title.
199
- */
200
- function page_title( $title = '' ) {
201
-
202
- if ( is_callable( 'Astra_Ext_White_Label_Markup::get_whitelabel_string' ) ) {
203
- $astra_sites_name = Astra_Ext_White_Label_Markup::get_whitelabel_string( 'astra-sites', 'name' );
204
- if ( ! empty( $astra_sites_name ) ) {
205
- $title = Astra_Ext_White_Label_Markup::get_whitelabel_string( 'astra-sites', 'name' );
206
- }
207
- }
208
-
209
- return $title;
210
- }
211
-
212
- /**
213
- * Is Astra sites White labeled
214
- *
215
- * @since 1.2.13
216
- *
217
- * @return string
218
- */
219
- function is_white_labeled() {
220
- if ( ! is_callable( 'Astra_Ext_White_Label_Markup::get_whitelabel_string' ) ) {
221
- return false;
222
- }
223
-
224
- $astra_sites_name = Astra_Ext_White_Label_Markup::get_whitelabel_string( 'astra-sites', 'name' );
225
- if ( empty( $astra_sites_name ) ) {
226
- return false;
227
- }
228
-
229
- return true;
230
- }
231
-
232
- }
233
-
234
- /**
235
- * Kicking this off by calling 'get_instance()' method
236
- */
237
- Astra_Sites_White_Label::get_instance();
238
-
239
- endif;
1
+ <?php
2
+ /**
3
+ * Astra Sites White Label
4
+ *
5
+ * @package Astra Sites
6
+ * @since 1.0.12
7
+ */
8
+
9
+ if ( ! class_exists( 'Astra_Sites_White_Label' ) ) :
10
+
11
+ /**
12
+ * Astra_Sites_White_Label
13
+ *
14
+ * @since 1.0.12
15
+ */
16
+ class Astra_Sites_White_Label {
17
+
18
+ /**
19
+ * Instance
20
+ *
21
+ * @since 1.0.12
22
+ *
23
+ * @var object Class Object.
24
+ * @access private
25
+ */
26
+ private static $instance;
27
+
28
+ /**
29
+ * Member Variable
30
+ *
31
+ * @since 1.0.12
32
+ *
33
+ * @var array branding
34
+ * @access private
35
+ */
36
+ private static $branding;
37
+
38
+ /**
39
+ * Settings
40
+ *
41
+ * @since 1.2.11
42
+ *
43
+ * @var array settings
44
+ *
45
+ * @access private
46
+ */
47
+ private $settings;
48
+
49
+ /**
50
+ * Initiator
51
+ *
52
+ * @since 1.0.12
53
+ *
54
+ * @return object initialized object of class.
55
+ */
56
+ public static function get_instance() {
57
+ if ( ! isset( self::$instance ) ) {
58
+ self::$instance = new self;
59
+ }
60
+ return self::$instance;
61
+ }
62
+
63
+ /**
64
+ * Constructor
65
+ *
66
+ * @since 1.0.12
67
+ */
68
+ public function __construct() {
69
+ add_filter( 'all_plugins', array( $this, 'plugins_page' ) );
70
+ add_filter( 'astra_addon_branding_options', __CLASS__ . '::settings' );
71
+ add_action( 'astra_pro_white_label_add_form', __CLASS__ . '::add_white_lavel_form' );
72
+ add_filter( 'astra_sites_menu_page_title', array( $this, 'page_title' ) );
73
+ add_filter( 'astra_sites_page_title', array( $this, 'page_title' ) );
74
+
75
+ // Display the link with the plugin meta.
76
+ if ( is_admin() ) {
77
+ add_filter( 'plugin_row_meta', array( $this, 'plugin_links' ), 10, 4 );
78
+ }
79
+ }
80
+
81
+ /**
82
+ * White labels the plugins page.
83
+ *
84
+ * @since 1.0.12
85
+ *
86
+ * @param array $plugins Plugins Array.
87
+ * @return array
88
+ */
89
+ function plugins_page( $plugins ) {
90
+
91
+ if ( ! is_callable( 'Astra_Ext_White_Label_Markup::get_whitelabel_string' ) ) {
92
+ return $plugins;
93
+ }
94
+
95
+ if ( ! isset( $plugins[ ASTRA_SITES_BASE ] ) ) {
96
+ return $plugins;
97
+ }
98
+
99
+ // Set White Labels.
100
+ $name = Astra_Ext_White_Label_Markup::get_whitelabel_string( 'astra-sites', 'name' );
101
+ $description = Astra_Ext_White_Label_Markup::get_whitelabel_string( 'astra-sites', 'description' );
102
+ $author = Astra_Ext_White_Label_Markup::get_whitelabel_string( 'astra-agency', 'author' );
103
+ $author_uri = Astra_Ext_White_Label_Markup::get_whitelabel_string( 'astra-agency', 'author_url' );
104
+
105
+ if ( ! empty( $name ) ) {
106
+ $plugins[ ASTRA_SITES_BASE ]['Name'] = $name;
107
+
108
+ // Remove Plugin URI if Agency White Label name is set.
109
+ $plugins[ ASTRA_SITES_BASE ]['PluginURI'] = '';
110
+ }
111
+
112
+ if ( ! empty( $description ) ) {
113
+ $plugins[ ASTRA_SITES_BASE ]['Description'] = $description;
114
+ }
115
+
116
+ if ( ! empty( $author ) ) {
117
+ $plugins[ ASTRA_SITES_BASE ]['Author'] = $author;
118
+ }
119
+
120
+ if ( ! empty( $author_uri ) ) {
121
+ $plugins[ ASTRA_SITES_BASE ]['AuthorURI'] = $author_uri;
122
+ }
123
+
124
+ return $plugins;
125
+ }
126
+
127
+ /**
128
+ * Remove a "view details" link from the plugin list table
129
+ *
130
+ * @since 1.0.12
131
+ *
132
+ * @param array $plugin_meta List of links.
133
+ * @param string $plugin_file Relative path to the main plugin file from the plugins directory.
134
+ * @param array $plugin_data Data from the plugin headers.
135
+ * @return array
136
+ */
137
+ public function plugin_links( $plugin_meta, $plugin_file, $plugin_data ) {
138
+
139
+ if ( ! is_callable( 'Astra_Ext_White_Label_Markup::get_whitelabel_string' ) ) {
140
+ return $plugin_meta;
141
+ }
142
+
143
+ // Set White Labels.
144
+ if ( ASTRA_SITES_BASE === $plugin_file ) {
145
+
146
+ $name = Astra_Ext_White_Label_Markup::get_whitelabel_string( 'astra-sites', 'name' );
147
+ $description = Astra_Ext_White_Label_Markup::get_whitelabel_string( 'astra-sites', 'description' );
148
+
149
+ // Remove Plugin URI if Agency White Label name is set.
150
+ if ( ! empty( $name ) ) {
151
+ unset( $plugin_meta[2] );
152
+ }
153
+ }
154
+
155
+ return $plugin_meta;
156
+ }
157
+
158
+ /**
159
+ * Add White Label setting's
160
+ *
161
+ * @since 1.0.12
162
+ *
163
+ * @param array $settings White label setting.
164
+ * @return array
165
+ */
166
+ public static function settings( $settings = array() ) {
167
+
168
+ $settings['astra-sites'] = array(
169
+ 'name' => '',
170
+ 'description' => '',
171
+ );
172
+
173
+ return $settings;
174
+ }
175
+
176
+ /**
177
+ * Add White Label form
178
+ *
179
+ * @since 1.0.12
180
+ *
181
+ * @param array $settings White label setting.
182
+ * @return void
183
+ */
184
+ public static function add_white_lavel_form( $settings = array() ) {
185
+
186
+ /* translators: %1$s product name */
187
+ $plugin_name = sprintf( __( '%1$s Branding', 'astra-sites' ), ASTRA_SITES_NAME );
188
+
189
+ require_once ASTRA_SITES_DIR . 'inc/includes/white-label.php';
190
+ }
191
+
192
+ /**
193
+ * Page Title
194
+ *
195
+ * @since 1.0.12
196
+ *
197
+ * @param string $title Page Title.
198
+ * @return string Filtered Page Title.
199
+ */
200
+ function page_title( $title = '' ) {
201
+
202
+ if ( is_callable( 'Astra_Ext_White_Label_Markup::get_whitelabel_string' ) ) {
203
+ $astra_sites_name = Astra_Ext_White_Label_Markup::get_whitelabel_string( 'astra-sites', 'name' );
204
+ if ( ! empty( $astra_sites_name ) ) {
205
+ $title = Astra_Ext_White_Label_Markup::get_whitelabel_string( 'astra-sites', 'name' );
206
+ }
207
+ }
208
+
209
+ return $title;
210
+ }
211
+
212
+ /**
213
+ * Is Astra sites White labeled
214
+ *
215
+ * @since 1.2.13
216
+ *
217
+ * @return string
218
+ */
219
+ function is_white_labeled() {
220
+ if ( ! is_callable( 'Astra_Ext_White_Label_Markup::get_whitelabel_string' ) ) {
221
+ return false;
222
+ }
223
+
224
+ $astra_sites_name = Astra_Ext_White_Label_Markup::get_whitelabel_string( 'astra-sites', 'name' );
225
+ if ( empty( $astra_sites_name ) ) {
226
+ return false;
227
+ }
228
+
229
+ return true;
230
+ }
231
+
232
+ }
233
+
234
+ /**
235
+ * Kicking this off by calling 'get_instance()' method
236
+ */
237
+ Astra_Sites_White_Label::get_instance();
238
+
239
+ endif;
inc/classes/class-astra-sites.php CHANGED
@@ -359,7 +359,7 @@ if ( ! class_exists( 'Astra_Sites' ) ) :
359
  'btnActivating' => __( 'Activating', 'astra-sites' ) . '&hellip;',
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' ) . '&hellip;',
359
  'btnActivating' => __( 'Activating', 'astra-sites' ) . '&hellip;',
360
  'btnActive' => __( 'Active', 'astra-sites' ),
361
  'importFailBtn' => __( 'Import failed.', 'astra-sites' ),
362
+ 'importFailBtnLarge' => __( 'Import failed.', 'astra-sites' ),
363
  'importDemo' => __( 'Import This Site', 'astra-sites' ),
364
  'importingDemo' => __( 'Importing..', 'astra-sites' ),
365
  'DescExpand' => __( 'Read more', 'astra-sites' ) . '&hellip;',
inc/classes/compatibility/class-astra-sites-compatibility.php CHANGED
@@ -1,69 +1,69 @@
1
- <?php
2
- /**
3
- * Astra Sites Compatibility for 3rd party plugins.
4
- *
5
- * @package Astra Sites
6
- * @since 1.0.11
7
- */
8
-
9
- if ( ! class_exists( 'Astra_Sites_Compatibility' ) ) :
10
-
11
- /**
12
- * Astra Sites Compatibility
13
- *
14
- * @since 1.0.11
15
- */
16
- class Astra_Sites_Compatibility {
17
-
18
- /**
19
- * Instance
20
- *
21
- * @access private
22
- * @var object Class object.
23
- * @since 1.0.11
24
- */
25
- private static $instance;
26
-
27
- /**
28
- * Initiator
29
- *
30
- * @since 1.0.11
31
- * @return object initialized object of class.
32
- */
33
- public static function instance() {
34
- if ( ! isset( self::$instance ) ) {
35
- self::$instance = new self;
36
- }
37
- return self::$instance;
38
- }
39
-
40
- /**
41
- * Constructor
42
- *
43
- * @since 1.0.11
44
- */
45
- public function __construct() {
46
-
47
- // Plugin - Astra Pro.
48
- require_once ASTRA_SITES_DIR . 'inc/classes/compatibility/astra-pro/class-astra-sites-compatibility-astra-pro.php';
49
-
50
- // Plugin - Site Origin Widgets.
51
- require_once ASTRA_SITES_DIR . 'inc/classes/compatibility/so-widgets-bundle/class-astra-sites-compatibility-so-widgets.php';
52
-
53
- // Plugin - WooCommerce.
54
- require_once ASTRA_SITES_DIR . 'inc/classes/compatibility/woocommerce/class-astra-sites-compatibility-woocommerce.php';
55
-
56
- // Plugin - LearnDash LMS.
57
- require_once ASTRA_SITES_DIR . 'inc/classes/compatibility/sfwd-lms/class-astra-sites-compatibility-sfwd-lms.php';
58
- }
59
-
60
- }
61
-
62
- /**
63
- * Kicking this off by calling 'instance()' method
64
- */
65
- Astra_Sites_Compatibility::instance();
66
-
67
- endif;
68
-
69
-
1
+ <?php
2
+ /**
3
+ * Astra Sites Compatibility for 3rd party plugins.
4
+ *
5
+ * @package Astra Sites
6
+ * @since 1.0.11
7
+ */
8
+
9
+ if ( ! class_exists( 'Astra_Sites_Compatibility' ) ) :
10
+
11
+ /**
12
+ * Astra Sites Compatibility
13
+ *
14
+ * @since 1.0.11
15
+ */
16
+ class Astra_Sites_Compatibility {
17
+
18
+ /**
19
+ * Instance
20
+ *
21
+ * @access private
22
+ * @var object Class object.
23
+ * @since 1.0.11
24
+ */
25
+ private static $instance;
26
+
27
+ /**
28
+ * Initiator
29
+ *
30
+ * @since 1.0.11
31
+ * @return object initialized object of class.
32
+ */
33
+ public static function instance() {
34
+ if ( ! isset( self::$instance ) ) {
35
+ self::$instance = new self;
36
+ }
37
+ return self::$instance;
38
+ }
39
+
40
+ /**
41
+ * Constructor
42
+ *
43
+ * @since 1.0.11
44
+ */
45
+ public function __construct() {
46
+
47
+ // Plugin - Astra Pro.
48
+ require_once ASTRA_SITES_DIR . 'inc/classes/compatibility/astra-pro/class-astra-sites-compatibility-astra-pro.php';
49
+
50
+ // Plugin - Site Origin Widgets.
51
+ require_once ASTRA_SITES_DIR . 'inc/classes/compatibility/so-widgets-bundle/class-astra-sites-compatibility-so-widgets.php';
52
+
53
+ // Plugin - WooCommerce.
54
+ require_once ASTRA_SITES_DIR . 'inc/classes/compatibility/woocommerce/class-astra-sites-compatibility-woocommerce.php';
55
+
56
+ // Plugin - LearnDash LMS.
57
+ require_once ASTRA_SITES_DIR . 'inc/classes/compatibility/sfwd-lms/class-astra-sites-compatibility-sfwd-lms.php';
58
+ }
59
+
60
+ }
61
+
62
+ /**
63
+ * Kicking this off by calling 'instance()' method
64
+ */
65
+ Astra_Sites_Compatibility::instance();
66
+
67
+ endif;
68
+
69
+
inc/importers/batch-processing/class-astra-sites-batch-processing-beaver-builder.php CHANGED
@@ -1,261 +1,261 @@
1
- <?php
2
- /**
3
- * Batch Processing
4
- *
5
- * @package Astra Sites
6
- * @since 1.0.14
7
- */
8
-
9
- if ( ! class_exists( 'Astra_Sites_Batch_Processing_Beaver_Builder' ) ) :
10
-
11
- /**
12
- * Astra_Sites_Batch_Processing_Beaver_Builder
13
- *
14
- * @since 1.0.14
15
- */
16
- class Astra_Sites_Batch_Processing_Beaver_Builder {
17
-
18
- /**
19
- * Instance
20
- *
21
- * @since 1.0.14
22
- * @access private
23
- * @var object Class object.
24
- */
25
- private static $instance;
26
-
27
- /**
28
- * Initiator
29
- *
30
- * @since 1.0.14
31
- * @return object initialized object of class.
32
- */
33
- public static function get_instance() {
34
-
35
- if ( ! isset( self::$instance ) ) {
36
- self::$instance = new self;
37
- }
38
- return self::$instance;
39
- }
40
-
41
- /**
42
- * Constructor
43
- *
44
- * @since 1.0.14
45
- */
46
- public function __construct() {
47
- }
48
-
49
- /**
50
- * Import
51
- *
52
- * @since 1.0.14
53
- * @return void
54
- */
55
- public function import() {
56
-
57
- Astra_Sites_Importer_Log::add( '---- Processing WordPress Posts / Pages - for Beaver Builder ----' );
58
- if ( ! is_callable( 'FLBuilderModel::get_post_types' ) ) {
59
- return;
60
- }
61
-
62
- $post_types = FLBuilderModel::get_post_types( 'post-types' );
63
- if ( empty( $post_types ) && ! is_array( $post_types ) ) {
64
- return;
65
- }
66
-
67
- $post_ids = Astra_Sites_Batch_Processing::get_pages( $post_types );
68
- if ( empty( $post_ids ) && ! is_array( $post_ids ) ) {
69
- return;
70
- }
71
-
72
- foreach ( $post_ids as $post_id ) {
73
- $is_bb_post = get_post_meta( $post_id, '_fl_builder_enabled', true );
74
- if ( $is_bb_post ) {
75
- $this->import_single_post( $post_id );
76
- }
77
- }
78
- }
79
-
80
- /**
81
- * Update post meta.
82
- *
83
- * @param integer $post_id Post ID.
84
- * @return void
85
- */
86
- public function import_single_post( $post_id = 0 ) {
87
-
88
- Astra_Sites_Importer_Log::add( 'Post ID: ' . $post_id );
89
- if ( ! empty( $post_id ) ) {
90
-
91
- // Get page builder data.
92
- $data = get_post_meta( $post_id, '_fl_builder_data', true );
93
-
94
- if ( ! empty( $data ) ) {
95
- foreach ( $data as $key => $el ) {
96
-
97
- // Update 'row' images.
98
- if ( 'row' === $el->type ) {
99
- $data[ $key ]->settings = self::update_row( $el->settings );
100
- }
101
-
102
- // Update 'module' images.
103
- if ( 'module' === $el->type ) {
104
- $data[ $key ]->settings = self::update_module( $el->settings );
105
- }
106
-
107
- // Update 'column' images.
108
- if ( 'column' === $el->type ) {
109
- $data[ $key ]->settings = self::update_column( $el->settings );
110
- }
111
- }
112
-
113
- // Update page builder data.
114
- update_post_meta( $post_id, '_fl_builder_data', $data );
115
- update_post_meta( $post_id, '_fl_builder_draft', $data );
116
-
117
- // Clear all cache.
118
- FLBuilderModel::delete_asset_cache_for_all_posts();
119
- }
120
- }
121
-
122
- }
123
-
124
- /**
125
- * Import Module Images.
126
- *
127
- * @param object $settings Module settings object.
128
- * @return object
129
- */
130
- public static function update_module( $settings ) {
131
-
132
- // 1) Set photos.
133
- $settings = self::import_photo( $settings );
134
-
135
- /**
136
- * 2) Set `$settings->data` for Only type 'image-icon'
137
- *
138
- * @todo Remove the condition `'image-icon' === $settings->type` if `$settings->data` is used only for the Image Icon.
139
- */
140
- if (
141
- isset( $settings->data ) &&
142
- isset( $settings->photo ) && ! empty( $settings->photo ) &&
143
- 'image-icon' === $settings->type
144
- ) {
145
- $settings->data = FLBuilderPhoto::get_attachment_data( $settings->photo );
146
- }
147
-
148
- // 3) Set `list item` module images.
149
- if ( isset( $settings->add_list_item ) ) {
150
- foreach ( $settings->add_list_item as $key => $value ) {
151
- $settings->add_list_item[ $key ] = self::import_photo( $value );
152
- }
153
- }
154
-
155
- // 4) Set `list item` module images.
156
- if ( isset( $settings->text ) ) {
157
- $ids_mapping = get_option( 'astra_sites_wpforms_ids_mapping', array() );
158
- if ( $ids_mapping ) {
159
-
160
- // Keep old data in temp.
161
- $updated_data = $settings->text;
162
-
163
- // Update WP form IDs.
164
- foreach ( $ids_mapping as $old_id => $new_id ) {
165
- $updated_data = str_replace( '[wpforms id="' . $old_id, '[wpforms id="' . $new_id, $updated_data );
166
- }
167
-
168
- // Update modified data.
169
- $settings->text = $updated_data;
170
- }
171
- }
172
-
173
- return $settings;
174
- }
175
-
176
- /**
177
- * Import Column Images.
178
- *
179
- * @param object $settings Column settings object.
180
- * @return object
181
- */
182
- public static function update_column( $settings ) {
183
-
184
- // 1) Set BG Images.
185
- $settings = self::import_bg_image( $settings );
186
-
187
- return $settings;
188
- }
189
-
190
- /**
191
- * Import Row Images.
192
- *
193
- * @param object $settings Row settings object.
194
- * @return object
195
- */
196
- public static function update_row( $settings ) {
197
-
198
- // 1) Set BG Images.
199
- $settings = self::import_bg_image( $settings );
200
-
201
- return $settings;
202
- }
203
-
204
- /**
205
- * Helper: Import BG Images.
206
- *
207
- * @param object $settings Row settings object.
208
- * @return object
209
- */
210
- public static function import_bg_image( $settings ) {
211
-
212
- if (
213
- ( ! empty( $settings->bg_image ) && ! empty( $settings->bg_image_src ) )
214
- ) {
215
- $image = array(
216
- 'url' => $settings->bg_image_src,
217
- 'id' => $settings->bg_image,
218
- );
219
-
220
- $downloaded_image = Astra_Sites_Image_Importer::get_instance()->import( $image );
221
-
222
- $settings->bg_image_src = $downloaded_image['url'];
223
- $settings->bg_image = $downloaded_image['id'];
224
- }
225
-
226
- return $settings;
227
- }
228
-
229
- /**
230
- * Helper: Import Photo.
231
- *
232
- * @param object $settings Row settings object.
233
- * @return object
234
- */
235
- public static function import_photo( $settings ) {
236
-
237
- if ( ! empty( $settings->photo ) && ! empty( $settings->photo_src ) ) {
238
-
239
- $image = array(
240
- 'url' => $settings->photo_src,
241
- 'id' => $settings->photo,
242
- );
243
-
244
- $downloaded_image = Astra_Sites_Image_Importer::get_instance()->import( $image );
245
-
246
- $settings->photo_src = $downloaded_image['url'];
247
- $settings->photo = $downloaded_image['id'];
248
- }
249
-
250
- return $settings;
251
- }
252
-
253
-
254
- }
255
-
256
- /**
257
- * Kicking this off by calling 'get_instance()' method
258
- */
259
- Astra_Sites_Batch_Processing_Beaver_Builder::get_instance();
260
-
261
- endif;
1
+ <?php
2
+ /**
3
+ * Batch Processing
4
+ *
5
+ * @package Astra Sites
6
+ * @since 1.0.14
7
+ */
8
+
9
+ if ( ! class_exists( 'Astra_Sites_Batch_Processing_Beaver_Builder' ) ) :
10
+
11
+ /**
12
+ * Astra_Sites_Batch_Processing_Beaver_Builder
13
+ *
14
+ * @since 1.0.14
15
+ */
16
+ class Astra_Sites_Batch_Processing_Beaver_Builder {
17
+
18
+ /**
19
+ * Instance
20
+ *
21
+ * @since 1.0.14
22
+ * @access private
23
+ * @var object Class object.
24
+ */
25
+ private static $instance;
26
+
27
+ /**
28
+ * Initiator
29
+ *
30
+ * @since 1.0.14
31
+ * @return object initialized object of class.
32
+ */
33
+ public static function get_instance() {
34
+
35
+ if ( ! isset( self::$instance ) ) {
36
+ self::$instance = new self;
37
+ }
38
+ return self::$instance;
39
+ }
40
+
41
+ /**
42
+ * Constructor
43
+ *
44
+ * @since 1.0.14
45
+ */
46
+ public function __construct() {
47
+ }
48
+
49
+ /**
50
+ * Import
51
+ *
52
+ * @since 1.0.14
53
+ * @return void
54
+ */
55
+ public function import() {
56
+
57
+ Astra_Sites_Importer_Log::add( '---- Processing WordPress Posts / Pages - for Beaver Builder ----' );
58
+ if ( ! is_callable( 'FLBuilderModel::get_post_types' ) ) {
59
+ return;
60
+ }
61
+
62
+ $post_types = FLBuilderModel::get_post_types( 'post-types' );
63
+ if ( empty( $post_types ) && ! is_array( $post_types ) ) {
64
+ return;
65
+ }
66
+
67
+ $post_ids = Astra_Sites_Batch_Processing::get_pages( $post_types );
68
+ if ( empty( $post_ids ) && ! is_array( $post_ids ) ) {
69
+ return;
70
+ }
71
+
72
+ foreach ( $post_ids as $post_id ) {
73
+ $is_bb_post = get_post_meta( $post_id, '_fl_builder_enabled', true );
74
+ if ( $is_bb_post ) {
75
+ $this->import_single_post( $post_id );
76
+ }
77
+ }
78
+ }
79
+
80
+ /**
81
+ * Update post meta.
82
+ *
83
+ * @param integer $post_id Post ID.
84
+ * @return void
85
+ */
86
+ public function import_single_post( $post_id = 0 ) {
87
+
88
+ Astra_Sites_Importer_Log::add( 'Post ID: ' . $post_id );
89
+ if ( ! empty( $post_id ) ) {
90
+
91
+ // Get page builder data.
92
+ $data = get_post_meta( $post_id, '_fl_builder_data', true );
93
+
94
+ if ( ! empty( $data ) ) {
95
+ foreach ( $data as $key => $el ) {
96
+
97
+ // Update 'row' images.
98
+ if ( 'row' === $el->type ) {
99
+ $data[ $key ]->settings = self::update_row( $el->settings );
100
+ }
101
+
102
+ // Update 'module' images.
103
+ if ( 'module' === $el->type ) {
104
+ $data[ $key ]->settings = self::update_module( $el->settings );
105
+ }
106
+
107
+ // Update 'column' images.
108
+ if ( 'column' === $el->type ) {
109
+ $data[ $key ]->settings = self::update_column( $el->settings );
110
+ }
111
+ }
112
+
113
+ // Update page builder data.
114
+ update_post_meta( $post_id, '_fl_builder_data', $data );
115
+ update_post_meta( $post_id, '_fl_builder_draft', $data );
116
+
117
+ // Clear all cache.
118
+ FLBuilderModel::delete_asset_cache_for_all_posts();
119
+ }
120
+ }
121
+
122
+ }
123
+
124
+ /**
125
+ * Import Module Images.
126
+ *
127
+ * @param object $settings Module settings object.
128
+ * @return object
129
+ */
130
+ public static function update_module( $settings ) {
131
+
132
+ // 1) Set photos.
133
+ $settings = self::import_photo( $settings );
134
+
135
+ /**
136
+ * 2) Set `$settings->data` for Only type 'image-icon'
137
+ *
138
+ * @todo Remove the condition `'image-icon' === $settings->type` if `$settings->data` is used only for the Image Icon.
139
+ */
140
+ if (
141
+ isset( $settings->data ) &&
142
+ isset( $settings->photo ) && ! empty( $settings->photo ) &&
143
+ 'image-icon' === $settings->type
144
+ ) {
145
+ $settings->data = FLBuilderPhoto::get_attachment_data( $settings->photo );
146
+ }
147
+
148
+ // 3) Set `list item` module images.
149
+ if ( isset( $settings->add_list_item ) ) {
150
+ foreach ( $settings->add_list_item as $key => $value ) {
151
+ $settings->add_list_item[ $key ] = self::import_photo( $value );
152
+ }
153
+ }
154
+
155
+ // 4) Set `list item` module images.
156
+ if ( isset( $settings->text ) ) {
157
+ $ids_mapping = get_option( 'astra_sites_wpforms_ids_mapping', array() );
158
+ if ( $ids_mapping ) {
159
+
160
+ // Keep old data in temp.
161
+ $updated_data = $settings->text;
162
+
163
+ // Update WP form IDs.
164
+ foreach ( $ids_mapping as $old_id => $new_id ) {
165
+ $updated_data = str_replace( '[wpforms id="' . $old_id, '[wpforms id="' . $new_id, $updated_data );
166
+ }
167
+
168
+ // Update modified data.
169
+ $settings->text = $updated_data;
170
+ }
171
+ }
172
+
173
+ return $settings;
174
+ }
175
+
176
+ /**
177
+ * Import Column Images.
178
+ *
179
+ * @param object $settings Column settings object.
180
+ * @return object
181
+ */
182
+ public static function update_column( $settings ) {
183
+
184
+ // 1) Set BG Images.
185
+ $settings = self::import_bg_image( $settings );
186
+
187
+ return $settings;
188
+ }
189
+
190
+ /**
191
+ * Import Row Images.
192
+ *
193
+ * @param object $settings Row settings object.
194
+ * @return object
195
+ */
196
+ public static function update_row( $settings ) {
197
+
198
+ // 1) Set BG Images.
199
+ $settings = self::import_bg_image( $settings );
200
+
201
+ return $settings;
202
+ }
203
+
204
+ /**
205
+ * Helper: Import BG Images.
206
+ *
207
+ * @param object $settings Row settings object.
208
+ * @return object
209
+ */
210
+ public static function import_bg_image( $settings ) {
211
+
212
+ if (
213
+ ( ! empty( $settings->bg_image ) && ! empty( $settings->bg_image_src ) )
214
+ ) {
215
+ $image = array(
216
+ 'url' => $settings->bg_image_src,
217
+ 'id' => $settings->bg_image,
218
+ );
219
+
220
+ $downloaded_image = Astra_Sites_Image_Importer::get_instance()->import( $image );
221
+
222
+ $settings->bg_image_src = $downloaded_image['url'];
223
+ $settings->bg_image = $downloaded_image['id'];
224
+ }
225
+
226
+ return $settings;
227
+ }
228
+
229
+ /**
230
+ * Helper: Import Photo.
231
+ *
232
+ * @param object $settings Row settings object.
233
+ * @return object
234
+ */
235
+ public static function import_photo( $settings ) {
236
+
237
+ if ( ! empty( $settings->photo ) && ! empty( $settings->photo_src ) ) {
238
+
239
+ $image = array(
240
+ 'url' => $settings->photo_src,
241
+ 'id' => $settings->photo,
242
+ );
243
+
244
+ $downloaded_image = Astra_Sites_Image_Importer::get_instance()->import( $image );
245
+
246
+ $settings->photo_src = $downloaded_image['url'];
247
+ $settings->photo = $downloaded_image['id'];
248
+ }
249
+
250
+ return $settings;
251
+ }
252
+
253
+
254
+ }
255
+
256
+ /**
257
+ * Kicking this off by calling 'get_instance()' method
258
+ */
259
+ Astra_Sites_Batch_Processing_Beaver_Builder::get_instance();
260
+
261
+ endif;
inc/importers/batch-processing/class-astra-sites-batch-processing-brizy.php CHANGED
@@ -1,125 +1,125 @@
1
- <?php
2
- /**
3
- * Batch Processing
4
- *
5
- * @package Astra Sites
6
- * @since 1.2.14
7
- */
8
-
9
- if ( ! class_exists( 'Astra_Sites_Batch_Processing_Brizy' ) ) :
10
-
11
- /**
12
- * Astra Sites Batch Processing Brizy
13
- *
14
- * @since 1.2.14
15
- */
16
- class Astra_Sites_Batch_Processing_Brizy {
17
-
18
- /**
19
- * Instance
20
- *
21
- * @since 1.2.14
22
- * @access private
23
- * @var object Class object.
24
- */
25
- private static $instance;
26
-
27
- /**
28
- * Initiator
29
- *
30
- * @since 1.2.14
31
- * @return object initialized object of class.
32
- */
33
- public static function get_instance() {
34
-
35
- if ( ! isset( self::$instance ) ) {
36
- self::$instance = new self;
37
- }
38
- return self::$instance;
39
- }
40
-
41
- /**
42
- * Constructor
43
- *
44
- * @since 1.2.14
45
- */
46
- public function __construct() {}
47
-
48
- /**
49
- * Import
50
- *
51
- * @since 1.2.14
52
- * @return void
53
- */
54
- public function import() {
55
-
56
- Astra_Sites_Importer_Log::add( '---- Processing WordPress Posts / Pages - for "Brizy" ----' );
57
- if ( ! is_callable( 'Brizy_Editor_Storage_Common::instance' ) ) {
58
- return;
59
- }
60
-
61
- $post_types = Brizy_Editor_Storage_Common::instance()->get( 'post-types' );
62
- if ( empty( $post_types ) && ! is_array( $post_types ) ) {
63
- return;
64
- }
65
-
66
- $post_ids = Astra_Sites_Batch_Processing::get_pages( $post_types );
67
- if ( empty( $post_ids ) && ! is_array( $post_ids ) ) {
68
- return;
69
- }
70
-
71
- foreach ( $post_ids as $post_id ) {
72
- $is_brizy_post = get_post_meta( $post_id, 'brizy_post_uid', true );
73
- if ( $is_brizy_post ) {
74
- $this->import_single_post( $post_id );
75
- }
76
- }
77
- }
78
-
79
- /**
80
- * Update post meta.
81
- *
82
- * @param integer $post_id Post ID.
83
- * @return void
84
- */
85
- public function import_single_post( $post_id = 0 ) {
86
-
87
- $ids_mapping = get_option( 'astra_sites_wpforms_ids_mapping', array() );
88
-
89
- // Empty mapping? Then return.
90
- if ( empty( $ids_mapping ) ) {
91
- return;
92
- }
93
-
94
- $json_value = null;
95
-
96
- $post = Brizy_Editor_Post::get( (int) $post_id );
97
- $data = $post->storage()->get( Brizy_Editor_Post::BRIZY_POST, false );
98
-
99
- // Decode current data.
100
- $json_value = base64_decode( $data['editor_data'] );
101
-
102
- // Update WPForm IDs.
103
- foreach ( $ids_mapping as $old_id => $new_id ) {
104
- $json_value = str_replace( '[wpforms id=\"' . $old_id, '[wpforms id=\"' . $new_id, $json_value );
105
- }
106
-
107
- // Encode modified data.
108
- $data['editor_data'] = base64_encode( $json_value );
109
-
110
- $post->set_editor_data( $json_value );
111
-
112
- $post->storage()->set( Brizy_Editor_Post::BRIZY_POST, $data );
113
-
114
- $post->compile_page();
115
- $post->save();
116
- }
117
-
118
- }
119
-
120
- /**
121
- * Kicking this off by calling 'get_instance()' method
122
- */
123
- Astra_Sites_Batch_Processing_Brizy::get_instance();
124
-
125
- endif;
1
+ <?php
2
+ /**
3
+ * Batch Processing
4
+ *
5
+ * @package Astra Sites
6
+ * @since 1.2.14
7
+ */
8
+
9
+ if ( ! class_exists( 'Astra_Sites_Batch_Processing_Brizy' ) ) :
10
+
11
+ /**
12
+ * Astra Sites Batch Processing Brizy
13
+ *
14
+ * @since 1.2.14
15
+ */
16
+ class Astra_Sites_Batch_Processing_Brizy {
17
+
18
+ /**
19
+ * Instance
20
+ *
21
+ * @since 1.2.14
22
+ * @access private
23
+ * @var object Class object.
24
+ */
25
+ private static $instance;
26
+
27
+ /**
28
+ * Initiator
29
+ *
30
+ * @since 1.2.14
31
+ * @return object initialized object of class.
32
+ */
33
+ public static function get_instance() {
34
+
35
+ if ( ! isset( self::$instance ) ) {
36
+ self::$instance = new self;
37
+ }
38
+ return self::$instance;
39
+ }
40
+
41
+ /**
42
+ * Constructor
43
+ *
44
+ * @since 1.2.14
45
+ */
46
+ public function __construct() {}
47
+
48
+ /**
49
+ * Import
50
+ *
51
+ * @since 1.2.14
52
+ * @return void
53
+ */
54
+ public function import() {
55
+
56
+ Astra_Sites_Importer_Log::add( '---- Processing WordPress Posts / Pages - for "Brizy" ----' );
57
+ if ( ! is_callable( 'Brizy_Editor_Storage_Common::instance' ) ) {
58
+ return;
59
+ }
60
+
61
+ $post_types = Brizy_Editor_Storage_Common::instance()->get( 'post-types' );
62
+ if ( empty( $post_types ) && ! is_array( $post_types ) ) {
63
+ return;
64
+ }
65
+
66
+ $post_ids = Astra_Sites_Batch_Processing::get_pages( $post_types );
67
+ if ( empty( $post_ids ) && ! is_array( $post_ids ) ) {
68
+ return;
69
+ }
70
+
71
+ foreach ( $post_ids as $post_id ) {
72
+ $is_brizy_post = get_post_meta( $post_id, 'brizy_post_uid', true );
73
+ if ( $is_brizy_post ) {
74
+ $this->import_single_post( $post_id );
75
+ }
76
+ }
77
+ }
78
+
79
+ /**
80
+ * Update post meta.
81
+ *
82
+ * @param integer $post_id Post ID.
83
+ * @return void
84
+ */
85
+ public function import_single_post( $post_id = 0 ) {
86
+
87
+ $ids_mapping = get_option( 'astra_sites_wpforms_ids_mapping', array() );
88
+
89
+ // Empty mapping? Then return.
90
+ if ( empty( $ids_mapping ) ) {
91
+ return;
92
+ }
93
+
94
+ $json_value = null;
95
+
96
+ $post = Brizy_Editor_Post::get( (int) $post_id );
97
+ $data = $post->storage()->get( Brizy_Editor_Post::BRIZY_POST, false );
98
+
99
+ // Decode current data.
100
+ $json_value = base64_decode( $data['editor_data'] );
101
+
102
+ // Update WPForm IDs.
103
+ foreach ( $ids_mapping as $old_id => $new_id ) {
104
+ $json_value = str_replace( '[wpforms id=\"' . $old_id, '[wpforms id=\"' . $new_id, $json_value );
105
+ }
106
+
107
+ // Encode modified data.
108
+ $data['editor_data'] = base64_encode( $json_value );
109
+
110
+ $post->set_editor_data( $json_value );
111
+
112
+ $post->storage()->set( Brizy_Editor_Post::BRIZY_POST, $data );
113
+
114
+ $post->compile_page();
115
+ $post->save();
116
+ }
117
+
118
+ }
119
+
120
+ /**
121
+ * Kicking this off by calling 'get_instance()' method
122
+ */
123
+ Astra_Sites_Batch_Processing_Brizy::get_instance();
124
+
125
+ endif;
inc/importers/batch-processing/class-astra-sites-batch-processing-elementor.php CHANGED
@@ -1,109 +1,109 @@
1
- <?php
2
- /**
3
- * Elementor Importer
4
- *
5
- * @package Astra Sites
6
- */
7
-
8
- namespace Elementor\TemplateLibrary;
9
-
10
- if ( ! defined( 'ABSPATH' ) ) {
11
- exit; // Exit if accessed directly.
12
- }
13
-
14
- // If plugin - 'Elementor' not exist then return.
15
- if ( ! class_exists( '\Elementor\Plugin' ) ) {
16
- return;
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
- /**
30
- * Elementor template library local source.
31
- *
32
- * Elementor template library local source handler class is responsible for
33
- * handling local Elementor templates saved by the user locally on his site.
34
- *
35
- * @since 1.2.13 Added compatibility for Elemetnor v2.5.0
36
- * @since 1.0.0
37
- */
38
- class Astra_Sites_Batch_Processing_Elementor extends Source_Local {
39
-
40
- /**
41
- * Import
42
- *
43
- * @since 1.0.14
44
- * @return void
45
- */
46
- public function import() {
47
-
48
- $post_types = \Astra_Sites_Batch_Processing::get_post_types_supporting( 'elementor' );
49
- if ( empty( $post_types ) && ! is_array( $post_types ) ) {
50
- return;
51
- }
52
-
53
- $post_ids = \Astra_Sites_Batch_Processing::get_pages( $post_types );
54
- if ( empty( $post_ids ) && ! is_array( $post_ids ) ) {
55
- return;
56
- }
57
-
58
- foreach ( $post_ids as $post_id ) {
59
- $is_elementor_post = get_post_meta( $post_id, '_elementor_version', true );
60
- if ( $is_elementor_post ) {
61
- $this->import_single_post( $post_id );
62
- }
63
- }
64
- }
65
- /**
66
- * Update post meta.
67
- *
68
- * @since 1.0.14
69
- * @param integer $post_id Post ID.
70
- * @return void
71
- */
72
- public function import_single_post( $post_id = 0 ) {
73
-
74
- if ( ! empty( $post_id ) ) {
75
-
76
- $hotlink_imported = get_post_meta( $post_id, '_astra_sites_hotlink_imported', true );
77
-
78
- if ( empty( $hotlink_imported ) ) {
79
-
80
- $data = get_post_meta( $post_id, '_elementor_data', true );
81
-
82
- if ( ! empty( $data ) ) {
83
-
84
- // Update WP form IDs.
85
- $ids_mapping = get_option( 'astra_sites_wpforms_ids_mapping', array() );
86
- if ( $ids_mapping ) {
87
- foreach ( $ids_mapping as $old_id => $new_id ) {
88
- $data = str_replace( '[wpforms id=\"' . $old_id, '[wpforms id=\"' . $new_id, $data );
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' );
97
-
98
- // Update processed meta.
99
- update_metadata( 'post', $post_id, '_elementor_data', $data );
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
- }
107
- }
108
- }
109
- }
1
+ <?php
2
+ /**
3
+ * Elementor Importer
4
+ *
5
+ * @package Astra Sites
6
+ */
7
+
8
+ namespace Elementor\TemplateLibrary;
9
+
10
+ if ( ! defined( 'ABSPATH' ) ) {
11
+ exit; // Exit if accessed directly.
12
+ }
13
+
14
+ // If plugin - 'Elementor' not exist then return.
15
+ if ( ! class_exists( '\Elementor\Plugin' ) ) {
16
+ return;
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
+ /**
30
+ * Elementor template library local source.
31
+ *
32
+ * Elementor template library local source handler class is responsible for
33
+ * handling local Elementor templates saved by the user locally on his site.
34
+ *
35
+ * @since 1.2.13 Added compatibility for Elemetnor v2.5.0
36
+ * @since 1.0.0
37
+ */
38
+ class Astra_Sites_Batch_Processing_Elementor extends Source_Local {
39
+
40
+ /**
41
+ * Import
42
+ *
43
+ * @since 1.0.14
44
+ * @return void
45
+ */
46
+ public function import() {
47
+
48
+ $post_types = \Astra_Sites_Batch_Processing::get_post_types_supporting( 'elementor' );
49
+ if ( empty( $post_types ) && ! is_array( $post_types ) ) {
50
+ return;
51
+ }
52
+
53
+ $post_ids = \Astra_Sites_Batch_Processing::get_pages( $post_types );
54
+ if ( empty( $post_ids ) && ! is_array( $post_ids ) ) {
55
+ return;
56
+ }
57
+
58
+ foreach ( $post_ids as $post_id ) {
59
+ $is_elementor_post = get_post_meta( $post_id, '_elementor_version', true );
60
+ if ( $is_elementor_post ) {
61
+ $this->import_single_post( $post_id );
62
+ }
63
+ }
64
+ }
65
+ /**
66
+ * Update post meta.
67
+ *
68
+ * @since 1.0.14
69
+ * @param integer $post_id Post ID.
70
+ * @return void
71
+ */
72
+ public function import_single_post( $post_id = 0 ) {
73
+
74
+ if ( ! empty( $post_id ) ) {
75
+
76
+ $hotlink_imported = get_post_meta( $post_id, '_astra_sites_hotlink_imported', true );
77
+
78
+ if ( empty( $hotlink_imported ) ) {
79
+
80
+ $data = get_post_meta( $post_id, '_elementor_data', true );
81
+
82
+ if ( ! empty( $data ) ) {
83
+
84
+ // Update WP form IDs.
85
+ $ids_mapping = get_option( 'astra_sites_wpforms_ids_mapping', array() );
86
+ if ( $ids_mapping ) {
87
+ foreach ( $ids_mapping as $old_id => $new_id ) {
88
+ $data = str_replace( '[wpforms id=\"' . $old_id, '[wpforms id=\"' . $new_id, $data );
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' );
97
+
98
+ // Update processed meta.
99
+ update_metadata( 'post', $post_id, '_elementor_data', $data );
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
+ }
107
+ }
108
+ }
109
+ }
inc/importers/batch-processing/class-astra-sites-batch-processing-gutenberg.php CHANGED
@@ -1,167 +1,167 @@
1
- <?php
2
- /**
3
- * Batch Processing
4
- *
5
- * @package Astra Sites
6
- * @since 1.2.14
7
- */
8
-
9
- if ( ! class_exists( 'Astra_Sites_Batch_Processing_Gutenberg' ) ) :
10
-
11
- /**
12
- * Astra Sites Batch Processing Brizy
13
- *
14
- * @since 1.2.14
15
- */
16
- class Astra_Sites_Batch_Processing_Gutenberg {
17
-
18
- /**
19
- * Instance
20
- *
21
- * @since 1.2.14
22
- * @access private
23
- * @var object Class object.
24
- */
25
- private static $instance;
26
-
27
- /**
28
- * Initiator
29
- *
30
- * @since 1.2.14
31
- * @return object initialized object of class.
32
- */
33
- public static function get_instance() {
34
-
35
- if ( ! isset( self::$instance ) ) {
36
- self::$instance = new self;
37
- }
38
- return self::$instance;
39
- }
40
-
41
- /**
42
- * Constructor
43
- *
44
- * @since 1.2.14
45
- */
46
- public function __construct() {}
47
-
48
- /**
49
- * Allowed tags for the batch update process.
50
- *
51
- * @param array $allowedposttags Array of default allowable HTML tags.
52
- * @param string|array $context The context for which to retrieve tags. Allowed values are 'post',
53
- * 'strip', 'data', 'entities', or the name of a field filter such as
54
- * 'pre_user_description'.
55
- * @return array Array of allowed HTML tags and their allowed attributes.
56
- */
57
- function allowed_tags_and_attributes( $allowedposttags, $context ) {
58
-
59
- // Keep only for 'post' contenxt.
60
- if ( 'post' === $context ) {
61
-
62
- // <svg> tag and attributes.
63
- $allowedposttags['svg'] = array(
64
- 'xmlns' => true,
65
- 'viewbox' => true,
66
- );
67
-
68
- // <path> tag and attributes.
69
- $allowedposttags['path'] = array(
70
- 'd' => true,
71
- );
72
- }
73
-
74
- return $allowedposttags;
75
- }
76
-
77
- /**
78
- * Import
79
- *
80
- * @since 1.2.14
81
- * @return void
82
- */
83
- public function import() {
84
-
85
- // Allow the SVG tags in batch update process.
86
- add_filter( 'wp_kses_allowed_html', array( $this, 'allowed_tags_and_attributes' ), 10, 2 );
87
-
88
- Astra_Sites_Importer_Log::add( '---- Processing WordPress Posts / Pages - for "Gutenberg" ----' );
89
-
90
- $post_types = apply_filters( 'astra_sites_gutenberg_batch_process_post_types', array( 'page' ) );
91
-
92
- $post_ids = Astra_Sites_Batch_Processing::get_pages( $post_types );
93
- if ( empty( $post_ids ) && ! is_array( $post_ids ) ) {
94
- return;
95
- }
96
-
97
- foreach ( $post_ids as $post_id ) {
98
- $this->import_single_post( $post_id );
99
- }
100
- }
101
-
102
- /**
103
- * Update post meta.
104
- *
105
- * @param integer $post_id Post ID.
106
- * @return void
107
- */
108
- public function import_single_post( $post_id = 0 ) {
109
-
110
- $ids_mapping = get_option( 'astra_sites_wpforms_ids_mapping', array() );
111
-
112
- // Post content.
113
- $content = get_post_field( 'post_content', $post_id );
114
-
115
- if ( ! empty( $ids_mapping ) ) {
116
- // Replace ID's.
117
- foreach ( $ids_mapping as $old_id => $new_id ) {
118
- $content = str_replace( '[wpforms id="' . $old_id, '[wpforms id="' . $new_id, $content );
119
- }
120
- }
121
-
122
- // This replaces the category ID in UAG Post blocks.
123
- $site_options = get_option( 'astra_sites_import_data', array() );
124
-
125
- if ( isset( $site_options['astra-site-taxonomy-mapping'] ) ) {
126
-
127
- $tax_mapping = $site_options['astra-site-taxonomy-mapping'];
128
-
129
- if ( isset( $tax_mapping['post'] ) ) {
130
-
131
- $catogory_mapping = ( isset( $tax_mapping['post']['category'] ) ) ? $tax_mapping['post']['category'] : array();
132
-
133
- if ( is_array( $catogory_mapping ) ) {
134
-
135
- foreach ( $catogory_mapping as $key => $value ) {
136
-
137
- $this_site_term = get_term_by( 'slug', $value['slug'], 'category' );
138
- $content = str_replace( '"categories":"' . $value['id'], '"categories":"' . $this_site_term->term_id, $content );
139
- }
140
- }
141
- }
142
- }
143
-
144
- // # Tweak
145
- // Gutenberg break block markup from render. Because the '&' is updated in database with '&amp;' and it
146
- // expects as 'u0026amp;'. So, Converted '&amp;' with 'u0026amp;'.
147
- //
148
- // @todo This affect for normal page content too. Detect only Gutenberg pages and process only on it.
149
- $content = str_replace( '&amp;', "\u0026amp;", $content );
150
-
151
- // Update content.
152
- wp_update_post(
153
- array(
154
- 'ID' => $post_id,
155
- 'post_content' => $content,
156
- )
157
- );
158
- }
159
-
160
- }
161
-
162
- /**
163
- * Kicking this off by calling 'get_instance()' method
164
- */
165
- Astra_Sites_Batch_Processing_Gutenberg::get_instance();
166
-
167
- endif;
1
+ <?php
2
+ /**
3
+ * Batch Processing
4
+ *
5
+ * @package Astra Sites
6
+ * @since 1.2.14
7
+ */
8
+
9
+ if ( ! class_exists( 'Astra_Sites_Batch_Processing_Gutenberg' ) ) :
10
+
11
+ /**
12
+ * Astra Sites Batch Processing Brizy
13
+ *
14
+ * @since 1.2.14
15
+ */
16
+ class Astra_Sites_Batch_Processing_Gutenberg {
17
+
18
+ /**
19
+ * Instance
20
+ *
21
+ * @since 1.2.14
22
+ * @access private
23
+ * @var object Class object.
24
+ */
25
+ private static $instance;
26
+
27
+ /**
28
+ * Initiator
29
+ *
30
+ * @since 1.2.14
31
+ * @return object initialized object of class.
32
+ */
33
+ public static function get_instance() {
34
+
35
+ if ( ! isset( self::$instance ) ) {
36
+ self::$instance = new self;
37
+ }
38
+ return self::$instance;
39
+ }
40
+
41
+ /**
42
+ * Constructor
43
+ *
44
+ * @since 1.2.14
45
+ */
46
+ public function __construct() {}
47
+
48
+ /**
49
+ * Allowed tags for the batch update process.
50
+ *
51
+ * @param array $allowedposttags Array of default allowable HTML tags.
52
+ * @param string|array $context The context for which to retrieve tags. Allowed values are 'post',
53
+ * 'strip', 'data', 'entities', or the name of a field filter such as
54
+ * 'pre_user_description'.
55
+ * @return array Array of allowed HTML tags and their allowed attributes.
56
+ */
57
+ function allowed_tags_and_attributes( $allowedposttags, $context ) {
58
+
59
+ // Keep only for 'post' contenxt.
60
+ if ( 'post' === $context ) {
61
+
62
+ // <svg> tag and attributes.
63
+ $allowedposttags['svg'] = array(
64
+ 'xmlns' => true,
65
+ 'viewbox' => true,
66
+ );
67
+
68
+ // <path> tag and attributes.
69
+ $allowedposttags['path'] = array(
70
+ 'd' => true,
71
+ );
72
+ }
73
+
74
+ return $allowedposttags;
75
+ }
76
+
77
+ /**
78
+ * Import
79
+ *
80
+ * @since 1.2.14
81
+ * @return void
82
+ */
83
+ public function import() {
84
+
85
+ // Allow the SVG tags in batch update process.
86
+ add_filter( 'wp_kses_allowed_html', array( $this, 'allowed_tags_and_attributes' ), 10, 2 );
87
+
88
+ Astra_Sites_Importer_Log::add( '---- Processing WordPress Posts / Pages - for "Gutenberg" ----' );
89
+
90
+ $post_types = apply_filters( 'astra_sites_gutenberg_batch_process_post_types', array( 'page' ) );
91
+
92
+ $post_ids = Astra_Sites_Batch_Processing::get_pages( $post_types );
93
+ if ( empty( $post_ids ) && ! is_array( $post_ids ) ) {
94
+ return;
95
+ }
96
+
97
+ foreach ( $post_ids as $post_id ) {
98
+ $this->import_single_post( $post_id );
99
+ }
100
+ }
101
+
102
+ /**
103
+ * Update post meta.
104
+ *
105
+ * @param integer $post_id Post ID.
106
+ * @return void
107
+ */
108
+ public function import_single_post( $post_id = 0 ) {
109
+
110
+ $ids_mapping = get_option( 'astra_sites_wpforms_ids_mapping', array() );
111
+
112
+ // Post content.
113
+ $content = get_post_field( 'post_content', $post_id );
114
+
115
+ if ( ! empty( $ids_mapping ) ) {
116
+ // Replace ID's.
117
+ foreach ( $ids_mapping as $old_id => $new_id ) {
118
+ $content = str_replace( '[wpforms id="' . $old_id, '[wpforms id="' . $new_id, $content );
119
+ }
120
+ }
121
+
122
+ // This replaces the category ID in UAG Post blocks.
123
+ $site_options = get_option( 'astra_sites_import_data', array() );
124
+
125
+ if ( isset( $site_options['astra-site-taxonomy-mapping'] ) ) {
126
+
127
+ $tax_mapping = $site_options['astra-site-taxonomy-mapping'];
128
+
129
+ if ( isset( $tax_mapping['post'] ) ) {
130
+
131
+ $catogory_mapping = ( isset( $tax_mapping['post']['category'] ) ) ? $tax_mapping['post']['category'] : array();
132
+
133
+ if ( is_array( $catogory_mapping ) ) {
134
+
135
+ foreach ( $catogory_mapping as $key => $value ) {
136
+
137
+ $this_site_term = get_term_by( 'slug', $value['slug'], 'category' );
138
+ $content = str_replace( '"categories":"' . $value['id'], '"categories":"' . $this_site_term->term_id, $content );
139
+ }
140
+ }
141
+ }
142
+ }
143
+
144
+ // # Tweak
145
+ // Gutenberg break block markup from render. Because the '&' is updated in database with '&amp;' and it
146
+ // expects as 'u0026amp;'. So, Converted '&amp;' with 'u0026amp;'.
147
+ //
148
+ // @todo This affect for normal page content too. Detect only Gutenberg pages and process only on it.
149
+ $content = str_replace( '&amp;', "\u0026amp;", $content );
150
+
151
+ // Update content.
152
+ wp_update_post(
153
+ array(
154
+ 'ID' => $post_id,
155
+ 'post_content' => $content,
156
+ )
157
+ );
158
+ }
159
+
160
+ }
161
+
162
+ /**
163
+ * Kicking this off by calling 'get_instance()' method
164
+ */
165
+ Astra_Sites_Batch_Processing_Gutenberg::get_instance();
166
+
167
+ endif;
inc/importers/batch-processing/class-astra-sites-batch-processing.php CHANGED
@@ -1,227 +1,227 @@
1
- <?php
2
- /**
3
- * Batch Processing
4
- *
5
- * @package Astra Sites
6
- * @since 1.0.14
7
- */
8
-
9
- if ( ! class_exists( 'Astra_Sites_Batch_Processing' ) ) :
10
-
11
- /**
12
- * Astra_Sites_Batch_Processing
13
- *
14
- * @since 1.0.14
15
- */
16
- class Astra_Sites_Batch_Processing {
17
-
18
- /**
19
- * Instance
20
- *
21
- * @since 1.0.14
22
- * @var object Class object.
23
- * @access private
24
- */
25
- private static $instance;
26
-
27
- /**
28
- * Process All
29
- *
30
- * @since 1.0.14
31
- * @var object Class object.
32
- * @access public
33
- */
34
- public static $process_all;
35
-
36
- /**
37
- * Initiator
38
- *
39
- * @since 1.0.14
40
- * @return object initialized object of class.
41
- */
42
- public static function get_instance() {
43
- if ( ! isset( self::$instance ) ) {
44
- self::$instance = new self;
45
- }
46
- return self::$instance;
47
- }
48
-
49
- /**
50
- * Constructor
51
- *
52
- * @since 1.0.14
53
- */
54
- public function __construct() {
55
-
56
- // Core Helpers - Image.
57
- // @todo This file is required for Elementor.
58
- // Once we implement our logic for updating elementor data then we'll delete this file.
59
- require_once ABSPATH . 'wp-admin/includes/image.php';
60
-
61
- // Core Helpers - Image Downloader.
62
- require_once ASTRA_SITES_DIR . 'inc/importers/batch-processing/helpers/class-astra-sites-image-importer.php';
63
-
64
- // Core Helpers - Batch Processing.
65
- require_once ASTRA_SITES_DIR . 'inc/importers/batch-processing/helpers/class-wp-async-request.php';
66
- require_once ASTRA_SITES_DIR . 'inc/importers/batch-processing/helpers/class-wp-background-process.php';
67
- require_once ASTRA_SITES_DIR . 'inc/importers/batch-processing/helpers/class-wp-background-process-astra.php';
68
-
69
- // Prepare Widgets.
70
- require_once ASTRA_SITES_DIR . 'inc/importers/batch-processing/class-astra-sites-batch-processing-widgets.php';
71
-
72
- // Prepare Page Builders.
73
- require_once ASTRA_SITES_DIR . 'inc/importers/batch-processing/class-astra-sites-batch-processing-beaver-builder.php';
74
- require_once ASTRA_SITES_DIR . 'inc/importers/batch-processing/class-astra-sites-batch-processing-elementor.php';
75
- require_once ASTRA_SITES_DIR . 'inc/importers/batch-processing/class-astra-sites-batch-processing-gutenberg.php';
76
- require_once ASTRA_SITES_DIR . 'inc/importers/batch-processing/class-astra-sites-batch-processing-brizy.php';
77
-
78
- // Prepare Misc.
79
- require_once ASTRA_SITES_DIR . 'inc/importers/batch-processing/class-astra-sites-batch-processing-misc.php';
80
-
81
- self::$process_all = new WP_Background_Process_Astra();
82
-
83
- // Start image importing after site import complete.
84
- add_filter( 'astra_sites_image_importer_skip_image', array( $this, 'skip_image' ), 10, 2 );
85
- add_action( 'astra_sites_import_complete', array( $this, 'start_process' ) );
86
- }
87
-
88
- /**
89
- * Skip Image from Batch Processing.
90
- *
91
- * @since 1.0.14
92
- *
93
- * @param boolean $can_process Batch process image status.
94
- * @param array $attachment Batch process image input.
95
- * @return boolean
96
- */
97
- function skip_image( $can_process, $attachment ) {
98
-
99
- if ( isset( $attachment['url'] ) && ! empty( $attachment['url'] ) ) {
100
- if (
101
- strpos( $attachment['url'], 'brainstormforce.com' ) !== false ||
102
- strpos( $attachment['url'], 'wpastra.com' ) !== false ||
103
- strpos( $attachment['url'], 'sharkz.in' ) !== false ||
104
- strpos( $attachment['url'], 'websitedemos.net' ) !== false
105
- ) {
106
- return false;
107
- }
108
- }
109
-
110
- return true;
111
- }
112
-
113
- /**
114
- * Start Image Import
115
- *
116
- * @since 1.0.14
117
- *
118
- * @return void
119
- */
120
- public function start_process() {
121
-
122
- Astra_Sites_Importer_Log::add( 'Batch Process Started!' );
123
- Astra_Sites_Importer_Log::add( Astra_Sites_White_Label::get_instance()->page_title( ASTRA_SITES_NAME ) . ' - Importing Images for Blog name \'' . get_bloginfo( 'name' ) . '\' (' . get_current_blog_id() . ')' );
124
-
125
- // Add "widget" in import [queue].
126
- if ( class_exists( 'Astra_Sites_Batch_Processing_Widgets' ) ) {
127
- self::$process_all->push_to_queue( Astra_Sites_Batch_Processing_Widgets::get_instance() );
128
- }
129
-
130
- // Add "gutenberg" in import [queue].
131
- self::$process_all->push_to_queue( Astra_Sites_Batch_Processing_Gutenberg::get_instance() );
132
-
133
- // Add "brizy" in import [queue].
134
- if ( is_plugin_active( 'brizy/brizy.php' ) ) {
135
- self::$process_all->push_to_queue( Astra_Sites_Batch_Processing_Brizy::get_instance() );
136
- }
137
-
138
- // Add "bb-plugin" in import [queue].
139
- // Add "beaver-builder-lite-version" in import [queue].
140
- if ( is_plugin_active( 'beaver-builder-lite-version/fl-builder.php' ) || is_plugin_active( 'bb-plugin/fl-builder.php' ) ) {
141
- self::$process_all->push_to_queue( Astra_Sites_Batch_Processing_Beaver_Builder::get_instance() );
142
- }
143
-
144
- // Add "elementor" in import [queue].
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 {
152
- Astra_Sites_Importer_Log::add( 'Couldn\'t not import image due to allow_url_fopen() is disabled!' );
153
- }
154
-
155
- // Add "astra-addon" in import [queue].
156
- if ( is_plugin_active( 'astra-addon/astra-addon.php' ) ) {
157
- if ( class_exists( 'Astra_Sites_Compatibility_Astra_Pro' ) ) {
158
- self::$process_all->push_to_queue( Astra_Sites_Compatibility_Astra_Pro::get_instance() );
159
- }
160
- }
161
-
162
- // Add "misc" in import [queue].
163
- self::$process_all->push_to_queue( Astra_Sites_Batch_Processing_Misc::get_instance() );
164
-
165
- // Dispatch Queue.
166
- self::$process_all->save()->dispatch();
167
- }
168
-
169
- /**
170
- * Get all post id's
171
- *
172
- * @since 1.0.14
173
- *
174
- * @param array $post_types Post types.
175
- * @return array
176
- */
177
- public static function get_pages( $post_types = array() ) {
178
-
179
- if ( $post_types ) {
180
- $args = array(
181
- 'post_type' => $post_types,
182
-
183
- // Query performance optimization.
184
- 'fields' => 'ids',
185
- 'no_found_rows' => true,
186
- 'post_status' => 'publish',
187
- 'posts_per_page' => -1,
188
- );
189
-
190
- $query = new WP_Query( $args );
191
-
192
- // Have posts?
193
- if ( $query->have_posts() ) :
194
-
195
- return $query->posts;
196
-
197
- endif;
198
- }
199
-
200
- return null;
201
- }
202
-
203
- /**
204
- * Get Supporting Post Types..
205
- *
206
- * @since 1.3.7
207
- * @param integer $feature Feature.
208
- * @return array
209
- */
210
- public static function get_post_types_supporting( $feature ) {
211
- global $_wp_post_type_features;
212
-
213
- $post_types = array_keys(
214
- wp_filter_object_list( $_wp_post_type_features, array( $feature => true ) )
215
- );
216
-
217
- return $post_types;
218
- }
219
-
220
- }
221
-
222
- /**
223
- * Kicking this off by calling 'get_instance()' method
224
- */
225
- Astra_Sites_Batch_Processing::get_instance();
226
-
227
- endif;
1
+ <?php
2
+ /**
3
+ * Batch Processing
4
+ *
5
+ * @package Astra Sites
6
+ * @since 1.0.14
7
+ */
8
+
9
+ if ( ! class_exists( 'Astra_Sites_Batch_Processing' ) ) :
10
+
11
+ /**
12
+ * Astra_Sites_Batch_Processing
13
+ *
14
+ * @since 1.0.14
15
+ */
16
+ class Astra_Sites_Batch_Processing {
17
+
18
+ /**
19
+ * Instance
20
+ *
21
+ * @since 1.0.14
22
+ * @var object Class object.
23
+ * @access private
24
+ */
25
+ private static $instance;
26
+
27
+ /**
28
+ * Process All
29
+ *
30
+ * @since 1.0.14
31
+ * @var object Class object.
32
+ * @access public
33
+ */
34
+ public static $process_all;
35
+
36
+ /**
37
+ * Initiator
38
+ *
39
+ * @since 1.0.14
40
+ * @return object initialized object of class.
41
+ */
42
+ public static function get_instance() {
43
+ if ( ! isset( self::$instance ) ) {
44
+ self::$instance = new self;
45
+ }
46
+ return self::$instance;
47
+ }
48
+
49
+ /**
50
+ * Constructor
51
+ *
52
+ * @since 1.0.14
53
+ */
54
+ public function __construct() {
55
+
56
+ // Core Helpers - Image.
57
+ // @todo This file is required for Elementor.
58
+ // Once we implement our logic for updating elementor data then we'll delete this file.
59
+ require_once ABSPATH . 'wp-admin/includes/image.php';
60
+
61
+ // Core Helpers - Image Downloader.
62
+ require_once ASTRA_SITES_DIR . 'inc/importers/batch-processing/helpers/class-astra-sites-image-importer.php';
63
+
64
+ // Core Helpers - Batch Processing.
65
+ require_once ASTRA_SITES_DIR . 'inc/importers/batch-processing/helpers/class-wp-async-request.php';
66
+ require_once ASTRA_SITES_DIR . 'inc/importers/batch-processing/helpers/class-wp-background-process.php';
67
+ require_once ASTRA_SITES_DIR . 'inc/importers/batch-processing/helpers/class-wp-background-process-astra.php';
68
+
69
+ // Prepare Widgets.
70
+ require_once ASTRA_SITES_DIR . 'inc/importers/batch-processing/class-astra-sites-batch-processing-widgets.php';
71
+
72
+ // Prepare Page Builders.
73
+ require_once ASTRA_SITES_DIR . 'inc/importers/batch-processing/class-astra-sites-batch-processing-beaver-builder.php';
74
+ require_once ASTRA_SITES_DIR . 'inc/importers/batch-processing/class-astra-sites-batch-processing-elementor.php';
75
+ require_once ASTRA_SITES_DIR . 'inc/importers/batch-processing/class-astra-sites-batch-processing-gutenberg.php';
76
+ require_once ASTRA_SITES_DIR . 'inc/importers/batch-processing/class-astra-sites-batch-processing-brizy.php';
77
+
78
+ // Prepare Misc.
79
+ require_once ASTRA_SITES_DIR . 'inc/importers/batch-processing/class-astra-sites-batch-processing-misc.php';
80
+
81
+ self::$process_all = new WP_Background_Process_Astra();
82
+
83
+ // Start image importing after site import complete.
84
+ add_filter( 'astra_sites_image_importer_skip_image', array( $this, 'skip_image' ), 10, 2 );
85
+ add_action( 'astra_sites_import_complete', array( $this, 'start_process' ) );
86
+ }
87
+
88
+ /**
89
+ * Skip Image from Batch Processing.
90
+ *
91
+ * @since 1.0.14
92
+ *
93
+ * @param boolean $can_process Batch process image status.
94
+ * @param array $attachment Batch process image input.
95
+ * @return boolean
96
+ */
97
+ function skip_image( $can_process, $attachment ) {
98
+
99
+ if ( isset( $attachment['url'] ) && ! empty( $attachment['url'] ) ) {
100
+ if (
101
+ strpos( $attachment['url'], 'brainstormforce.com' ) !== false ||
102
+ strpos( $attachment['url'], 'wpastra.com' ) !== false ||
103
+ strpos( $attachment['url'], 'sharkz.in' ) !== false ||
104
+ strpos( $attachment['url'], 'websitedemos.net' ) !== false
105
+ ) {
106
+ return false;
107
+ }
108
+ }
109
+
110
+ return true;
111
+ }
112
+
113
+ /**
114
+ * Start Image Import
115
+ *
116
+ * @since 1.0.14
117
+ *
118
+ * @return void
119
+ */
120
+ public function start_process() {
121
+
122
+ Astra_Sites_Importer_Log::add( 'Batch Process Started!' );
123
+ Astra_Sites_Importer_Log::add( Astra_Sites_White_Label::get_instance()->page_title( ASTRA_SITES_NAME ) . ' - Importing Images for Blog name \'' . get_bloginfo( 'name' ) . '\' (' . get_current_blog_id() . ')' );
124
+
125
+ // Add "widget" in import [queue].
126
+ if ( class_exists( 'Astra_Sites_Batch_Processing_Widgets' ) ) {
127
+ self::$process_all->push_to_queue( Astra_Sites_Batch_Processing_Widgets::get_instance() );
128
+ }
129
+
130
+ // Add "gutenberg" in import [queue].
131
+ self::$process_all->push_to_queue( Astra_Sites_Batch_Processing_Gutenberg::get_instance() );
132
+
133
+ // Add "brizy" in import [queue].
134
+ if ( is_plugin_active( 'brizy/brizy.php' ) ) {
135
+ self::$process_all->push_to_queue( Astra_Sites_Batch_Processing_Brizy::get_instance() );
136
+ }
137
+
138
+ // Add "bb-plugin" in import [queue].
139
+ // Add "beaver-builder-lite-version" in import [queue].
140
+ if ( is_plugin_active( 'beaver-builder-lite-version/fl-builder.php' ) || is_plugin_active( 'bb-plugin/fl-builder.php' ) ) {
141
+ self::$process_all->push_to_queue( Astra_Sites_Batch_Processing_Beaver_Builder::get_instance() );
142
+ }
143
+
144
+ // Add "elementor" in import [queue].
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 {
152
+ Astra_Sites_Importer_Log::add( 'Couldn\'t not import image due to allow_url_fopen() is disabled!' );
153
+ }
154
+
155
+ // Add "astra-addon" in import [queue].
156
+ if ( is_plugin_active( 'astra-addon/astra-addon.php' ) ) {
157
+ if ( class_exists( 'Astra_Sites_Compatibility_Astra_Pro' ) ) {
158
+ self::$process_all->push_to_queue( Astra_Sites_Compatibility_Astra_Pro::get_instance() );
159
+ }
160
+ }
161
+
162
+ // Add "misc" in import [queue].
163
+ self::$process_all->push_to_queue( Astra_Sites_Batch_Processing_Misc::get_instance() );
164
+
165
+ // Dispatch Queue.
166
+ self::$process_all->save()->dispatch();
167
+ }
168
+
169
+ /**
170
+ * Get all post id's
171
+ *
172
+ * @since 1.0.14
173
+ *
174
+ * @param array $post_types Post types.
175
+ * @return array
176
+ */
177
+ public static function get_pages( $post_types = array() ) {
178
+
179
+ if ( $post_types ) {
180
+ $args = array(
181
+ 'post_type' => $post_types,
182
+
183
+ // Query performance optimization.
184
+ 'fields' => 'ids',
185
+ 'no_found_rows' => true,
186
+ 'post_status' => 'publish',
187
+ 'posts_per_page' => -1,
188
+ );
189
+
190
+ $query = new WP_Query( $args );
191
+
192
+ // Have posts?
193
+ if ( $query->have_posts() ) :
194
+
195
+ return $query->posts;
196
+
197
+ endif;
198
+ }
199
+
200
+ return null;
201
+ }
202
+
203
+ /**
204
+ * Get Supporting Post Types..
205
+ *
206
+ * @since 1.3.7
207
+ * @param integer $feature Feature.
208
+ * @return array
209
+ */
210
+ public static function get_post_types_supporting( $feature ) {
211
+ global $_wp_post_type_features;
212
+
213
+ $post_types = array_keys(
214
+ wp_filter_object_list( $_wp_post_type_features, array( $feature => true ) )
215
+ );
216
+
217
+ return $post_types;
218
+ }
219
+
220
+ }
221
+
222
+ /**
223
+ * Kicking this off by calling 'get_instance()' method
224
+ */
225
+ Astra_Sites_Batch_Processing::get_instance();
226
+
227
+ endif;
inc/importers/batch-processing/helpers/class-astra-sites-image-importer.php CHANGED
@@ -1,263 +1,263 @@
1
- <?php
2
- /**
3
- * Image Importer
4
- *
5
- * => How to use?
6
- *
7
- * $image = array(
8
- * 'url' => '<image-url>',
9
- * 'id' => '<image-id>',
10
- * );
11
- *
12
- * $downloaded_image = Astra_Sites_Image_Importer::get_instance()->import( $image );
13
- *
14
- * @package Astra Sites
15
- * @since 1.0.14
16
- */
17
-
18
- if ( ! class_exists( 'Astra_Sites_Image_Importer' ) ) :
19
-
20
- /**
21
- * Astra Sites Image Importer
22
- *
23
- * @since 1.0.14
24
- */
25
- class Astra_Sites_Image_Importer {
26
-
27
- /**
28
- * Instance
29
- *
30
- * @since 1.0.14
31
- * @var object Class object.
32
- * @access private
33
- */
34
- private static $instance;
35
-
36
- /**
37
- * Images IDs
38
- *
39
- * @var array The Array of already image IDs.
40
- * @since 1.0.14
41
- */
42
- private $already_imported_ids = array();
43
-
44
- /**
45
- * Initiator
46
- *
47
- * @since 1.0.14
48
- * @return object initialized object of class.
49
- */
50
- public static function get_instance() {
51
- if ( ! isset( self::$instance ) ) {
52
- self::$instance = new self;
53
- }
54
- return self::$instance;
55
- }
56
-
57
- /**
58
- * Constructor
59
- *
60
- * @since 1.0.14
61
- */
62
- public function __construct() {
63
-
64
- if ( ! function_exists( 'WP_Filesystem' ) ) {
65
- require_once ABSPATH . 'wp-admin/includes/file.php';
66
- }
67
-
68
- WP_Filesystem();
69
- }
70
-
71
- /**
72
- * Process Image Download
73
- *
74
- * @since 1.0.14
75
- * @param array $attachments Attachment array.
76
- * @return array Attachment array.
77
- */
78
- public function process( $attachments ) {
79
-
80
- $downloaded_images = array();
81
-
82
- foreach ( $attachments as $key => $attachment ) {
83
- $downloaded_images[] = $this->import( $attachment );
84
- }
85
-
86
- return $downloaded_images;
87
- }
88
-
89
- /**
90
- * Get Hash Image.
91
- *
92
- * @since 1.0.14
93
- * @param string $attachment_url Attachment URL.
94
- * @return string Hash string.
95
- */
96
- private function get_hash_image( $attachment_url ) {
97
- return sha1( $attachment_url );
98
- }
99
-
100
- /**
101
- * Get Saved Image.
102
- *
103
- * @since 1.0.14
104
- * @param string $attachment Attachment Data.
105
- * @return string Hash string.
106
- */
107
- private function get_saved_image( $attachment ) {
108
-
109
- if ( apply_filters( 'astra_sites_image_importer_skip_image', false, $attachment ) ) {
110
- Astra_Sites_Importer_Log::add( 'BATCH - SKIP Image - {from filter} - ' . $attachment['url'] . ' - Filter name `astra_sites_image_importer_skip_image`.' );
111
- return $attachment;
112
- }
113
-
114
- global $wpdb;
115
-
116
- // Already imported? Then return!
117
- if ( isset( $this->already_imported_ids[ $attachment['id'] ] ) ) {
118
- Astra_Sites_Importer_Log::add( 'BATCH - SKIP Image {already imported from batch process} - ' . $attachment['url'] . ' - already imported.' );
119
- return $this->already_imported_ids[ $attachment['id'] ];
120
- }
121
-
122
- // 1. Is already imported in Batch Import Process?
123
- $post_id = $wpdb->get_var(
124
- $wpdb->prepare(
125
- 'SELECT `post_id` FROM `' . $wpdb->postmeta . '`
126
- WHERE `meta_key` = \'_astra_sites_image_hash\'
127
- AND `meta_value` = %s
128
- ;',
129
- $this->get_hash_image( $attachment['url'] )
130
- )
131
- );
132
-
133
- // 2. Is image already imported though XML?
134
- if ( empty( $post_id ) ) {
135
-
136
- // Get file name without extension.
137
- // To check it exist in attachment.
138
- $filename = basename( $attachment['url'] );
139
-
140
- $post_id = $wpdb->get_var(
141
- $wpdb->prepare(
142
- "SELECT post_id FROM {$wpdb->postmeta}
143
- WHERE meta_key = '_wp_attached_file'
144
- AND meta_value LIKE %s",
145
- '%' . $filename . '%'
146
- )
147
- );
148
-
149
- Astra_Sites_Importer_Log::add( 'BATCH - SKIP Image {already imported from xml} - ' . $attachment['url'] );
150
- }
151
-
152
- if ( $post_id ) {
153
- $new_attachment = array(
154
- 'id' => $post_id,
155
- 'url' => wp_get_attachment_url( $post_id ),
156
- );
157
- $this->already_imported_ids[ $attachment['id'] ] = $new_attachment;
158
-
159
- return $new_attachment;
160
- }
161
-
162
- return false;
163
- }
164
-
165
- /**
166
- * Import Image
167
- *
168
- * @since 1.0.14
169
- * @param array $attachment Attachment array.
170
- * @return array Attachment array.
171
- */
172
- public function import( $attachment ) {
173
-
174
- $saved_image = $this->get_saved_image( $attachment );
175
- if ( $saved_image ) {
176
- return $saved_image;
177
- }
178
-
179
- $file_content = wp_remote_retrieve_body(
180
- wp_safe_remote_get(
181
- $attachment['url'],
182
- array(
183
- 'timeout' => '60',
184
- 'sslverify' => false,
185
- )
186
- )
187
- );
188
-
189
- // Empty file content?
190
- if ( empty( $file_content ) ) {
191
- Astra_Sites_Importer_Log::add( 'BATCH - FAIL Image {Error: Failed wp_remote_retrieve_body} - ' . $attachment['url'] );
192
- return $attachment;
193
- }
194
-
195
- // Extract the file name and extension from the URL.
196
- $filename = basename( $attachment['url'] );
197
-
198
- $upload = wp_upload_bits(
199
- $filename,
200
- null,
201
- $file_content
202
- );
203
-
204
- $post = array(
205
- 'post_title' => $filename,
206
- 'guid' => $upload['url'],
207
- );
208
-
209
- $info = wp_check_filetype( $upload['file'] );
210
- if ( $info ) {
211
- $post['post_mime_type'] = $info['type'];
212
- } else {
213
- // For now just return the origin attachment.
214
- return $attachment;
215
- }
216
-
217
- $post_id = wp_insert_attachment( $post, $upload['file'] );
218
- wp_update_attachment_metadata(
219
- $post_id,
220
- wp_generate_attachment_metadata( $post_id, $upload['file'] )
221
- );
222
- update_post_meta( $post_id, '_astra_sites_image_hash', $this->get_hash_image( $attachment['url'] ) );
223
-
224
- $new_attachment = array(
225
- 'id' => $post_id,
226
- 'url' => $upload['url'],
227
- );
228
-
229
- Astra_Sites_Importer_Log::add( 'BATCH - SUCCESS Image {Imported} - ' . $new_attachment['url'] );
230
-
231
- $this->already_imported_ids[ $attachment['id'] ] = $new_attachment;
232
-
233
- return $new_attachment;
234
- }
235
-
236
- /**
237
- * Is Image URL
238
- *
239
- * @since 1.3.10
240
- *
241
- * @param string $url URL.
242
- * @return boolean
243
- */
244
- function is_image_url( $url = '' ) {
245
- if ( empty( $url ) ) {
246
- return false;
247
- }
248
-
249
- if ( preg_match( '/^((https?:\/\/)|(www\.))([a-z0-9-].?)+(:[0-9]+)?\/[\w\-]+\.(jpg|png|svg|gif|jpeg)\/?$/i', $url ) ) {
250
- return true;
251
- }
252
-
253
- return false;
254
- }
255
-
256
- }
257
-
258
- /**
259
- * Kicking this off by calling 'get_instance()' method
260
- */
261
- Astra_Sites_Image_Importer::get_instance();
262
-
263
- endif;
1
+ <?php
2
+ /**
3
+ * Image Importer
4
+ *
5
+ * => How to use?
6
+ *
7
+ * $image = array(
8
+ * 'url' => '<image-url>',
9
+ * 'id' => '<image-id>',
10
+ * );
11
+ *
12
+ * $downloaded_image = Astra_Sites_Image_Importer::get_instance()->import( $image );
13
+ *
14
+ * @package Astra Sites
15
+ * @since 1.0.14
16
+ */
17
+
18
+ if ( ! class_exists( 'Astra_Sites_Image_Importer' ) ) :
19
+
20
+ /**
21
+ * Astra Sites Image Importer
22
+ *
23
+ * @since 1.0.14
24
+ */
25
+ class Astra_Sites_Image_Importer {
26
+
27
+ /**
28
+ * Instance
29
+ *
30
+ * @since 1.0.14
31
+ * @var object Class object.
32
+ * @access private
33
+ */
34
+ private static $instance;
35
+
36
+ /**
37
+ * Images IDs
38
+ *
39
+ * @var array The Array of already image IDs.
40
+ * @since 1.0.14
41
+ */
42
+ private $already_imported_ids = array();
43
+
44
+ /**
45
+ * Initiator
46
+ *
47
+ * @since 1.0.14
48
+ * @return object initialized object of class.
49
+ */
50
+ public static function get_instance() {
51
+ if ( ! isset( self::$instance ) ) {
52
+ self::$instance = new self;
53
+ }
54
+ return self::$instance;
55
+ }
56
+
57
+ /**
58
+ * Constructor
59
+ *
60
+ * @since 1.0.14
61
+ */
62
+ public function __construct() {
63
+
64
+ if ( ! function_exists( 'WP_Filesystem' ) ) {
65
+ require_once ABSPATH . 'wp-admin/includes/file.php';
66
+ }
67
+
68
+ WP_Filesystem();
69
+ }
70
+
71
+ /**
72
+ * Process Image Download
73
+ *
74
+ * @since 1.0.14
75
+ * @param array $attachments Attachment array.
76
+ * @return array Attachment array.
77
+ */
78
+ public function process( $attachments ) {
79
+
80
+ $downloaded_images = array();
81
+
82
+ foreach ( $attachments as $key => $attachment ) {
83
+ $downloaded_images[] = $this->import( $attachment );
84
+ }
85
+
86
+ return $downloaded_images;
87
+ }
88
+
89
+ /**
90
+ * Get Hash Image.
91
+ *
92
+ * @since 1.0.14
93
+ * @param string $attachment_url Attachment URL.
94
+ * @return string Hash string.
95
+ */
96
+ private function get_hash_image( $attachment_url ) {
97
+ return sha1( $attachment_url );
98
+ }
99
+
100
+ /**
101
+ * Get Saved Image.
102
+ *
103
+ * @since 1.0.14
104
+ * @param string $attachment Attachment Data.
105
+ * @return string Hash string.
106
+ */
107
+ private function get_saved_image( $attachment ) {
108
+
109
+ if ( apply_filters( 'astra_sites_image_importer_skip_image', false, $attachment ) ) {
110
+ Astra_Sites_Importer_Log::add( 'BATCH - SKIP Image - {from filter} - ' . $attachment['url'] . ' - Filter name `astra_sites_image_importer_skip_image`.' );
111
+ return $attachment;
112
+ }
113
+
114
+ global $wpdb;
115
+
116
+ // Already imported? Then return!
117
+ if ( isset( $this->already_imported_ids[ $attachment['id'] ] ) ) {
118
+ Astra_Sites_Importer_Log::add( 'BATCH - SKIP Image {already imported from batch process} - ' . $attachment['url'] . ' - already imported.' );
119
+ return $this->already_imported_ids[ $attachment['id'] ];
120
+ }
121
+
122
+ // 1. Is already imported in Batch Import Process?
123
+ $post_id = $wpdb->get_var(
124
+ $wpdb->prepare(
125
+ 'SELECT `post_id` FROM `' . $wpdb->postmeta . '`
126
+ WHERE `meta_key` = \'_astra_sites_image_hash\'
127
+ AND `meta_value` = %s
128
+ ;',
129
+ $this->get_hash_image( $attachment['url'] )
130
+ )
131
+ );
132
+
133
+ // 2. Is image already imported though XML?
134
+ if ( empty( $post_id ) ) {
135
+
136
+ // Get file name without extension.
137
+ // To check it exist in attachment.
138
+ $filename = basename( $attachment['url'] );
139
+
140
+ $post_id = $wpdb->get_var(
141
+ $wpdb->prepare(
142
+ "SELECT post_id FROM {$wpdb->postmeta}
143
+ WHERE meta_key = '_wp_attached_file'
144
+ AND meta_value LIKE %s",
145
+ '%' . $filename . '%'
146
+ )
147
+ );
148
+
149
+ Astra_Sites_Importer_Log::add( 'BATCH - SKIP Image {already imported from xml} - ' . $attachment['url'] );
150
+ }
151
+
152
+ if ( $post_id ) {
153
+ $new_attachment = array(
154
+ 'id' => $post_id,
155
+ 'url' => wp_get_attachment_url( $post_id ),
156
+ );
157
+ $this->already_imported_ids[ $attachment['id'] ] = $new_attachment;
158
+
159
+ return $new_attachment;
160
+ }
161
+
162
+ return false;
163
+ }
164
+
165
+ /**
166
+ * Import Image
167
+ *
168
+ * @since 1.0.14
169
+ * @param array $attachment Attachment array.
170
+ * @return array Attachment array.
171
+ */
172
+ public function import( $attachment ) {
173
+
174
+ $saved_image = $this->get_saved_image( $attachment );
175
+ if ( $saved_image ) {
176
+ return $saved_image;
177
+ }
178
+
179
+ $file_content = wp_remote_retrieve_body(
180
+ wp_safe_remote_get(
181
+ $attachment['url'],
182
+ array(
183
+ 'timeout' => '60',
184
+ 'sslverify' => false,
185
+ )
186
+ )
187
+ );
188
+
189
+ // Empty file content?
190
+ if ( empty( $file_content ) ) {
191
+ Astra_Sites_Importer_Log::add( 'BATCH - FAIL Image {Error: Failed wp_remote_retrieve_body} - ' . $attachment['url'] );
192
+ return $attachment;
193
+ }
194
+
195
+ // Extract the file name and extension from the URL.
196
+ $filename = basename( $attachment['url'] );
197
+
198
+ $upload = wp_upload_bits(
199
+ $filename,
200
+ null,
201
+ $file_content
202
+ );
203
+
204
+ $post = array(
205
+ 'post_title' => $filename,
206
+ 'guid' => $upload['url'],
207
+ );
208
+
209
+ $info = wp_check_filetype( $upload['file'] );
210
+ if ( $info ) {
211
+ $post['post_mime_type'] = $info['type'];
212
+ } else {
213
+ // For now just return the origin attachment.
214
+ return $attachment;
215
+ }
216
+
217
+ $post_id = wp_insert_attachment( $post, $upload['file'] );
218
+ wp_update_attachment_metadata(
219
+ $post_id,
220
+ wp_generate_attachment_metadata( $post_id, $upload['file'] )
221
+ );
222
+ update_post_meta( $post_id, '_astra_sites_image_hash', $this->get_hash_image( $attachment['url'] ) );
223
+
224
+ $new_attachment = array(
225
+ 'id' => $post_id,
226
+ 'url' => $upload['url'],
227
+ );
228
+
229
+ Astra_Sites_Importer_Log::add( 'BATCH - SUCCESS Image {Imported} - ' . $new_attachment['url'] );
230
+
231
+ $this->already_imported_ids[ $attachment['id'] ] = $new_attachment;
232
+
233
+ return $new_attachment;
234
+ }
235
+
236
+ /**
237
+ * Is Image URL
238
+ *
239
+ * @since 1.3.10
240
+ *
241
+ * @param string $url URL.
242
+ * @return boolean
243
+ */
244
+ function is_image_url( $url = '' ) {
245
+ if ( empty( $url ) ) {
246
+ return false;
247
+ }
248
+
249
+ if ( preg_match( '/^((https?:\/\/)|(www\.))([a-z0-9-].?)+(:[0-9]+)?\/[\w\-]+\.(jpg|png|svg|gif|jpeg)\/?$/i', $url ) ) {
250
+ return true;
251
+ }
252
+
253
+ return false;
254
+ }
255
+
256
+ }
257
+
258
+ /**
259
+ * Kicking this off by calling 'get_instance()' method
260
+ */
261
+ Astra_Sites_Image_Importer::get_instance();
262
+
263
+ endif;
inc/importers/class-astra-site-options-import.php CHANGED
@@ -1,309 +1,309 @@
1
- <?php
2
- /**
3
- * Customizer Site options importer class.
4
- *
5
- * @since 1.0.0
6
- * @package Astra Addon
7
- */
8
-
9
- defined( 'ABSPATH' ) or exit;
10
-
11
- /**
12
- * Customizer Site options importer class.
13
- *
14
- * @since 1.0.0
15
- */
16
- class Astra_Site_Options_Import {
17
-
18
- /**
19
- * Instance of Astra_Site_Options_Importer
20
- *
21
- * @since 1.0.0
22
- * @var (Object) Astra_Site_Options_Importer
23
- */
24
- private static $_instance = null;
25
-
26
- /**
27
- * Instanciate Astra_Site_Options_Importer
28
- *
29
- * @since 1.0.0
30
- * @return (Object) Astra_Site_Options_Importer
31
- */
32
- public static function instance() {
33
- if ( ! isset( self::$_instance ) ) {
34
- self::$_instance = new self();
35
- }
36
-
37
- return self::$_instance;
38
- }
39
-
40
- /**
41
- * Site Options
42
- *
43
- * @since 1.0.2
44
- *
45
- * @return array List of defined array.
46
- */
47
- private static function site_options() {
48
- return array(
49
- 'custom_logo',
50
- 'nav_menu_locations',
51
- 'show_on_front',
52
- 'page_on_front',
53
- 'page_for_posts',
54
-
55
- // Plugin: SiteOrigin Widgets Bundle.
56
- 'siteorigin_widgets_active',
57
-
58
- // Plugin: Elementor.
59
- 'elementor_container_width',
60
- 'elementor_cpt_support',
61
- 'elementor_css_print_method',
62
- 'elementor_default_generic_fonts',
63
- 'elementor_disable_color_schemes',
64
- 'elementor_disable_typography_schemes',
65
- 'elementor_editor_break_lines',
66
- 'elementor_exclude_user_roles',
67
- 'elementor_global_image_lightbox',
68
- 'elementor_page_title_selector',
69
- 'elementor_scheme_color',
70
- 'elementor_scheme_color-picker',
71
- 'elementor_scheme_typography',
72
- 'elementor_space_between_widgets',
73
- 'elementor_stretched_section_container',
74
-
75
- // Plugin: Beaver Builder.
76
- '_fl_builder_enabled_icons',
77
- '_fl_builder_enabled_modules',
78
- '_fl_builder_post_types',
79
- '_fl_builder_color_presets',
80
- '_fl_builder_services',
81
- '_fl_builder_settings',
82
- '_fl_builder_user_access',
83
- '_fl_builder_enabled_templates',
84
-
85
- // Plugin: WooCommerce.
86
- // Pages.
87
- 'woocommerce_shop_page_title',
88
- 'woocommerce_cart_page_title',
89
- 'woocommerce_checkout_page_title',
90
- 'woocommerce_myaccount_page_title',
91
- 'woocommerce_edit_address_page_title',
92
- 'woocommerce_view_order_page_title',
93
- 'woocommerce_change_password_page_title',
94
- 'woocommerce_logout_page_title',
95
-
96
- // Account & Privacy.
97
- 'woocommerce_enable_guest_checkout',
98
- 'woocommerce_enable_checkout_login_reminder',
99
- 'woocommerce_enable_signup_and_login_from_checkout',
100
- 'woocommerce_enable_myaccount_registration',
101
- 'woocommerce_registration_generate_username',
102
-
103
- // Plugin: WPForms.
104
- 'wpforms_settings',
105
-
106
- // Categories.
107
- 'woocommerce_product_cat',
108
-
109
- // Plugin: LearnDash LMS.
110
- 'learndash_settings_theme_ld30',
111
- 'learndash_settings_courses_themes',
112
-
113
- );
114
- }
115
-
116
- /**
117
- * Import site options.
118
- *
119
- * @since 1.0.2 Updated option if exist in defined option array 'site_options()'.
120
- *
121
- * @since 1.0.0
122
- *
123
- * @param (Array) $options Array of site options to be imported from the demo.
124
- */
125
- public function import_options( $options = array() ) {
126
-
127
- if ( ! isset( $options ) ) {
128
- return;
129
- }
130
-
131
- foreach ( $options as $option_name => $option_value ) {
132
-
133
- // Is option exist in defined array site_options()?
134
- if ( null !== $option_value ) {
135
-
136
- // Is option exist in defined array site_options()?
137
- if ( in_array( $option_name, self::site_options(), true ) ) {
138
-
139
- switch ( $option_name ) {
140
-
141
- // Set WooCommerce page ID by page Title.
142
- case 'woocommerce_shop_page_title':
143
- case 'woocommerce_cart_page_title':
144
- case 'woocommerce_checkout_page_title':
145
- case 'woocommerce_myaccount_page_title':
146
- case 'woocommerce_edit_address_page_title':
147
- case 'woocommerce_view_order_page_title':
148
- case 'woocommerce_change_password_page_title':
149
- case 'woocommerce_logout_page_title':
150
- $this->update_woocommerce_page_id_by_option_value( $option_name, $option_value );
151
- break;
152
-
153
- case 'page_for_posts':
154
- case 'page_on_front':
155
- $this->update_page_id_by_option_value( $option_name, $option_value );
156
- break;
157
-
158
- // nav menu locations.
159
- case 'nav_menu_locations':
160
- $this->set_nav_menu_locations( $option_value );
161
- break;
162
-
163
- // import WooCommerce category images.
164
- case 'woocommerce_product_cat':
165
- $this->set_woocommerce_product_cat( $option_value );
166
- break;
167
-
168
- // insert logo.
169
- case 'custom_logo':
170
- $this->insert_logo( $option_value );
171
- break;
172
-
173
- default:
174
- update_option( $option_name, $option_value );
175
- break;
176
- }
177
- }
178
- }
179
- }
180
- }
181
-
182
- /**
183
- * Update post option
184
- *
185
- * @since 1.0.2
186
- *
187
- * @param string $option_name Option name.
188
- * @param mixed $option_value Option value.
189
- * @return void
190
- */
191
- private function update_page_id_by_option_value( $option_name, $option_value ) {
192
- $page = get_page_by_title( $option_value );
193
- if ( is_object( $page ) ) {
194
- update_option( $option_name, $page->ID );
195
- }
196
- }
197
-
198
- /**
199
- * Update WooCommerce page ids.
200
- *
201
- * @since 1.1.6
202
- *
203
- * @param string $option_name Option name.
204
- * @param mixed $option_value Option value.
205
- * @return void
206
- */
207
- private function update_woocommerce_page_id_by_option_value( $option_name, $option_value ) {
208
- $option_name = str_replace( '_title', '_id', $option_name );
209
- $this->update_page_id_by_option_value( $option_name, $option_value );
210
- }
211
-
212
- /**
213
- * In WP nav menu is stored as ( 'menu_location' => 'menu_id' );
214
- * In export we send 'menu_slug' like ( 'menu_location' => 'menu_slug' );
215
- * In import we set 'menu_id' from menu slug like ( 'menu_location' => 'menu_id' );
216
- *
217
- * @since 1.0.0
218
- * @param array $nav_menu_locations Array of nav menu locations.
219
- */
220
- private function set_nav_menu_locations( $nav_menu_locations = array() ) {
221
-
222
- $menu_locations = array();
223
-
224
- // Update menu locations.
225
- if ( isset( $nav_menu_locations ) ) {
226
-
227
- foreach ( $nav_menu_locations as $menu => $value ) {
228
-
229
- $term = get_term_by( 'slug', $value, 'nav_menu' );
230
-
231
- if ( is_object( $term ) ) {
232
- $menu_locations[ $menu ] = $term->term_id;
233
- }
234
- }
235
-
236
- set_theme_mod( 'nav_menu_locations', $menu_locations );
237
- }
238
- }
239
-
240
- /**
241
- * Set WooCommerce category images.
242
- *
243
- * @since 1.1.4
244
- *
245
- * @param array $cats Array of categories.
246
- */
247
- private function set_woocommerce_product_cat( $cats = array() ) {
248
-
249
- $menu_locations = array();
250
-
251
- if ( isset( $cats ) ) {
252
-
253
- foreach ( $cats as $key => $cat ) {
254
-
255
- if ( ! empty( $cat['slug'] ) && ! empty( $cat['thumbnail_src'] ) ) {
256
-
257
- $image = (object) Astra_Sites_Helper::_sideload_image( $cat['thumbnail_src'] );
258
-
259
- if ( ! is_wp_error( $image ) ) {
260
-
261
- if ( isset( $image->attachment_id ) && ! empty( $image->attachment_id ) ) {
262
-
263
- $term = get_term_by( 'slug', $cat['slug'], 'product_cat' );
264
-
265
- if ( is_object( $term ) ) {
266
- update_term_meta( $term->term_id, 'thumbnail_id', $image->attachment_id );
267
- }
268
- }
269
- }
270
- }
271
- }
272
- }
273
- }
274
-
275
- /**
276
- * Insert Logo By URL
277
- *
278
- * @since 1.0.0
279
- * @param string $image_url Logo URL.
280
- * @return void
281
- */
282
- private function insert_logo( $image_url = '' ) {
283
- $attachment_id = $this->download_image( $image_url );
284
- if ( $attachment_id ) {
285
- set_theme_mod( 'custom_logo', $attachment_id );
286
- }
287
- }
288
-
289
- /**
290
- * Download image by URL
291
- *
292
- * @since 1.3.13
293
- *
294
- * @param string $image_url Logo URL.
295
- * @return mixed false|Attachment ID
296
- */
297
- private function download_image( $image_url = '' ) {
298
- $data = (object) Astra_Sites_Helper::_sideload_image( $image_url );
299
-
300
- if ( ! is_wp_error( $data ) ) {
301
- if ( isset( $data->attachment_id ) && ! empty( $data->attachment_id ) ) {
302
- return $data->attachment_id;
303
- }
304
- }
305
-
306
- return false;
307
- }
308
-
309
- }
1
+ <?php
2
+ /**
3
+ * Customizer Site options importer class.
4
+ *
5
+ * @since 1.0.0
6
+ * @package Astra Addon
7
+ */
8
+
9
+ defined( 'ABSPATH' ) or exit;
10
+
11
+ /**
12
+ * Customizer Site options importer class.
13
+ *
14
+ * @since 1.0.0
15
+ */
16
+ class Astra_Site_Options_Import {
17
+
18
+ /**
19
+ * Instance of Astra_Site_Options_Importer
20
+ *
21
+ * @since 1.0.0
22
+ * @var (Object) Astra_Site_Options_Importer
23
+ */
24
+ private static $_instance = null;
25
+
26
+ /**
27
+ * Instanciate Astra_Site_Options_Importer
28
+ *
29
+ * @since 1.0.0
30
+ * @return (Object) Astra_Site_Options_Importer
31
+ */
32
+ public static function instance() {
33
+ if ( ! isset( self::$_instance ) ) {
34
+ self::$_instance = new self();
35
+ }
36
+
37
+ return self::$_instance;
38
+ }
39
+
40
+ /**
41
+ * Site Options
42
+ *
43
+ * @since 1.0.2
44
+ *
45
+ * @return array List of defined array.
46
+ */
47
+ private static function site_options() {
48
+ return array(
49
+ 'custom_logo',
50
+ 'nav_menu_locations',
51
+ 'show_on_front',
52
+ 'page_on_front',
53
+ 'page_for_posts',
54
+
55
+ // Plugin: SiteOrigin Widgets Bundle.
56
+ 'siteorigin_widgets_active',
57
+
58
+ // Plugin: Elementor.
59
+ 'elementor_container_width',
60
+ 'elementor_cpt_support',
61
+ 'elementor_css_print_method',
62
+ 'elementor_default_generic_fonts',
63
+ 'elementor_disable_color_schemes',
64
+ 'elementor_disable_typography_schemes',
65
+ 'elementor_editor_break_lines',
66
+ 'elementor_exclude_user_roles',
67
+ 'elementor_global_image_lightbox',
68
+ 'elementor_page_title_selector',
69
+ 'elementor_scheme_color',
70
+ 'elementor_scheme_color-picker',
71
+ 'elementor_scheme_typography',
72
+ 'elementor_space_between_widgets',
73
+ 'elementor_stretched_section_container',
74
+
75
+ // Plugin: Beaver Builder.
76
+ '_fl_builder_enabled_icons',
77
+ '_fl_builder_enabled_modules',
78
+ '_fl_builder_post_types',
79
+ '_fl_builder_color_presets',
80
+ '_fl_builder_services',
81
+ '_fl_builder_settings',
82
+ '_fl_builder_user_access',
83
+ '_fl_builder_enabled_templates',
84
+
85
+ // Plugin: WooCommerce.
86
+ // Pages.
87
+ 'woocommerce_shop_page_title',
88
+ 'woocommerce_cart_page_title',
89
+ 'woocommerce_checkout_page_title',
90
+ 'woocommerce_myaccount_page_title',
91
+ 'woocommerce_edit_address_page_title',
92
+ 'woocommerce_view_order_page_title',
93
+ 'woocommerce_change_password_page_title',
94
+ 'woocommerce_logout_page_title',
95
+
96
+ // Account & Privacy.
97
+ 'woocommerce_enable_guest_checkout',
98
+ 'woocommerce_enable_checkout_login_reminder',
99
+ 'woocommerce_enable_signup_and_login_from_checkout',
100
+ 'woocommerce_enable_myaccount_registration',
101
+ 'woocommerce_registration_generate_username',
102
+
103
+ // Plugin: WPForms.
104
+ 'wpforms_settings',
105
+
106
+ // Categories.
107
+ 'woocommerce_product_cat',
108
+
109
+ // Plugin: LearnDash LMS.
110
+ 'learndash_settings_theme_ld30',
111
+ 'learndash_settings_courses_themes',
112
+
113
+ );
114
+ }
115
+
116
+ /**
117
+ * Import site options.
118
+ *
119
+ * @since 1.0.2 Updated option if exist in defined option array 'site_options()'.
120
+ *
121
+ * @since 1.0.0
122
+ *
123
+ * @param (Array) $options Array of site options to be imported from the demo.
124
+ */
125
+ public function import_options( $options = array() ) {
126
+
127
+ if ( ! isset( $options ) ) {
128
+ return;
129
+ }
130
+
131
+ foreach ( $options as $option_name => $option_value ) {
132
+
133
+ // Is option exist in defined array site_options()?
134
+ if ( null !== $option_value ) {
135
+
136
+ // Is option exist in defined array site_options()?
137
+ if ( in_array( $option_name, self::site_options(), true ) ) {
138
+
139
+ switch ( $option_name ) {
140
+
141
+ // Set WooCommerce page ID by page Title.
142
+ case 'woocommerce_shop_page_title':
143
+ case 'woocommerce_cart_page_title':
144
+ case 'woocommerce_checkout_page_title':
145
+ case 'woocommerce_myaccount_page_title':
146
+ case 'woocommerce_edit_address_page_title':
147
+ case 'woocommerce_view_order_page_title':
148
+ case 'woocommerce_change_password_page_title':
149
+ case 'woocommerce_logout_page_title':
150
+ $this->update_woocommerce_page_id_by_option_value( $option_name, $option_value );
151
+ break;
152
+
153
+ case 'page_for_posts':
154
+ case 'page_on_front':
155
+ $this->update_page_id_by_option_value( $option_name, $option_value );
156
+ break;
157
+
158
+ // nav menu locations.
159
+ case 'nav_menu_locations':
160
+ $this->set_nav_menu_locations( $option_value );
161
+ break;
162
+
163
+ // import WooCommerce category images.
164
+ case 'woocommerce_product_cat':
165
+ $this->set_woocommerce_product_cat( $option_value );
166
+ break;
167
+
168
+ // insert logo.
169
+ case 'custom_logo':
170
+ $this->insert_logo( $option_value );
171
+ break;
172
+
173
+ default:
174
+ update_option( $option_name, $option_value );
175
+ break;
176
+ }
177
+ }
178
+ }
179
+ }
180
+ }
181
+
182
+ /**
183
+ * Update post option
184
+ *
185
+ * @since 1.0.2
186
+ *
187
+ * @param string $option_name Option name.
188
+ * @param mixed $option_value Option value.
189
+ * @return void
190
+ */
191
+ private function update_page_id_by_option_value( $option_name, $option_value ) {
192
+ $page = get_page_by_title( $option_value );
193
+ if ( is_object( $page ) ) {
194
+ update_option( $option_name, $page->ID );
195
+ }
196
+ }
197
+
198
+ /**
199
+ * Update WooCommerce page ids.
200
+ *
201
+ * @since 1.1.6
202
+ *
203
+ * @param string $option_name Option name.
204
+ * @param mixed $option_value Option value.
205
+ * @return void
206
+ */
207
+ private function update_woocommerce_page_id_by_option_value( $option_name, $option_value ) {
208
+ $option_name = str_replace( '_title', '_id', $option_name );
209
+ $this->update_page_id_by_option_value( $option_name, $option_value );
210
+ }
211
+
212
+ /**
213
+ * In WP nav menu is stored as ( 'menu_location' => 'menu_id' );
214
+ * In export we send 'menu_slug' like ( 'menu_location' => 'menu_slug' );
215
+ * In import we set 'menu_id' from menu slug like ( 'menu_location' => 'menu_id' );
216
+ *
217
+ * @since 1.0.0
218
+ * @param array $nav_menu_locations Array of nav menu locations.
219
+ */
220
+ private function set_nav_menu_locations( $nav_menu_locations = array() ) {
221
+
222
+ $menu_locations = array();
223
+
224
+ // Update menu locations.
225
+ if ( isset( $nav_menu_locations ) ) {
226
+
227
+ foreach ( $nav_menu_locations as $menu => $value ) {
228
+
229
+ $term = get_term_by( 'slug', $value, 'nav_menu' );
230
+
231
+ if ( is_object( $term ) ) {
232
+ $menu_locations[ $menu ] = $term->term_id;
233
+ }
234
+ }
235
+
236
+ set_theme_mod( 'nav_menu_locations', $menu_locations );
237
+ }
238
+ }
239
+
240
+ /**
241
+ * Set WooCommerce category images.
242
+ *
243
+ * @since 1.1.4
244
+ *
245
+ * @param array $cats Array of categories.
246
+ */
247
+ private function set_woocommerce_product_cat( $cats = array() ) {
248
+
249
+ $menu_locations = array();
250
+
251
+ if ( isset( $cats ) ) {
252
+
253
+ foreach ( $cats as $key => $cat ) {
254
+
255
+ if ( ! empty( $cat['slug'] ) && ! empty( $cat['thumbnail_src'] ) ) {
256
+
257
+ $image = (object) Astra_Sites_Helper::_sideload_image( $cat['thumbnail_src'] );
258
+
259
+ if ( ! is_wp_error( $image ) ) {
260
+
261
+ if ( isset( $image->attachment_id ) && ! empty( $image->attachment_id ) ) {
262
+
263
+ $term = get_term_by( 'slug', $cat['slug'], 'product_cat' );
264
+
265
+ if ( is_object( $term ) ) {
266
+ update_term_meta( $term->term_id, 'thumbnail_id', $image->attachment_id );
267
+ }
268
+ }
269
+ }
270
+ }
271
+ }
272
+ }
273
+ }
274
+
275
+ /**
276
+ * Insert Logo By URL
277
+ *
278
+ * @since 1.0.0
279
+ * @param string $image_url Logo URL.
280
+ * @return void
281
+ */
282
+ private function insert_logo( $image_url = '' ) {
283
+ $attachment_id = $this->download_image( $image_url );
284
+ if ( $attachment_id ) {
285
+ set_theme_mod( 'custom_logo', $attachment_id );
286
+ }
287
+ }
288
+
289
+ /**
290
+ * Download image by URL
291
+ *
292
+ * @since 1.3.13
293
+ *
294
+ * @param string $image_url Logo URL.
295
+ * @return mixed false|Attachment ID
296
+ */
297
+ private function download_image( $image_url = '' ) {
298
+ $data = (object) Astra_Sites_Helper::_sideload_image( $image_url );
299
+
300
+ if ( ! is_wp_error( $data ) ) {
301
+ if ( isset( $data->attachment_id ) && ! empty( $data->attachment_id ) ) {
302
+ return $data->attachment_id;
303
+ }
304
+ }
305
+
306
+ return false;
307
+ }
308
+
309
+ }
inc/importers/class-astra-sites-helper.php CHANGED
@@ -1,311 +1,311 @@
1
- <?php
2
- /**
3
- * Astra Site Helper
4
- *
5
- * @since 1.0.0
6
- * @package Astra Sites
7
- */
8
-
9
- if ( ! class_exists( 'Astra_Sites_Helper' ) ) :
10
-
11
- /**
12
- * Astra_Sites_Helper
13
- *
14
- * @since 1.0.0
15
- */
16
- class Astra_Sites_Helper {
17
-
18
- /**
19
- * Instance
20
- *
21
- * @access private
22
- * @var object Instance
23
- * @since 1.0.0
24
- */
25
- private static $instance;
26
-
27
- /**
28
- * Initiator
29
- *
30
- * @since 1.0.0
31
- * @return object initialized object of class.
32
- */
33
- public static function get_instance() {
34
- if ( ! isset( self::$instance ) ) {
35
- self::$instance = new self;
36
- }
37
- return self::$instance;
38
- }
39
-
40
- /**
41
- * Constructor
42
- *
43
- * @since 1.0.0
44
- */
45
- public function __construct() {
46
- add_filter( 'wie_import_data', array( $this, 'custom_menu_widget' ) );
47
- add_filter( 'wp_prepare_attachment_for_js', array( $this, 'add_svg_image_support' ), 10, 3 );
48
- }
49
-
50
- /**
51
- * Add svg image support
52
- *
53
- * @since 1.1.5
54
- *
55
- * @param array $response Attachment response.
56
- * @param object $attachment Attachment object.
57
- * @param array $meta Attachment meta data.
58
- */
59
- function add_svg_image_support( $response, $attachment, $meta ) {
60
- if ( ! function_exists( 'simplexml_load_file' ) ) {
61
- return $response;
62
- }
63
-
64
- if ( ! empty( $response['sizes'] ) ) {
65
- return $response;
66
- }
67
-
68
- if ( 'image/svg+xml' !== $response['mime'] ) {
69
- return $response;
70
- }
71
-
72
- $svg_path = get_attached_file( $attachment->ID );
73
-
74
- $dimensions = self::get_svg_dimensions( $svg_path );
75
-
76
- $response['sizes'] = array(
77
- 'full' => array(
78
- 'url' => $response['url'],
79
- 'width' => $dimensions->width,
80
- 'height' => $dimensions->height,
81
- 'orientation' => $dimensions->width > $dimensions->height ? 'landscape' : 'portrait',
82
- ),
83
- );
84
-
85
- return $response;
86
- }
87
-
88
- /**
89
- * Get SVG Dimensions
90
- *
91
- * @since 1.1.5
92
- *
93
- * @param string $svg SVG file path.
94
- * @return array Return SVG file height & width for valid SVG file.
95
- */
96
- public static function get_svg_dimensions( $svg ) {
97
-
98
- $svg = simplexml_load_file( $svg );
99
-
100
- if ( false === $svg ) {
101
- $width = '0';
102
- $height = '0';
103
- } else {
104
- $attributes = $svg->attributes();
105
- $width = (string) $attributes->width;
106
- $height = (string) $attributes->height;
107
- }
108
-
109
- return (object) array(
110
- 'width' => $width,
111
- 'height' => $height,
112
- );
113
- }
114
-
115
- /**
116
- * Custom Menu Widget
117
- *
118
- * In widget export we set the nav menu slug instead of ID.
119
- * So, In import process we check get menu id by slug and set
120
- * it in import widget process.
121
- *
122
- * @since 1.0.7
123
- *
124
- * @param object $all_sidebars Widget data.
125
- * @return object Set custom menu id by slug.
126
- */
127
- function custom_menu_widget( $all_sidebars ) {
128
-
129
- // Get current menu ID & Slugs.
130
- $menu_locations = array();
131
- $nav_menus = (object) wp_get_nav_menus();
132
- if ( isset( $nav_menus ) ) {
133
- foreach ( $nav_menus as $menu_key => $menu ) {
134
- if ( is_object( $menu ) ) {
135
- $menu_locations[ $menu->term_id ] = $menu->slug;
136
- }
137
- }
138
- }
139
-
140
- // Import widget data.
141
- $all_sidebars = (object) $all_sidebars;
142
- foreach ( $all_sidebars as $widgets_key => $widgets ) {
143
- foreach ( $widgets as $widget_key => $widget ) {
144
-
145
- // Found slug in current menu list.
146
- if ( isset( $widget->nav_menu ) ) {
147
- $menu_id = array_search( $widget->nav_menu, $menu_locations, true );
148
- if ( ! empty( $menu_id ) ) {
149
- $all_sidebars->$widgets_key->$widget_key->nav_menu = $menu_id;
150
- }
151
- }
152
- }
153
- }
154
-
155
- return $all_sidebars;
156
- }
157
-
158
- /**
159
- * Download File Into Uploads Directory
160
- *
161
- * @param string $file Download File URL.
162
- * @return array Downloaded file data.
163
- */
164
- public static function download_file( $file = '' ) {
165
-
166
- // Gives us access to the download_url() and wp_handle_sideload() functions.
167
- require_once( ABSPATH . 'wp-admin/includes/file.php' );
168
-
169
- $timeout_seconds = 5;
170
-
171
- // Download file to temp dir.
172
- $temp_file = download_url( $file, $timeout_seconds );
173
-
174
- // WP Error.
175
- if ( is_wp_error( $temp_file ) ) {
176
- return array(
177
- 'success' => false,
178
- 'data' => $temp_file->get_error_message(),
179
- );
180
- }
181
-
182
- // Array based on $_FILE as seen in PHP file uploads.
183
- $file_args = array(
184
- 'name' => basename( $file ),
185
- 'tmp_name' => $temp_file,
186
- 'error' => 0,
187
- 'size' => filesize( $temp_file ),
188
- );
189
-
190
- $overrides = array(
191
-
192
- // Tells WordPress to not look for the POST form
193
- // fields that would normally be present as
194
- // we downloaded the file from a remote server, so there
195
- // will be no form fields
196
- // Default is true.
197
- 'test_form' => false,
198
-
199
- // Setting this to false lets WordPress allow empty files, not recommended.
200
- // Default is true.
201
- 'test_size' => true,
202
-
203
- // A properly uploaded file will pass this test. There should be no reason to override this one.
204
- 'test_upload' => true,
205
-
206
- 'mimes' => array(
207
- 'xml' => 'text/xml',
208
- 'json' => 'text/plain',
209
- ),
210
- );
211
-
212
- // Move the temporary file into the uploads directory.
213
- $results = wp_handle_sideload( $file_args, $overrides );
214
-
215
- if ( isset( $results['error'] ) ) {
216
- return array(
217
- 'success' => false,
218
- 'data' => $results,
219
- );
220
- }
221
-
222
- // Success.
223
- return array(
224
- 'success' => true,
225
- 'data' => $results,
226
- );
227
- }
228
-
229
- /**
230
- * Downloads an image from the specified URL.
231
- *
232
- * Taken from the core media_sideload_image() function and
233
- * modified to return an array of data instead of html.
234
- *
235
- * @since 1.0.10
236
- *
237
- * @param string $file The image file path.
238
- * @return array An array of image data.
239
- */
240
- static public function _sideload_image( $file ) {
241
- $data = new stdClass();
242
-
243
- if ( ! function_exists( 'media_handle_sideload' ) ) {
244
- require_once( ABSPATH . 'wp-admin/includes/media.php' );
245
- require_once( ABSPATH . 'wp-admin/includes/file.php' );
246
- require_once( ABSPATH . 'wp-admin/includes/image.php' );
247
- }
248
-
249
- if ( ! empty( $file ) ) {
250
-
251
- // Set variables for storage, fix file filename for query strings.
252
- preg_match( '/[^\?]+\.(jpe?g|jpe|svg|gif|png)\b/i', $file, $matches );
253
- $file_array = array();
254
- $file_array['name'] = basename( $matches[0] );
255
-
256
- // Download file to temp location.
257
- $file_array['tmp_name'] = download_url( $file );
258
-
259
- // If error storing temporarily, return the error.
260
- if ( is_wp_error( $file_array['tmp_name'] ) ) {
261
- return $file_array['tmp_name'];
262
- }
263
-
264
- // Do the validation and storage stuff.
265
- $id = media_handle_sideload( $file_array, 0 );
266
-
267
- // If error storing permanently, unlink.
268
- if ( is_wp_error( $id ) ) {
269
- unlink( $file_array['tmp_name'] );
270
- return $id;
271
- }
272
-
273
- // Build the object to return.
274
- $meta = wp_get_attachment_metadata( $id );
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;
283
- }
284
-
285
- /**
286
- * Checks to see whether a string is an image url or not.
287
- *
288
- * @since 1.0.10
289
- *
290
- * @param string $string The string to check.
291
- * @return bool Whether the string is an image url or not.
292
- */
293
- static public function _is_image_url( $string = '' ) {
294
- if ( is_string( $string ) ) {
295
-
296
- if ( preg_match( '/\.(jpg|jpeg|svg|png|gif)/i', $string ) ) {
297
- return true;
298
- }
299
- }
300
-
301
- return false;
302
- }
303
-
304
- }
305
-
306
- /**
307
- * Kicking this off by calling 'get_instance()' method
308
- */
309
- Astra_Sites_Helper::get_instance();
310
-
311
- endif;
1
+ <?php
2
+ /**
3
+ * Astra Site Helper
4
+ *
5
+ * @since 1.0.0
6
+ * @package Astra Sites
7
+ */
8
+
9
+ if ( ! class_exists( 'Astra_Sites_Helper' ) ) :
10
+
11
+ /**
12
+ * Astra_Sites_Helper
13
+ *
14
+ * @since 1.0.0
15
+ */
16
+ class Astra_Sites_Helper {
17
+
18
+ /**
19
+ * Instance
20
+ *
21
+ * @access private
22
+ * @var object Instance
23
+ * @since 1.0.0
24
+ */
25
+ private static $instance;
26
+
27
+ /**
28
+ * Initiator
29
+ *
30
+ * @since 1.0.0
31
+ * @return object initialized object of class.
32
+ */
33
+ public static function get_instance() {
34
+ if ( ! isset( self::$instance ) ) {
35
+ self::$instance = new self;
36
+ }
37
+ return self::$instance;
38
+ }
39
+
40
+ /**
41
+ * Constructor
42
+ *
43
+ * @since 1.0.0
44
+ */
45
+ public function __construct() {
46
+ add_filter( 'wie_import_data', array( $this, 'custom_menu_widget' ) );
47
+ add_filter( 'wp_prepare_attachment_for_js', array( $this, 'add_svg_image_support' ), 10, 3 );
48
+ }
49
+
50
+ /**
51
+ * Add svg image support
52
+ *
53
+ * @since 1.1.5
54
+ *
55
+ * @param array $response Attachment response.
56
+ * @param object $attachment Attachment object.
57
+ * @param array $meta Attachment meta data.
58
+ */
59
+ function add_svg_image_support( $response, $attachment, $meta ) {
60
+ if ( ! function_exists( 'simplexml_load_file' ) ) {
61
+ return $response;
62
+ }
63
+
64
+ if ( ! empty( $response['sizes'] ) ) {
65
+ return $response;
66
+ }
67
+
68
+ if ( 'image/svg+xml' !== $response['mime'] ) {
69
+ return $response;
70
+ }
71
+
72
+ $svg_path = get_attached_file( $attachment->ID );
73
+
74
+ $dimensions = self::get_svg_dimensions( $svg_path );
75
+
76
+ $response['sizes'] = array(
77
+ 'full' => array(
78
+ 'url' => $response['url'],
79
+ 'width' => $dimensions->width,
80
+ 'height' => $dimensions->height,
81
+ 'orientation' => $dimensions->width > $dimensions->height ? 'landscape' : 'portrait',
82
+ ),
83
+ );
84
+
85
+ return $response;
86
+ }
87
+
88
+ /**
89
+ * Get SVG Dimensions
90
+ *
91
+ * @since 1.1.5
92
+ *
93
+ * @param string $svg SVG file path.
94
+ * @return array Return SVG file height & width for valid SVG file.
95
+ */
96
+ public static function get_svg_dimensions( $svg ) {
97
+
98
+ $svg = simplexml_load_file( $svg );
99
+
100
+ if ( false === $svg ) {
101
+ $width = '0';
102
+ $height = '0';
103
+ } else {
104
+ $attributes = $svg->attributes();
105
+ $width = (string) $attributes->width;
106
+ $height = (string) $attributes->height;
107
+ }
108
+
109
+ return (object) array(
110
+ 'width' => $width,
111
+ 'height' => $height,
112
+ );
113
+ }
114
+
115
+ /**
116
+ * Custom Menu Widget
117
+ *
118
+ * In widget export we set the nav menu slug instead of ID.
119
+ * So, In import process we check get menu id by slug and set
120
+ * it in import widget process.
121
+ *
122
+ * @since 1.0.7
123
+ *
124
+ * @param object $all_sidebars Widget data.
125
+ * @return object Set custom menu id by slug.
126
+ */
127
+ function custom_menu_widget( $all_sidebars ) {
128
+
129
+ // Get current menu ID & Slugs.
130
+ $menu_locations = array();
131
+ $nav_menus = (object) wp_get_nav_menus();
132
+ if ( isset( $nav_menus ) ) {
133
+ foreach ( $nav_menus as $menu_key => $menu ) {
134
+ if ( is_object( $menu ) ) {
135
+ $menu_locations[ $menu->term_id ] = $menu->slug;
136
+ }
137
+ }
138
+ }
139
+
140
+ // Import widget data.
141
+ $all_sidebars = (object) $all_sidebars;
142
+ foreach ( $all_sidebars as $widgets_key => $widgets ) {
143
+ foreach ( $widgets as $widget_key => $widget ) {
144
+
145
+ // Found slug in current menu list.
146
+ if ( isset( $widget->nav_menu ) ) {
147
+ $menu_id = array_search( $widget->nav_menu, $menu_locations, true );
148
+ if ( ! empty( $menu_id ) ) {
149
+ $all_sidebars->$widgets_key->$widget_key->nav_menu = $menu_id;
150
+ }
151
+ }
152
+ }
153
+ }
154
+
155
+ return $all_sidebars;
156
+ }
157
+
158
+ /**
159
+ * Download File Into Uploads Directory
160
+ *
161
+ * @param string $file Download File URL.
162
+ * @return array Downloaded file data.
163
+ */
164
+ public static function download_file( $file = '' ) {
165
+
166
+ // Gives us access to the download_url() and wp_handle_sideload() functions.
167
+ require_once( ABSPATH . 'wp-admin/includes/file.php' );
168
+
169
+ $timeout_seconds = 5;
170
+
171
+ // Download file to temp dir.
172
+ $temp_file = download_url( $file, $timeout_seconds );
173
+
174
+ // WP Error.
175
+ if ( is_wp_error( $temp_file ) ) {
176
+ return array(
177
+ 'success' => false,
178
+ 'data' => $temp_file->get_error_message(),
179
+ );
180
+ }
181
+
182
+ // Array based on $_FILE as seen in PHP file uploads.
183
+ $file_args = array(
184
+ 'name' => basename( $file ),
185
+ 'tmp_name' => $temp_file,
186
+ 'error' => 0,
187
+ 'size' => filesize( $temp_file ),
188
+ );
189
+
190
+ $overrides = array(
191
+
192
+ // Tells WordPress to not look for the POST form
193
+ // fields that would normally be present as
194
+ // we downloaded the file from a remote server, so there
195
+ // will be no form fields
196
+ // Default is true.
197
+ 'test_form' => false,
198
+
199
+ // Setting this to false lets WordPress allow empty files, not recommended.
200
+ // Default is true.
201
+ 'test_size' => true,
202
+
203
+ // A properly uploaded file will pass this test. There should be no reason to override this one.
204
+ 'test_upload' => true,
205
+
206
+ 'mimes' => array(
207
+ 'xml' => 'text/xml',
208
+ 'json' => 'text/plain',
209
+ ),
210
+ );
211
+
212
+ // Move the temporary file into the uploads directory.
213
+ $results = wp_handle_sideload( $file_args, $overrides );
214
+
215
+ if ( isset( $results['error'] ) ) {
216
+ return array(
217
+ 'success' => false,
218
+ 'data' => $results,
219
+ );
220
+ }
221
+
222
+ // Success.
223
+ return array(
224
+ 'success' => true,
225
+ 'data' => $results,
226
+ );
227
+ }
228
+
229
+ /**
230
+ * Downloads an image from the specified URL.
231
+ *
232
+ * Taken from the core media_sideload_image() function and
233
+ * modified to return an array of data instead of html.
234
+ *
235
+ * @since 1.0.10
236
+ *
237
+ * @param string $file The image file path.
238
+ * @return array An array of image data.
239
+ */
240
+ static public function _sideload_image( $file ) {
241
+ $data = new stdClass();
242
+
243
+ if ( ! function_exists( 'media_handle_sideload' ) ) {
244
+ require_once( ABSPATH . 'wp-admin/includes/media.php' );
245
+ require_once( ABSPATH . 'wp-admin/includes/file.php' );
246
+ require_once( ABSPATH . 'wp-admin/includes/image.php' );
247
+ }
248
+
249
+ if ( ! empty( $file ) ) {
250
+
251
+ // Set variables for storage, fix file filename for query strings.
252
+ preg_match( '/[^\?]+\.(jpe?g|jpe|svg|gif|png)\b/i', $file, $matches );
253
+ $file_array = array();
254
+ $file_array['name'] = basename( $matches[0] );
255
+
256
+ // Download file to temp location.
257
+ $file_array['tmp_name'] = download_url( $file );
258
+
259
+ // If error storing temporarily, return the error.
260
+ if ( is_wp_error( $file_array['tmp_name'] ) ) {
261
+ return $file_array['tmp_name'];
262
+ }
263
+
264
+ // Do the validation and storage stuff.
265
+ $id = media_handle_sideload( $file_array, 0 );
266
+
267
+ // If error storing permanently, unlink.
268
+ if ( is_wp_error( $id ) ) {
269
+ unlink( $file_array['tmp_name'] );
270
+ return $id;
271
+ }
272
+
273
+ // Build the object to return.
274
+ $meta = wp_get_attachment_metadata( $id );
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;
283
+ }
284
+
285
+ /**
286
+ * Checks to see whether a string is an image url or not.
287
+ *
288
+ * @since 1.0.10
289
+ *
290
+ * @param string $string The string to check.
291
+ * @return bool Whether the string is an image url or not.
292
+ */
293
+ static public function _is_image_url( $string = '' ) {
294
+ if ( is_string( $string ) ) {
295
+
296
+ if ( preg_match( '/\.(jpg|jpeg|svg|png|gif)/i', $string ) ) {
297
+ return true;
298
+ }
299
+ }
300
+
301
+ return false;
302
+ }
303
+
304
+ }
305
+
306
+ /**
307
+ * Kicking this off by calling 'get_instance()' method
308
+ */
309
+ Astra_Sites_Helper::get_instance();
310
+
311
+ endif;
inc/importers/wxr-importer/class-astra-wxr-importer.php CHANGED
@@ -1,446 +1,446 @@
1
- <?php
2
- /**
3
- * Class Astra WXR Importer
4
- *
5
- * @since 1.0.0
6
- * @package Astra Addon
7
- */
8
-
9
- defined( 'ABSPATH' ) or exit;
10
-
11
- /**
12
- * Class Astra WXR Importer
13
- *
14
- * @since 1.0.0
15
- */
16
- class Astra_WXR_Importer {
17
-
18
- /**
19
- * Instance of Astra_WXR_Importer
20
- *
21
- * @since 1.0.0
22
- * @var Astra_WXR_Importer
23
- */
24
- private static $_instance = null;
25
-
26
- /**
27
- * Instantiate Astra_WXR_Importer
28
- *
29
- * @since 1.0.0
30
- * @return (Object) Astra_WXR_Importer.
31
- */
32
- public static function instance() {
33
- if ( ! isset( self::$_instance ) ) {
34
- self::$_instance = new self();
35
- }
36
-
37
- return self::$_instance;
38
- }
39
-
40
- /**
41
- * Constructor.
42
- *
43
- * @since 1.0.0
44
- */
45
- private function __construct() {
46
-
47
- require_once ABSPATH . '/wp-admin/includes/class-wp-importer.php';
48
- require_once ASTRA_SITES_DIR . 'inc/importers/wxr-importer/class-logger.php';
49
- require_once ASTRA_SITES_DIR . 'inc/importers/wxr-importer/class-wp-importer-logger-serversentevents.php';
50
- require_once ASTRA_SITES_DIR . 'inc/importers/wxr-importer/class-wxr-importer.php';
51
- require_once ASTRA_SITES_DIR . 'inc/importers/wxr-importer/class-wxr-import-info.php';
52
-
53
- add_filter( 'upload_mimes', array( $this, 'custom_upload_mimes' ) );
54
- add_action( 'wp_ajax_astra-wxr-import', array( $this, 'sse_import' ) );
55
- add_filter( 'wxr_importer.pre_process.user', '__return_null' );
56
- add_filter( 'wxr_importer.pre_process.post', array( $this, 'gutenberg_content_fix' ), 10, 4 );
57
-
58
- if ( version_compare( get_bloginfo( 'version' ), '5.1.0', '>=' ) ) {
59
- add_filter( 'wp_check_filetype_and_ext', array( $this, 'real_mime_types_5_1_0' ), 10, 5 );
60
- } else {
61
- add_filter( 'wp_check_filetype_and_ext', array( $this, 'real_mime_types' ), 10, 4 );
62
- }
63
-
64
- }
65
-
66
- /**
67
- * Track Imported Post
68
- *
69
- * @param int $post_id Post ID.
70
- * @return void
71
- */
72
- function track_post( $post_id ) {
73
- Astra_Sites_Importer_Log::add( 'Inserted - Post ' . $post_id . ' - ' . get_post_type( $post_id ) . ' - ' . get_the_title( $post_id ) );
74
- update_post_meta( $post_id, '_astra_sites_imported_post', true );
75
- }
76
-
77
- /**
78
- * Track Imported Term
79
- *
80
- * @param int $term_id Term ID.
81
- * @return void
82
- */
83
- function track_term( $term_id ) {
84
- $term = get_term( $term_id );
85
- if ( $term ) {
86
- Astra_Sites_Importer_Log::add( 'Inserted - Term ' . $term_id . ' - ' . json_encode( $term ) );
87
- }
88
- update_term_meta( $term_id, '_astra_sites_imported_term', true );
89
- }
90
-
91
- /**
92
- * Gutenberg Content Data Fix
93
- *
94
- * Gutenberg encode the page content. In import process the encoded characterless e.g. <, > are
95
- * decoded into HTML tag and it break the Gutenberg render markup.
96
- *
97
- * Note: We have not check the post is created with Gutenberg or not. We have imported other sites
98
- * and confirm that this works for every other page builders too.
99
- *
100
- * @since 1.2.12
101
- *
102
- * @param array $data Post data. (Return empty to skip.).
103
- * @param array $meta Meta data.
104
- * @param array $comments Comments on the post.
105
- * @param array $terms Terms on the post.
106
- */
107
- function gutenberg_content_fix( $data, $meta, $comments, $terms ) {
108
- if ( isset( $data['post_content'] ) ) {
109
- $data['post_content'] = wp_slash( $data['post_content'] );
110
- }
111
- return $data;
112
- }
113
-
114
- /**
115
- * Different MIME type of different PHP version
116
- *
117
- * Filters the "real" file type of the given file.
118
- *
119
- * @since 1.2.9
120
- *
121
- * @param array $defaults File data array containing 'ext', 'type', and
122
- * 'proper_filename' keys.
123
- * @param string $file Full path to the file.
124
- * @param string $filename The name of the file (may differ from $file due to
125
- * $file being in a tmp directory).
126
- * @param array $mimes Key is the file extension with value as the mime type.
127
- * @param string $real_mime Real MIME type of the uploaded file.
128
- */
129
- function real_mime_types_5_1_0( $defaults, $file, $filename, $mimes, $real_mime ) {
130
- return $this->real_mimes( $defaults, $filename );
131
- }
132
-
133
- /**
134
- * Different MIME type of different PHP version
135
- *
136
- * Filters the "real" file type of the given file.
137
- *
138
- * @since 1.2.9
139
- *
140
- * @param array $defaults File data array containing 'ext', 'type', and
141
- * 'proper_filename' keys.
142
- * @param string $file Full path to the file.
143
- * @param string $filename The name of the file (may differ from $file due to
144
- * $file being in a tmp directory).
145
- * @param array $mimes Key is the file extension with value as the mime type.
146
- */
147
- function real_mime_types( $defaults, $file, $filename, $mimes ) {
148
- return $this->real_mimes( $defaults, $filename );
149
- }
150
-
151
- /**
152
- * Real Mime Type
153
- *
154
- * @since 1.2.15
155
- *
156
- * @param array $defaults File data array containing 'ext', 'type', and
157
- * 'proper_filename' keys.
158
- * @param string $filename The name of the file (may differ from $file due to
159
- * $file being in a tmp directory).
160
- */
161
- function real_mimes( $defaults, $filename ) {
162
-
163
- // Set EXT and real MIME type only for the file name `wxr.xml`.
164
- if ( 'wxr.xml' === $filename ) {
165
- $defaults['ext'] = 'xml';
166
- $defaults['type'] = 'text/xml';
167
- }
168
-
169
- // Set EXT and real MIME type only for the file name `wpforms.json`.
170
- if ( 'wpforms.json' === $filename ) {
171
- $defaults['ext'] = 'json';
172
- $defaults['type'] = 'text/plain';
173
- }
174
-
175
- return $defaults;
176
- }
177
-
178
- /**
179
- * Constructor.
180
- *
181
- * @since 1.1.0
182
- */
183
- function sse_import() {
184
-
185
- // Start the event stream.
186
- header( 'Content-Type: text/event-stream, charset=UTF-8' );
187
-
188
- // Turn off PHP output compression.
189
- $previous = error_reporting( error_reporting() ^ E_WARNING );
190
- ini_set( 'output_buffering', 'off' );
191
- ini_set( 'zlib.output_compression', false );
192
- error_reporting( $previous );
193
-
194
- if ( $GLOBALS['is_nginx'] ) {
195
- // Setting this header instructs Nginx to disable fastcgi_buffering
196
- // and disable gzip for this request.
197
- header( 'X-Accel-Buffering: no' );
198
- header( 'Content-Encoding: none' );
199
- }
200
-
201
- $xml_url = urldecode( $_REQUEST['xml_url'] );
202
- if ( empty( $xml_url ) ) {
203
- exit;
204
- }
205
-
206
- // 2KB padding for IE
207
- echo ':' . str_repeat( ' ', 2048 ) . "\n\n";
208
-
209
- // Time to run the import!
210
- set_time_limit( 0 );
211
-
212
- // Ensure we're not buffered.
213
- wp_ob_end_flush_all();
214
- flush();
215
-
216
- // Are we allowed to create users?
217
- add_filter( 'wxr_importer.pre_process.user', '__return_null' );
218
-
219
- // Keep track of our progress.
220
- add_action( 'wxr_importer.processed.post', array( $this, 'imported_post' ), 10, 2 );
221
- add_action( 'wxr_importer.process_failed.post', array( $this, 'imported_post' ), 10, 2 );
222
- add_action( 'wxr_importer.process_already_imported.post', array( $this, 'already_imported_post' ), 10, 2 );
223
- add_action( 'wxr_importer.process_skipped.post', array( $this, 'already_imported_post' ), 10, 2 );
224
- add_action( 'wxr_importer.processed.comment', array( $this, 'imported_comment' ) );
225
- add_action( 'wxr_importer.process_already_imported.comment', array( $this, 'imported_comment' ) );
226
- add_action( 'wxr_importer.processed.term', array( $this, 'imported_term' ) );
227
- add_action( 'wxr_importer.process_failed.term', array( $this, 'imported_term' ) );
228
- add_action( 'wxr_importer.process_already_imported.term', array( $this, 'imported_term' ) );
229
- add_action( 'wxr_importer.processed.user', array( $this, 'imported_user' ) );
230
- add_action( 'wxr_importer.process_failed.user', array( $this, 'imported_user' ) );
231
-
232
- // Keep track of our progress.
233
- add_action( 'wxr_importer.processed.post', array( $this, 'track_post' ) );
234
- add_action( 'wxr_importer.processed.term', array( $this, 'track_term' ) );
235
-
236
- // Flush once more.
237
- flush();
238
-
239
- $importer = $this->get_importer();
240
- $response = $importer->import( $xml_url );
241
-
242
- // Let the browser know we're done.
243
- $complete = array(
244
- 'action' => 'complete',
245
- 'error' => false,
246
- );
247
- if ( is_wp_error( $response ) ) {
248
- $complete['error'] = $response->get_error_message();
249
- }
250
-
251
- $this->emit_sse_message( $complete );
252
- exit;
253
- }
254
-
255
- /**
256
- * Add .xml files as supported format in the uploader.
257
- *
258
- * @since 1.1.5 Added SVG file support.
259
- *
260
- * @since 1.0.0
261
- *
262
- * @param array $mimes Already supported mime types.
263
- */
264
- public function custom_upload_mimes( $mimes ) {
265
-
266
- // Allow SVG files.
267
- $mimes['svg'] = 'image/svg+xml';
268
- $mimes['svgz'] = 'image/svg+xml';
269
-
270
- // Allow XML files.
271
- $mimes['xml'] = 'text/xml';
272
-
273
- // Allow JSON files.
274
- $mimes['json'] = 'application/json';
275
-
276
- return $mimes;
277
- }
278
-
279
- /**
280
- * Start the xml import.
281
- *
282
- * @since 1.0.0
283
- *
284
- * @param (String) $path Absolute path to the XML file.
285
- */
286
- public function get_xml_data( $path ) {
287
-
288
- $args = array(
289
- 'action' => 'astra-wxr-import',
290
- 'id' => '1',
291
- 'xml_url' => $path,
292
- );
293
- $url = add_query_arg( urlencode_deep( $args ), admin_url( 'admin-ajax.php' ) );
294
-
295
- $data = $this->get_data( $path );
296
-
297
- return array(
298
- 'count' => array(
299
- 'posts' => $data->post_count,
300
- 'media' => $data->media_count,
301
- 'users' => count( $data->users ),
302
- 'comments' => $data->comment_count,
303
- 'terms' => $data->term_count,
304
- ),
305
- 'url' => $url,
306
- 'strings' => array(
307
- 'complete' => __( 'Import complete!', 'astra-sites' ),
308
- ),
309
- );
310
- }
311
-
312
- /**
313
- * Get XML data.
314
- *
315
- * @since 1.1.0
316
- * @param string $url Downloaded XML file absolute URL.
317
- * @return array XML file data.
318
- */
319
- function get_data( $url ) {
320
- $importer = $this->get_importer();
321
- $data = $importer->get_preliminary_information( $url );
322
- if ( is_wp_error( $data ) ) {
323
- return $data;
324
- }
325
- return $data;
326
- }
327
-
328
- /**
329
- * Get Importer
330
- *
331
- * @since 1.1.0
332
- * @return object Importer object.
333
- */
334
- public function get_importer() {
335
- $options = apply_filters(
336
- 'astra_sites_xml_import_options',
337
- array(
338
- 'fetch_attachments' => true,
339
- 'default_author' => get_current_user_id(),
340
- )
341
- );
342
-
343
- $importer = new WXR_Importer( $options );
344
- $logger = new WP_Importer_Logger_ServerSentEvents();
345
-
346
- $importer->set_logger( $logger );
347
- return $importer;
348
- }
349
-
350
- /**
351
- * Send message when a post has been imported.
352
- *
353
- * @since 1.1.0
354
- * @param int $id Post ID.
355
- * @param array $data Post data saved to the DB.
356
- */
357
- public function imported_post( $id, $data ) {
358
- $this->emit_sse_message(
359
- array(
360
- 'action' => 'updateDelta',
361
- 'type' => ( 'attachment' === $data['post_type'] ) ? 'media' : 'posts',
362
- 'delta' => 1,
363
- )
364
- );
365
- }
366
-
367
- /**
368
- * Send message when a post is marked as already imported.
369
- *
370
- * @since 1.1.0
371
- * @param array $data Post data saved to the DB.
372
- */
373
- public function already_imported_post( $data ) {
374
- $this->emit_sse_message(
375
- array(
376
- 'action' => 'updateDelta',
377
- 'type' => ( 'attachment' === $data['post_type'] ) ? 'media' : 'posts',
378
- 'delta' => 1,
379
- )
380
- );
381
- }
382
-
383
- /**
384
- * Send message when a comment has been imported.
385
- *
386
- * @since 1.1.0
387
- */
388
- public function imported_comment() {
389
- $this->emit_sse_message(
390
- array(
391
- 'action' => 'updateDelta',
392
- 'type' => 'comments',
393
- 'delta' => 1,
394
- )
395
- );
396
- }
397
-
398
- /**
399
- * Send message when a term has been imported.
400
- *
401
- * @since 1.1.0
402
- */
403
- public function imported_term() {
404
- $this->emit_sse_message(
405
- array(
406
- 'action' => 'updateDelta',
407
- 'type' => 'terms',
408
- 'delta' => 1,
409
- )
410
- );
411
- }
412
-
413
- /**
414
- * Send message when a user has been imported.
415
- *
416
- * @since 1.1.0
417
- */
418
- public function imported_user() {
419
- $this->emit_sse_message(
420
- array(
421
- 'action' => 'updateDelta',
422
- 'type' => 'users',
423
- 'delta' => 1,
424
- )
425
- );
426
- }
427
-
428
- /**
429
- * Emit a Server-Sent Events message.
430
- *
431
- * @since 1.1.0
432
- * @param mixed $data Data to be JSON-encoded and sent in the message.
433
- */
434
- public function emit_sse_message( $data ) {
435
- echo "event: message\n";
436
- echo 'data: ' . wp_json_encode( $data ) . "\n\n";
437
-
438
- // Extra padding.
439
- echo ':' . str_repeat( ' ', 2048 ) . "\n\n";
440
-
441
- flush();
442
- }
443
-
444
- }
445
-
446
- Astra_WXR_Importer::instance();
1
+ <?php
2
+ /**
3
+ * Class Astra WXR Importer
4
+ *
5
+ * @since 1.0.0
6
+ * @package Astra Addon
7
+ */
8
+
9
+ defined( 'ABSPATH' ) or exit;
10
+
11
+ /**
12
+ * Class Astra WXR Importer
13
+ *
14
+ * @since 1.0.0
15
+ */
16
+ class Astra_WXR_Importer {
17
+
18
+ /**
19
+ * Instance of Astra_WXR_Importer
20
+ *
21
+ * @since 1.0.0
22
+ * @var Astra_WXR_Importer
23
+ */
24
+ private static $_instance = null;
25
+
26
+ /**
27
+ * Instantiate Astra_WXR_Importer
28
+ *
29
+ * @since 1.0.0
30
+ * @return (Object) Astra_WXR_Importer.
31
+ */
32
+ public static function instance() {
33
+ if ( ! isset( self::$_instance ) ) {
34
+ self::$_instance = new self();
35
+ }
36
+
37
+ return self::$_instance;
38
+ }
39
+
40
+ /**
41
+ * Constructor.
42
+ *
43
+ * @since 1.0.0
44
+ */
45
+ private function __construct() {
46
+
47
+ require_once ABSPATH . '/wp-admin/includes/class-wp-importer.php';
48
+ require_once ASTRA_SITES_DIR . 'inc/importers/wxr-importer/class-logger.php';
49
+ require_once ASTRA_SITES_DIR . 'inc/importers/wxr-importer/class-wp-importer-logger-serversentevents.php';
50
+ require_once ASTRA_SITES_DIR . 'inc/importers/wxr-importer/class-wxr-importer.php';
51
+ require_once ASTRA_SITES_DIR . 'inc/importers/wxr-importer/class-wxr-import-info.php';
52
+
53
+ add_filter( 'upload_mimes', array( $this, 'custom_upload_mimes' ) );
54
+ add_action( 'wp_ajax_astra-wxr-import', array( $this, 'sse_import' ) );
55
+ add_filter( 'wxr_importer.pre_process.user', '__return_null' );
56
+ add_filter( 'wxr_importer.pre_process.post', array( $this, 'gutenberg_content_fix' ), 10, 4 );
57
+
58
+ if ( version_compare( get_bloginfo( 'version' ), '5.1.0', '>=' ) ) {
59
+ add_filter( 'wp_check_filetype_and_ext', array( $this, 'real_mime_types_5_1_0' ), 10, 5 );
60
+ } else {
61
+ add_filter( 'wp_check_filetype_and_ext', array( $this, 'real_mime_types' ), 10, 4 );
62
+ }
63
+
64
+ }
65
+
66
+ /**
67
+ * Track Imported Post
68
+ *
69
+ * @param int $post_id Post ID.
70
+ * @return void
71
+ */
72
+ function track_post( $post_id ) {
73
+ Astra_Sites_Importer_Log::add( 'Inserted - Post ' . $post_id . ' - ' . get_post_type( $post_id ) . ' - ' . get_the_title( $post_id ) );
74
+ update_post_meta( $post_id, '_astra_sites_imported_post', true );
75
+ }
76
+
77
+ /**
78
+ * Track Imported Term
79
+ *
80
+ * @param int $term_id Term ID.
81
+ * @return void
82
+ */
83
+ function track_term( $term_id ) {
84
+ $term = get_term( $term_id );
85
+ if ( $term ) {
86
+ Astra_Sites_Importer_Log::add( 'Inserted - Term ' . $term_id . ' - ' . json_encode( $term ) );
87
+ }
88
+ update_term_meta( $term_id, '_astra_sites_imported_term', true );
89
+ }
90
+
91
+ /**
92
+ * Gutenberg Content Data Fix
93
+ *
94
+ * Gutenberg encode the page content. In import process the encoded characterless e.g. <, > are
95
+ * decoded into HTML tag and it break the Gutenberg render markup.
96
+ *
97
+ * Note: We have not check the post is created with Gutenberg or not. We have imported other sites
98
+ * and confirm that this works for every other page builders too.
99
+ *
100
+ * @since 1.2.12
101
+ *
102
+ * @param array $data Post data. (Return empty to skip.).
103
+ * @param array $meta Meta data.
104
+ * @param array $comments Comments on the post.
105
+ * @param array $terms Terms on the post.
106
+ */
107
+ function gutenberg_content_fix( $data, $meta, $comments, $terms ) {
108
+ if ( isset( $data['post_content'] ) ) {
109
+ $data['post_content'] = wp_slash( $data['post_content'] );
110
+ }
111
+ return $data;
112
+ }
113
+
114
+ /**
115
+ * Different MIME type of different PHP version
116
+ *
117
+ * Filters the "real" file type of the given file.
118
+ *
119
+ * @since 1.2.9
120
+ *
121
+ * @param array $defaults File data array containing 'ext', 'type', and
122
+ * 'proper_filename' keys.
123
+ * @param string $file Full path to the file.
124
+ * @param string $filename The name of the file (may differ from $file due to
125
+ * $file being in a tmp directory).
126
+ * @param array $mimes Key is the file extension with value as the mime type.
127
+ * @param string $real_mime Real MIME type of the uploaded file.
128
+ */
129
+ function real_mime_types_5_1_0( $defaults, $file, $filename, $mimes, $real_mime ) {
130
+ return $this->real_mimes( $defaults, $filename );
131
+ }
132
+
133
+ /**
134
+ * Different MIME type of different PHP version
135
+ *
136
+ * Filters the "real" file type of the given file.
137
+ *
138
+ * @since 1.2.9
139
+ *
140
+ * @param array $defaults File data array containing 'ext', 'type', and
141
+ * 'proper_filename' keys.
142
+ * @param string $file Full path to the file.
143
+ * @param string $filename The name of the file (may differ from $file due to
144
+ * $file being in a tmp directory).
145
+ * @param array $mimes Key is the file extension with value as the mime type.
146
+ */
147
+ function real_mime_types( $defaults, $file, $filename, $mimes ) {
148
+ return $this->real_mimes( $defaults, $filename );
149
+ }
150
+
151
+ /**
152
+ * Real Mime Type
153
+ *
154
+ * @since 1.2.15
155
+ *
156
+ * @param array $defaults File data array containing 'ext', 'type', and
157
+ * 'proper_filename' keys.
158
+ * @param string $filename The name of the file (may differ from $file due to
159
+ * $file being in a tmp directory).
160
+ */
161
+ function real_mimes( $defaults, $filename ) {
162
+
163
+ // Set EXT and real MIME type only for the file name `wxr.xml`.
164
+ if ( 'wxr.xml' === $filename ) {
165
+ $defaults['ext'] = 'xml';
166
+ $defaults['type'] = 'text/xml';
167
+ }
168
+
169
+ // Set EXT and real MIME type only for the file name `wpforms.json`.
170
+ if ( 'wpforms.json' === $filename ) {
171
+ $defaults['ext'] = 'json';
172
+ $defaults['type'] = 'text/plain';
173
+ }
174
+
175
+ return $defaults;
176
+ }
177
+
178
+ /**
179
+ * Constructor.
180
+ *
181
+ * @since 1.1.0
182
+ */
183
+ function sse_import() {
184
+
185
+ // Start the event stream.
186
+ header( 'Content-Type: text/event-stream, charset=UTF-8' );
187
+
188
+ // Turn off PHP output compression.
189
+ $previous = error_reporting( error_reporting() ^ E_WARNING );
190
+ ini_set( 'output_buffering', 'off' );
191
+ ini_set( 'zlib.output_compression', false );
192
+ error_reporting( $previous );
193
+
194
+ if ( $GLOBALS['is_nginx'] ) {
195
+ // Setting this header instructs Nginx to disable fastcgi_buffering
196
+ // and disable gzip for this request.
197
+ header( 'X-Accel-Buffering: no' );
198
+ header( 'Content-Encoding: none' );
199
+ }
200
+
201
+ $xml_url = urldecode( $_REQUEST['xml_url'] );
202
+ if ( empty( $xml_url ) ) {
203
+ exit;
204
+ }
205
+
206
+ // 2KB padding for IE
207
+ echo ':' . str_repeat( ' ', 2048 ) . "\n\n";
208
+
209
+ // Time to run the import!
210
+ set_time_limit( 0 );
211
+
212
+ // Ensure we're not buffered.
213
+ wp_ob_end_flush_all();
214
+ flush();
215
+
216
+ // Are we allowed to create users?
217
+ add_filter( 'wxr_importer.pre_process.user', '__return_null' );
218
+
219
+ // Keep track of our progress.
220
+ add_action( 'wxr_importer.processed.post', array( $this, 'imported_post' ), 10, 2 );
221
+ add_action( 'wxr_importer.process_failed.post', array( $this, 'imported_post' ), 10, 2 );
222
+ add_action( 'wxr_importer.process_already_imported.post', array( $this, 'already_imported_post' ), 10, 2 );
223
+ add_action( 'wxr_importer.process_skipped.post', array( $this, 'already_imported_post' ), 10, 2 );
224
+ add_action( 'wxr_importer.processed.comment', array( $this, 'imported_comment' ) );
225
+ add_action( 'wxr_importer.process_already_imported.comment', array( $this, 'imported_comment' ) );
226
+ add_action( 'wxr_importer.processed.term', array( $this, 'imported_term' ) );
227
+ add_action( 'wxr_importer.process_failed.term', array( $this, 'imported_term' ) );
228
+ add_action( 'wxr_importer.process_already_imported.term', array( $this, 'imported_term' ) );
229
+ add_action( 'wxr_importer.processed.user', array( $this, 'imported_user' ) );
230
+ add_action( 'wxr_importer.process_failed.user', array( $this, 'imported_user' ) );
231
+
232
+ // Keep track of our progress.
233
+ add_action( 'wxr_importer.processed.post', array( $this, 'track_post' ) );
234
+ add_action( 'wxr_importer.processed.term', array( $this, 'track_term' ) );
235
+
236
+ // Flush once more.
237
+ flush();
238
+
239
+ $importer = $this->get_importer();
240
+ $response = $importer->import( $xml_url );
241
+
242
+ // Let the browser know we're done.
243
+ $complete = array(
244
+ 'action' => 'complete',
245
+ 'error' => false,
246
+ );
247
+ if ( is_wp_error( $response ) ) {
248
+ $complete['error'] = $response->get_error_message();
249
+ }
250
+
251
+ $this->emit_sse_message( $complete );
252
+ exit;
253
+ }
254
+
255
+ /**
256
+ * Add .xml files as supported format in the uploader.
257
+ *
258
+ * @since 1.1.5 Added SVG file support.
259
+ *
260
+ * @since 1.0.0
261
+ *
262
+ * @param array $mimes Already supported mime types.
263
+ */
264
+ public function custom_upload_mimes( $mimes ) {
265
+
266
+ // Allow SVG files.
267
+ $mimes['svg'] = 'image/svg+xml';
268
+ $mimes['svgz'] = 'image/svg+xml';
269
+
270
+ // Allow XML files.
271
+ $mimes['xml'] = 'text/xml';
272
+
273
+ // Allow JSON files.
274
+ $mimes['json'] = 'application/json';
275
+
276
+ return $mimes;
277
+ }
278
+
279
+ /**
280
+ * Start the xml import.
281
+ *
282
+ * @since 1.0.0
283
+ *
284
+ * @param (String) $path Absolute path to the XML file.
285
+ */
286
+ public function get_xml_data( $path ) {
287
+
288
+ $args = array(
289
+ 'action' => 'astra-wxr-import',
290
+ 'id' => '1',
291
+ 'xml_url' => $path,
292
+ );
293
+ $url = add_query_arg( urlencode_deep( $args ), admin_url( 'admin-ajax.php' ) );
294
+
295
+ $data = $this->get_data( $path );
296
+
297
+ return array(
298
+ 'count' => array(
299
+ 'posts' => $data->post_count,
300
+ 'media' => $data->media_count,
301
+ 'users' => count( $data->users ),
302
+ 'comments' => $data->comment_count,
303
+ 'terms' => $data->term_count,
304
+ ),
305
+ 'url' => $url,
306
+ 'strings' => array(
307
+ 'complete' => __( 'Import complete!', 'astra-sites' ),
308
+ ),
309
+ );
310
+ }
311
+
312
+ /**
313
+ * Get XML data.
314
+ *
315
+ * @since 1.1.0
316
+ * @param string $url Downloaded XML file absolute URL.
317
+ * @return array XML file data.
318
+ */
319
+ function get_data( $url ) {
320
+ $importer = $this->get_importer();
321
+ $data = $importer->get_preliminary_information( $url );
322
+ if ( is_wp_error( $data ) ) {
323
+ return $data;
324
+ }
325
+ return $data;
326
+ }
327
+
328
+ /**
329
+ * Get Importer
330
+ *
331
+ * @since 1.1.0
332
+ * @return object Importer object.
333
+ */
334
+ public function get_importer() {
335
+ $options = apply_filters(
336
+ 'astra_sites_xml_import_options',
337
+ array(
338
+ 'fetch_attachments' => true,
339
+ 'default_author' => get_current_user_id(),
340
+ )
341
+ );
342
+
343
+ $importer = new WXR_Importer( $options );
344
+ $logger = new WP_Importer_Logger_ServerSentEvents();
345
+
346
+ $importer->set_logger( $logger );
347
+ return $importer;
348
+ }
349
+
350
+ /**
351
+ * Send message when a post has been imported.
352
+ *
353
+ * @since 1.1.0
354
+ * @param int $id Post ID.
355
+ * @param array $data Post data saved to the DB.
356
+ */
357
+ public function imported_post( $id, $data ) {
358
+ $this->emit_sse_message(
359
+ array(
360
+ 'action' => 'updateDelta',
361
+ 'type' => ( 'attachment' === $data['post_type'] ) ? 'media' : 'posts',
362
+ 'delta' => 1,
363
+ )
364
+ );
365
+ }
366
+
367
+ /**
368
+ * Send message when a post is marked as already imported.
369
+ *
370
+ * @since 1.1.0
371
+ * @param array $data Post data saved to the DB.
372
+ */
373
+ public function already_imported_post( $data ) {
374
+ $this->emit_sse_message(
375
+ array(
376
+ 'action' => 'updateDelta',
377
+ 'type' => ( 'attachment' === $data['post_type'] ) ? 'media' : 'posts',
378
+ 'delta' => 1,
379
+ )
380
+ );
381
+ }
382
+
383
+ /**
384
+ * Send message when a comment has been imported.
385
+ *
386
+ * @since 1.1.0
387
+ */
388
+ public function imported_comment() {
389
+ $this->emit_sse_message(
390
+ array(
391
+ 'action' => 'updateDelta',
392
+ 'type' => 'comments',
393
+ 'delta' => 1,
394
+ )
395
+ );
396
+ }
397
+
398
+ /**
399
+ * Send message when a term has been imported.
400
+ *
401
+ * @since 1.1.0
402
+ */
403
+ public function imported_term() {
404
+ $this->emit_sse_message(
405
+ array(
406
+ 'action' => 'updateDelta',
407
+ 'type' => 'terms',
408
+ 'delta' => 1,
409
+ )
410
+ );
411
+ }
412
+
413
+ /**
414
+ * Send message when a user has been imported.
415
+ *
416
+ * @since 1.1.0
417
+ */
418
+ public function imported_user() {
419
+ $this->emit_sse_message(
420
+ array(
421
+ 'action' => 'updateDelta',
422
+ 'type' => 'users',
423
+ 'delta' => 1,
424
+ )
425
+ );
426
+ }
427
+
428
+ /**
429
+ * Emit a Server-Sent Events message.
430
+ *
431
+ * @since 1.1.0
432
+ * @param mixed $data Data to be JSON-encoded and sent in the message.
433
+ */
434
+ public function emit_sse_message( $data ) {
435
+ echo "event: message\n";
436
+ echo 'data: ' . wp_json_encode( $data ) . "\n\n";
437
+
438
+ // Extra padding.
439
+ echo ':' . str_repeat( ' ', 2048 ) . "\n\n";
440
+
441
+ flush();
442
+ }
443
+
444
+ }
445
+
446
+ Astra_WXR_Importer::instance();
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.17\n"
6
  "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/astra-sites\n"
7
- "POT-Creation-Date: 2019-06-28 10:54:05+00:00\n"
8
  "MIME-Version: 1.0\n"
9
  "Content-Type: text/plain; charset=utf-8\n"
10
  "Content-Transfer-Encoding: 8bit\n"
@@ -22,7 +22,7 @@ msgstr ""
22
  "X-Poedit-SearchPath-0: .\n"
23
  "X-Poedit-Bookmarks: \n"
24
  "X-Textdomain-Support: yes\n"
25
- "X-Generator: grunt-wp-i18n 1.0.3\n"
26
 
27
  #: astra-sites.php:18
28
  msgid "Astra Sites"
@@ -50,34 +50,34 @@ msgstr ""
50
  msgid "You have not \"customize\" access to import the Astra site."
51
  msgstr ""
52
 
53
- #: inc/classes/class-astra-sites-importer.php:150
54
  msgid "Request site API URL is empty. Try again!"
55
  msgstr ""
56
 
57
- #: inc/classes/class-astra-sites-importer.php:250
58
  msgid "Customizer data is empty!"
59
  msgstr ""
60
 
61
- #: inc/classes/class-astra-sites-importer.php:264
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
 
68
- #: inc/classes/class-astra-sites-importer.php:282
69
  msgid "There was an error downloading the XML file."
70
  msgstr ""
71
 
72
- #: inc/classes/class-astra-sites-importer.php:288
73
  msgid "Invalid site XML file!"
74
  msgstr ""
75
 
76
- #: inc/classes/class-astra-sites-importer.php:315
77
  msgid "Site options are empty!"
78
  msgstr ""
79
 
80
- #: inc/classes/class-astra-sites-importer.php:345
81
  msgid "Widget data is empty!"
82
  msgstr ""
83
 
@@ -243,14 +243,10 @@ msgstr ""
243
  msgid "Active"
244
  msgstr ""
245
 
246
- #: inc/classes/class-astra-sites.php:361
247
  msgid "Import failed."
248
  msgstr ""
249
 
250
- #: inc/classes/class-astra-sites.php:362
251
- msgid "Import failed. See error log."
252
- msgstr ""
253
-
254
  #: inc/classes/class-astra-sites.php:363
255
  msgid "Import This Site"
256
  msgstr ""
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.18\n"
6
  "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/astra-sites\n"
7
+ "POT-Creation-Date: 2019-09-05 09:54:50+00:00\n"
8
  "MIME-Version: 1.0\n"
9
  "Content-Type: text/plain; charset=utf-8\n"
10
  "Content-Transfer-Encoding: 8bit\n"
22
  "X-Poedit-SearchPath-0: .\n"
23
  "X-Poedit-Bookmarks: \n"
24
  "X-Textdomain-Support: yes\n"
25
+ "X-Generator: grunt-wp-i18n1.0.0\n"
26
 
27
  #: astra-sites.php:18
28
  msgid "Astra Sites"
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
 
68
+ #: inc/classes/class-astra-sites-importer.php:281
69
  msgid "There was an error downloading the XML file."
70
  msgstr ""
71
 
72
+ #: inc/classes/class-astra-sites-importer.php:287
73
  msgid "Invalid site XML file!"
74
  msgstr ""
75
 
76
+ #: inc/classes/class-astra-sites-importer.php:314
77
  msgid "Site options are empty!"
78
  msgstr ""
79
 
80
+ #: inc/classes/class-astra-sites-importer.php:344
81
  msgid "Widget data is empty!"
82
  msgstr ""
83
 
243
  msgid "Active"
244
  msgstr ""
245
 
246
+ #: inc/classes/class-astra-sites.php:361 inc/classes/class-astra-sites.php:362
247
  msgid "Import failed."
248
  msgstr ""
249
 
 
 
 
 
250
  #: inc/classes/class-astra-sites.php:363
251
  msgid "Import This Site"
252
  msgstr ""
readme.txt CHANGED
@@ -5,7 +5,7 @@ Tags: Elementor,Beaver Builder,Templates,Gutenberg,Astra Starter Sites
5
  Requires at least: 4.4
6
  Requires PHP: 5.3
7
  Tested up to: 5.2
8
- Stable tag: 1.3.17
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
@@ -46,7 +46,7 @@ You can extend this library with premium ready-to-use website demos by purchasin
46
 
47
  = WHY PEOPLE LOVE THE ASTRA THEME? =
48
 
49
- Over 300,000+ users are empowering their websites with Astra! From beginners to industry experts, everyone is loving Astra for its performance and ease of use.
50
 
51
  = Here are a few reasons why they love Astra - =
52
 
@@ -54,14 +54,10 @@ Over 300,000+ users are empowering their websites with Astra! From beginners to
54
 
55
  **Easy Customization** - With all the settings managed through the customizer, Astra keeps it simple and gives you lots of options to customize everything with a few clicks.
56
 
57
- **Compatibility with Page Builders** - Astra is built to work great with all major page builders like Elementor, Beaver Builder, Brizy, Divi, etc. With support for custom layouts and templates, it has soon become a favorite <a href="https://wpastra.com/theme-for-elementor/?utm_source=wp-repo&utm_medium=astra_desc&utm_campaign=starter_sites">theme for Elementor</a>, Beaver Builder and all the others
58
-
59
- **Pixel Perfect Design** - Astra reduces your design time by giving you pixel-perfect FREE ready-to-use website demos within a huge library of starter sites.
60
 
61
  **Deeper Integrations** - Astra works seamlessly with all WooCommerce plugins, LifterLMS, LearnDash etc. This means that you can create and beautify eCommerce websites and those that offer online courses in minutes.
62
 
63
- **Ready-to-use complete website demos** - You get the above collection of ready-to-use free starter sites that can be imported and used with the Astra theme.
64
-
65
  Fetch the website, tweak images and content and go live!
66
 
67
  Use this imported site as a base for your project and don't waste time starting from scratch!
@@ -121,8 +117,11 @@ We are open to suggestions and would love to work on topics that our users are l
121
 
122
  == Changelog ==
123
 
 
 
 
124
  v1.3.17 - 28-June-2019
125
- - Minor changes in Links
126
 
127
  v1.3.16 - 21-June-2019
128
  - Fix: WooCommerce onboarding setup blocked issue fixed.
5
  Requires at least: 4.4
6
  Requires PHP: 5.3
7
  Tested up to: 5.2
8
+ Stable tag: 1.3.18
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
46
 
47
  = WHY PEOPLE LOVE THE ASTRA THEME? =
48
 
49
+ Over 200,000+ users are empowering their websites with Astra! From beginners to industry experts, everyone is loving Astra for its performance and ease of use.
50
 
51
  = Here are a few reasons why they love Astra - =
52
 
54
 
55
  **Easy Customization** - With all the settings managed through the customizer, Astra keeps it simple and gives you lots of options to customize everything with a few clicks.
56
 
57
+ **Pixel Perfect Design** - Astra reduces your design time by giving you pixel-perfect FREE ready-to-use websites demos within a huge library of starter sites.
 
 
58
 
59
  **Deeper Integrations** - Astra works seamlessly with all WooCommerce plugins, LifterLMS, LearnDash etc. This means that you can create and beautify eCommerce websites and those that offer online courses in minutes.
60
 
 
 
61
  Fetch the website, tweak images and content and go live!
62
 
63
  Use this imported site as a base for your project and don't waste time starting from scratch!
117
 
118
  == Changelog ==
119
 
120
+ v1.3.18 - 5-September-2019
121
+ - Improvement: Error handling while getting import data from API request.
122
+
123
  v1.3.17 - 28-June-2019
124
+ - Improvement: Minor changes in Links
125
 
126
  v1.3.16 - 21-June-2019
127
  - Fix: WooCommerce onboarding setup blocked issue fixed.