Astra Starter Sites - Version 1.3.6

Version Description

Download this release

Release Info

Developer Nikschavan
Plugin Icon Astra Starter Sites
Version 1.3.6
Comparing to
See all releases

Code changes from version 1.3.5 to 1.3.6

Files changed (24) hide show
  1. astra-sites.php +54 -54
  2. inc/assets/js/render-grid.js +7 -0
  3. inc/classes/class-astra-sites-importer-log.php +413 -412
  4. inc/classes/class-astra-sites-importer.php +572 -570
  5. inc/classes/class-astra-sites-page.php +434 -434
  6. inc/classes/class-astra-sites-white-label.php +239 -239
  7. inc/classes/class-astra-sites.php +600 -601
  8. inc/classes/compatibility/astra-pro/class-astra-sites-compatibility-astra-pro.php +300 -299
  9. inc/importers/batch-processing/class-astra-sites-batch-processing-beaver-builder.php +261 -261
  10. inc/importers/batch-processing/class-astra-sites-batch-processing-brizy.php +125 -125
  11. inc/importers/batch-processing/class-astra-sites-batch-processing-elementor.php +109 -109
  12. inc/importers/batch-processing/class-astra-sites-batch-processing-gutenberg.php +165 -146
  13. inc/importers/batch-processing/class-astra-sites-batch-processing-misc.php +137 -137
  14. inc/importers/batch-processing/class-astra-sites-batch-processing-widgets.php +97 -97
  15. inc/importers/batch-processing/class-astra-sites-batch-processing.php +210 -210
  16. inc/importers/batch-processing/helpers/class-astra-sites-image-importer.php +243 -243
  17. inc/importers/batch-processing/helpers/class-wp-background-process-astra.php +69 -69
  18. inc/importers/class-astra-site-options-import.php +289 -289
  19. inc/importers/class-astra-sites-helper.php +311 -311
  20. inc/importers/wxr-importer/class-astra-wxr-importer.php +446 -446
  21. inc/includes/admin-page.php +420 -420
  22. inc/lib/astra-notices/class-astra-notices.php +334 -334
  23. languages/astra-sites.pot +69 -69
  24. readme.txt +6 -2
astra-sites.php CHANGED
@@ -1,54 +1,54 @@
1
- <?php
2
- /**
3
- * Plugin Name: Astra Starter Sites – Elementor, Beaver Builder & Gutenberg Templates
4
- * Plugin URI: http://www.wpastra.com/pro/
5
- * Description: Import free sites build with Astra theme.
6
- * Version: 1.3.5
7
- * Author: Brainstorm Force
8
- * Author URI: http://www.brainstormforce.com
9
- * Text Domain: astra-sites
10
- *
11
- * @package Astra Sites
12
- */
13
-
14
- /**
15
- * Set constants.
16
- */
17
- if ( ! defined( 'ASTRA_SITES_NAME' ) ) {
18
- define( 'ASTRA_SITES_NAME', __( 'Astra Sites', 'astra-sites' ) );
19
- }
20
-
21
- if ( ! defined( 'ASTRA_SITES_VER' ) ) {
22
- define( 'ASTRA_SITES_VER', '1.3.5' );
23
- }
24
-
25
- if ( ! defined( 'ASTRA_SITES_FILE' ) ) {
26
- define( 'ASTRA_SITES_FILE', __FILE__ );
27
- }
28
-
29
- if ( ! defined( 'ASTRA_SITES_BASE' ) ) {
30
- define( 'ASTRA_SITES_BASE', plugin_basename( ASTRA_SITES_FILE ) );
31
- }
32
-
33
- if ( ! defined( 'ASTRA_SITES_DIR' ) ) {
34
- define( 'ASTRA_SITES_DIR', plugin_dir_path( ASTRA_SITES_FILE ) );
35
- }
36
-
37
- if ( ! defined( 'ASTRA_SITES_URI' ) ) {
38
- define( 'ASTRA_SITES_URI', plugins_url( '/', ASTRA_SITES_FILE ) );
39
- }
40
-
41
- if ( ! function_exists( 'astra_sites_setup' ) ) :
42
-
43
- /**
44
- * Astra Sites Setup
45
- *
46
- * @since 1.0.5
47
- */
48
- function astra_sites_setup() {
49
- require_once ASTRA_SITES_DIR . 'inc/classes/class-astra-sites.php';
50
- }
51
-
52
- add_action( 'plugins_loaded', 'astra_sites_setup' );
53
-
54
- endif;
1
+ <?php
2
+ /**
3
+ * Plugin Name: Astra Starter Sites – Elementor, Beaver Builder & Gutenberg Templates
4
+ * Plugin URI: http://www.wpastra.com/pro/
5
+ * Description: Import free sites build with Astra theme.
6
+ * Version: 1.3.6
7
+ * Author: Brainstorm Force
8
+ * Author URI: http://www.brainstormforce.com
9
+ * Text Domain: astra-sites
10
+ *
11
+ * @package Astra Sites
12
+ */
13
+
14
+ /**
15
+ * Set constants.
16
+ */
17
+ if ( ! defined( 'ASTRA_SITES_NAME' ) ) {
18
+ define( 'ASTRA_SITES_NAME', __( 'Astra Sites', 'astra-sites' ) );
19
+ }
20
+
21
+ if ( ! defined( 'ASTRA_SITES_VER' ) ) {
22
+ define( 'ASTRA_SITES_VER', '1.3.6' );
23
+ }
24
+
25
+ if ( ! defined( 'ASTRA_SITES_FILE' ) ) {
26
+ define( 'ASTRA_SITES_FILE', __FILE__ );
27
+ }
28
+
29
+ if ( ! defined( 'ASTRA_SITES_BASE' ) ) {
30
+ define( 'ASTRA_SITES_BASE', plugin_basename( ASTRA_SITES_FILE ) );
31
+ }
32
+
33
+ if ( ! defined( 'ASTRA_SITES_DIR' ) ) {
34
+ define( 'ASTRA_SITES_DIR', plugin_dir_path( ASTRA_SITES_FILE ) );
35
+ }
36
+
37
+ if ( ! defined( 'ASTRA_SITES_URI' ) ) {
38
+ define( 'ASTRA_SITES_URI', plugins_url( '/', ASTRA_SITES_FILE ) );
39
+ }
40
+
41
+ if ( ! function_exists( 'astra_sites_setup' ) ) :
42
+
43
+ /**
44
+ * Astra Sites Setup
45
+ *
46
+ * @since 1.0.5
47
+ */
48
+ function astra_sites_setup() {
49
+ require_once ASTRA_SITES_DIR . 'inc/classes/class-astra-sites.php';
50
+ }
51
+
52
+ add_action( 'plugins_loaded', 'astra_sites_setup' );
53
+
54
+ endif;
inc/assets/js/render-grid.js CHANGED
@@ -611,6 +611,13 @@
611
  api_params['astra-site-page-builder'] = page_builder_id;
612
  }
613
 
 
 
 
 
 
 
 
614
  // API Request.
615
  var api_post = {
616
  id: 'astra-sites',
611
  api_params['astra-site-page-builder'] = page_builder_id;
612
  }
613
 
614
+ if( astraRenderGrid.sites && astraRenderGrid.sites.site_url ) {
615
+ api_params['site_url'] = astraRenderGrid.sites.site_url;
616
+ }
617
+ if( astraRenderGrid.sites && astraRenderGrid.sites.purchase_key ) {
618
+ api_params['purchase_key'] = astraRenderGrid.sites.purchase_key;
619
+ }
620
+
621
  // API Request.
622
  var api_post = {
623
  id: 'astra-sites',
inc/classes/class-astra-sites-importer-log.php CHANGED
@@ -1,412 +1,413 @@
1
- <?php
2
- /**
3
- * Astra Sites Importer Log
4
- *
5
- * @since 1.1.0
6
- * @package Astra Sites
7
- */
8
-
9
- defined( 'ABSPATH' ) or exit;
10
-
11
- if ( ! class_exists( 'Astra_Sites_Importer_Log' ) ) :
12
-
13
- /**
14
- * Astra Sites Importer
15
- */
16
- class Astra_Sites_Importer_Log {
17
-
18
- /**
19
- * Instance
20
- *
21
- * @since 1.1.0
22
- * @var (Object) Class object
23
- */
24
- private static $_instance = null;
25
-
26
- /**
27
- * Log File
28
- *
29
- * @since 1.1.0
30
- * @var (Object) Class object
31
- */
32
- private static $log_file = null;
33
-
34
- /**
35
- * Set Instance
36
- *
37
- * @since 1.1.0
38
- *
39
- * @return object Class object.
40
- */
41
- public static function get_instance() {
42
- if ( ! isset( self::$_instance ) ) {
43
- self::$_instance = new self;
44
- }
45
-
46
- return self::$_instance;
47
- }
48
-
49
- /**
50
- * Constructor.
51
- *
52
- * @since 1.1.0
53
- */
54
- private function __construct() {
55
-
56
- // Check file read/write permissions.
57
- add_action( 'admin_init', array( $this, 'has_file_read_write' ) );
58
-
59
- }
60
-
61
- /**
62
- * Check file read/write permissions and process.
63
- *
64
- * @since 1.1.0
65
- * @return null
66
- */
67
- function has_file_read_write() {
68
-
69
- // Get user credentials for WP file-system API.
70
- $astra_sites_import = wp_nonce_url( admin_url( 'themes.php?page=astra-sites' ), 'astra-import' );
71
- if ( false === ( $creds = request_filesystem_credentials( $astra_sites_import, '', false, false, null ) ) ) {
72
- return;
73
- }
74
-
75
- // Set log file.
76
- self::set_log_file();
77
-
78
- // Initial AJAX Import Hooks.
79
- add_action( 'astra_sites_import_start', array( $this, 'start' ), 10, 2 );
80
- }
81
-
82
- /**
83
- * Add log file URL in UI response.
84
- *
85
- * @since 1.1.0
86
- */
87
- public static function add_log_file_url() {
88
-
89
- $upload_dir = self::log_dir();
90
- $upload_path = trailingslashit( $upload_dir['url'] );
91
- $file_abs_url = get_option( 'astra_sites_recent_import_log_file', self::$log_file );
92
- $file_url = $upload_path . basename( $file_abs_url );
93
-
94
- return array(
95
- 'abs_url' => $file_abs_url,
96
- 'url' => $file_url,
97
- );
98
- }
99
-
100
- /**
101
- * Current Time for log.
102
- *
103
- * @since 1.1.0
104
- * @return string Current time with time zone.
105
- */
106
- public static function current_time() {
107
- return date( 'H:i:s' ) . ' ' . date_default_timezone_get();
108
- }
109
-
110
- /**
111
- * Import Start
112
- *
113
- * @since 1.1.0
114
- * @param array $data Import Data.
115
- * @param string $demo_api_uri Import site API URL.
116
- * @return void
117
- */
118
- function start( $data = array(), $demo_api_uri = '' ) {
119
-
120
- Astra_Sites_Importer_Log::add( 'Started Import Process' );
121
-
122
- Astra_Sites_Importer_Log::add( '# System Details: ' );
123
- Astra_Sites_Importer_Log::add( "Debug Mode \t\t: " . self::get_debug_mode() );
124
- Astra_Sites_Importer_Log::add( "Operating System \t: " . self::get_os() );
125
- Astra_Sites_Importer_Log::add( "Software \t\t: " . self::get_software() );
126
- Astra_Sites_Importer_Log::add( "MySQL version \t\t: " . self::get_mysql_version() );
127
- Astra_Sites_Importer_Log::add( "XML Reader \t\t: " . self::get_xmlreader_status() );
128
- Astra_Sites_Importer_Log::add( "PHP Version \t\t: " . self::get_php_version() );
129
- Astra_Sites_Importer_Log::add( "PHP Max Input Vars \t: " . self::get_php_max_input_vars() );
130
- Astra_Sites_Importer_Log::add( "PHP Max Post Size \t: " . self::get_php_max_post_size() );
131
- Astra_Sites_Importer_Log::add( "PHP Extension GD \t: " . self::get_php_extension_gd() );
132
- Astra_Sites_Importer_Log::add( "PHP Max Execution Time \t: " . self::get_max_execution_time() );
133
- Astra_Sites_Importer_Log::add( "Max Upload Size \t: " . size_format( wp_max_upload_size() ) );
134
- Astra_Sites_Importer_Log::add( "Memory Limit \t\t: " . self::get_memory_limit() );
135
- Astra_Sites_Importer_Log::add( "Timezone \t\t: " . self::get_timezone() );
136
- Astra_Sites_Importer_Log::add( PHP_EOL . '-----' . PHP_EOL );
137
- Astra_Sites_Importer_Log::add( 'Importing Started! - ' . self::current_time() );
138
-
139
- Astra_Sites_Importer_Log::add( '---' . PHP_EOL );
140
- Astra_Sites_Importer_Log::add( 'WHY IMPORT PROCESS CAN FAIL? READ THIS - ' );
141
- Astra_Sites_Importer_Log::add( 'https://wpastra.com/docs/?p=1314&utm_source=demo-import-panel&utm_campaign=import-error&utm_medium=wp-dashboard' . PHP_EOL );
142
- Astra_Sites_Importer_Log::add( '---' . PHP_EOL );
143
-
144
- }
145
-
146
- /**
147
- * Get an instance of WP_Filesystem_Direct.
148
- *
149
- * @since 1.1.0
150
- * @return object A WP_Filesystem_Direct instance.
151
- */
152
- static public function get_filesystem() {
153
- global $wp_filesystem;
154
-
155
- require_once ABSPATH . '/wp-admin/includes/file.php';
156
-
157
- WP_Filesystem();
158
-
159
- return $wp_filesystem;
160
- }
161
-
162
- /**
163
- * Get Log File
164
- *
165
- * @since 1.1.0
166
- * @return string log file URL.
167
- */
168
- public static function get_log_file() {
169
- return self::$log_file;
170
- }
171
-
172
- /**
173
- * Log file directory
174
- *
175
- * @since 1.1.0
176
- * @param string $dir_name Directory Name.
177
- * @return array Uploads directory array.
178
- */
179
- public static function log_dir( $dir_name = 'astra-sites' ) {
180
-
181
- $upload_dir = wp_upload_dir();
182
-
183
- // Build the paths.
184
- $dir_info = array(
185
- 'path' => $upload_dir['basedir'] . '/' . $dir_name . '/',
186
- 'url' => $upload_dir['baseurl'] . '/' . $dir_name . '/',
187
- );
188
-
189
- // Create the upload dir if it doesn't exist.
190
- if ( ! file_exists( $dir_info['path'] ) ) {
191
-
192
- // Create the directory.
193
- wp_mkdir_p( $dir_info['path'] );
194
-
195
- // Add an index file for security.
196
- self::get_filesystem()->put_contents( $dir_info['path'] . 'index.html', '' );
197
- }
198
-
199
- return $dir_info;
200
- }
201
-
202
- /**
203
- * Set log file
204
- *
205
- * @since 1.1.0
206
- */
207
- public static function set_log_file() {
208
-
209
- $upload_dir = self::log_dir();
210
-
211
- $upload_path = trailingslashit( $upload_dir['path'] );
212
-
213
- // File format e.g. 'import-31-Oct-2017-06-39-12.txt'.
214
- self::$log_file = $upload_path . 'import-' . date( 'd-M-Y-h-i-s' ) . '.txt';
215
-
216
- if ( ! get_option( 'astra_sites_recent_import_log_file', false ) ) {
217
- update_option( 'astra_sites_recent_import_log_file', self::$log_file );
218
- }
219
- }
220
-
221
- /**
222
- * Write content to a file.
223
- *
224
- * @since 1.1.0
225
- * @param string $content content to be saved to the file.
226
- */
227
- public static function add( $content ) {
228
-
229
- if ( get_option( 'astra_sites_recent_import_log_file', false ) ) {
230
- $log_file = get_option( 'astra_sites_recent_import_log_file', self::$log_file );
231
- } else {
232
- $log_file = self::$log_file;
233
- }
234
-
235
- $existing_data = '';
236
- if ( file_exists( $log_file ) ) {
237
- $existing_data = self::get_filesystem()->get_contents( $log_file );
238
- }
239
-
240
- // Style separator.
241
- $separator = PHP_EOL;
242
-
243
- self::get_filesystem()->put_contents( $log_file, $existing_data . $separator . $content, FS_CHMOD_FILE );
244
- }
245
-
246
- /**
247
- * Debug Mode
248
- *
249
- * @since 1.1.0
250
- * @return string Enabled for Debug mode ON and Disabled for Debug mode Off.
251
- */
252
- public static function get_debug_mode() {
253
- if ( WP_DEBUG ) {
254
- return __( 'Enabled', 'astra-sites' );
255
- }
256
-
257
- return __( 'Disabled', 'astra-sites' );
258
- }
259
-
260
- /**
261
- * Memory Limit
262
- *
263
- * @since 1.1.0
264
- * @return string Memory limit.
265
- */
266
- public static function get_memory_limit() {
267
-
268
- $required_memory = '64M';
269
- $memory_limit_in_bytes_current = wp_convert_hr_to_bytes( WP_MEMORY_LIMIT );
270
- $memory_limit_in_bytes_required = wp_convert_hr_to_bytes( $required_memory );
271
-
272
- if ( $memory_limit_in_bytes_current < $memory_limit_in_bytes_required ) {
273
- return sprintf(
274
- /* translators: %1$s Memory Limit, %2$s Recommended memory limit. */
275
- _x( 'Current memory limit %1$s. We recommend setting memory to at least %2$s.', 'Recommended Memory Limit', 'astra-sites' ),
276
- WP_MEMORY_LIMIT,
277
- $required_memory
278
- );
279
- }
280
-
281
- return WP_MEMORY_LIMIT;
282
- }
283
-
284
- /**
285
- * Timezone
286
- *
287
- * @since 1.1.0
288
- * @see https://codex.wordpress.org/Option_Reference/
289
- *
290
- * @return string Current timezone.
291
- */
292
- public static function get_timezone() {
293
- $timezone = get_option( 'timezone_string' );
294
-
295
- if ( ! $timezone ) {
296
- return get_option( 'gmt_offset' );
297
- }
298
-
299
- return $timezone;
300
- }
301
-
302
- /**
303
- * Operating System
304
- *
305
- * @since 1.1.0
306
- * @return string Current Operating System.
307
- */
308
- public static function get_os() {
309
- return PHP_OS;
310
- }
311
-
312
- /**
313
- * Server Software
314
- *
315
- * @since 1.1.0
316
- * @return string Current Server Software.
317
- */
318
- public static function get_software() {
319
- return $_SERVER['SERVER_SOFTWARE'];
320
- }
321
-
322
- /**
323
- * MySql Version
324
- *
325
- * @since 1.1.0
326
- * @return string Current MySql Version.
327
- */
328
- public static function get_mysql_version() {
329
- global $wpdb;
330
- return $wpdb->db_version();
331
- }
332
-
333
- /**
334
- * XML Reader
335
- *
336
- * @since 1.2.8
337
- * @return string Current XML Reader status.
338
- */
339
- public static function get_xmlreader_status() {
340
-
341
- if ( class_exists( 'XMLReader' ) ) {
342
- return __( 'Yes', 'astra-sites' );
343
- }
344
-
345
- return __( 'No', 'astra-sites' );
346
- }
347
-
348
- /**
349
- * PHP Version
350
- *
351
- * @since 1.1.0
352
- * @return string Current PHP Version.
353
- */
354
- public static function get_php_version() {
355
- if ( version_compare( PHP_VERSION, '5.4', '<' ) ) {
356
- return _x( 'We recommend to use php 5.4 or higher', 'PHP Version', 'astra-sites' );
357
- }
358
- return PHP_VERSION;
359
- }
360
-
361
- /**
362
- * PHP Max Input Vars
363
- *
364
- * @since 1.1.0
365
- * @return string Current PHP Max Input Vars
366
- */
367
- public static function get_php_max_input_vars() {
368
- return ini_get( 'max_input_vars' ); // phpcs:disable PHPCompatibility.IniDirectives.NewIniDirectives.max_input_varsFound
369
- }
370
-
371
- /**
372
- * PHP Max Post Size
373
- *
374
- * @since 1.1.0
375
- * @return string Current PHP Max Post Size
376
- */
377
- public static function get_php_max_post_size() {
378
- return ini_get( 'post_max_size' );
379
- }
380
-
381
- /**
382
- * PHP Max Execution Time
383
- *
384
- * @since 1.1.0
385
- * @return string Current Max Execution Time
386
- */
387
- public static function get_max_execution_time() {
388
- return ini_get( 'max_execution_time' );
389
- }
390
-
391
- /**
392
- * PHP GD Extension
393
- *
394
- * @since 1.1.0
395
- * @return string Current PHP GD Extension
396
- */
397
- public static function get_php_extension_gd() {
398
- if ( extension_loaded( 'gd' ) ) {
399
- return __( 'Yes', 'astra-sites' );
400
- }
401
-
402
- return __( 'No', 'astra-sites' );
403
- }
404
-
405
- }
406
-
407
- /**
408
- * Kicking this off by calling 'get_instance()' method
409
- */
410
- Astra_Sites_Importer_Log::get_instance();
411
-
412
- endif;
 
1
+ <?php
2
+ /**
3
+ * Astra Sites Importer Log
4
+ *
5
+ * @since 1.1.0
6
+ * @package Astra Sites
7
+ */
8
+
9
+ defined( 'ABSPATH' ) or exit;
10
+
11
+ if ( ! class_exists( 'Astra_Sites_Importer_Log' ) ) :
12
+
13
+ /**
14
+ * Astra Sites Importer
15
+ */
16
+ class Astra_Sites_Importer_Log {
17
+
18
+ /**
19
+ * Instance
20
+ *
21
+ * @since 1.1.0
22
+ * @var (Object) Class object
23
+ */
24
+ private static $_instance = null;
25
+
26
+ /**
27
+ * Log File
28
+ *
29
+ * @since 1.1.0
30
+ * @var (Object) Class object
31
+ */
32
+ private static $log_file = null;
33
+
34
+ /**
35
+ * Set Instance
36
+ *
37
+ * @since 1.1.0
38
+ *
39
+ * @return object Class object.
40
+ */
41
+ public static function get_instance() {
42
+ if ( ! isset( self::$_instance ) ) {
43
+ self::$_instance = new self;
44
+ }
45
+
46
+ return self::$_instance;
47
+ }
48
+
49
+ /**
50
+ * Constructor.
51
+ *
52
+ * @since 1.1.0
53
+ */
54
+ private function __construct() {
55
+
56
+ // Check file read/write permissions.
57
+ add_action( 'admin_init', array( $this, 'has_file_read_write' ) );
58
+
59
+ }
60
+
61
+ /**
62
+ * Check file read/write permissions and process.
63
+ *
64
+ * @since 1.1.0
65
+ * @return null
66
+ */
67
+ function has_file_read_write() {
68
+
69
+ // Get user credentials for WP file-system API.
70
+ $astra_sites_import = wp_nonce_url( admin_url( 'themes.php?page=astra-sites' ), 'astra-import' );
71
+ $creds = request_filesystem_credentials( $astra_sites_import, '', false, false, null );
72
+ if ( false === $creds ) {
73
+ return;
74
+ }
75
+
76
+ // Set log file.
77
+ self::set_log_file();
78
+
79
+ // Initial AJAX Import Hooks.
80
+ add_action( 'astra_sites_import_start', array( $this, 'start' ), 10, 2 );
81
+ }
82
+
83
+ /**
84
+ * Add log file URL in UI response.
85
+ *
86
+ * @since 1.1.0
87
+ */
88
+ public static function add_log_file_url() {
89
+
90
+ $upload_dir = self::log_dir();
91
+ $upload_path = trailingslashit( $upload_dir['url'] );
92
+ $file_abs_url = get_option( 'astra_sites_recent_import_log_file', self::$log_file );
93
+ $file_url = $upload_path . basename( $file_abs_url );
94
+
95
+ return array(
96
+ 'abs_url' => $file_abs_url,
97
+ 'url' => $file_url,
98
+ );
99
+ }
100
+
101
+ /**
102
+ * Current Time for log.
103
+ *
104
+ * @since 1.1.0
105
+ * @return string Current time with time zone.
106
+ */
107
+ public static function current_time() {
108
+ return date( 'H:i:s' ) . ' ' . date_default_timezone_get();
109
+ }
110
+
111
+ /**
112
+ * Import Start
113
+ *
114
+ * @since 1.1.0
115
+ * @param array $data Import Data.
116
+ * @param string $demo_api_uri Import site API URL.
117
+ * @return void
118
+ */
119
+ function start( $data = array(), $demo_api_uri = '' ) {
120
+
121
+ Astra_Sites_Importer_Log::add( 'Started Import Process' );
122
+
123
+ Astra_Sites_Importer_Log::add( '# System Details: ' );
124
+ Astra_Sites_Importer_Log::add( "Debug Mode \t\t: " . self::get_debug_mode() );
125
+ Astra_Sites_Importer_Log::add( "Operating System \t: " . self::get_os() );
126
+ Astra_Sites_Importer_Log::add( "Software \t\t: " . self::get_software() );
127
+ Astra_Sites_Importer_Log::add( "MySQL version \t\t: " . self::get_mysql_version() );
128
+ Astra_Sites_Importer_Log::add( "XML Reader \t\t: " . self::get_xmlreader_status() );
129
+ Astra_Sites_Importer_Log::add( "PHP Version \t\t: " . self::get_php_version() );
130
+ Astra_Sites_Importer_Log::add( "PHP Max Input Vars \t: " . self::get_php_max_input_vars() );
131
+ Astra_Sites_Importer_Log::add( "PHP Max Post Size \t: " . self::get_php_max_post_size() );
132
+ Astra_Sites_Importer_Log::add( "PHP Extension GD \t: " . self::get_php_extension_gd() );
133
+ Astra_Sites_Importer_Log::add( "PHP Max Execution Time \t: " . self::get_max_execution_time() );
134
+ Astra_Sites_Importer_Log::add( "Max Upload Size \t: " . size_format( wp_max_upload_size() ) );
135
+ Astra_Sites_Importer_Log::add( "Memory Limit \t\t: " . self::get_memory_limit() );
136
+ Astra_Sites_Importer_Log::add( "Timezone \t\t: " . self::get_timezone() );
137
+ Astra_Sites_Importer_Log::add( PHP_EOL . '-----' . PHP_EOL );
138
+ Astra_Sites_Importer_Log::add( 'Importing Started! - ' . self::current_time() );
139
+
140
+ Astra_Sites_Importer_Log::add( '---' . PHP_EOL );
141
+ Astra_Sites_Importer_Log::add( 'WHY IMPORT PROCESS CAN FAIL? READ THIS - ' );
142
+ Astra_Sites_Importer_Log::add( 'https://wpastra.com/docs/?p=1314&utm_source=demo-import-panel&utm_campaign=import-error&utm_medium=wp-dashboard' . PHP_EOL );
143
+ Astra_Sites_Importer_Log::add( '---' . PHP_EOL );
144
+
145
+ }
146
+
147
+ /**
148
+ * Get an instance of WP_Filesystem_Direct.
149
+ *
150
+ * @since 1.1.0
151
+ * @return object A WP_Filesystem_Direct instance.
152
+ */
153
+ static public function get_filesystem() {
154
+ global $wp_filesystem;
155
+
156
+ require_once ABSPATH . '/wp-admin/includes/file.php';
157
+
158
+ WP_Filesystem();
159
+
160
+ return $wp_filesystem;
161
+ }
162
+
163
+ /**
164
+ * Get Log File
165
+ *
166
+ * @since 1.1.0
167
+ * @return string log file URL.
168
+ */
169
+ public static function get_log_file() {
170
+ return self::$log_file;
171
+ }
172
+
173
+ /**
174
+ * Log file directory
175
+ *
176
+ * @since 1.1.0
177
+ * @param string $dir_name Directory Name.
178
+ * @return array Uploads directory array.
179
+ */
180
+ public static function log_dir( $dir_name = 'astra-sites' ) {
181
+
182
+ $upload_dir = wp_upload_dir();
183
+
184
+ // Build the paths.
185
+ $dir_info = array(
186
+ 'path' => $upload_dir['basedir'] . '/' . $dir_name . '/',
187
+ 'url' => $upload_dir['baseurl'] . '/' . $dir_name . '/',
188
+ );
189
+
190
+ // Create the upload dir if it doesn't exist.
191
+ if ( ! file_exists( $dir_info['path'] ) ) {
192
+
193
+ // Create the directory.
194
+ wp_mkdir_p( $dir_info['path'] );
195
+
196
+ // Add an index file for security.
197
+ self::get_filesystem()->put_contents( $dir_info['path'] . 'index.html', '' );
198
+ }
199
+
200
+ return $dir_info;
201
+ }
202
+
203
+ /**
204
+ * Set log file
205
+ *
206
+ * @since 1.1.0
207
+ */
208
+ public static function set_log_file() {
209
+
210
+ $upload_dir = self::log_dir();
211
+
212
+ $upload_path = trailingslashit( $upload_dir['path'] );
213
+
214
+ // File format e.g. 'import-31-Oct-2017-06-39-12.txt'.
215
+ self::$log_file = $upload_path . 'import-' . date( 'd-M-Y-h-i-s' ) . '.txt';
216
+
217
+ if ( ! get_option( 'astra_sites_recent_import_log_file', false ) ) {
218
+ update_option( 'astra_sites_recent_import_log_file', self::$log_file );
219
+ }
220
+ }
221
+
222
+ /**
223
+ * Write content to a file.
224
+ *
225
+ * @since 1.1.0
226
+ * @param string $content content to be saved to the file.
227
+ */
228
+ public static function add( $content ) {
229
+
230
+ if ( get_option( 'astra_sites_recent_import_log_file', false ) ) {
231
+ $log_file = get_option( 'astra_sites_recent_import_log_file', self::$log_file );
232
+ } else {
233
+ $log_file = self::$log_file;
234
+ }
235
+
236
+ $existing_data = '';
237
+ if ( file_exists( $log_file ) ) {
238
+ $existing_data = self::get_filesystem()->get_contents( $log_file );
239
+ }
240
+
241
+ // Style separator.
242
+ $separator = PHP_EOL;
243
+
244
+ self::get_filesystem()->put_contents( $log_file, $existing_data . $separator . $content, FS_CHMOD_FILE );
245
+ }
246
+
247
+ /**
248
+ * Debug Mode
249
+ *
250
+ * @since 1.1.0
251
+ * @return string Enabled for Debug mode ON and Disabled for Debug mode Off.
252
+ */
253
+ public static function get_debug_mode() {
254
+ if ( WP_DEBUG ) {
255
+ return __( 'Enabled', 'astra-sites' );
256
+ }
257
+
258
+ return __( 'Disabled', 'astra-sites' );
259
+ }
260
+
261
+ /**
262
+ * Memory Limit
263
+ *
264
+ * @since 1.1.0
265
+ * @return string Memory limit.
266
+ */
267
+ public static function get_memory_limit() {
268
+
269
+ $required_memory = '64M';
270
+ $memory_limit_in_bytes_current = wp_convert_hr_to_bytes( WP_MEMORY_LIMIT );
271
+ $memory_limit_in_bytes_required = wp_convert_hr_to_bytes( $required_memory );
272
+
273
+ if ( $memory_limit_in_bytes_current < $memory_limit_in_bytes_required ) {
274
+ return sprintf(
275
+ /* translators: %1$s Memory Limit, %2$s Recommended memory limit. */
276
+ _x( 'Current memory limit %1$s. We recommend setting memory to at least %2$s.', 'Recommended Memory Limit', 'astra-sites' ),
277
+ WP_MEMORY_LIMIT,
278
+ $required_memory
279
+ );
280
+ }
281
+
282
+ return WP_MEMORY_LIMIT;
283
+ }
284
+
285
+ /**
286
+ * Timezone
287
+ *
288
+ * @since 1.1.0
289
+ * @see https://codex.wordpress.org/Option_Reference/
290
+ *
291
+ * @return string Current timezone.
292
+ */
293
+ public static function get_timezone() {
294
+ $timezone = get_option( 'timezone_string' );
295
+
296
+ if ( ! $timezone ) {
297
+ return get_option( 'gmt_offset' );
298
+ }
299
+
300
+ return $timezone;
301
+ }
302
+
303
+ /**
304
+ * Operating System
305
+ *
306
+ * @since 1.1.0
307
+ * @return string Current Operating System.
308
+ */
309
+ public static function get_os() {
310
+ return PHP_OS;
311
+ }
312
+
313
+ /**
314
+ * Server Software
315
+ *
316
+ * @since 1.1.0
317
+ * @return string Current Server Software.
318
+ */
319
+ public static function get_software() {
320
+ return $_SERVER['SERVER_SOFTWARE'];
321
+ }
322
+
323
+ /**
324
+ * MySql Version
325
+ *
326
+ * @since 1.1.0
327
+ * @return string Current MySql Version.
328
+ */
329
+ public static function get_mysql_version() {
330
+ global $wpdb;
331
+ return $wpdb->db_version();
332
+ }
333
+
334
+ /**
335
+ * XML Reader
336
+ *
337
+ * @since 1.2.8
338
+ * @return string Current XML Reader status.
339
+ */
340
+ public static function get_xmlreader_status() {
341
+
342
+ if ( class_exists( 'XMLReader' ) ) {
343
+ return __( 'Yes', 'astra-sites' );
344
+ }
345
+
346
+ return __( 'No', 'astra-sites' );
347
+ }
348
+
349
+ /**
350
+ * PHP Version
351
+ *
352
+ * @since 1.1.0
353
+ * @return string Current PHP Version.
354
+ */
355
+ public static function get_php_version() {
356
+ if ( version_compare( PHP_VERSION, '5.4', '<' ) ) {
357
+ return _x( 'We recommend to use php 5.4 or higher', 'PHP Version', 'astra-sites' );
358
+ }
359
+ return PHP_VERSION;
360
+ }
361
+
362
+ /**
363
+ * PHP Max Input Vars
364
+ *
365
+ * @since 1.1.0
366
+ * @return string Current PHP Max Input Vars
367
+ */
368
+ public static function get_php_max_input_vars() {
369
+ return ini_get( 'max_input_vars' ); // phpcs:disable PHPCompatibility.IniDirectives.NewIniDirectives.max_input_varsFound
370
+ }
371
+
372
+ /**
373
+ * PHP Max Post Size
374
+ *
375
+ * @since 1.1.0
376
+ * @return string Current PHP Max Post Size
377
+ */
378
+ public static function get_php_max_post_size() {
379
+ return ini_get( 'post_max_size' );
380
+ }
381
+
382
+ /**
383
+ * PHP Max Execution Time
384
+ *
385
+ * @since 1.1.0
386
+ * @return string Current Max Execution Time
387
+ */
388
+ public static function get_max_execution_time() {
389
+ return ini_get( 'max_execution_time' );
390
+ }
391
+
392
+ /**
393
+ * PHP GD Extension
394
+ *
395
+ * @since 1.1.0
396
+ * @return string Current PHP GD Extension
397
+ */
398
+ public static function get_php_extension_gd() {
399
+ if ( extension_loaded( 'gd' ) ) {
400
+ return __( 'Yes', 'astra-sites' );
401
+ }
402
+
403
+ return __( 'No', 'astra-sites' );
404
+ }
405
+
406
+ }
407
+
408
+ /**
409
+ * Kicking this off by calling 'get_instance()' method
410
+ */
411
+ Astra_Sites_Importer_Log::get_instance();
412
+
413
+ endif;
inc/classes/class-astra-sites-importer.php CHANGED
@@ -1,570 +1,572 @@
1
- <?php
2
- /**
3
- * Astra Sites Importer
4
- *
5
- * @since 1.0.0
6
- * @package Astra Sites
7
- */
8
-
9
- defined( 'ABSPATH' ) or exit;
10
-
11
- if ( ! class_exists( 'Astra_Sites_Importer' ) ) :
12
-
13
- /**
14
- * Astra Sites Importer
15
- */
16
- class Astra_Sites_Importer {
17
-
18
- /**
19
- * Instance
20
- *
21
- * @since 1.0.0
22
- * @var (Object) Class object
23
- */
24
- public static $_instance = null;
25
-
26
- /**
27
- * Set Instance
28
- *
29
- * @since 1.0.0
30
- *
31
- * @return object Class object.
32
- */
33
- public static function get_instance() {
34
- if ( ! isset( self::$_instance ) ) {
35
- self::$_instance = new self;
36
- }
37
-
38
- return self::$_instance;
39
- }
40
-
41
- /**
42
- * Constructor.
43
- *
44
- * @since 1.0.0
45
- */
46
- public function __construct() {
47
-
48
- require_once ASTRA_SITES_DIR . 'inc/classes/class-astra-sites-importer-log.php';
49
- require_once ASTRA_SITES_DIR . 'inc/importers/class-astra-sites-helper.php';
50
- require_once ASTRA_SITES_DIR . 'inc/importers/class-widgets-importer.php';
51
- require_once ASTRA_SITES_DIR . 'inc/importers/class-astra-customizer-import.php';
52
- require_once ASTRA_SITES_DIR . 'inc/importers/class-astra-site-options-import.php';
53
-
54
- // Import AJAX.
55
- add_action( 'wp_ajax_astra-sites-import-set-site-data', array( $this, 'import_start' ) );
56
- add_action( 'wp_ajax_astra-sites-import-wpforms', array( $this, 'import_wpforms' ) );
57
- add_action( 'wp_ajax_astra-sites-import-customizer-settings', array( $this, 'import_customizer_settings' ) );
58
- add_action( 'wp_ajax_astra-sites-import-prepare-xml', array( $this, 'prepare_xml_data' ) );
59
- add_action( 'wp_ajax_astra-sites-import-options', array( $this, 'import_options' ) );
60
- add_action( 'wp_ajax_astra-sites-import-widgets', array( $this, 'import_widgets' ) );
61
- add_action( 'wp_ajax_astra-sites-import-end', array( $this, 'import_end' ) );
62
-
63
- // Hooks in AJAX.
64
- add_action( 'astra_sites_import_complete', array( $this, 'clear_cache' ) );
65
- add_action( 'init', array( $this, 'load_importer' ) );
66
-
67
- require_once ASTRA_SITES_DIR . 'inc/importers/batch-processing/class-astra-sites-batch-processing.php';
68
-
69
- add_action( 'astra_sites_image_import_complete', array( $this, 'clear_cache' ) );
70
-
71
- // Reset Customizer Data.
72
- add_action( 'wp_ajax_astra-sites-reset-customizer-data', array( $this, 'reset_customizer_data' ) );
73
- add_action( 'wp_ajax_astra-sites-reset-site-options', array( $this, 'reset_site_options' ) );
74
- add_action( 'wp_ajax_astra-sites-reset-widgets-data', array( $this, 'reset_widgets_data' ) );
75
-
76
- // Reset Post & Terms.
77
- add_action( 'wp_ajax_astra-sites-delete-posts', array( $this, 'delete_imported_posts' ) );
78
- add_action( 'wp_ajax_astra-sites-delete-wp-forms', array( $this, 'delete_imported_wp_forms' ) );
79
- add_action( 'wp_ajax_astra-sites-delete-terms', array( $this, 'delete_imported_terms' ) );
80
- }
81
-
82
- /**
83
- * Load WordPress WXR importer.
84
- */
85
- public function load_importer() {
86
- require_once ASTRA_SITES_DIR . 'inc/importers/wxr-importer/class-astra-wxr-importer.php';
87
- }
88
-
89
- /**
90
- * Start Site Import
91
- *
92
- * @since 1.1.0
93
- * @return void
94
- */
95
- function import_start() {
96
-
97
- if ( ! current_user_can( 'customize' ) ) {
98
- wp_send_json_error( __( 'You have not "customize" access to import the Astra site.', 'astra-sites' ) );
99
- }
100
-
101
- $demo_api_uri = isset( $_POST['api_url'] ) ? esc_url( $_POST['api_url'] ) : '';
102
-
103
- if ( ! empty( $demo_api_uri ) ) {
104
-
105
- $demo_data = self::get_astra_single_demo( $demo_api_uri );
106
-
107
- update_option( 'astra_sites_import_data', $demo_data );
108
-
109
- if ( is_wp_error( $demo_data ) ) {
110
- wp_send_json_error( $demo_data->get_error_message() );
111
- } else {
112
- $log_file = Astra_Sites_Importer_Log::add_log_file_url();
113
- if ( isset( $log_file['url'] ) && ! empty( $log_file['url'] ) ) {
114
- $demo_data['log_file'] = $log_file['url'];
115
- }
116
- do_action( 'astra_sites_import_start', $demo_data, $demo_api_uri );
117
- }
118
-
119
- wp_send_json_success( $demo_data );
120
-
121
- } else {
122
- wp_send_json_error( __( 'Request site API URL is empty. Try again!', 'astra-sites' ) );
123
- }
124
-
125
- }
126
-
127
- /**
128
- * Import WP Forms
129
- *
130
- * @since 1.2.14
131
- *
132
- * @return void
133
- */
134
- function import_wpforms() {
135
-
136
- $wpforms_url = ( isset( $_REQUEST['wpforms_url'] ) ) ? urldecode( $_REQUEST['wpforms_url'] ) : '';
137
- $ids_mapping = array();
138
-
139
- if ( ! empty( $wpforms_url ) && function_exists( 'wpforms_encode' ) ) {
140
-
141
- // Download XML file.
142
- $xml_path = Astra_Sites_Helper::download_file( $wpforms_url );
143
-
144
- if ( $xml_path['success'] ) {
145
- if ( isset( $xml_path['data']['file'] ) ) {
146
-
147
- $ext = strtolower( pathinfo( $xml_path['data']['file'], PATHINFO_EXTENSION ) );
148
-
149
- if ( 'json' === $ext ) {
150
- $forms = json_decode( file_get_contents( $xml_path['data']['file'] ), true );
151
-
152
- if ( ! empty( $forms ) ) {
153
-
154
- foreach ( $forms as $form ) {
155
- $title = ! empty( $form['settings']['form_title'] ) ? $form['settings']['form_title'] : '';
156
- $desc = ! empty( $form['settings']['form_desc'] ) ? $form['settings']['form_desc'] : '';
157
-
158
- $new_id = post_exists( $title );
159
-
160
- if ( ! $new_id ) {
161
- $new_id = wp_insert_post(
162
- array(
163
- 'post_title' => $title,
164
- 'post_status' => 'publish',
165
- 'post_type' => 'wpforms',
166
- 'post_excerpt' => $desc,
167
- )
168
- );
169
-
170
- // Set meta for tracking the post.
171
- update_post_meta( $new_id, '_astra_sites_imported_wp_forms', true );
172
- Astra_Sites_Importer_Log::add( 'Inserted WP Form ' . $new_id );
173
- }
174
-
175
- if ( $new_id ) {
176
-
177
- // ID mapping.
178
- $ids_mapping[ $form['id'] ] = $new_id;
179
-
180
- $form['id'] = $new_id;
181
- wp_update_post(
182
- array(
183
- 'ID' => $new_id,
184
- 'post_content' => wpforms_encode( $form ),
185
- )
186
- );
187
- }
188
- }
189
- }
190
- }
191
- }
192
- }
193
- }
194
-
195
- update_option( 'astra_sites_wpforms_ids_mapping', $ids_mapping );
196
-
197
- wp_send_json_success( $ids_mapping );
198
- }
199
-
200
- /**
201
- * Import Customizer Settings.
202
- *
203
- * @since 1.0.14
204
- * @return void
205
- */
206
- function import_customizer_settings() {
207
-
208
- $customizer_data = ( isset( $_POST['customizer_data'] ) ) ? (array) json_decode( stripcslashes( $_POST['customizer_data'] ), 1 ) : array();
209
-
210
- if ( ! empty( $customizer_data ) ) {
211
-
212
- Astra_Sites_Importer_Log::add( 'Imported Customizer Settings ' . json_encode( $customizer_data ) );
213
-
214
- // Set meta for tracking the post.
215
- update_option( '_astra_sites_old_customizer_data', $customizer_data );
216
-
217
- Astra_Customizer_Import::instance()->import( $customizer_data );
218
-
219
- wp_send_json_success( $customizer_data );
220
-
221
- } else {
222
- wp_send_json_error( __( 'Customizer data is empty!', 'astra-sites' ) );
223
- }
224
-
225
- }
226
-
227
- /**
228
- * Prepare XML Data.
229
- *
230
- * @since 1.1.0
231
- * @return void
232
- */
233
- function prepare_xml_data() {
234
-
235
- if ( ! class_exists( 'XMLReader' ) ) {
236
- 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' ) );
237
- }
238
-
239
- $wxr_url = ( isset( $_REQUEST['wxr_url'] ) ) ? urldecode( $_REQUEST['wxr_url'] ) : '';
240
-
241
- if ( isset( $wxr_url ) ) {
242
-
243
- Astra_Sites_Importer_Log::add( 'Importing from XML ' . $xml );
244
-
245
- // Download XML file.
246
- $xml_path = Astra_Sites_Helper::download_file( $wxr_url );
247
-
248
- if ( $xml_path['success'] ) {
249
- if ( isset( $xml_path['data']['file'] ) ) {
250
- $data = Astra_WXR_Importer::instance()->get_xml_data( $xml_path['data']['file'] );
251
- $data['xml'] = $xml_path['data'];
252
- wp_send_json_success( $data );
253
- } else {
254
- wp_send_json_error( __( 'There was an error downloading the XML file.', 'astra-sites' ) );
255
- }
256
- } else {
257
- wp_send_json_error( $xml_path['data'] );
258
- }
259
- } else {
260
- wp_send_json_error( __( 'Invalid site XML file!', 'astra-sites' ) );
261
- }
262
-
263
- }
264
-
265
- /**
266
- * Import Options.
267
- *
268
- * @since 1.0.14
269
- * @return void
270
- */
271
- function import_options() {
272
-
273
- $options_data = ( isset( $_POST['options_data'] ) ) ? (array) json_decode( stripcslashes( $_POST['options_data'] ), 1 ) : '';
274
-
275
- if ( ! empty( $options_data ) ) {
276
-
277
- // Set meta for tracking the post.
278
- if ( is_array( $options_data ) ) {
279
- Astra_Sites_Importer_Log::add( 'Imported - Site Options ' . json_encode( $options_data ) );
280
- update_option( '_astra_sites_old_site_options', $options_data );
281
- }
282
-
283
- $options_importer = Astra_Site_Options_Import::instance();
284
- $options_importer->import_options( $options_data );
285
- wp_send_json_success( $options_data );
286
- } else {
287
- wp_send_json_error( __( 'Site options are empty!', 'astra-sites' ) );
288
- }
289
-
290
- }
291
-
292
- /**
293
- * Import Widgets.
294
- *
295
- * @since 1.0.14
296
- * @return void
297
- */
298
- function import_widgets() {
299
-
300
- $widgets_data = ( isset( $_POST['widgets_data'] ) ) ? (object) json_decode( stripcslashes( $_POST['widgets_data'] ) ) : '';
301
-
302
- Astra_Sites_Importer_Log::add( 'Imported - Widgets ' . json_encode( $widgets_data ) );
303
-
304
- if ( ! empty( $widgets_data ) ) {
305
-
306
- $widgets_importer = Astra_Widget_Importer::instance();
307
- $status = $widgets_importer->import_widgets_data( $widgets_data );
308
-
309
- // Set meta for tracking the post.
310
- if ( is_object( $widgets_data ) ) {
311
- $widgets_data = (array) $widgets_data;
312
- update_option( '_astra_sites_old_widgets_data', $widgets_data );
313
- }
314
-
315
- wp_send_json_success( $widgets_data );
316
- } else {
317
- wp_send_json_error( __( 'Widget data is empty!', 'astra-sites' ) );
318
- }
319
-
320
- }
321
-
322
- /**
323
- * Import End.
324
- *
325
- * @since 1.0.14
326
- * @return void
327
- */
328
- function import_end() {
329
- do_action( 'astra_sites_import_complete' );
330
- }
331
-
332
-
333
- /**
334
- * Get single demo.
335
- *
336
- * @since 1.0.0
337
- *
338
- * @param (String) $demo_api_uri API URL of a demo.
339
- *
340
- * @return (Array) $astra_demo_data demo data for the demo.
341
- */
342
- public static function get_astra_single_demo( $demo_api_uri ) {
343
-
344
- // default values.
345
- $remote_args = array();
346
- $defaults = array(
347
- 'id' => '',
348
- 'astra-site-widgets-data' => '',
349
- 'astra-site-customizer-data' => '',
350
- 'astra-site-options-data' => '',
351
- 'astra-post-data-mapping' => '',
352
- 'astra-site-wxr-path' => '',
353
- 'astra-site-wpforms-path' => '',
354
- 'astra-enabled-extensions' => '',
355
- 'astra-custom-404' => '',
356
- 'required-plugins' => '',
357
- );
358
-
359
- $api_args = apply_filters(
360
- 'astra_sites_api_args',
361
- array(
362
- 'timeout' => 15,
363
- )
364
- );
365
-
366
- // Use this for premium demos.
367
- $request_params = apply_filters(
368
- 'astra_sites_api_params',
369
- array(
370
- 'purchase_key' => '',
371
- 'site_url' => '',
372
- )
373
- );
374
-
375
- $demo_api_uri = add_query_arg( $request_params, $demo_api_uri );
376
-
377
- // API Call.
378
- $response = wp_remote_get( $demo_api_uri, $api_args );
379
-
380
- if ( is_wp_error( $response ) || ( isset( $response->status ) && 0 == $response->status ) ) {
381
- if ( isset( $response->status ) ) {
382
- $data = json_decode( $response, true );
383
- } else {
384
- return new WP_Error( 'api_invalid_response_code', $response->get_error_message() );
385
- }
386
- } else {
387
- $data = json_decode( wp_remote_retrieve_body( $response ), true );
388
- }
389
-
390
- $data = json_decode( wp_remote_retrieve_body( $response ), true );
391
-
392
- if ( ! isset( $data['code'] ) ) {
393
- $remote_args['id'] = $data['id'];
394
- $remote_args['astra-site-widgets-data'] = json_decode( $data['astra-site-widgets-data'] );
395
- $remote_args['astra-site-customizer-data'] = $data['astra-site-customizer-data'];
396
- $remote_args['astra-site-options-data'] = $data['astra-site-options-data'];
397
- $remote_args['astra-post-data-mapping'] = $data['astra-post-data-mapping'];
398
- $remote_args['astra-site-wxr-path'] = $data['astra-site-wxr-path'];
399
- $remote_args['astra-site-wpforms-path'] = $data['astra-site-wpforms-path'];
400
- $remote_args['astra-enabled-extensions'] = $data['astra-enabled-extensions'];
401
- $remote_args['astra-custom-404'] = $data['astra-custom-404'];
402
- $remote_args['required-plugins'] = $data['required-plugins'];
403
- }
404
-
405
- // Merge remote demo and defaults.
406
- return wp_parse_args( $remote_args, $defaults );
407
- }
408
-
409
- /**
410
- * Clear Cache.
411
- *
412
- * @since 1.0.9
413
- */
414
- public function clear_cache() {
415
- // Clear 'Elementor' file cache.
416
- if ( class_exists( '\Elementor\Plugin' ) ) {
417
- Elementor\Plugin::$instance->posts_css_manager->clear_cache();
418
- }
419
-
420
- // Clear 'Builder Builder' cache.
421
- if ( is_callable( 'FLBuilderModel::delete_asset_cache_for_all_posts' ) ) {
422
- FLBuilderModel::delete_asset_cache_for_all_posts();
423
- }
424
-
425
- // Clear 'Astra Addon' cache.
426
- if ( is_callable( 'Astra_Minify::refresh_assets' ) ) {
427
- Astra_Minify::refresh_assets();
428
- }
429
-
430
- Astra_Sites_Importer_Log::add( 'Complete ' );
431
- }
432
-
433
- /**
434
- * Reset customizer data
435
- *
436
- * @since 1.3.0
437
- * @return void
438
- */
439
- function reset_customizer_data() {
440
- Astra_Sites_Importer_Log::add( 'Deleted customizer Settings ' . json_encode( get_option( 'astra-settings', array() ) ) );
441
-
442
- delete_option( 'astra-settings' );
443
-
444
- wp_send_json_success();
445
- }
446
-
447
- /**
448
- * Reset site options
449
- *
450
- * @since 1.3.0
451
- * @return void
452
- */
453
- function reset_site_options() {
454
-
455
- $options = get_option( '_astra_sites_old_site_options', array() );
456
-
457
- Astra_Sites_Importer_Log::add( 'Deleted - Site Options ' . json_encode( $options ) );
458
-
459
- if ( $options ) {
460
- foreach ( $options as $option_key => $option_value ) {
461
- delete_option( $option_key );
462
- }
463
- }
464
-
465
- wp_send_json_success();
466
- }
467
-
468
- /**
469
- * Reset widgets data
470
- *
471
- * @since 1.3.0
472
- * @return void
473
- */
474
- function reset_widgets_data() {
475
- $old_widgets = get_option( '_astra_sites_old_widgets_data', array() );
476
-
477
- Astra_Sites_Importer_Log::add( 'DELETED - WIDGETS ' . json_encode( $old_widgets ) );
478
-
479
- if ( $old_widgets ) {
480
- $sidebars_widgets = get_option( 'sidebars_widgets', array() );
481
-
482
- foreach ( $old_widgets as $sidebar_id => $widgets ) {
483
-
484
- if ( $widgets ) {
485
- foreach ( $widgets as $widget_key => $widget_data ) {
486
-
487
- if ( isset( $sidebars_widgets['wp_inactive_widgets'] ) ) {
488
- if ( ! in_array( $widget_key, $sidebars_widgets['wp_inactive_widgets'] ) ) {
489
- $sidebars_widgets['wp_inactive_widgets'][] = $widget_key;
490
- }
491
- }
492
- }
493
- }
494
- }
495
-
496
- update_option( 'sidebars_widgets', $sidebars_widgets );
497
- }
498
-
499
- wp_send_json_success();
500
- }
501
-
502
- /**
503
- * Delete imported posts
504
- *
505
- * @since 1.3.0
506
- * @return void
507
- */
508
- function delete_imported_posts() {
509
- $post_id = isset( $_REQUEST['post_id'] ) ? absint( $_REQUEST['post_id'] ) : '';
510
- $message = 'Deleted - Post ID ' . $post_id . ' - ' . get_post_type( $post_id ) . ' - ' . get_the_title( $post_id );
511
-
512
- Astra_Sites_Importer_Log::add( $message );
513
- wp_delete_post( $post_id, true );
514
-
515
- /* translators: %s is the post ID */
516
- wp_send_json_success( $message );
517
- }
518
-
519
- /**
520
- * Delete imported WP forms
521
- *
522
- * @since 1.3.0
523
- * @return void
524
- */
525
- function delete_imported_wp_forms() {
526
- $post_id = isset( $_REQUEST['post_id'] ) ? absint( $_REQUEST['post_id'] ) : '';
527
-
528
- $message = 'Deleted - Form ID ' . $post_id . ' - ' . get_post_type( $post_id ) . ' - ' . get_the_title( $post_id );
529
-
530
- Astra_Sites_Importer_Log::add( $message );
531
-
532
- wp_delete_post( $post_id, true );
533
-
534
- /* translators: %s is the form ID */
535
- wp_send_json_success( $message );
536
- }
537
-
538
- /**
539
- * Delete imported terms
540
- *
541
- * @since 1.3.0
542
- * @return void
543
- */
544
- function delete_imported_terms() {
545
-
546
- $term_id = isset( $_REQUEST['term_id'] ) ? absint( $_REQUEST['term_id'] ) : '';
547
-
548
- $message = '';
549
-
550
- if ( $term_id ) {
551
- $term = get_term( $term_id );
552
- if ( $term ) {
553
- $message = 'Deleted - Term ' . $term_id . ' - ' . $term->name . ' ' . $term->taxonomy;
554
- Astra_Sites_Importer_Log::add( $message );
555
- wp_delete_term( $term_id, $term->taxonomy );
556
- }
557
- }
558
-
559
- /* translators: %s is the term ID */
560
- wp_send_json_success( $message );
561
- }
562
-
563
- }
564
-
565
- /**
566
- * Kicking this off by calling 'get_instance()' method
567
- */
568
- Astra_Sites_Importer::get_instance();
569
-
570
- endif;
 
 
1
+ <?php
2
+ /**
3
+ * Astra Sites Importer
4
+ *
5
+ * @since 1.0.0
6
+ * @package Astra Sites
7
+ */
8
+
9
+ defined( 'ABSPATH' ) or exit;
10
+
11
+ if ( ! class_exists( 'Astra_Sites_Importer' ) ) :
12
+
13
+ /**
14
+ * Astra Sites Importer
15
+ */
16
+ class Astra_Sites_Importer {
17
+
18
+ /**
19
+ * Instance
20
+ *
21
+ * @since 1.0.0
22
+ * @var (Object) Class object
23
+ */
24
+ public static $_instance = null;
25
+
26
+ /**
27
+ * Set Instance
28
+ *
29
+ * @since 1.0.0
30
+ *
31
+ * @return object Class object.
32
+ */
33
+ public static function get_instance() {
34
+ if ( ! isset( self::$_instance ) ) {
35
+ self::$_instance = new self;
36
+ }
37
+
38
+ return self::$_instance;
39
+ }
40
+
41
+ /**
42
+ * Constructor.
43
+ *
44
+ * @since 1.0.0
45
+ */
46
+ public function __construct() {
47
+
48
+ require_once ASTRA_SITES_DIR . 'inc/classes/class-astra-sites-importer-log.php';
49
+ require_once ASTRA_SITES_DIR . 'inc/importers/class-astra-sites-helper.php';
50
+ require_once ASTRA_SITES_DIR . 'inc/importers/class-widgets-importer.php';
51
+ require_once ASTRA_SITES_DIR . 'inc/importers/class-astra-customizer-import.php';
52
+ require_once ASTRA_SITES_DIR . 'inc/importers/class-astra-site-options-import.php';
53
+
54
+ // Import AJAX.
55
+ add_action( 'wp_ajax_astra-sites-import-set-site-data', array( $this, 'import_start' ) );
56
+ add_action( 'wp_ajax_astra-sites-import-wpforms', array( $this, 'import_wpforms' ) );
57
+ add_action( 'wp_ajax_astra-sites-import-customizer-settings', array( $this, 'import_customizer_settings' ) );
58
+ add_action( 'wp_ajax_astra-sites-import-prepare-xml', array( $this, 'prepare_xml_data' ) );
59
+ add_action( 'wp_ajax_astra-sites-import-options', array( $this, 'import_options' ) );
60
+ add_action( 'wp_ajax_astra-sites-import-widgets', array( $this, 'import_widgets' ) );
61
+ add_action( 'wp_ajax_astra-sites-import-end', array( $this, 'import_end' ) );
62
+
63
+ // Hooks in AJAX.
64
+ add_action( 'astra_sites_import_complete', array( $this, 'clear_cache' ) );
65
+ add_action( 'init', array( $this, 'load_importer' ) );
66
+
67
+ require_once ASTRA_SITES_DIR . 'inc/importers/batch-processing/class-astra-sites-batch-processing.php';
68
+
69
+ add_action( 'astra_sites_image_import_complete', array( $this, 'clear_cache' ) );
70
+
71
+ // Reset Customizer Data.
72
+ add_action( 'wp_ajax_astra-sites-reset-customizer-data', array( $this, 'reset_customizer_data' ) );
73
+ add_action( 'wp_ajax_astra-sites-reset-site-options', array( $this, 'reset_site_options' ) );
74
+ add_action( 'wp_ajax_astra-sites-reset-widgets-data', array( $this, 'reset_widgets_data' ) );
75
+
76
+ // Reset Post & Terms.
77
+ add_action( 'wp_ajax_astra-sites-delete-posts', array( $this, 'delete_imported_posts' ) );
78
+ add_action( 'wp_ajax_astra-sites-delete-wp-forms', array( $this, 'delete_imported_wp_forms' ) );
79
+ add_action( 'wp_ajax_astra-sites-delete-terms', array( $this, 'delete_imported_terms' ) );
80
+ }
81
+
82
+ /**
83
+ * Load WordPress WXR importer.
84
+ */
85
+ public function load_importer() {
86
+ require_once ASTRA_SITES_DIR . 'inc/importers/wxr-importer/class-astra-wxr-importer.php';
87
+ }
88
+
89
+ /**
90
+ * Start Site Import
91
+ *
92
+ * @since 1.1.0
93
+ * @return void
94
+ */
95
+ function import_start() {
96
+
97
+ if ( ! current_user_can( 'customize' ) ) {
98
+ wp_send_json_error( __( 'You have not "customize" access to import the Astra site.', 'astra-sites' ) );
99
+ }
100
+
101
+ $demo_api_uri = isset( $_POST['api_url'] ) ? esc_url( $_POST['api_url'] ) : '';
102
+
103
+ if ( ! empty( $demo_api_uri ) ) {
104
+
105
+ $demo_data = self::get_astra_single_demo( $demo_api_uri );
106
+
107
+ update_option( 'astra_sites_import_data', $demo_data );
108
+
109
+ if ( is_wp_error( $demo_data ) ) {
110
+ wp_send_json_error( $demo_data->get_error_message() );
111
+ } else {
112
+ $log_file = Astra_Sites_Importer_Log::add_log_file_url();
113
+ if ( isset( $log_file['url'] ) && ! empty( $log_file['url'] ) ) {
114
+ $demo_data['log_file'] = $log_file['url'];
115
+ }
116
+ do_action( 'astra_sites_import_start', $demo_data, $demo_api_uri );
117
+ }
118
+
119
+ wp_send_json_success( $demo_data );
120
+
121
+ } else {
122
+ wp_send_json_error( __( 'Request site API URL is empty. Try again!', 'astra-sites' ) );
123
+ }
124
+
125
+ }
126
+
127
+ /**
128
+ * Import WP Forms
129
+ *
130
+ * @since 1.2.14
131
+ *
132
+ * @return void
133
+ */
134
+ function import_wpforms() {
135
+
136
+ $wpforms_url = ( isset( $_REQUEST['wpforms_url'] ) ) ? urldecode( $_REQUEST['wpforms_url'] ) : '';
137
+ $ids_mapping = array();
138
+
139
+ if ( ! empty( $wpforms_url ) && function_exists( 'wpforms_encode' ) ) {
140
+
141
+ // Download XML file.
142
+ $xml_path = Astra_Sites_Helper::download_file( $wpforms_url );
143
+
144
+ if ( $xml_path['success'] ) {
145
+ if ( isset( $xml_path['data']['file'] ) ) {
146
+
147
+ $ext = strtolower( pathinfo( $xml_path['data']['file'], PATHINFO_EXTENSION ) );
148
+
149
+ if ( 'json' === $ext ) {
150
+ $forms = json_decode( file_get_contents( $xml_path['data']['file'] ), true );
151
+
152
+ if ( ! empty( $forms ) ) {
153
+
154
+ foreach ( $forms as $form ) {
155
+ $title = ! empty( $form['settings']['form_title'] ) ? $form['settings']['form_title'] : '';
156
+ $desc = ! empty( $form['settings']['form_desc'] ) ? $form['settings']['form_desc'] : '';
157
+
158
+ $new_id = post_exists( $title );
159
+
160
+ if ( ! $new_id ) {
161
+ $new_id = wp_insert_post(
162
+ array(
163
+ 'post_title' => $title,
164
+ 'post_status' => 'publish',
165
+ 'post_type' => 'wpforms',
166
+ 'post_excerpt' => $desc,
167
+ )
168
+ );
169
+
170
+ // Set meta for tracking the post.
171
+ update_post_meta( $new_id, '_astra_sites_imported_wp_forms', true );
172
+ Astra_Sites_Importer_Log::add( 'Inserted WP Form ' . $new_id );
173
+ }
174
+
175
+ if ( $new_id ) {
176
+
177
+ // ID mapping.
178
+ $ids_mapping[ $form['id'] ] = $new_id;
179
+
180
+ $form['id'] = $new_id;
181
+ wp_update_post(
182
+ array(
183
+ 'ID' => $new_id,
184
+ 'post_content' => wpforms_encode( $form ),
185
+ )
186
+ );
187
+ }
188
+ }
189
+ }
190
+ }
191
+ }
192
+ }
193
+ }
194
+
195
+ update_option( 'astra_sites_wpforms_ids_mapping', $ids_mapping );
196
+
197
+ wp_send_json_success( $ids_mapping );
198
+ }
199
+
200
+ /**
201
+ * Import Customizer Settings.
202
+ *
203
+ * @since 1.0.14
204
+ * @return void
205
+ */
206
+ function import_customizer_settings() {
207
+
208
+ $customizer_data = ( isset( $_POST['customizer_data'] ) ) ? (array) json_decode( stripcslashes( $_POST['customizer_data'] ), 1 ) : array();
209
+
210
+ if ( ! empty( $customizer_data ) ) {
211
+
212
+ Astra_Sites_Importer_Log::add( 'Imported Customizer Settings ' . json_encode( $customizer_data ) );
213
+
214
+ // Set meta for tracking the post.
215
+ update_option( '_astra_sites_old_customizer_data', $customizer_data );
216
+
217
+ Astra_Customizer_Import::instance()->import( $customizer_data );
218
+
219
+ wp_send_json_success( $customizer_data );
220
+
221
+ } else {
222
+ wp_send_json_error( __( 'Customizer data is empty!', 'astra-sites' ) );
223
+ }
224
+
225
+ }
226
+
227
+ /**
228
+ * Prepare XML Data.
229
+ *
230
+ * @since 1.1.0
231
+ * @return void
232
+ */
233
+ function prepare_xml_data() {
234
+
235
+ if ( ! class_exists( 'XMLReader' ) ) {
236
+ 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' ) );
237
+ }
238
+
239
+ $wxr_url = ( isset( $_REQUEST['wxr_url'] ) ) ? urldecode( $_REQUEST['wxr_url'] ) : '';
240
+
241
+ if ( isset( $wxr_url ) ) {
242
+
243
+ Astra_Sites_Importer_Log::add( 'Importing from XML ' . $wxr_url );
244
+
245
+ // Download XML file.
246
+ $xml_path = Astra_Sites_Helper::download_file( $wxr_url );
247
+
248
+ if ( $xml_path['success'] ) {
249
+ if ( isset( $xml_path['data']['file'] ) ) {
250
+ $data = Astra_WXR_Importer::instance()->get_xml_data( $xml_path['data']['file'] );
251
+ $data['xml'] = $xml_path['data'];
252
+ wp_send_json_success( $data );
253
+ } else {
254
+ wp_send_json_error( __( 'There was an error downloading the XML file.', 'astra-sites' ) );
255
+ }
256
+ } else {
257
+ wp_send_json_error( $xml_path['data'] );
258
+ }
259
+ } else {
260
+ wp_send_json_error( __( 'Invalid site XML file!', 'astra-sites' ) );
261
+ }
262
+
263
+ }
264
+
265
+ /**
266
+ * Import Options.
267
+ *
268
+ * @since 1.0.14
269
+ * @return void
270
+ */
271
+ function import_options() {
272
+
273
+ $options_data = ( isset( $_POST['options_data'] ) ) ? (array) json_decode( stripcslashes( $_POST['options_data'] ), 1 ) : '';
274
+
275
+ if ( ! empty( $options_data ) ) {
276
+
277
+ // Set meta for tracking the post.
278
+ if ( is_array( $options_data ) ) {
279
+ Astra_Sites_Importer_Log::add( 'Imported - Site Options ' . json_encode( $options_data ) );
280
+ update_option( '_astra_sites_old_site_options', $options_data );
281
+ }
282
+
283
+ $options_importer = Astra_Site_Options_Import::instance();
284
+ $options_importer->import_options( $options_data );
285
+ wp_send_json_success( $options_data );
286
+ } else {
287
+ wp_send_json_error( __( 'Site options are empty!', 'astra-sites' ) );
288
+ }
289
+
290
+ }
291
+
292
+ /**
293
+ * Import Widgets.
294
+ *
295
+ * @since 1.0.14
296
+ * @return void
297
+ */
298
+ function import_widgets() {
299
+
300
+ $widgets_data = ( isset( $_POST['widgets_data'] ) ) ? (object) json_decode( stripcslashes( $_POST['widgets_data'] ) ) : '';
301
+
302
+ Astra_Sites_Importer_Log::add( 'Imported - Widgets ' . json_encode( $widgets_data ) );
303
+
304
+ if ( ! empty( $widgets_data ) ) {
305
+
306
+ $widgets_importer = Astra_Widget_Importer::instance();
307
+ $status = $widgets_importer->import_widgets_data( $widgets_data );
308
+
309
+ // Set meta for tracking the post.
310
+ if ( is_object( $widgets_data ) ) {
311
+ $widgets_data = (array) $widgets_data;
312
+ update_option( '_astra_sites_old_widgets_data', $widgets_data );
313
+ }
314
+
315
+ wp_send_json_success( $widgets_data );
316
+ } else {
317
+ wp_send_json_error( __( 'Widget data is empty!', 'astra-sites' ) );
318
+ }
319
+
320
+ }
321
+
322
+ /**
323
+ * Import End.
324
+ *
325
+ * @since 1.0.14
326
+ * @return void
327
+ */
328
+ function import_end() {
329
+ do_action( 'astra_sites_import_complete' );
330
+ }
331
+
332
+
333
+ /**
334
+ * Get single demo.
335
+ *
336
+ * @since 1.0.0
337
+ *
338
+ * @param (String) $demo_api_uri API URL of a demo.
339
+ *
340
+ * @return (Array) $astra_demo_data demo data for the demo.
341
+ */
342
+ public static function get_astra_single_demo( $demo_api_uri ) {
343
+
344
+ // default values.
345
+ $remote_args = array();
346
+ $defaults = array(
347
+ 'id' => '',
348
+ 'astra-site-widgets-data' => '',
349
+ 'astra-site-customizer-data' => '',
350
+ 'astra-site-options-data' => '',
351
+ 'astra-post-data-mapping' => '',
352
+ 'astra-site-wxr-path' => '',
353
+ 'astra-site-wpforms-path' => '',
354
+ 'astra-enabled-extensions' => '',
355
+ 'astra-custom-404' => '',
356
+ 'required-plugins' => '',
357
+ 'astra-site-taxonomy-mapping' => '',
358
+ );
359
+
360
+ $api_args = apply_filters(
361
+ 'astra_sites_api_args',
362
+ array(
363
+ 'timeout' => 15,
364
+ )
365
+ );
366
+
367
+ // Use this for premium demos.
368
+ $request_params = apply_filters(
369
+ 'astra_sites_api_params',
370
+ array(
371
+ 'purchase_key' => '',
372
+ 'site_url' => '',
373
+ )
374
+ );
375
+
376
+ $demo_api_uri = add_query_arg( $request_params, $demo_api_uri );
377
+
378
+ // API Call.
379
+ $response = wp_remote_get( $demo_api_uri, $api_args );
380
+
381
+ if ( is_wp_error( $response ) || ( isset( $response->status ) && 0 === $response->status ) ) {
382
+ if ( isset( $response->status ) ) {
383
+ $data = json_decode( $response, true );
384
+ } else {
385
+ return new WP_Error( 'api_invalid_response_code', $response->get_error_message() );
386
+ }
387
+ } else {
388
+ $data = json_decode( wp_remote_retrieve_body( $response ), true );
389
+ }
390
+
391
+ $data = json_decode( wp_remote_retrieve_body( $response ), true );
392
+
393
+ if ( ! isset( $data['code'] ) ) {
394
+ $remote_args['id'] = $data['id'];
395
+ $remote_args['astra-site-widgets-data'] = json_decode( $data['astra-site-widgets-data'] );
396
+ $remote_args['astra-site-customizer-data'] = $data['astra-site-customizer-data'];
397
+ $remote_args['astra-site-options-data'] = $data['astra-site-options-data'];
398
+ $remote_args['astra-post-data-mapping'] = $data['astra-post-data-mapping'];
399
+ $remote_args['astra-site-wxr-path'] = $data['astra-site-wxr-path'];
400
+ $remote_args['astra-site-wpforms-path'] = $data['astra-site-wpforms-path'];
401
+ $remote_args['astra-enabled-extensions'] = $data['astra-enabled-extensions'];
402
+ $remote_args['astra-custom-404'] = $data['astra-custom-404'];
403
+ $remote_args['required-plugins'] = $data['required-plugins'];
404
+ $remote_args['astra-site-taxonomy-mapping'] = $data['astra-site-taxonomy-mapping'];
405
+ }
406
+
407
+ // Merge remote demo and defaults.
408
+ return wp_parse_args( $remote_args, $defaults );
409
+ }
410
+
411
+ /**
412
+ * Clear Cache.
413
+ *
414
+ * @since 1.0.9
415
+ */
416
+ public function clear_cache() {
417
+ // Clear 'Elementor' file cache.
418
+ if ( class_exists( '\Elementor\Plugin' ) ) {
419
+ Elementor\Plugin::$instance->posts_css_manager->clear_cache();
420
+ }
421
+
422
+ // Clear 'Builder Builder' cache.
423
+ if ( is_callable( 'FLBuilderModel::delete_asset_cache_for_all_posts' ) ) {
424
+ FLBuilderModel::delete_asset_cache_for_all_posts();
425
+ }
426
+
427
+ // Clear 'Astra Addon' cache.
428
+ if ( is_callable( 'Astra_Minify::refresh_assets' ) ) {
429
+ Astra_Minify::refresh_assets();
430
+ }
431
+
432
+ Astra_Sites_Importer_Log::add( 'Complete ' );
433
+ }
434
+
435
+ /**
436
+ * Reset customizer data
437
+ *
438
+ * @since 1.3.0
439
+ * @return void
440
+ */
441
+ function reset_customizer_data() {
442
+ Astra_Sites_Importer_Log::add( 'Deleted customizer Settings ' . json_encode( get_option( 'astra-settings', array() ) ) );
443
+
444
+ delete_option( 'astra-settings' );
445
+
446
+ wp_send_json_success();
447
+ }
448
+
449
+ /**
450
+ * Reset site options
451
+ *
452
+ * @since 1.3.0
453
+ * @return void
454
+ */
455
+ function reset_site_options() {
456
+
457
+ $options = get_option( '_astra_sites_old_site_options', array() );
458
+
459
+ Astra_Sites_Importer_Log::add( 'Deleted - Site Options ' . json_encode( $options ) );
460
+
461
+ if ( $options ) {
462
+ foreach ( $options as $option_key => $option_value ) {
463
+ delete_option( $option_key );
464
+ }
465
+ }
466
+
467
+ wp_send_json_success();
468
+ }
469
+
470
+ /**
471
+ * Reset widgets data
472
+ *
473
+ * @since 1.3.0
474
+ * @return void
475
+ */
476
+ function reset_widgets_data() {
477
+ $old_widgets = get_option( '_astra_sites_old_widgets_data', array() );
478
+
479
+ Astra_Sites_Importer_Log::add( 'DELETED - WIDGETS ' . json_encode( $old_widgets ) );
480
+
481
+ if ( $old_widgets ) {
482
+ $sidebars_widgets = get_option( 'sidebars_widgets', array() );
483
+
484
+ foreach ( $old_widgets as $sidebar_id => $widgets ) {
485
+
486
+ if ( $widgets ) {
487
+ foreach ( $widgets as $widget_key => $widget_data ) {
488
+
489
+ if ( isset( $sidebars_widgets['wp_inactive_widgets'] ) ) {
490
+ if ( ! in_array( $widget_key, $sidebars_widgets['wp_inactive_widgets'], true ) ) {
491
+ $sidebars_widgets['wp_inactive_widgets'][] = $widget_key;
492
+ }
493
+ }
494
+ }
495
+ }
496
+ }
497
+
498
+ update_option( 'sidebars_widgets', $sidebars_widgets );
499
+ }
500
+
501
+ wp_send_json_success();
502
+ }
503
+
504
+ /**
505
+ * Delete imported posts
506
+ *
507
+ * @since 1.3.0
508
+ * @return void
509
+ */
510
+ function delete_imported_posts() {
511
+ $post_id = isset( $_REQUEST['post_id'] ) ? absint( $_REQUEST['post_id'] ) : '';
512
+ $message = 'Deleted - Post ID ' . $post_id . ' - ' . get_post_type( $post_id ) . ' - ' . get_the_title( $post_id );
513
+
514
+ Astra_Sites_Importer_Log::add( $message );
515
+ wp_delete_post( $post_id, true );
516
+
517
+ /* translators: %s is the post ID */
518
+ wp_send_json_success( $message );
519
+ }
520
+
521
+ /**
522
+ * Delete imported WP forms
523
+ *
524
+ * @since 1.3.0
525
+ * @return void
526
+ */
527
+ function delete_imported_wp_forms() {
528
+ $post_id = isset( $_REQUEST['post_id'] ) ? absint( $_REQUEST['post_id'] ) : '';
529
+
530
+ $message = 'Deleted - Form ID ' . $post_id . ' - ' . get_post_type( $post_id ) . ' - ' . get_the_title( $post_id );
531
+
532
+ Astra_Sites_Importer_Log::add( $message );
533
+
534
+ wp_delete_post( $post_id, true );
535
+
536
+ /* translators: %s is the form ID */
537
+ wp_send_json_success( $message );
538
+ }
539
+
540
+ /**
541
+ * Delete imported terms
542
+ *
543
+ * @since 1.3.0
544
+ * @return void
545
+ */
546
+ function delete_imported_terms() {
547
+
548
+ $term_id = isset( $_REQUEST['term_id'] ) ? absint( $_REQUEST['term_id'] ) : '';
549
+
550
+ $message = '';
551
+
552
+ if ( $term_id ) {
553
+ $term = get_term( $term_id );
554
+ if ( $term ) {
555
+ $message = 'Deleted - Term ' . $term_id . ' - ' . $term->name . ' ' . $term->taxonomy;
556
+ Astra_Sites_Importer_Log::add( $message );
557
+ wp_delete_term( $term_id, $term->taxonomy );
558
+ }
559
+ }
560
+
561
+ /* translators: %s is the term ID */
562
+ wp_send_json_success( $message );
563
+ }
564
+
565
+ }
566
+
567
+ /**
568
+ * Kicking this off by calling 'get_instance()' method
569
+ */
570
+ Astra_Sites_Importer::get_instance();
571
+
572
+ endif;
inc/classes/class-astra-sites-page.php CHANGED
@@ -1,434 +1,434 @@
1
- <?php
2
- /**
3
- * Astra Sites Page
4
- *
5
- * @since 1.0.6
6
- * @package Astra Sites
7
- */
8
-
9
- if ( ! defined( 'ABSPATH' ) ) {
10
- exit;
11
- }
12
-
13
- if ( ! class_exists( 'Astra_Sites_Page' ) ) {
14
-
15
- /**
16
- * Astra Admin Settings
17
- */
18
- class Astra_Sites_Page {
19
-
20
- /**
21
- * View all actions
22
- *
23
- * @since 1.0.6
24
- * @var array $view_actions
25
- */
26
- public $view_actions = array();
27
-
28
- /**
29
- * Member Variable
30
- *
31
- * @var instance
32
- */
33
- private static $instance;
34
-
35
- /**
36
- * Initiator
37
- *
38
- * @since 1.3.0
39
- */
40
- public static function get_instance() {
41
- if ( ! isset( self::$instance ) ) {
42
- self::$instance = new self;
43
- }
44
- return self::$instance;
45
- }
46
-
47
- /**
48
- * Constructor
49
- *
50
- * @since 1.3.0
51
- */
52
- public function __construct() {
53
-
54
- if ( ! is_admin() ) {
55
- return;
56
- }
57
-
58
- add_action( 'after_setup_theme', array( $this, 'init_admin_settings' ), 99 );
59
- add_action( 'admin_init', array( $this, 'save_page_builder' ) );
60
- add_action( 'admin_notices', array( $this, 'getting_started' ) );
61
- }
62
-
63
- /**
64
- * Admin notice
65
- *
66
- * @since 1.3.5
67
- *
68
- * @return void
69
- */
70
- function getting_started() {
71
- if ( 'plugins' !== get_current_screen()->base ) {
72
- return;
73
- }
74
-
75
- $processed = get_user_meta( get_current_user_id(), '_astra_sites_gettings_started', true );
76
- $product_name = Astra_Sites_White_Label::get_instance()->page_title( 'Astra' );
77
-
78
- if ( $processed ) {
79
- return;
80
- }
81
-
82
- ?>
83
- <div class="notice notice-info is-dismissible astra-sites-getting-started-notice">
84
- <?php /* translators: %1$s is the admin page URL, %2$s is product name. */ ?>
85
- <p><?php printf( __( 'Thank you for choosing %1$s! Check the library of <a class="astra-sites-getting-started-btn" href="%2$s">ready starter sites here »</a>', 'astra-sites' ), $product_name, admin_url( 'themes.php?page=astra-sites' ) ); ?></p>
86
- </div>
87
- <?php
88
- }
89
-
90
- /**
91
- * Save Page Builder
92
- *
93
- * @return void
94
- */
95
- function save_page_builder() {
96
-
97
- // Only admins can save settings.
98
- if ( ! current_user_can( 'manage_options' ) ) {
99
- return;
100
- }
101
-
102
- // Make sure we have a valid nonce.
103
- if ( isset( $_REQUEST['astra-sites-page-builder'] ) && wp_verify_nonce( $_REQUEST['astra-sites-page-builder'], 'astra-sites-welcome-screen' ) ) {
104
-
105
- // Stored Settings.
106
- $stored_data = $this->get_settings();
107
-
108
- // New settings.
109
- $new_data = array(
110
- 'page_builder' => ( isset( $_REQUEST['page_builder'] ) ) ? sanitize_key( $_REQUEST['page_builder'] ) : '',
111
- );
112
-
113
- // Merge settings.
114
- $data = wp_parse_args( $new_data, $stored_data );
115
-
116
- // Update settings.
117
- update_option( 'astra_sites_settings', $data );
118
-
119
- wp_redirect( admin_url( '/themes.php?page=astra-sites' ) );
120
- }
121
- }
122
-
123
- /**
124
- * Get single setting value
125
- *
126
- * @param string $key Setting key.
127
- * @param mixed $defaults Setting value.
128
- * @return mixed Stored setting value.
129
- */
130
- function get_setting( $key = '', $defaults = '' ) {
131
-
132
- $settings = $this->get_settings();
133
-
134
- if ( empty( $settings ) ) {
135
- return $defaults;
136
- }
137
-
138
- if ( array_key_exists( $key, $settings ) ) {
139
- return $settings[ $key ];
140
- }
141
-
142
- return $defaults;
143
- }
144
-
145
- /**
146
- * Get Settings
147
- *
148
- * @return array Stored settings.
149
- */
150
- function get_settings() {
151
-
152
- $defaults = array(
153
- 'page_builder' => '',
154
- );
155
-
156
- $stored_data = get_option( 'astra_sites_settings', $defaults );
157
-
158
- return wp_parse_args( $stored_data, $defaults );
159
- }
160
-
161
- /**
162
- * Admin settings init
163
- */
164
- public function init_admin_settings() {
165
- add_action( 'admin_menu', array( $this, 'add_admin_menu' ), 100 );
166
- add_action( 'admin_notices', array( $this, 'notices' ) );
167
- add_action( 'astra_sites_menu_general_action', array( $this, 'general_page' ) );
168
- }
169
-
170
- /**
171
- * Admin notice
172
- *
173
- * @since 1.2.8
174
- */
175
- public function notices() {
176
-
177
- if ( 'appearance_page_astra-sites' !== get_current_screen()->id ) {
178
- return;
179
- }
180
-
181
- if ( ! class_exists( 'XMLReader' ) ) {
182
- ?>
183
- <div class="notice astra-sites-xml-notice notice-error">
184
- <p><b><?php _e( 'Required XMLReader PHP extension is missing on your server!', 'astra-sites' ); ?></b></p>
185
- <?php /* translators: %s is the white label name. */ ?>
186
- <p><?php printf( __( '%s import requires XMLReader extension to be installed. Please contact your web hosting provider and ask them to install and activate the XMLReader PHP extension.', 'astra-sites' ), ASTRA_SITES_NAME ); ?></p>
187
- </div>
188
- <?php
189
- }
190
- }
191
-
192
- /**
193
- * Init Nav Menu
194
- *
195
- * @param mixed $action Action name.
196
- * @since 1.0.6
197
- */
198
- public function init_nav_menu( $action = '' ) {
199
-
200
- if ( '' !== $action ) {
201
- $this->render_tab_menu( $action );
202
- }
203
- }
204
-
205
- /**
206
- * Render tab menu
207
- *
208
- * @param mixed $action Action name.
209
- * @since 1.0.6
210
- */
211
- public function render_tab_menu( $action = '' ) {
212
- ?>
213
- <div id="astra-sites-menu-page">
214
- <?php $this->render( $action ); ?>
215
- </div>
216
- <?php
217
- }
218
-
219
- /**
220
- * View actions
221
- *
222
- * @since 1.0.11
223
- */
224
- public function get_view_actions() {
225
-
226
- if ( empty( $this->view_actions ) ) {
227
-
228
- $this->view_actions = apply_filters(
229
- 'astra_sites_menu_item',
230
- array()
231
- );
232
- }
233
-
234
- return $this->view_actions;
235
- }
236
-
237
- /**
238
- * Prints HTML content for tabs
239
- *
240
- * @param mixed $action Action name.
241
- * @since 1.0.6
242
- */
243
- public function render( $action ) {
244
-
245
- // Settings update message.
246
- if ( isset( $_REQUEST['message'] ) && ( 'saved' == $_REQUEST['message'] || 'saved_ext' == $_REQUEST['message'] ) ) {
247
- ?>
248
- <span id="message" class="notice notice-success is-dismissive"><p> <?php esc_html_e( 'Settings saved successfully.', 'astra-sites' ); ?> </p></span>
249
- <?php
250
- }
251
-
252
- $default_page_builder = $this->get_setting( 'page_builder' );
253
-
254
- if ( empty( $default_page_builder ) || isset( $_GET['change-page-builder'] ) ) {
255
-
256
- $plugins = get_option( 'active_plugins', array() );
257
- $page_builders = array();
258
- if ( $plugins ) {
259
- foreach ( $plugins as $key => $plugin_init ) {
260
- if ( false !== strpos( $plugin_init, 'elementor' ) ) {
261
- $page_builders[] = 'elementor';
262
- }
263
- if ( false !== strpos( $plugin_init, 'beaver-builder' ) ) {
264
- $page_builders[] = 'beaver-builder';
265
- }
266
- if ( false !== strpos( $plugin_init, 'brizy' ) ) {
267
- $page_builders[] = 'brizy';
268
- }
269
- }
270
- }
271
- $page_builders = array_unique( $page_builders );
272
- $page_builders[] = 'gutenberg';
273
- $page_builders = implode( ',', $page_builders );
274
- ?>
275
- <div class="astra-sites-welcome" data-plugins="<?php echo esc_attr( $page_builders ); ?>">
276
- <div class="inner">
277
- <form id="astra-sites-welcome-form" enctype="multipart/form-data" method="post">
278
- <h1><?php _e( 'Select Page Builder', 'astra-sites' ); ?></h1>
279
- <p><?php _e( 'Astra offers starter sites that can be imported in one click. These templates are available in few different page builders. Please choose your preferred page builder from the list below.', 'astra-sites' ); ?></p>
280
- <div class="fields">
281
- <ul class="page-builders">
282
- <li>
283
- <label>
284
- <input type="radio" name="page_builder" value="gutenberg">
285
- <img src="<?php echo esc_url( ASTRA_SITES_URI . 'inc/assets/images/gutenberg.jpg' ); ?>" />
286
- <div class="title"><?php _e( 'Gutenberg', 'astra-sites' ); ?></div>
287
- </label>
288
- </li>
289
- <li>
290
- <label>
291
- <input type="radio" name="page_builder" value="elementor">
292
- <img src="<?php echo esc_url( ASTRA_SITES_URI . 'inc/assets/images/elementor.jpg' ); ?>" />
293
- <div class="title"><?php _e( 'Elementor', 'astra-sites' ); ?></div>
294
- </label>
295
- </li>
296
- <li>
297
- <label>
298
- <input type="radio" name="page_builder" value="beaver-builder">
299
- <img src="<?php echo esc_url( ASTRA_SITES_URI . 'inc/assets/images/beaver-builder.png' ); ?>" />
300
- <div class="title"><?php _e( 'Beaver Builder', 'astra-sites' ); ?></div>
301
- </li>
302
- <li>
303
- <label>
304
- <input type="radio" name="page_builder" value="brizy">
305
- <img src="<?php echo esc_url( ASTRA_SITES_URI . 'inc/assets/images/brizy.jpg' ); ?>" />
306
- <div class="title"><?php _e( 'Brizy', 'astra-sites' ); ?></div>
307
- </label>
308
- </li>
309
- </ul>
310
- <div class="astra-sites-page-builder-notice" style="display: none;">
311
- <p class="description"><?php _e( 'Please select your favorite page builder to continue..', 'astra-sites' ); ?></p>
312
- </div>
313
- <?php submit_button( __( 'Next', 'astra-sites' ), 'primary button-hero disabled' ); ?>
314
- </div>
315
-
316
- <input type="hidden" name="message" value="saved" />
317
- <?php wp_nonce_field( 'astra-sites-welcome-screen', 'astra-sites-page-builder' ); ?>
318
- </form>
319
- </div>
320
- </div>
321
- <?php } else { ?>
322
- <?php
323
- $page_title = apply_filters( 'astra_sites_page_title', __( 'Astra Starter Sites - Your Library of 100+ Ready Templates!', 'astra-sites' ) );
324
- ?>
325
- <div class="nav-tab-wrapper">
326
- <h1 class='astra-sites-title'> <?php echo esc_html( $page_title ); ?> </h1>
327
- <form id="astra-sites-welcome-form-inline" enctype="multipart/form-data" method="post">
328
- <div class="fields">
329
- <select name="page_builder" required="required">
330
- <option value="gutenberg" <?php selected( $default_page_builder, 'gutenberg' ); ?>><?php _e( 'Block Editor (Gutenberg)', 'astra-sites' ); ?></option>
331
- <option value="elementor" <?php selected( $default_page_builder, 'elementor' ); ?>><?php _e( 'Elementor', 'astra-sites' ); ?></option>
332
- <option value="beaver-builder" <?php selected( $default_page_builder, 'beaver-builder' ); ?>><?php _e( 'Beaver Builder', 'astra-sites' ); ?></option>
333
- <option value="brizy" <?php selected( $default_page_builder, 'brizy' ); ?>><?php _e( 'Brizy', 'astra-sites' ); ?></option>
334
- </select>
335
- </div>
336
- <input type="hidden" name="message" value="saved" />
337
- <?php wp_nonce_field( 'astra-sites-welcome-screen', 'astra-sites-page-builder' ); ?>
338
- </form>
339
- <?php
340
- $view_actions = $this->get_view_actions();
341
-
342
- foreach ( $view_actions as $slug => $data ) {
343
-
344
- if ( ! $data['show'] ) {
345
- continue;
346
- }
347
-
348
- $url = $this->get_page_url( $slug );
349
-
350
- if ( 'general' == $slug ) {
351
- update_option( 'astra_parent_page_url', $url );
352
- }
353
-
354
- $active = ( $slug == $action ) ? 'nav-tab-active' : '';
355
- ?>
356
- <a class='nav-tab <?php echo esc_attr( $active ); ?>' href='<?php echo esc_url( $url ); ?>'> <?php echo esc_html( $data['label'] ); ?> </a>
357
- <?php } ?>
358
- </div><!-- .nav-tab-wrapper -->
359
- <?php
360
- }
361
- }
362
-
363
- /**
364
- * Get and return page URL
365
- *
366
- * @param string $menu_slug Menu name.
367
- * @since 1.0.6
368
- * @return string page url
369
- */
370
- public function get_page_url( $menu_slug ) {
371
-
372
- $parent_page = 'themes.php';
373
-
374
- if ( strpos( $parent_page, '?' ) !== false ) {
375
- $query_var = '&page=astra-sites';
376
- } else {
377
- $query_var = '?page=astra-sites';
378
- }
379
-
380
- $parent_page_url = admin_url( $parent_page . $query_var );
381
-
382
- $url = $parent_page_url . '&action=' . $menu_slug;
383
-
384
- return esc_url( $url );
385
- }
386
-
387
- /**
388
- * Add main menu
389
- *
390
- * @since 1.0.6
391
- */
392
- public function add_admin_menu() {
393
- $page_title = apply_filters( 'astra_sites_menu_page_title', __( 'Astra Starter Sites', 'astra-sites' ) );
394
-
395
- $page = add_theme_page( $page_title, $page_title, 'manage_options', 'astra-sites', array( $this, 'menu_callback' ) );
396
- }
397
-
398
- /**
399
- * Menu callback
400
- *
401
- * @since 1.0.6
402
- */
403
- public function menu_callback() {
404
-
405
- $current_slug = isset( $_GET['action'] ) ? esc_attr( $_GET['action'] ) : 'general';
406
-
407
- $active_tab = str_replace( '_', '-', $current_slug );
408
- $current_slug = str_replace( '-', '_', $current_slug );
409
-
410
- ?>
411
- <div class="astra-sites-menu-page-wrapper">
412
- <?php $this->init_nav_menu( $active_tab ); ?>
413
- <?php do_action( 'astra_sites_menu_' . esc_attr( $current_slug ) . '_action' ); ?>
414
- </div>
415
- <?php
416
- }
417
-
418
- /**
419
- * Include general page
420
- *
421
- * @since 1.0.6
422
- */
423
- public function general_page() {
424
- $default_page_builder = $this->get_setting( 'page_builder' );
425
- if ( empty( $default_page_builder ) || isset( $_GET['change-page-builder'] ) ) {
426
- return;
427
- }
428
- require_once ASTRA_SITES_DIR . 'inc/includes/admin-page.php';
429
- }
430
- }
431
-
432
- Astra_Sites_Page::get_instance();
433
-
434
- }// End if.
1
+ <?php
2
+ /**
3
+ * Astra Sites Page
4
+ *
5
+ * @since 1.0.6
6
+ * @package Astra Sites
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ if ( ! class_exists( 'Astra_Sites_Page' ) ) {
14
+
15
+ /**
16
+ * Astra Admin Settings
17
+ */
18
+ class Astra_Sites_Page {
19
+
20
+ /**
21
+ * View all actions
22
+ *
23
+ * @since 1.0.6
24
+ * @var array $view_actions
25
+ */
26
+ public $view_actions = array();
27
+
28
+ /**
29
+ * Member Variable
30
+ *
31
+ * @var instance
32
+ */
33
+ private static $instance;
34
+
35
+ /**
36
+ * Initiator
37
+ *
38
+ * @since 1.3.0
39
+ */
40
+ public static function get_instance() {
41
+ if ( ! isset( self::$instance ) ) {
42
+ self::$instance = new self;
43
+ }
44
+ return self::$instance;
45
+ }
46
+
47
+ /**
48
+ * Constructor
49
+ *
50
+ * @since 1.3.0
51
+ */
52
+ public function __construct() {
53
+
54
+ if ( ! is_admin() ) {
55
+ return;
56
+ }
57
+
58
+ add_action( 'after_setup_theme', array( $this, 'init_admin_settings' ), 99 );
59
+ add_action( 'admin_init', array( $this, 'save_page_builder' ) );
60
+ add_action( 'admin_notices', array( $this, 'getting_started' ) );
61
+ }
62
+
63
+ /**
64
+ * Admin notice
65
+ *
66
+ * @since 1.3.5
67
+ *
68
+ * @return void
69
+ */
70
+ function getting_started() {
71
+ if ( 'plugins' !== get_current_screen()->base ) {
72
+ return;
73
+ }
74
+
75
+ $processed = get_user_meta( get_current_user_id(), '_astra_sites_gettings_started', true );
76
+ $product_name = Astra_Sites_White_Label::get_instance()->page_title( 'Astra' );
77
+
78
+ if ( $processed ) {
79
+ return;
80
+ }
81
+
82
+ ?>
83
+ <div class="notice notice-info is-dismissible astra-sites-getting-started-notice">
84
+ <?php /* translators: %1$s is the admin page URL, %2$s is product name. */ ?>
85
+ <p><?php printf( __( 'Thank you for choosing %1$s! Check the library of <a class="astra-sites-getting-started-btn" href="%2$s">ready starter sites here »</a>', 'astra-sites' ), $product_name, admin_url( 'themes.php?page=astra-sites' ) ); ?></p>
86
+ </div>
87
+ <?php
88
+ }
89
+
90
+ /**
91
+ * Save Page Builder
92
+ *
93
+ * @return void
94
+ */
95
+ function save_page_builder() {
96
+
97
+ // Only admins can save settings.
98
+ if ( ! current_user_can( 'manage_options' ) ) {
99
+ return;
100
+ }
101
+
102
+ // Make sure we have a valid nonce.
103
+ if ( isset( $_REQUEST['astra-sites-page-builder'] ) && wp_verify_nonce( $_REQUEST['astra-sites-page-builder'], 'astra-sites-welcome-screen' ) ) {
104
+
105
+ // Stored Settings.
106
+ $stored_data = $this->get_settings();
107
+
108
+ // New settings.
109
+ $new_data = array(
110
+ 'page_builder' => ( isset( $_REQUEST['page_builder'] ) ) ? sanitize_key( $_REQUEST['page_builder'] ) : '',
111
+ );
112
+
113
+ // Merge settings.
114
+ $data = wp_parse_args( $new_data, $stored_data );
115
+
116
+ // Update settings.
117
+ update_option( 'astra_sites_settings', $data );
118
+
119
+ wp_redirect( admin_url( '/themes.php?page=astra-sites' ) );
120
+ }
121
+ }
122
+
123
+ /**
124
+ * Get single setting value
125
+ *
126
+ * @param string $key Setting key.
127
+ * @param mixed $defaults Setting value.
128
+ * @return mixed Stored setting value.
129
+ */
130
+ function get_setting( $key = '', $defaults = '' ) {
131
+
132
+ $settings = $this->get_settings();
133
+
134
+ if ( empty( $settings ) ) {
135
+ return $defaults;
136
+ }
137
+
138
+ if ( array_key_exists( $key, $settings ) ) {
139
+ return $settings[ $key ];
140
+ }
141
+
142
+ return $defaults;
143
+ }
144
+
145
+ /**
146
+ * Get Settings
147
+ *
148
+ * @return array Stored settings.
149
+ */
150
+ function get_settings() {
151
+
152
+ $defaults = array(
153
+ 'page_builder' => '',
154
+ );
155
+
156
+ $stored_data = get_option( 'astra_sites_settings', $defaults );
157
+
158
+ return wp_parse_args( $stored_data, $defaults );
159
+ }
160
+
161
+ /**
162
+ * Admin settings init
163
+ */
164
+ public function init_admin_settings() {
165
+ add_action( 'admin_menu', array( $this, 'add_admin_menu' ), 100 );
166
+ add_action( 'admin_notices', array( $this, 'notices' ) );
167
+ add_action( 'astra_sites_menu_general_action', array( $this, 'general_page' ) );
168
+ }
169
+
170
+ /**
171
+ * Admin notice
172
+ *
173
+ * @since 1.2.8
174
+ */
175
+ public function notices() {
176
+
177
+ if ( 'appearance_page_astra-sites' !== get_current_screen()->id ) {
178
+ return;
179
+ }
180
+
181
+ if ( ! class_exists( 'XMLReader' ) ) {
182
+ ?>
183
+ <div class="notice astra-sites-xml-notice notice-error">
184
+ <p><b><?php _e( 'Required XMLReader PHP extension is missing on your server!', 'astra-sites' ); ?></b></p>
185
+ <?php /* translators: %s is the white label name. */ ?>
186
+ <p><?php printf( __( '%s import requires XMLReader extension to be installed. Please contact your web hosting provider and ask them to install and activate the XMLReader PHP extension.', 'astra-sites' ), ASTRA_SITES_NAME ); ?></p>
187
+ </div>
188
+ <?php
189
+ }
190
+ }
191
+
192
+ /**
193
+ * Init Nav Menu
194
+ *
195
+ * @param mixed $action Action name.
196
+ * @since 1.0.6
197
+ */
198
+ public function init_nav_menu( $action = '' ) {
199
+
200
+ if ( '' !== $action ) {
201
+ $this->render_tab_menu( $action );
202
+ }
203
+ }
204
+
205
+ /**
206
+ * Render tab menu
207
+ *
208
+ * @param mixed $action Action name.
209
+ * @since 1.0.6
210
+ */
211
+ public function render_tab_menu( $action = '' ) {
212
+ ?>
213
+ <div id="astra-sites-menu-page">
214
+ <?php $this->render( $action ); ?>
215
+ </div>
216
+ <?php
217
+ }
218
+
219
+ /**
220
+ * View actions
221
+ *
222
+ * @since 1.0.11
223
+ */
224
+ public function get_view_actions() {
225
+
226
+ if ( empty( $this->view_actions ) ) {
227
+
228
+ $this->view_actions = apply_filters(
229
+ 'astra_sites_menu_item',
230
+ array()
231
+ );
232
+ }
233
+
234
+ return $this->view_actions;
235
+ }
236
+
237
+ /**
238
+ * Prints HTML content for tabs
239
+ *
240
+ * @param mixed $action Action name.
241
+ * @since 1.0.6
242
+ */
243
+ public function render( $action ) {
244
+
245
+ // Settings update message.
246
+ if ( isset( $_REQUEST['message'] ) && ( 'saved' === $_REQUEST['message'] || 'saved_ext' === $_REQUEST['message'] ) ) {
247
+ ?>
248
+ <span id="message" class="notice notice-success is-dismissive"><p> <?php esc_html_e( 'Settings saved successfully.', 'astra-sites' ); ?> </p></span>
249
+ <?php
250
+ }
251
+
252
+ $default_page_builder = $this->get_setting( 'page_builder' );
253
+
254
+ if ( empty( $default_page_builder ) || isset( $_GET['change-page-builder'] ) ) {
255
+
256
+ $plugins = get_option( 'active_plugins', array() );
257
+ $page_builders = array();
258
+ if ( $plugins ) {
259
+ foreach ( $plugins as $key => $plugin_init ) {
260
+ if ( false !== strpos( $plugin_init, 'elementor' ) ) {
261
+ $page_builders[] = 'elementor';
262
+ }
263
+ if ( false !== strpos( $plugin_init, 'beaver-builder' ) ) {
264
+ $page_builders[] = 'beaver-builder';
265
+ }
266
+ if ( false !== strpos( $plugin_init, 'brizy' ) ) {
267
+ $page_builders[] = 'brizy';
268
+ }
269
+ }
270
+ }
271
+ $page_builders = array_unique( $page_builders );
272
+ $page_builders[] = 'gutenberg';
273
+ $page_builders = implode( ',', $page_builders );
274
+ ?>
275
+ <div class="astra-sites-welcome" data-plugins="<?php echo esc_attr( $page_builders ); ?>">
276
+ <div class="inner">
277
+ <form id="astra-sites-welcome-form" enctype="multipart/form-data" method="post">
278
+ <h1><?php _e( 'Select Page Builder', 'astra-sites' ); ?></h1>
279
+ <p><?php _e( 'Astra offers starter sites that can be imported in one click. These templates are available in few different page builders. Please choose your preferred page builder from the list below.', 'astra-sites' ); ?></p>
280
+ <div class="fields">
281
+ <ul class="page-builders">
282
+ <li>
283
+ <label>
284
+ <input type="radio" name="page_builder" value="gutenberg">
285
+ <img src="<?php echo esc_url( ASTRA_SITES_URI . 'inc/assets/images/gutenberg.jpg' ); ?>" />
286
+ <div class="title"><?php _e( 'Gutenberg', 'astra-sites' ); ?></div>
287
+ </label>
288
+ </li>
289
+ <li>
290
+ <label>
291
+ <input type="radio" name="page_builder" value="elementor">
292
+ <img src="<?php echo esc_url( ASTRA_SITES_URI . 'inc/assets/images/elementor.jpg' ); ?>" />
293
+ <div class="title"><?php _e( 'Elementor', 'astra-sites' ); ?></div>
294
+ </label>
295
+ </li>
296
+ <li>
297
+ <label>
298
+ <input type="radio" name="page_builder" value="beaver-builder">
299
+ <img src="<?php echo esc_url( ASTRA_SITES_URI . 'inc/assets/images/beaver-builder.png' ); ?>" />
300
+ <div class="title"><?php _e( 'Beaver Builder', 'astra-sites' ); ?></div>
301
+ </li>
302
+ <li>
303
+ <label>
304
+ <input type="radio" name="page_builder" value="brizy">
305
+ <img src="<?php echo esc_url( ASTRA_SITES_URI . 'inc/assets/images/brizy.jpg' ); ?>" />
306
+ <div class="title"><?php _e( 'Brizy', 'astra-sites' ); ?></div>
307
+ </label>
308
+ </li>
309
+ </ul>
310
+ <div class="astra-sites-page-builder-notice" style="display: none;">
311
+ <p class="description"><?php _e( 'Please select your favorite page builder to continue..', 'astra-sites' ); ?></p>
312
+ </div>
313
+ <?php submit_button( __( 'Next', 'astra-sites' ), 'primary button-hero disabled' ); ?>
314
+ </div>
315
+
316
+ <input type="hidden" name="message" value="saved" />
317
+ <?php wp_nonce_field( 'astra-sites-welcome-screen', 'astra-sites-page-builder' ); ?>
318
+ </form>
319
+ </div>
320
+ </div>
321
+ <?php } else { ?>
322
+ <?php
323
+ $page_title = apply_filters( 'astra_sites_page_title', __( 'Astra Starter Sites - Your Library of 100+ Ready Templates!', 'astra-sites' ) );
324
+ ?>
325
+ <div class="nav-tab-wrapper">
326
+ <h1 class='astra-sites-title'> <?php echo esc_html( $page_title ); ?> </h1>
327
+ <form id="astra-sites-welcome-form-inline" enctype="multipart/form-data" method="post">
328
+ <div class="fields">
329
+ <select name="page_builder" required="required">
330
+ <option value="gutenberg" <?php selected( $default_page_builder, 'gutenberg' ); ?>><?php _e( 'Block Editor (Gutenberg)', 'astra-sites' ); ?></option>
331
+ <option value="elementor" <?php selected( $default_page_builder, 'elementor' ); ?>><?php _e( 'Elementor', 'astra-sites' ); ?></option>
332
+ <option value="beaver-builder" <?php selected( $default_page_builder, 'beaver-builder' ); ?>><?php _e( 'Beaver Builder', 'astra-sites' ); ?></option>
333
+ <option value="brizy" <?php selected( $default_page_builder, 'brizy' ); ?>><?php _e( 'Brizy', 'astra-sites' ); ?></option>
334
+ </select>
335
+ </div>
336
+ <input type="hidden" name="message" value="saved" />
337
+ <?php wp_nonce_field( 'astra-sites-welcome-screen', 'astra-sites-page-builder' ); ?>
338
+ </form>
339
+ <?php
340
+ $view_actions = $this->get_view_actions();
341
+
342
+ foreach ( $view_actions as $slug => $data ) {
343
+
344
+ if ( ! $data['show'] ) {
345
+ continue;
346
+ }
347
+
348
+ $url = $this->get_page_url( $slug );
349
+
350
+ if ( 'general' === $slug ) {
351
+ update_option( 'astra_parent_page_url', $url );
352
+ }
353
+
354
+ $active = ( $slug === $action ) ? 'nav-tab-active' : '';
355
+ ?>
356
+ <a class='nav-tab <?php echo esc_attr( $active ); ?>' href='<?php echo esc_url( $url ); ?>'> <?php echo esc_html( $data['label'] ); ?> </a>
357
+ <?php } ?>
358
+ </div><!-- .nav-tab-wrapper -->
359
+ <?php
360
+ }
361
+ }
362
+
363
+ /**
364
+ * Get and return page URL
365
+ *
366
+ * @param string $menu_slug Menu name.
367
+ * @since 1.0.6
368
+ * @return string page url
369
+ */
370
+ public function get_page_url( $menu_slug ) {
371
+
372
+ $parent_page = 'themes.php';
373
+
374
+ if ( strpos( $parent_page, '?' ) !== false ) {
375
+ $query_var = '&page=astra-sites';
376
+ } else {
377
+ $query_var = '?page=astra-sites';
378
+ }
379
+
380
+ $parent_page_url = admin_url( $parent_page . $query_var );
381
+
382
+ $url = $parent_page_url . '&action=' . $menu_slug;
383
+
384
+ return esc_url( $url );
385
+ }
386
+
387
+ /**
388
+ * Add main menu
389
+ *
390
+ * @since 1.0.6
391
+ */
392
+ public function add_admin_menu() {
393
+ $page_title = apply_filters( 'astra_sites_menu_page_title', __( 'Astra Starter Sites', 'astra-sites' ) );
394
+
395
+ $page = add_theme_page( $page_title, $page_title, 'manage_options', 'astra-sites', array( $this, 'menu_callback' ) );
396
+ }
397
+
398
+ /**
399
+ * Menu callback
400
+ *
401
+ * @since 1.0.6
402
+ */
403
+ public function menu_callback() {
404
+
405
+ $current_slug = isset( $_GET['action'] ) ? esc_attr( $_GET['action'] ) : 'general';
406
+
407
+ $active_tab = str_replace( '_', '-', $current_slug );
408
+ $current_slug = str_replace( '-', '_', $current_slug );
409
+
410
+ ?>
411
+ <div class="astra-sites-menu-page-wrapper">
412
+ <?php $this->init_nav_menu( $active_tab ); ?>
413
+ <?php do_action( 'astra_sites_menu_' . esc_attr( $current_slug ) . '_action' ); ?>
414
+ </div>
415
+ <?php
416
+ }
417
+
418
+ /**
419
+ * Include general page
420
+ *
421
+ * @since 1.0.6
422
+ */
423
+ public function general_page() {
424
+ $default_page_builder = $this->get_setting( 'page_builder' );
425
+ if ( empty( $default_page_builder ) || isset( $_GET['change-page-builder'] ) ) {
426
+ return;
427
+ }
428
+ require_once ASTRA_SITES_DIR . 'inc/includes/admin-page.php';
429
+ }
430
+ }
431
+
432
+ Astra_Sites_Page::get_instance();
433
+
434
+ }// End if.
inc/classes/class-astra-sites-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
@@ -1,601 +1,600 @@
1
- <?php
2
- /**
3
- * Astra Sites
4
- *
5
- * @since 1.0.0
6
- * @package Astra Sites
7
- */
8
-
9
- defined( 'ABSPATH' ) or exit;
10
-
11
- if ( ! class_exists( 'Astra_Sites' ) ) :
12
-
13
- /**
14
- * Astra_Sites
15
- */
16
- class Astra_Sites {
17
-
18
- /**
19
- * API URL which is used to get the response from.
20
- *
21
- * @since 1.0.0
22
- * @var (String) URL
23
- */
24
- public static $api_url;
25
-
26
- /**
27
- * Instance of Astra_Sites
28
- *
29
- * @since 1.0.0
30
- * @var (Object) Astra_Sites
31
- */
32
- private static $_instance = null;
33
-
34
- /**
35
- * Instance of Astra_Sites.
36
- *
37
- * @since 1.0.0
38
- *
39
- * @return object Class object.
40
- */
41
- public static function get_instance() {
42
- if ( ! isset( self::$_instance ) ) {
43
- self::$_instance = new self;
44
- }
45
-
46
- return self::$_instance;
47
- }
48
-
49
- /**
50
- * Constructor.
51
- *
52
- * @since 1.0.0
53
- */
54
- private function __construct() {
55
-
56
- self::set_api_url();
57
-
58
- $this->includes();
59
-
60
- add_action( 'admin_notices', array( $this, 'add_notice' ), 1 );
61
- add_action( 'admin_notices', array( $this, 'admin_notices' ) );
62
- add_action( 'plugins_loaded', array( $this, 'load_textdomain' ) );
63
- add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue' ) );
64
-
65
- // AJAX.
66
- add_action( 'wp_ajax_astra-required-plugins', array( $this, 'required_plugin' ) );
67
- add_action( 'wp_ajax_astra-required-plugin-activate', array( $this, 'required_plugin_activate' ) );
68
- add_action( 'wp_ajax_astra-sites-backup-settings', array( $this, 'backup_settings' ) );
69
- add_action( 'wp_ajax_astra-sites-set-reset-data', array( $this, 'set_reset_data' ) );
70
- add_action( 'wp_ajax_astra-sites-activate-theme', array( $this, 'activate_theme' ) );
71
- add_action( 'wp_ajax_astra-sites-getting-started-notice', array( $this, 'getting_started_notice' ) );
72
- }
73
-
74
- /**
75
- * Close getting started notice for current user
76
- *
77
- * @since 1.3.5
78
- * @return void
79
- */
80
- function getting_started_notice() {
81
- update_user_meta( get_current_user_id(), '_astra_sites_gettings_started', true );
82
- wp_send_json_success();
83
- }
84
-
85
- /**
86
- * Activate theme
87
- *
88
- * @since 1.3.2
89
- * @return void
90
- */
91
- function activate_theme() {
92
-
93
- switch_theme( 'astra' );
94
-
95
- wp_send_json_success(
96
- array(
97
- 'success' => true,
98
- 'message' => __( 'Theme Activated', 'astra-sites' ),
99
- )
100
- );
101
- }
102
-
103
- /**
104
- * Set reset data
105
- */
106
- function set_reset_data() {
107
- if ( ! current_user_can( 'manage_options' ) ) {
108
- return;
109
- }
110
-
111
- global $wpdb;
112
-
113
- $post_ids = $wpdb->get_col( "SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key='_astra_sites_imported_post'" );
114
- $form_ids = $wpdb->get_col( "SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key='_astra_sites_imported_wp_forms'" );
115
- $term_ids = $wpdb->get_col( "SELECT term_id FROM {$wpdb->termmeta} WHERE meta_key='_astra_sites_imported_term'" );
116
-
117
- wp_send_json_success(
118
- array(
119
- 'reset_posts' => $post_ids,
120
- 'reset_wp_forms' => $form_ids,
121
- 'reset_terms' => $term_ids,
122
- )
123
- );
124
- }
125
-
126
- /**
127
- * Backup our existing settings.
128
- */
129
- function backup_settings() {
130
- if ( ! current_user_can( 'manage_options' ) ) {
131
- return;
132
- }
133
-
134
- $file_name = 'astra-sites-backup-' . date( 'd-M-Y-h-i-s' ) . '.json';
135
- $old_settings = get_option( 'astra-settings', array() );
136
- $upload_dir = Astra_Sites_Importer_Log::get_instance()->log_dir();
137
- $upload_path = trailingslashit( $upload_dir['path'] );
138
- $log_file = $upload_path . $file_name;
139
- $file_system = Astra_Sites_Importer_Log::get_instance()->get_filesystem();
140
-
141
- // If file system fails? Then take a backup in site option.
142
- if ( false == $file_system->put_contents( $log_file, json_encode( $old_settings ), FS_CHMOD_FILE ) ) {
143
- update_option( 'astra_sites_' . $file_name, $old_settings );
144
- }
145
-
146
- wp_send_json_success();
147
- }
148
-
149
- /**
150
- * Add Admin Notice.
151
- */
152
- function add_notice() {
153
-
154
- $theme_status = 'astra-sites-theme-' . $this->get_theme_status();
155
-
156
- Astra_Notices::add_notice(
157
- array(
158
- 'id' => 'astra-theme-activation-nag',
159
- 'type' => 'error',
160
- 'show_if' => ( ! defined( 'ASTRA_THEME_SETTINGS' ) ) ? true : false,
161
- /* translators: 1: theme.php file*/
162
- 'message' => sprintf( __( '<p>Astra Theme needs to be active for you to use currently installed "%1$s" plugin. <a href="#" class="%3$s" data-theme-slug="astra">Install & Activate Now</a></p>', 'astra-sites' ), ASTRA_SITES_NAME, esc_url( admin_url( 'themes.php?theme=astra' ) ), $theme_status ),
163
- 'dismissible' => true,
164
- 'dismissible-time' => WEEK_IN_SECONDS,
165
- )
166
- );
167
- }
168
-
169
- /**
170
- * Get theme install, active or inactive status.
171
- *
172
- * @since 1.3.2
173
- *
174
- * @return string Theme status
175
- */
176
- function get_theme_status() {
177
-
178
- $theme = wp_get_theme();
179
-
180
- // Theme installed and activate.
181
- if ( 'Astra' == $theme->name || 'Astra' == $theme->parent_theme ) {
182
- return 'installed-and-active';
183
- }
184
-
185
- // Theme installed but not activate.
186
- foreach ( (array) wp_get_themes() as $theme_dir => $theme ) {
187
- if ( 'Astra' == $theme->name || 'Astra' == $theme->parent_theme ) {
188
- return 'installed-but-inactive';
189
- }
190
- }
191
-
192
- return 'not-installed';
193
- }
194
-
195
- /**
196
- * Loads textdomain for the plugin.
197
- *
198
- * @since 1.0.1
199
- */
200
- function load_textdomain() {
201
- load_plugin_textdomain( 'astra-sites' );
202
- }
203
-
204
- /**
205
- * Admin Notices
206
- *
207
- * @since 1.0.5
208
- * @return void
209
- */
210
- function admin_notices() {
211
-
212
- if ( ! defined( 'ASTRA_THEME_SETTINGS' ) ) {
213
- return;
214
- }
215
-
216
- add_action( 'plugin_action_links_' . ASTRA_SITES_BASE, array( $this, 'action_links' ) );
217
- }
218
-
219
- /**
220
- * Show action links on the plugin screen.
221
- *
222
- * @param mixed $links Plugin Action links.
223
- * @return array
224
- */
225
- function action_links( $links ) {
226
- $action_links = array(
227
- 'settings' => '<a href="' . admin_url( 'themes.php?page=astra-sites' ) . '" aria-label="' . esc_attr__( 'See Library', 'astra-sites' ) . '">' . esc_html__( 'See Library', 'astra-sites' ) . '</a>',
228
- );
229
-
230
- return array_merge( $action_links, $links );
231
- }
232
-
233
- /**
234
- * Setter for $api_url
235
- *
236
- * @since 1.0.0
237
- */
238
- public static function set_api_url() {
239
-
240
- self::$api_url = apply_filters( 'astra_sites_api_url', 'https://websitedemos.net/wp-json/wp/v2/' );
241
-
242
- }
243
-
244
- /**
245
- * Enqueue admin scripts.
246
- *
247
- * @since 1.3.2 Added 'install-theme.js' to install and activate theme.
248
- * @since 1.0.5 Added 'getUpgradeText' and 'getUpgradeURL' localize variables.
249
- *
250
- * @since 1.0.0
251
- *
252
- * @param string $hook Current hook name.
253
- * @return void
254
- */
255
- public function admin_enqueue( $hook = '' ) {
256
-
257
- wp_enqueue_script( 'astra-sites-install-theme', ASTRA_SITES_URI . 'inc/assets/js/install-theme.js', array( 'jquery', 'updates' ), ASTRA_SITES_VER, true );
258
- wp_enqueue_style( 'astra-sites-install-theme', ASTRA_SITES_URI . 'inc/assets/css/install-theme.css', null, ASTRA_SITES_VER, 'all' );
259
-
260
- $data = apply_filters(
261
- 'astra_sites_install_theme_localize_vars',
262
- array(
263
- 'installed' => __( 'Installed! Activating..', 'astra-sites' ),
264
- 'activating' => __( 'Activating..', 'astra-sites' ),
265
- 'activated' => __( 'Activated! Reloading..', 'astra-sites' ),
266
- 'installing' => __( 'Installing..', 'astra-sites' ),
267
- 'ajaxurl' => esc_url( admin_url( 'admin-ajax.php' ) ),
268
- )
269
- );
270
- wp_localize_script( 'astra-sites-install-theme', 'AstraSitesInstallThemeVars', $data );
271
-
272
- if ( 'appearance_page_astra-sites' !== $hook ) {
273
- return;
274
- }
275
-
276
- global $is_IE, $is_edge;
277
-
278
- if ( $is_IE || $is_edge ) {
279
- wp_enqueue_script( 'astra-sites-eventsource', ASTRA_SITES_URI . 'inc/assets/js/eventsource.min.js', array( 'jquery', 'wp-util', 'updates' ), ASTRA_SITES_VER, true );
280
- }
281
-
282
- // Fetch.
283
- wp_register_script( 'astra-sites-fetch', ASTRA_SITES_URI . 'inc/assets/js/fetch.umd.js', array( 'jquery' ), ASTRA_SITES_VER, true );
284
-
285
- // API.
286
- wp_register_script( 'astra-sites-api', ASTRA_SITES_URI . 'inc/assets/js/astra-sites-api.js', array( 'jquery', 'astra-sites-fetch' ), ASTRA_SITES_VER, true );
287
-
288
- // Admin Page.
289
- wp_enqueue_style( 'astra-sites-admin', ASTRA_SITES_URI . 'inc/assets/css/admin.css', ASTRA_SITES_VER, true );
290
- wp_enqueue_script( 'astra-sites-admin-page', ASTRA_SITES_URI . 'inc/assets/js/admin-page.js', array( 'jquery', 'wp-util', 'updates' ), ASTRA_SITES_VER, true );
291
- wp_enqueue_script( 'astra-sites-render-grid', ASTRA_SITES_URI . 'inc/assets/js/render-grid.js', array( 'wp-util', 'astra-sites-api', 'imagesloaded', 'jquery' ), ASTRA_SITES_VER, true );
292
-
293
- $data = apply_filters(
294
- 'astra_sites_localize_vars',
295
- array(
296
- 'ApiURL' => self::$api_url,
297
- 'filters' => array(
298
- 'page_builder' => array(
299
- 'title' => __( 'Page Builder', 'astra-sites' ),
300
- 'slug' => 'astra-site-page-builder',
301
- 'trigger' => 'astra-api-category-loaded',
302
- ),
303
- 'categories' => array(
304
- 'title' => __( 'Categories', 'astra-sites' ),
305
- 'slug' => 'astra-site-category',
306
- 'trigger' => 'astra-api-category-loaded',
307
- ),
308
- ),
309
- )
310
- );
311
- wp_localize_script( 'astra-sites-api', 'astraSitesApi', $data );
312
-
313
- // Use this for premium demos.
314
- $request_params = apply_filters(
315
- 'astra_sites_api_params',
316
- array(
317
- 'purchase_key' => '',
318
- 'site_url' => '',
319
- 'par-page' => 30,
320
- )
321
- );
322
-
323
- $data = apply_filters(
324
- 'astra_sites_render_localize_vars',
325
- array(
326
- 'sites' => $request_params,
327
- 'page-builders' => array(),
328
- 'categories' => array(),
329
- 'settings' => array(),
330
- 'default_page_builder' => Astra_Sites_Page::get_instance()->get_setting( 'page_builder' ),
331
- )
332
- );
333
-
334
- wp_localize_script( 'astra-sites-render-grid', 'astraRenderGrid', $data );
335
-
336
- $data = apply_filters(
337
- 'astra_sites_localize_vars',
338
- array(
339
- 'debug' => ( ( defined( 'WP_DEBUG' ) && WP_DEBUG ) || isset( $_GET['debug'] ) ) ? true : false,
340
- 'isPro' => defined( 'ASTRA_PRO_SITES_NAME' ) ? true : false,
341
- 'isWhiteLabeled' => Astra_Sites_White_Label::get_instance()->is_white_labeled(),
342
- 'ajaxurl' => esc_url( admin_url( 'admin-ajax.php' ) ),
343
- 'siteURL' => site_url(),
344
- 'docUrl' => 'https://wpastra.com/',
345
- 'getProText' => __( 'Get Agency Bundle', 'astra-sites' ),
346
- 'getProURL' => esc_url( 'https://wpastra.com/agency/?utm_source=demo-import-panel&utm_campaign=astra-sites&utm_medium=wp-dashboard' ),
347
- 'getUpgradeText' => __( 'Upgrade', 'astra-sites' ),
348
- 'getUpgradeURL' => esc_url( 'https://wpastra.com/agency/?utm_source=demo-import-panel&utm_campaign=astra-sites&utm_medium=wp-dashboard' ),
349
- '_ajax_nonce' => wp_create_nonce( 'astra-sites' ),
350
- 'requiredPlugins' => array(),
351
- 'XMLReaderDisabled' => ! class_exists( 'XMLReader' ) ? true : false,
352
- 'strings' => array(
353
- /* translators: %s are HTML tags. */
354
- 'warningXMLReader' => sprintf( __( '%1$sRequired XMLReader PHP extension is missing on your server!%2$sAstra Sites import requires XMLReader extension to be installed. Please contact your web hosting provider and ask them to install and activate the XMLReader PHP extension.', 'astra-sites' ), '<div class="notice astra-sites-xml-notice notice-error"><p><b>', '</b></p><p>', '</p></div>' ),
355
- 'warningBeforeCloseWindow' => __( 'Warning! Astra Site Import process is not complete. Don\'t close the window until import process complete. Do you still want to leave the window?', 'astra-sites' ),
356
- 'importFailedBtnSmall' => __( 'Error!', 'astra-sites' ),
357
- 'importFailedBtnLarge' => __( 'Error! Read Possibilities.', 'astra-sites' ),
358
- 'importFailedURL' => esc_url( 'https://wpastra.com/docs/?p=1314&utm_source=demo-import-panel&utm_campaign=astra-sites&utm_medium=import-failed' ),
359
- 'viewSite' => __( 'Done! View Site', 'astra-sites' ),
360
- 'btnActivating' => __( 'Activating', 'astra-sites' ) . '&hellip;',
361
- 'btnActive' => __( 'Active', 'astra-sites' ),
362
- 'importFailBtn' => __( 'Import failed.', 'astra-sites' ),
363
- 'importFailBtnLarge' => __( 'Import failed. See error log.', 'astra-sites' ),
364
- 'importDemo' => __( 'Import This Site', 'astra-sites' ),
365
- 'importingDemo' => __( 'Importing..', 'astra-sites' ),
366
- 'DescExpand' => __( 'Read more', 'astra-sites' ) . '&hellip;',
367
- 'DescCollapse' => __( 'Hide', 'astra-sites' ),
368
- 'responseError' => __( 'There was a problem receiving a response from server.', 'astra-sites' ),
369
- 'searchNoFound' => __( 'No Demos found, Try a different search.', 'astra-sites' ),
370
- ),
371
- 'log' => array(
372
- 'installingPlugin' => __( 'Installing plugin ', 'astra-sites' ),
373
- 'installed' => __( 'Plugin installed!', 'astra-sites' ),
374
- 'activating' => __( 'Activating plugin ', 'astra-sites' ),
375
- 'activated' => __( 'Plugin activated ', 'astra-sites' ),
376
- 'bulkActivation' => __( 'Bulk plugin activation...', 'astra-sites' ),
377
- 'activate' => __( 'Plugin activate - ', 'astra-sites' ),
378
- 'activationError' => __( 'Error! While activating plugin - ', 'astra-sites' ),
379
- 'bulkInstall' => __( 'Bulk plugin installation...', 'astra-sites' ),
380
- 'api' => __( 'Site API ', 'astra-sites' ),
381
- 'importing' => __( 'Importing..', 'astra-sites' ),
382
- 'processingRequest' => __( 'Processing requests...', 'astra-sites' ),
383
- 'importCustomizer' => __( 'Importing "Customizer Settings"...', 'astra-sites' ),
384
- 'importCustomizerSuccess' => __( 'Imported customizer settings!', 'astra-sites' ),
385
- 'importWPForms' => __( 'Importing "Contact Forms"...', 'astra-sites' ),
386
- 'importWPFormsSuccess' => __( 'Imported Contact Forms!', 'astra-sites' ),
387
- 'importXMLPrepare' => __( 'Preparing "XML" Data...', 'astra-sites' ),
388
- 'importXMLPrepareSuccess' => __( 'Set XML data!', 'astra-sites' ),
389
- 'importXML' => __( 'Importing "XML"...', 'astra-sites' ),
390
- 'importXMLSuccess' => __( 'Imported XML!', 'astra-sites' ),
391
- 'importOptions' => __( 'Importing "Options"...', 'astra-sites' ),
392
- 'importOptionsSuccess' => __( 'Imported Options!', 'astra-sites' ),
393
- 'importWidgets' => __( 'Importing "Widgets"...', 'astra-sites' ),
394
- 'importWidgetsSuccess' => __( 'Imported Widgets!', 'astra-sites' ),
395
- 'serverConfiguration' => esc_url( 'https://wpastra.com/docs/?p=1314&utm_source=demo-import-panel&utm_campaign=import-error&utm_medium=wp-dashboard' ),
396
- 'success' => __( 'View site: ', 'astra-sites' ),
397
- 'gettingData' => __( 'Getting Site Information..', 'astra-sites' ),
398
- 'importingCustomizer' => __( 'Importing Customizer Settings..', 'astra-sites' ),
399
- 'importingWPForms' => __( 'Importing Contact Forms..', 'astra-sites' ),
400
- 'importXMLPreparing' => __( 'Setting up import data..', 'astra-sites' ),
401
- 'importingXML' => __( 'Importing Content..', 'astra-sites' ),
402
- 'importingOptions' => __( 'Importing Site Options..', 'astra-sites' ),
403
- 'importingWidgets' => __( 'Importing Widgets..', 'astra-sites' ),
404
- 'importComplete' => __( 'Import Complete..', 'astra-sites' ),
405
- 'preview' => __( 'Previewing ', 'astra-sites' ),
406
- 'importLogText' => __( 'See Error Log &rarr;', 'astra-sites' ),
407
- ),
408
- )
409
- );
410
-
411
- wp_localize_script( 'astra-sites-admin-page', 'astraSitesAdmin', $data );
412
-
413
- }
414
-
415
- /**
416
- * Load all the required files in the importer.
417
- *
418
- * @since 1.0.0
419
- */
420
- private function includes() {
421
-
422
- require_once ASTRA_SITES_DIR . 'inc/lib/astra-notices/class-astra-notices.php';
423
- require_once ASTRA_SITES_DIR . 'inc/classes/class-astra-sites-white-label.php';
424
- require_once ASTRA_SITES_DIR . 'inc/classes/class-astra-sites-page.php';
425
- require_once ASTRA_SITES_DIR . 'inc/classes/compatibility/class-astra-sites-compatibility.php';
426
- require_once ASTRA_SITES_DIR . 'inc/classes/class-astra-sites-importer.php';
427
- }
428
-
429
- /**
430
- * Required Plugin Activate
431
- *
432
- * @since 1.0.0
433
- */
434
- public function required_plugin_activate() {
435
-
436
- if ( ! current_user_can( 'install_plugins' ) || ! isset( $_POST['init'] ) || ! $_POST['init'] ) {
437
- wp_send_json_error(
438
- array(
439
- 'success' => false,
440
- 'message' => __( 'No plugin specified', 'astra-sites' ),
441
- )
442
- );
443
- }
444
-
445
- $data = array();
446
- $plugin_init = ( isset( $_POST['init'] ) ) ? esc_attr( $_POST['init'] ) : '';
447
- $astra_site_options = ( isset( $_POST['options'] ) ) ? json_decode( stripslashes( $_POST['options'] ) ) : '';
448
- $enabled_extensions = ( isset( $_POST['enabledExtensions'] ) ) ? json_decode( stripslashes( $_POST['enabledExtensions'] ) ) : '';
449
-
450
- $data['astra_site_options'] = $astra_site_options;
451
- $data['enabled_extensions'] = $enabled_extensions;
452
-
453
- $activate = activate_plugin( $plugin_init, '', false, true );
454
-
455
- if ( is_wp_error( $activate ) ) {
456
- wp_send_json_error(
457
- array(
458
- 'success' => false,
459
- 'message' => $activate->get_error_message(),
460
- )
461
- );
462
- }
463
-
464
- do_action( 'astra_sites_after_plugin_activation', $plugin_init, $data );
465
-
466
- wp_send_json_success(
467
- array(
468
- 'success' => true,
469
- 'message' => __( 'Plugin Activated', 'astra-sites' ),
470
- )
471
- );
472
-
473
- }
474
-
475
- /**
476
- * Required Plugin
477
- *
478
- * @since 1.0.0
479
- * @return void
480
- */
481
- public function required_plugin() {
482
-
483
- // Verify Nonce.
484
- check_ajax_referer( 'astra-sites', '_ajax_nonce' );
485
-
486
- $response = array(
487
- 'active' => array(),
488
- 'inactive' => array(),
489
- 'notinstalled' => array(),
490
- );
491
-
492
- if ( ! current_user_can( 'customize' ) ) {
493
- wp_send_json_error( $response );
494
- }
495
-
496
- $required_plugins = ( isset( $_POST['required_plugins'] ) ) ? $_POST['required_plugins'] : array();
497
-
498
- if ( count( $required_plugins ) > 0 ) {
499
- foreach ( $required_plugins as $key => $plugin ) {
500
-
501
- /**
502
- * Has Pro Version Support?
503
- * And
504
- * Is Pro Version Installed?
505
- */
506
- $plugin_pro = self::pro_plugin_exist( $plugin['init'] );
507
- if ( $plugin_pro ) {
508
-
509
- // Pro - Active.
510
- if ( is_plugin_active( $plugin_pro['init'] ) ) {
511
- $response['active'][] = $plugin_pro;
512
-
513
- // Pro - Inactive.
514
- } else {
515
- $response['inactive'][] = $plugin_pro;
516
- }
517
- } else {
518
-
519
- // Lite - Installed but Inactive.
520
- if ( file_exists( WP_PLUGIN_DIR . '/' . $plugin['init'] ) && is_plugin_inactive( $plugin['init'] ) ) {
521
-
522
- $response['inactive'][] = $plugin;
523
-
524
- // Lite - Not Installed.
525
- } elseif ( ! file_exists( WP_PLUGIN_DIR . '/' . $plugin['init'] ) ) {
526
-
527
- $response['notinstalled'][] = $plugin;
528
-
529
- // Lite - Active.
530
- } else {
531
- $response['active'][] = $plugin;
532
- }
533
- }
534
- }
535
- }
536
-
537
- // Send response.
538
- wp_send_json_success( $response );
539
- }
540
-
541
- /**
542
- * Has Pro Version Support?
543
- * And
544
- * Is Pro Version Installed?
545
- *
546
- * Check Pro plugin version exist of requested plugin lite version.
547
- *
548
- * Eg. If plugin 'BB Lite Version' required to import demo. Then we check the 'BB Agency Version' is exist?
549
- * If yes then we only 'Activate' Agency Version. [We couldn't install agency version.]
550
- * Else we 'Activate' or 'Install' Lite Version.
551
- *
552
- * @since 1.0.1
553
- *
554
- * @param string $lite_version Lite version init file.
555
- * @return mixed Return false if not installed or not supported by us
556
- * else return 'Pro' version details.
557
- */
558
- public static function pro_plugin_exist( $lite_version = '' ) {
559
-
560
- // Lite init => Pro init.
561
- $plugins = apply_filters(
562
- 'astra_sites_pro_plugin_exist',
563
- array(
564
- 'beaver-builder-lite-version/fl-builder.php' => array(
565
- 'slug' => 'bb-plugin',
566
- 'init' => 'bb-plugin/fl-builder.php',
567
- 'name' => 'Beaver Builder Plugin',
568
- ),
569
- 'ultimate-addons-for-beaver-builder-lite/bb-ultimate-addon.php' => array(
570
- 'slug' => 'bb-ultimate-addon',
571
- 'init' => 'bb-ultimate-addon/bb-ultimate-addon.php',
572
- 'name' => 'Ultimate Addon for Beaver Builder',
573
- ),
574
- 'wpforms-lite/wpforms.php' => array(
575
- 'slug' => 'wpforms',
576
- 'init' => 'wpforms/wpforms.php',
577
- 'name' => 'WPForms',
578
- ),
579
- ),
580
- $lite_version
581
- );
582
-
583
- if ( isset( $plugins[ $lite_version ] ) ) {
584
-
585
- // Pro plugin directory exist?
586
- if ( file_exists( WP_PLUGIN_DIR . '/' . $plugins[ $lite_version ]['init'] ) ) {
587
- return $plugins[ $lite_version ];
588
- }
589
- }
590
-
591
- return false;
592
- }
593
-
594
- }
595
-
596
- /**
597
- * Kicking this off by calling 'get_instance()' method
598
- */
599
- Astra_Sites::get_instance();
600
-
601
- endif;
1
+ <?php
2
+ /**
3
+ * Astra Sites
4
+ *
5
+ * @since 1.0.0
6
+ * @package Astra Sites
7
+ */
8
+
9
+ defined( 'ABSPATH' ) or exit;
10
+
11
+ if ( ! class_exists( 'Astra_Sites' ) ) :
12
+
13
+ /**
14
+ * Astra_Sites
15
+ */
16
+ class Astra_Sites {
17
+
18
+ /**
19
+ * API URL which is used to get the response from.
20
+ *
21
+ * @since 1.0.0
22
+ * @var (String) URL
23
+ */
24
+ public static $api_url;
25
+
26
+ /**
27
+ * Instance of Astra_Sites
28
+ *
29
+ * @since 1.0.0
30
+ * @var (Object) Astra_Sites
31
+ */
32
+ private static $_instance = null;
33
+
34
+ /**
35
+ * Instance of Astra_Sites.
36
+ *
37
+ * @since 1.0.0
38
+ *
39
+ * @return object Class object.
40
+ */
41
+ public static function get_instance() {
42
+ if ( ! isset( self::$_instance ) ) {
43
+ self::$_instance = new self;
44
+ }
45
+
46
+ return self::$_instance;
47
+ }
48
+
49
+ /**
50
+ * Constructor.
51
+ *
52
+ * @since 1.0.0
53
+ */
54
+ private function __construct() {
55
+
56
+ self::set_api_url();
57
+
58
+ $this->includes();
59
+
60
+ add_action( 'admin_notices', array( $this, 'add_notice' ), 1 );
61
+ add_action( 'admin_notices', array( $this, 'admin_notices' ) );
62
+ add_action( 'plugins_loaded', array( $this, 'load_textdomain' ) );
63
+ add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue' ) );
64
+
65
+ // AJAX.
66
+ add_action( 'wp_ajax_astra-required-plugins', array( $this, 'required_plugin' ) );
67
+ add_action( 'wp_ajax_astra-required-plugin-activate', array( $this, 'required_plugin_activate' ) );
68
+ add_action( 'wp_ajax_astra-sites-backup-settings', array( $this, 'backup_settings' ) );
69
+ add_action( 'wp_ajax_astra-sites-set-reset-data', array( $this, 'set_reset_data' ) );
70
+ add_action( 'wp_ajax_astra-sites-activate-theme', array( $this, 'activate_theme' ) );
71
+ add_action( 'wp_ajax_astra-sites-getting-started-notice', array( $this, 'getting_started_notice' ) );
72
+ }
73
+
74
+ /**
75
+ * Close getting started notice for current user
76
+ *
77
+ * @since 1.3.5
78
+ * @return void
79
+ */
80
+ function getting_started_notice() {
81
+ update_user_meta( get_current_user_id(), '_astra_sites_gettings_started', true );
82
+ wp_send_json_success();
83
+ }
84
+
85
+ /**
86
+ * Activate theme
87
+ *
88
+ * @since 1.3.2
89
+ * @return void
90
+ */
91
+ function activate_theme() {
92
+
93
+ switch_theme( 'astra' );
94
+
95
+ wp_send_json_success(
96
+ array(
97
+ 'success' => true,
98
+ 'message' => __( 'Theme Activated', 'astra-sites' ),
99
+ )
100
+ );
101
+ }
102
+
103
+ /**
104
+ * Set reset data
105
+ */
106
+ function set_reset_data() {
107
+ if ( ! current_user_can( 'manage_options' ) ) {
108
+ return;
109
+ }
110
+
111
+ global $wpdb;
112
+
113
+ $post_ids = $wpdb->get_col( "SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key='_astra_sites_imported_post'" );
114
+ $form_ids = $wpdb->get_col( "SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key='_astra_sites_imported_wp_forms'" );
115
+ $term_ids = $wpdb->get_col( "SELECT term_id FROM {$wpdb->termmeta} WHERE meta_key='_astra_sites_imported_term'" );
116
+
117
+ wp_send_json_success(
118
+ array(
119
+ 'reset_posts' => $post_ids,
120
+ 'reset_wp_forms' => $form_ids,
121
+ 'reset_terms' => $term_ids,
122
+ )
123
+ );
124
+ }
125
+
126
+ /**
127
+ * Backup our existing settings.
128
+ */
129
+ function backup_settings() {
130
+ if ( ! current_user_can( 'manage_options' ) ) {
131
+ return;
132
+ }
133
+
134
+ $file_name = 'astra-sites-backup-' . date( 'd-M-Y-h-i-s' ) . '.json';
135
+ $old_settings = get_option( 'astra-settings', array() );
136
+ $upload_dir = Astra_Sites_Importer_Log::get_instance()->log_dir();
137
+ $upload_path = trailingslashit( $upload_dir['path'] );
138
+ $log_file = $upload_path . $file_name;
139
+ $file_system = Astra_Sites_Importer_Log::get_instance()->get_filesystem();
140
+
141
+ // If file system fails? Then take a backup in site option.
142
+ if ( false === $file_system->put_contents( $log_file, json_encode( $old_settings ), FS_CHMOD_FILE ) ) {
143
+ update_option( 'astra_sites_' . $file_name, $old_settings );
144
+ }
145
+
146
+ wp_send_json_success();
147
+ }
148
+
149
+ /**
150
+ * Add Admin Notice.
151
+ */
152
+ function add_notice() {
153
+
154
+ $theme_status = 'astra-sites-theme-' . $this->get_theme_status();
155
+
156
+ Astra_Notices::add_notice(
157
+ array(
158
+ 'id' => 'astra-theme-activation-nag',
159
+ 'type' => 'error',
160
+ 'show_if' => ( ! defined( 'ASTRA_THEME_SETTINGS' ) ) ? true : false,
161
+ /* translators: 1: theme.php file*/
162
+ 'message' => sprintf( __( '<p>Astra Theme needs to be active for you to use currently installed "%1$s" plugin. <a href="#" class="%3$s" data-theme-slug="astra">Install & Activate Now</a></p>', 'astra-sites' ), ASTRA_SITES_NAME, esc_url( admin_url( 'themes.php?theme=astra' ) ), $theme_status ),
163
+ 'dismissible' => true,
164
+ 'dismissible-time' => WEEK_IN_SECONDS,
165
+ )
166
+ );
167
+ }
168
+
169
+ /**
170
+ * Get theme install, active or inactive status.
171
+ *
172
+ * @since 1.3.2
173
+ *
174
+ * @return string Theme status
175
+ */
176
+ function get_theme_status() {
177
+
178
+ $theme = wp_get_theme();
179
+
180
+ // Theme installed and activate.
181
+ if ( 'Astra' === $theme->name || 'Astra' === $theme->parent_theme ) {
182
+ return 'installed-and-active';
183
+ }
184
+
185
+ // Theme installed but not activate.
186
+ foreach ( (array) wp_get_themes() as $theme_dir => $theme ) {
187
+ if ( 'Astra' === $theme->name || 'Astra' === $theme->parent_theme ) {
188
+ return 'installed-but-inactive';
189
+ }
190
+ }
191
+
192
+ return 'not-installed';
193
+ }
194
+
195
+ /**
196
+ * Loads textdomain for the plugin.
197
+ *
198
+ * @since 1.0.1
199
+ */
200
+ function load_textdomain() {
201
+ load_plugin_textdomain( 'astra-sites' );
202
+ }
203
+
204
+ /**
205
+ * Admin Notices
206
+ *
207
+ * @since 1.0.5
208
+ * @return void
209
+ */
210
+ function admin_notices() {
211
+
212
+ if ( ! defined( 'ASTRA_THEME_SETTINGS' ) ) {
213
+ return;
214
+ }
215
+
216
+ add_action( 'plugin_action_links_' . ASTRA_SITES_BASE, array( $this, 'action_links' ) );
217
+ }
218
+
219
+ /**
220
+ * Show action links on the plugin screen.
221
+ *
222
+ * @param mixed $links Plugin Action links.
223
+ * @return array
224
+ */
225
+ function action_links( $links ) {
226
+ $action_links = array(
227
+ 'settings' => '<a href="' . admin_url( 'themes.php?page=astra-sites' ) . '" aria-label="' . esc_attr__( 'See Library', 'astra-sites' ) . '">' . esc_html__( 'See Library', 'astra-sites' ) . '</a>',
228
+ );
229
+
230
+ return array_merge( $action_links, $links );
231
+ }
232
+
233
+ /**
234
+ * Setter for $api_url
235
+ *
236
+ * @since 1.0.0
237
+ */
238
+ public static function set_api_url() {
239
+ self::$api_url = apply_filters( 'astra_sites_api_url', 'https://websitedemos.net/wp-json/wp/v2/' );
240
+
241
+ }
242
+
243
+ /**
244
+ * Enqueue admin scripts.
245
+ *
246
+ * @since 1.3.2 Added 'install-theme.js' to install and activate theme.
247
+ * @since 1.0.5 Added 'getUpgradeText' and 'getUpgradeURL' localize variables.
248
+ *
249
+ * @since 1.0.0
250
+ *
251
+ * @param string $hook Current hook name.
252
+ * @return void
253
+ */
254
+ public function admin_enqueue( $hook = '' ) {
255
+
256
+ wp_enqueue_script( 'astra-sites-install-theme', ASTRA_SITES_URI . 'inc/assets/js/install-theme.js', array( 'jquery', 'updates' ), ASTRA_SITES_VER, true );
257
+ wp_enqueue_style( 'astra-sites-install-theme', ASTRA_SITES_URI . 'inc/assets/css/install-theme.css', null, ASTRA_SITES_VER, 'all' );
258
+
259
+ $data = apply_filters(
260
+ 'astra_sites_install_theme_localize_vars',
261
+ array(
262
+ 'installed' => __( 'Installed! Activating..', 'astra-sites' ),
263
+ 'activating' => __( 'Activating..', 'astra-sites' ),
264
+ 'activated' => __( 'Activated! Reloading..', 'astra-sites' ),
265
+ 'installing' => __( 'Installing..', 'astra-sites' ),
266
+ 'ajaxurl' => esc_url( admin_url( 'admin-ajax.php' ) ),
267
+ )
268
+ );
269
+ wp_localize_script( 'astra-sites-install-theme', 'AstraSitesInstallThemeVars', $data );
270
+
271
+ if ( 'appearance_page_astra-sites' !== $hook ) {
272
+ return;
273
+ }
274
+
275
+ global $is_IE, $is_edge;
276
+
277
+ if ( $is_IE || $is_edge ) {
278
+ wp_enqueue_script( 'astra-sites-eventsource', ASTRA_SITES_URI . 'inc/assets/js/eventsource.min.js', array( 'jquery', 'wp-util', 'updates' ), ASTRA_SITES_VER, true );
279
+ }
280
+
281
+ // Fetch.
282
+ wp_register_script( 'astra-sites-fetch', ASTRA_SITES_URI . 'inc/assets/js/fetch.umd.js', array( 'jquery' ), ASTRA_SITES_VER, true );
283
+
284
+ // API.
285
+ wp_register_script( 'astra-sites-api', ASTRA_SITES_URI . 'inc/assets/js/astra-sites-api.js', array( 'jquery', 'astra-sites-fetch' ), ASTRA_SITES_VER, true );
286
+
287
+ // Admin Page.
288
+ wp_enqueue_style( 'astra-sites-admin', ASTRA_SITES_URI . 'inc/assets/css/admin.css', ASTRA_SITES_VER, true );
289
+ wp_enqueue_script( 'astra-sites-admin-page', ASTRA_SITES_URI . 'inc/assets/js/admin-page.js', array( 'jquery', 'wp-util', 'updates' ), ASTRA_SITES_VER, true );
290
+ wp_enqueue_script( 'astra-sites-render-grid', ASTRA_SITES_URI . 'inc/assets/js/render-grid.js', array( 'wp-util', 'astra-sites-api', 'imagesloaded', 'jquery' ), ASTRA_SITES_VER, true );
291
+
292
+ $data = apply_filters(
293
+ 'astra_sites_localize_vars',
294
+ array(
295
+ 'ApiURL' => self::$api_url,
296
+ 'filters' => array(
297
+ 'page_builder' => array(
298
+ 'title' => __( 'Page Builder', 'astra-sites' ),
299
+ 'slug' => 'astra-site-page-builder',
300
+ 'trigger' => 'astra-api-category-loaded',
301
+ ),
302
+ 'categories' => array(
303
+ 'title' => __( 'Categories', 'astra-sites' ),
304
+ 'slug' => 'astra-site-category',
305
+ 'trigger' => 'astra-api-category-loaded',
306
+ ),
307
+ ),
308
+ )
309
+ );
310
+ wp_localize_script( 'astra-sites-api', 'astraSitesApi', $data );
311
+
312
+ // Use this for premium demos.
313
+ $request_params = apply_filters(
314
+ 'astra_sites_api_params',
315
+ array(
316
+ 'purchase_key' => '',
317
+ 'site_url' => '',
318
+ 'par-page' => 30,
319
+ )
320
+ );
321
+
322
+ $data = apply_filters(
323
+ 'astra_sites_render_localize_vars',
324
+ array(
325
+ 'sites' => $request_params,
326
+ 'page-builders' => array(),
327
+ 'categories' => array(),
328
+ 'settings' => array(),
329
+ 'default_page_builder' => Astra_Sites_Page::get_instance()->get_setting( 'page_builder' ),
330
+ )
331
+ );
332
+
333
+ wp_localize_script( 'astra-sites-render-grid', 'astraRenderGrid', $data );
334
+
335
+ $data = apply_filters(
336
+ 'astra_sites_localize_vars',
337
+ array(
338
+ 'debug' => ( ( defined( 'WP_DEBUG' ) && WP_DEBUG ) || isset( $_GET['debug'] ) ) ? true : false,
339
+ 'isPro' => defined( 'ASTRA_PRO_SITES_NAME' ) ? true : false,
340
+ 'isWhiteLabeled' => Astra_Sites_White_Label::get_instance()->is_white_labeled(),
341
+ 'ajaxurl' => esc_url( admin_url( 'admin-ajax.php' ) ),
342
+ 'siteURL' => site_url(),
343
+ 'docUrl' => 'https://wpastra.com/',
344
+ 'getProText' => __( 'Get Agency Bundle', 'astra-sites' ),
345
+ 'getProURL' => esc_url( 'https://wpastra.com/agency/?utm_source=demo-import-panel&utm_campaign=astra-sites&utm_medium=wp-dashboard' ),
346
+ 'getUpgradeText' => __( 'Upgrade', 'astra-sites' ),
347
+ 'getUpgradeURL' => esc_url( 'https://wpastra.com/agency/?utm_source=demo-import-panel&utm_campaign=astra-sites&utm_medium=wp-dashboard' ),
348
+ '_ajax_nonce' => wp_create_nonce( 'astra-sites' ),
349
+ 'requiredPlugins' => array(),
350
+ 'XMLReaderDisabled' => ! class_exists( 'XMLReader' ) ? true : false,
351
+ 'strings' => array(
352
+ /* translators: %s are HTML tags. */
353
+ 'warningXMLReader' => sprintf( __( '%1$sRequired XMLReader PHP extension is missing on your server!%2$sAstra Sites import requires XMLReader extension to be installed. Please contact your web hosting provider and ask them to install and activate the XMLReader PHP extension.', 'astra-sites' ), '<div class="notice astra-sites-xml-notice notice-error"><p><b>', '</b></p><p>', '</p></div>' ),
354
+ 'warningBeforeCloseWindow' => __( 'Warning! Astra Site Import process is not complete. Don\'t close the window until import process complete. Do you still want to leave the window?', 'astra-sites' ),
355
+ 'importFailedBtnSmall' => __( 'Error!', 'astra-sites' ),
356
+ 'importFailedBtnLarge' => __( 'Error! Read Possibilities.', 'astra-sites' ),
357
+ 'importFailedURL' => esc_url( 'https://wpastra.com/docs/?p=1314&utm_source=demo-import-panel&utm_campaign=astra-sites&utm_medium=import-failed' ),
358
+ 'viewSite' => __( 'Done! View Site', 'astra-sites' ),
359
+ 'btnActivating' => __( 'Activating', 'astra-sites' ) . '&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;',
366
+ 'DescCollapse' => __( 'Hide', 'astra-sites' ),
367
+ 'responseError' => __( 'There was a problem receiving a response from server.', 'astra-sites' ),
368
+ 'searchNoFound' => __( 'No Demos found, Try a different search.', 'astra-sites' ),
369
+ ),
370
+ 'log' => array(
371
+ 'installingPlugin' => __( 'Installing plugin ', 'astra-sites' ),
372
+ 'installed' => __( 'Plugin installed!', 'astra-sites' ),
373
+ 'activating' => __( 'Activating plugin ', 'astra-sites' ),
374
+ 'activated' => __( 'Plugin activated ', 'astra-sites' ),
375
+ 'bulkActivation' => __( 'Bulk plugin activation...', 'astra-sites' ),
376
+ 'activate' => __( 'Plugin activate - ', 'astra-sites' ),
377
+ 'activationError' => __( 'Error! While activating plugin - ', 'astra-sites' ),
378
+ 'bulkInstall' => __( 'Bulk plugin installation...', 'astra-sites' ),
379
+ 'api' => __( 'Site API ', 'astra-sites' ),
380
+ 'importing' => __( 'Importing..', 'astra-sites' ),
381
+ 'processingRequest' => __( 'Processing requests...', 'astra-sites' ),
382
+ 'importCustomizer' => __( 'Importing "Customizer Settings"...', 'astra-sites' ),
383
+ 'importCustomizerSuccess' => __( 'Imported customizer settings!', 'astra-sites' ),
384
+ 'importWPForms' => __( 'Importing "Contact Forms"...', 'astra-sites' ),
385
+ 'importWPFormsSuccess' => __( 'Imported Contact Forms!', 'astra-sites' ),
386
+ 'importXMLPrepare' => __( 'Preparing "XML" Data...', 'astra-sites' ),
387
+ 'importXMLPrepareSuccess' => __( 'Set XML data!', 'astra-sites' ),
388
+ 'importXML' => __( 'Importing "XML"...', 'astra-sites' ),
389
+ 'importXMLSuccess' => __( 'Imported XML!', 'astra-sites' ),
390
+ 'importOptions' => __( 'Importing "Options"...', 'astra-sites' ),
391
+ 'importOptionsSuccess' => __( 'Imported Options!', 'astra-sites' ),
392
+ 'importWidgets' => __( 'Importing "Widgets"...', 'astra-sites' ),
393
+ 'importWidgetsSuccess' => __( 'Imported Widgets!', 'astra-sites' ),
394
+ 'serverConfiguration' => esc_url( 'https://wpastra.com/docs/?p=1314&utm_source=demo-import-panel&utm_campaign=import-error&utm_medium=wp-dashboard' ),
395
+ 'success' => __( 'View site: ', 'astra-sites' ),
396
+ 'gettingData' => __( 'Getting Site Information..', 'astra-sites' ),
397
+ 'importingCustomizer' => __( 'Importing Customizer Settings..', 'astra-sites' ),
398
+ 'importingWPForms' => __( 'Importing Contact Forms..', 'astra-sites' ),
399
+ 'importXMLPreparing' => __( 'Setting up import data..', 'astra-sites' ),
400
+ 'importingXML' => __( 'Importing Content..', 'astra-sites' ),
401
+ 'importingOptions' => __( 'Importing Site Options..', 'astra-sites' ),
402
+ 'importingWidgets' => __( 'Importing Widgets..', 'astra-sites' ),
403
+ 'importComplete' => __( 'Import Complete..', 'astra-sites' ),
404
+ 'preview' => __( 'Previewing ', 'astra-sites' ),
405
+ 'importLogText' => __( 'See Error Log &rarr;', 'astra-sites' ),
406
+ ),
407
+ )
408
+ );
409
+
410
+ wp_localize_script( 'astra-sites-admin-page', 'astraSitesAdmin', $data );
411
+
412
+ }
413
+
414
+ /**
415
+ * Load all the required files in the importer.
416
+ *
417
+ * @since 1.0.0
418
+ */
419
+ private function includes() {
420
+
421
+ require_once ASTRA_SITES_DIR . 'inc/lib/astra-notices/class-astra-notices.php';
422
+ require_once ASTRA_SITES_DIR . 'inc/classes/class-astra-sites-white-label.php';
423
+ require_once ASTRA_SITES_DIR . 'inc/classes/class-astra-sites-page.php';
424
+ require_once ASTRA_SITES_DIR . 'inc/classes/compatibility/class-astra-sites-compatibility.php';
425
+ require_once ASTRA_SITES_DIR . 'inc/classes/class-astra-sites-importer.php';
426
+ }
427
+
428
+ /**
429
+ * Required Plugin Activate
430
+ *
431
+ * @since 1.0.0
432
+ */
433
+ public function required_plugin_activate() {
434
+
435
+ if ( ! current_user_can( 'install_plugins' ) || ! isset( $_POST['init'] ) || ! $_POST['init'] ) {
436
+ wp_send_json_error(
437
+ array(
438
+ 'success' => false,
439
+ 'message' => __( 'No plugin specified', 'astra-sites' ),
440
+ )
441
+ );
442
+ }
443
+
444
+ $data = array();
445
+ $plugin_init = ( isset( $_POST['init'] ) ) ? esc_attr( $_POST['init'] ) : '';
446
+ $astra_site_options = ( isset( $_POST['options'] ) ) ? json_decode( stripslashes( $_POST['options'] ) ) : '';
447
+ $enabled_extensions = ( isset( $_POST['enabledExtensions'] ) ) ? json_decode( stripslashes( $_POST['enabledExtensions'] ) ) : '';
448
+
449
+ $data['astra_site_options'] = $astra_site_options;
450
+ $data['enabled_extensions'] = $enabled_extensions;
451
+
452
+ $activate = activate_plugin( $plugin_init, '', false, true );
453
+
454
+ if ( is_wp_error( $activate ) ) {
455
+ wp_send_json_error(
456
+ array(
457
+ 'success' => false,
458
+ 'message' => $activate->get_error_message(),
459
+ )
460
+ );
461
+ }
462
+
463
+ do_action( 'astra_sites_after_plugin_activation', $plugin_init, $data );
464
+
465
+ wp_send_json_success(
466
+ array(
467
+ 'success' => true,
468
+ 'message' => __( 'Plugin Activated', 'astra-sites' ),
469
+ )
470
+ );
471
+
472
+ }
473
+
474
+ /**
475
+ * Required Plugin
476
+ *
477
+ * @since 1.0.0
478
+ * @return void
479
+ */
480
+ public function required_plugin() {
481
+
482
+ // Verify Nonce.
483
+ check_ajax_referer( 'astra-sites', '_ajax_nonce' );
484
+
485
+ $response = array(
486
+ 'active' => array(),
487
+ 'inactive' => array(),
488
+ 'notinstalled' => array(),
489
+ );
490
+
491
+ if ( ! current_user_can( 'customize' ) ) {
492
+ wp_send_json_error( $response );
493
+ }
494
+
495
+ $required_plugins = ( isset( $_POST['required_plugins'] ) ) ? $_POST['required_plugins'] : array();
496
+
497
+ if ( count( $required_plugins ) > 0 ) {
498
+ foreach ( $required_plugins as $key => $plugin ) {
499
+
500
+ /**
501
+ * Has Pro Version Support?
502
+ * And
503
+ * Is Pro Version Installed?
504
+ */
505
+ $plugin_pro = self::pro_plugin_exist( $plugin['init'] );
506
+ if ( $plugin_pro ) {
507
+
508
+ // Pro - Active.
509
+ if ( is_plugin_active( $plugin_pro['init'] ) ) {
510
+ $response['active'][] = $plugin_pro;
511
+
512
+ // Pro - Inactive.
513
+ } else {
514
+ $response['inactive'][] = $plugin_pro;
515
+ }
516
+ } else {
517
+
518
+ // Lite - Installed but Inactive.
519
+ if ( file_exists( WP_PLUGIN_DIR . '/' . $plugin['init'] ) && is_plugin_inactive( $plugin['init'] ) ) {
520
+
521
+ $response['inactive'][] = $plugin;
522
+
523
+ // Lite - Not Installed.
524
+ } elseif ( ! file_exists( WP_PLUGIN_DIR . '/' . $plugin['init'] ) ) {
525
+
526
+ $response['notinstalled'][] = $plugin;
527
+
528
+ // Lite - Active.
529
+ } else {
530
+ $response['active'][] = $plugin;
531
+ }
532
+ }
533
+ }
534
+ }
535
+
536
+ // Send response.
537
+ wp_send_json_success( $response );
538
+ }
539
+
540
+ /**
541
+ * Has Pro Version Support?
542
+ * And
543
+ * Is Pro Version Installed?
544
+ *
545
+ * Check Pro plugin version exist of requested plugin lite version.
546
+ *
547
+ * Eg. If plugin 'BB Lite Version' required to import demo. Then we check the 'BB Agency Version' is exist?
548
+ * If yes then we only 'Activate' Agency Version. [We couldn't install agency version.]
549
+ * Else we 'Activate' or 'Install' Lite Version.
550
+ *
551
+ * @since 1.0.1
552
+ *
553
+ * @param string $lite_version Lite version init file.
554
+ * @return mixed Return false if not installed or not supported by us
555
+ * else return 'Pro' version details.
556
+ */
557
+ public static function pro_plugin_exist( $lite_version = '' ) {
558
+
559
+ // Lite init => Pro init.
560
+ $plugins = apply_filters(
561
+ 'astra_sites_pro_plugin_exist',
562
+ array(
563
+ 'beaver-builder-lite-version/fl-builder.php' => array(
564
+ 'slug' => 'bb-plugin',
565
+ 'init' => 'bb-plugin/fl-builder.php',
566
+ 'name' => 'Beaver Builder Plugin',
567
+ ),
568
+ 'ultimate-addons-for-beaver-builder-lite/bb-ultimate-addon.php' => array(
569
+ 'slug' => 'bb-ultimate-addon',
570
+ 'init' => 'bb-ultimate-addon/bb-ultimate-addon.php',
571
+ 'name' => 'Ultimate Addon for Beaver Builder',
572
+ ),
573
+ 'wpforms-lite/wpforms.php' => array(
574
+ 'slug' => 'wpforms',
575
+ 'init' => 'wpforms/wpforms.php',
576
+ 'name' => 'WPForms',
577
+ ),
578
+ ),
579
+ $lite_version
580
+ );
581
+
582
+ if ( isset( $plugins[ $lite_version ] ) ) {
583
+
584
+ // Pro plugin directory exist?
585
+ if ( file_exists( WP_PLUGIN_DIR . '/' . $plugins[ $lite_version ]['init'] ) ) {
586
+ return $plugins[ $lite_version ];
587
+ }
588
+ }
589
+
590
+ return false;
591
+ }
592
+
593
+ }
594
+
595
+ /**
596
+ * Kicking this off by calling 'get_instance()' method
597
+ */
598
+ Astra_Sites::get_instance();
599
+
600
+ endif;
 
inc/classes/compatibility/astra-pro/class-astra-sites-compatibility-astra-pro.php CHANGED
@@ -1,299 +1,300 @@
1
- <?php
2
- /**
3
- * Astra Sites Compatibility for 'Astra Pro'
4
- *
5
- * @see https://wordpress.org/plugins/astra-pro/
6
- *
7
- * @package Astra Sites
8
- * @since 1.0.0
9
- */
10
-
11
- if ( ! class_exists( 'Astra_Sites_Compatibility_Astra_Pro' ) ) :
12
-
13
- /**
14
- * Astra_Sites_Compatibility_Astra_Pro
15
- *
16
- * @since 1.0.0
17
- */
18
- class Astra_Sites_Compatibility_Astra_Pro {
19
-
20
- /**
21
- * Instance
22
- *
23
- * @access private
24
- * @var object Class object.
25
- * @since 1.0.0
26
- */
27
- private static $instance;
28
-
29
- /**
30
- * Initiator
31
- *
32
- * @since 1.0.0
33
- * @return object initialized object of class.
34
- */
35
- public static function get_instance() {
36
- if ( ! isset( self::$instance ) ) {
37
- self::$instance = new self;
38
- }
39
- return self::$instance;
40
- }
41
-
42
- /**
43
- * Constructor
44
- *
45
- * @since 1.0.0
46
- */
47
- public function __construct() {
48
- add_action( 'astra_sites_after_plugin_activation', array( $this, 'astra_pro' ), 10, 2 );
49
- add_action( 'astra_sites_import_start', array( $this, 'import_enabled_extension' ), 10, 2 );
50
- add_action( 'astra_sites_import_complete', array( $this, 'clear_cache' ) );
51
- }
52
-
53
- /**
54
- * Import
55
- *
56
- * @since 1.1.6
57
- * @return void
58
- */
59
- public function import() {
60
- Astra_Sites_Importer_Log::add( '---- Processing Mapping - for Astra Pro ----' );
61
- self::start_post_mapping();
62
- }
63
-
64
- /**
65
- * Update Site Origin Active Widgets
66
- *
67
- * @since 1.0.0
68
- *
69
- * @param string $plugin_init Plugin init file.
70
- * @param array $data Data.
71
- * @return void
72
- */
73
- function astra_pro( $plugin_init = '', $data = array() ) {
74
-
75
- if ( 'astra-addon/astra-addon.php' === $plugin_init ) {
76
-
77
- $data = json_decode( json_encode( $data ), true );
78
-
79
- if ( isset( $data['enabled_extensions'] ) ) {
80
- $extensions = $data['enabled_extensions'];
81
-
82
- if ( ! empty( $extensions ) ) {
83
- if ( is_callable( 'Astra_Admin_Helper::update_admin_settings_option' ) ) {
84
- Astra_Admin_Helper::update_admin_settings_option( '_astra_ext_enabled_extensions', $extensions );
85
- }
86
- }
87
- }
88
- }
89
- }
90
-
91
- /**
92
- * Import custom 404 section.
93
- *
94
- * @since 1.0.0
95
- * @param array $demo_data Site all data render from API call.
96
- * @param array $demo_api_uri Demo URL.
97
- */
98
- public function import_custom_404( $demo_data = array(), $demo_api_uri = '' ) {
99
-
100
- if ( isset( $demo_data['astra-custom-404'] ) ) {
101
- if ( is_callable( 'Astra_Admin_Helper::update_admin_settings_option' ) ) {
102
- $options_404 = $demo_data['astra-custom-404'];
103
- Astra_Admin_Helper::update_admin_settings_option( '_astra_ext_custom_404', $options_404 );
104
- }
105
- }
106
- }
107
-
108
- /**
109
- * Import settings enabled Astra extensions from the demo.
110
- *
111
- * @since 1.0.0
112
- * @param array $demo_data Site all data render from API call.
113
- * @param array $demo_api_uri Demo URL.
114
- */
115
- public function import_enabled_extension( $demo_data = array(), $demo_api_uri = '' ) {
116
-
117
- if ( isset( $demo_data['astra-enabled-extensions'] ) ) {
118
- if ( is_callable( 'Astra_Admin_Helper::update_admin_settings_option' ) ) {
119
- Astra_Admin_Helper::update_admin_settings_option( '_astra_ext_enabled_extensions', $demo_data['astra-enabled-extensions'] );
120
- }
121
- }
122
- }
123
-
124
- /**
125
- * Start post meta mapping of Astra Addon
126
- *
127
- * @since 1.1.6
128
- *
129
- * @return null If there is no import option data found.
130
- */
131
- public static function start_post_mapping() {
132
- $demo_data = get_option( 'astra_sites_import_data', array() );
133
- if ( ! isset( $demo_data['astra-post-data-mapping'] ) ) {
134
- return;
135
- }
136
-
137
- $post_type = 'astra-advanced-hook';
138
- $posts = ( isset( $demo_data['astra-post-data-mapping'][ $post_type ] ) ) ? $demo_data['astra-post-data-mapping'][ $post_type ] : array();
139
- if ( ! empty( $posts ) ) {
140
- foreach ( $posts as $key => $post ) {
141
- $page = get_page_by_title( $post['post_title'], OBJECT, $post_type );
142
- if ( is_object( $page ) ) {
143
- self::update_location_rules( $page->ID, 'ast-advanced-hook-location', $post['mapping']['ast-advanced-hook-location'] );
144
- }
145
- }
146
- }
147
-
148
- $post_type = 'astra_adv_header';
149
- $posts = ( isset( $demo_data['astra-post-data-mapping'][ $post_type ] ) ) ? $demo_data['astra-post-data-mapping'][ $post_type ] : array();
150
- if ( ! empty( $posts ) ) {
151
- foreach ( $posts as $key => $post ) {
152
- $page = get_page_by_title( $post['post_title'], OBJECT, $post_type );
153
- if ( is_object( $page ) ) {
154
-
155
- self::update_location_rules( $page->ID, 'ast-advanced-headers-location', $post['mapping']['ast-advanced-headers-location'] );
156
- self::update_location_rules( $page->ID, 'ast-advanced-headers-exclusion', $post['mapping']['ast-advanced-headers-exclusion'] );
157
- self::update_header_mapping( $page->ID, 'ast-advanced-headers-design', $post['mapping']['ast-advanced-headers-design'] );
158
- }
159
- }
160
- }
161
- }
162
-
163
- /**
164
- * Update Header Mapping Data
165
- *
166
- * @since 1.1.6
167
- *
168
- * @param int $post_id Post ID.
169
- * @param string $meta_key Post meta key.
170
- * @param array $mapping Mapping array.
171
- * @return void
172
- */
173
- public static function update_header_mapping( $post_id = '', $meta_key = '', $mapping = array() ) {
174
- Astra_Sites_Importer_Log::add( 'Mapping "' . $meta_key . '" for ' . $post_id );
175
- $headers_old = get_post_meta( $post_id, $meta_key, true );
176
- $headers_new = self::get_header_mapping( $headers_old, $mapping );
177
- update_post_meta( $post_id, $meta_key, $headers_new );
178
- }
179
-
180
- /**
181
- * Update Location Rules
182
- *
183
- * @since 1.1.6
184
- *
185
- * @param int $post_id Post ID.
186
- * @param string $meta_key Post meta key.
187
- * @param array $mapping Mapping array.
188
- * @return void
189
- */
190
- public static function update_location_rules( $post_id = '', $meta_key = '', $mapping = array() ) {
191
- Astra_Sites_Importer_Log::add( 'Mapping "' . $meta_key . '" for ' . $post_id );
192
- $location_new = self::get_location_mappings( $mapping );
193
- update_post_meta( $post_id, $meta_key, $location_new );
194
- }
195
-
196
- /**
197
- * Get mapping locations.
198
- *
199
- * @since 1.1.6
200
- *
201
- * @param array $location Location data.
202
- * @return array Location mapping data.
203
- */
204
- public static function get_location_mappings( $location = array() ) {
205
- if ( empty( $location ) ) {
206
- return $location;
207
- }
208
-
209
- if ( ! isset( $location['specific'] ) || empty( $location['specific'] ) ) {
210
- return $location;
211
- }
212
-
213
- $mapping = array();
214
-
215
- if ( isset( $location['specific']['post'] ) ) {
216
- foreach ( $location['specific']['post'] as $post_type => $old_post_data ) {
217
- if ( is_array( $old_post_data ) ) {
218
- foreach ( $old_post_data as $post_key => $post ) {
219
- if ( $post_object = get_page_by_path( $post['slug'] ) ) {
220
- $mapping[] = 'post-' . absint( $post_object->ID );
221
- }
222
- }
223
- }
224
- }
225
- }
226
-
227
- if ( isset( $location['specific']['tax'] ) ) {
228
- foreach ( $location['specific']['tax'] as $taxonomy_type => $old_term_data ) {
229
- if ( is_array( $old_term_data ) ) {
230
- foreach ( $old_term_data as $term_key => $term_data ) {
231
- $term = get_term_by( 'slug', $term_data['slug'], $taxonomy_type );
232
- if ( is_object( $term ) ) {
233
- $mapping[] = 'tax-' . absint( $term->term_id );
234
- }
235
- }
236
- }
237
- }
238
- }
239
-
240
- $location['specific'] = $mapping;
241
-
242
- return $location;
243
- }
244
-
245
- /**
246
- * Get advanced header mapping data
247
- *
248
- * @since 1.1.6
249
- *
250
- * @param array $headers_old Header mapping stored data.
251
- * @param array $headers_data Header mapping data.
252
- * @return array Filtered header mapping data.
253
- */
254
- public static function get_header_mapping( $headers_old = array(), $headers_data = array() ) {
255
-
256
- // Set menu location by menu slug.
257
- if ( isset( $headers_data['menus'] ) && ! empty( $headers_data['menus'] ) ) {
258
- foreach ( $headers_data['menus'] as $header_option_name => $menu_data ) {
259
- $term = get_term_by( 'slug', $menu_data['slug'], 'nav_menu' );
260
- if ( is_object( $term ) ) {
261
- $headers_old[ $header_option_name ] = $term->term_id;
262
- }
263
- }
264
- }
265
-
266
- // Set image ID & URL after importing these on website.
267
- if ( isset( $headers_data['images'] ) && ! empty( $headers_data['images'] ) ) {
268
- foreach ( $headers_data['images'] as $key => $image_data ) {
269
- if ( isset( $image_data['image'] ) && ! empty( $image_data['image'] ) ) {
270
- $downloaded_image = Astra_Sites_Image_Importer::get_instance()->import( $image_data['image'] );
271
-
272
- $headers_old[ $image_data['key_map']['url'] ] = $downloaded_image['url'];
273
- $headers_old[ $image_data['key_map']['id'] ] = $downloaded_image['id'];
274
- }
275
- }
276
- }
277
-
278
- return $headers_old;
279
- }
280
-
281
- /**
282
- * Clear Cache
283
- *
284
- * @since 1.2.3
285
- * @return void
286
- */
287
- function clear_cache() {
288
- if ( is_callable( 'Astra_Minify::refresh_assets' ) ) {
289
- Astra_Minify::refresh_assets();
290
- }
291
- }
292
- }
293
-
294
- /**
295
- * Kicking this off by calling 'get_instance()' method
296
- */
297
- Astra_Sites_Compatibility_Astra_Pro::get_instance();
298
-
299
- endif;
 
1
+ <?php
2
+ /**
3
+ * Astra Sites Compatibility for 'Astra Pro'
4
+ *
5
+ * @see https://wordpress.org/plugins/astra-pro/
6
+ *
7
+ * @package Astra Sites
8
+ * @since 1.0.0
9
+ */
10
+
11
+ if ( ! class_exists( 'Astra_Sites_Compatibility_Astra_Pro' ) ) :
12
+
13
+ /**
14
+ * Astra_Sites_Compatibility_Astra_Pro
15
+ *
16
+ * @since 1.0.0
17
+ */
18
+ class Astra_Sites_Compatibility_Astra_Pro {
19
+
20
+ /**
21
+ * Instance
22
+ *
23
+ * @access private
24
+ * @var object Class object.
25
+ * @since 1.0.0
26
+ */
27
+ private static $instance;
28
+
29
+ /**
30
+ * Initiator
31
+ *
32
+ * @since 1.0.0
33
+ * @return object initialized object of class.
34
+ */
35
+ public static function get_instance() {
36
+ if ( ! isset( self::$instance ) ) {
37
+ self::$instance = new self;
38
+ }
39
+ return self::$instance;
40
+ }
41
+
42
+ /**
43
+ * Constructor
44
+ *
45
+ * @since 1.0.0
46
+ */
47
+ public function __construct() {
48
+ add_action( 'astra_sites_after_plugin_activation', array( $this, 'astra_pro' ), 10, 2 );
49
+ add_action( 'astra_sites_import_start', array( $this, 'import_enabled_extension' ), 10, 2 );
50
+ add_action( 'astra_sites_import_complete', array( $this, 'clear_cache' ) );
51
+ }
52
+
53
+ /**
54
+ * Import
55
+ *
56
+ * @since 1.1.6
57
+ * @return void
58
+ */
59
+ public function import() {
60
+ Astra_Sites_Importer_Log::add( '---- Processing Mapping - for Astra Pro ----' );
61
+ self::start_post_mapping();
62
+ }
63
+
64
+ /**
65
+ * Update Site Origin Active Widgets
66
+ *
67
+ * @since 1.0.0
68
+ *
69
+ * @param string $plugin_init Plugin init file.
70
+ * @param array $data Data.
71
+ * @return void
72
+ */
73
+ function astra_pro( $plugin_init = '', $data = array() ) {
74
+
75
+ if ( 'astra-addon/astra-addon.php' === $plugin_init ) {
76
+
77
+ $data = json_decode( json_encode( $data ), true );
78
+
79
+ if ( isset( $data['enabled_extensions'] ) ) {
80
+ $extensions = $data['enabled_extensions'];
81
+
82
+ if ( ! empty( $extensions ) ) {
83
+ if ( is_callable( 'Astra_Admin_Helper::update_admin_settings_option' ) ) {
84
+ Astra_Admin_Helper::update_admin_settings_option( '_astra_ext_enabled_extensions', $extensions );
85
+ }
86
+ }
87
+ }
88
+ }
89
+ }
90
+
91
+ /**
92
+ * Import custom 404 section.
93
+ *
94
+ * @since 1.0.0
95
+ * @param array $demo_data Site all data render from API call.
96
+ * @param array $demo_api_uri Demo URL.
97
+ */
98
+ public function import_custom_404( $demo_data = array(), $demo_api_uri = '' ) {
99
+
100
+ if ( isset( $demo_data['astra-custom-404'] ) ) {
101
+ if ( is_callable( 'Astra_Admin_Helper::update_admin_settings_option' ) ) {
102
+ $options_404 = $demo_data['astra-custom-404'];
103
+ Astra_Admin_Helper::update_admin_settings_option( '_astra_ext_custom_404', $options_404 );
104
+ }
105
+ }
106
+ }
107
+
108
+ /**
109
+ * Import settings enabled Astra extensions from the demo.
110
+ *
111
+ * @since 1.0.0
112
+ * @param array $demo_data Site all data render from API call.
113
+ * @param array $demo_api_uri Demo URL.
114
+ */
115
+ public function import_enabled_extension( $demo_data = array(), $demo_api_uri = '' ) {
116
+
117
+ if ( isset( $demo_data['astra-enabled-extensions'] ) ) {
118
+ if ( is_callable( 'Astra_Admin_Helper::update_admin_settings_option' ) ) {
119
+ Astra_Admin_Helper::update_admin_settings_option( '_astra_ext_enabled_extensions', $demo_data['astra-enabled-extensions'] );
120
+ }
121
+ }
122
+ }
123
+
124
+ /**
125
+ * Start post meta mapping of Astra Addon
126
+ *
127
+ * @since 1.1.6
128
+ *
129
+ * @return null If there is no import option data found.
130
+ */
131
+ public static function start_post_mapping() {
132
+ $demo_data = get_option( 'astra_sites_import_data', array() );
133
+ if ( ! isset( $demo_data['astra-post-data-mapping'] ) ) {
134
+ return;
135
+ }
136
+
137
+ $post_type = 'astra-advanced-hook';
138
+ $posts = ( isset( $demo_data['astra-post-data-mapping'][ $post_type ] ) ) ? $demo_data['astra-post-data-mapping'][ $post_type ] : array();
139
+ if ( ! empty( $posts ) ) {
140
+ foreach ( $posts as $key => $post ) {
141
+ $page = get_page_by_title( $post['post_title'], OBJECT, $post_type );
142
+ if ( is_object( $page ) ) {
143
+ self::update_location_rules( $page->ID, 'ast-advanced-hook-location', $post['mapping']['ast-advanced-hook-location'] );
144
+ }
145
+ }
146
+ }
147
+
148
+ $post_type = 'astra_adv_header';
149
+ $posts = ( isset( $demo_data['astra-post-data-mapping'][ $post_type ] ) ) ? $demo_data['astra-post-data-mapping'][ $post_type ] : array();
150
+ if ( ! empty( $posts ) ) {
151
+ foreach ( $posts as $key => $post ) {
152
+ $page = get_page_by_title( $post['post_title'], OBJECT, $post_type );
153
+ if ( is_object( $page ) ) {
154
+
155
+ self::update_location_rules( $page->ID, 'ast-advanced-headers-location', $post['mapping']['ast-advanced-headers-location'] );
156
+ self::update_location_rules( $page->ID, 'ast-advanced-headers-exclusion', $post['mapping']['ast-advanced-headers-exclusion'] );
157
+ self::update_header_mapping( $page->ID, 'ast-advanced-headers-design', $post['mapping']['ast-advanced-headers-design'] );
158
+ }
159
+ }
160
+ }
161
+ }
162
+
163
+ /**
164
+ * Update Header Mapping Data
165
+ *
166
+ * @since 1.1.6
167
+ *
168
+ * @param int $post_id Post ID.
169
+ * @param string $meta_key Post meta key.
170
+ * @param array $mapping Mapping array.
171
+ * @return void
172
+ */
173
+ public static function update_header_mapping( $post_id = '', $meta_key = '', $mapping = array() ) {
174
+ Astra_Sites_Importer_Log::add( 'Mapping "' . $meta_key . '" for ' . $post_id );
175
+ $headers_old = get_post_meta( $post_id, $meta_key, true );
176
+ $headers_new = self::get_header_mapping( $headers_old, $mapping );
177
+ update_post_meta( $post_id, $meta_key, $headers_new );
178
+ }
179
+
180
+ /**
181
+ * Update Location Rules
182
+ *
183
+ * @since 1.1.6
184
+ *
185
+ * @param int $post_id Post ID.
186
+ * @param string $meta_key Post meta key.
187
+ * @param array $mapping Mapping array.
188
+ * @return void
189
+ */
190
+ public static function update_location_rules( $post_id = '', $meta_key = '', $mapping = array() ) {
191
+ Astra_Sites_Importer_Log::add( 'Mapping "' . $meta_key . '" for ' . $post_id );
192
+ $location_new = self::get_location_mappings( $mapping );
193
+ update_post_meta( $post_id, $meta_key, $location_new );
194
+ }
195
+
196
+ /**
197
+ * Get mapping locations.
198
+ *
199
+ * @since 1.1.6
200
+ *
201
+ * @param array $location Location data.
202
+ * @return array Location mapping data.
203
+ */
204
+ public static function get_location_mappings( $location = array() ) {
205
+ if ( empty( $location ) ) {
206
+ return $location;
207
+ }
208
+
209
+ if ( ! isset( $location['specific'] ) || empty( $location['specific'] ) ) {
210
+ return $location;
211
+ }
212
+
213
+ $mapping = array();
214
+
215
+ if ( isset( $location['specific']['post'] ) ) {
216
+ foreach ( $location['specific']['post'] as $post_type => $old_post_data ) {
217
+ if ( is_array( $old_post_data ) ) {
218
+ foreach ( $old_post_data as $post_key => $post ) {
219
+ $post_object = get_page_by_path( $post['slug'] );
220
+ if ( $post_object ) {
221
+ $mapping[] = 'post-' . absint( $post_object->ID );
222
+ }
223
+ }
224
+ }
225
+ }
226
+ }
227
+
228
+ if ( isset( $location['specific']['tax'] ) ) {
229
+ foreach ( $location['specific']['tax'] as $taxonomy_type => $old_term_data ) {
230
+ if ( is_array( $old_term_data ) ) {
231
+ foreach ( $old_term_data as $term_key => $term_data ) {
232
+ $term = get_term_by( 'slug', $term_data['slug'], $taxonomy_type );
233
+ if ( is_object( $term ) ) {
234
+ $mapping[] = 'tax-' . absint( $term->term_id );
235
+ }
236
+ }
237
+ }
238
+ }
239
+ }
240
+
241
+ $location['specific'] = $mapping;
242
+
243
+ return $location;
244
+ }
245
+
246
+ /**
247
+ * Get advanced header mapping data
248
+ *
249
+ * @since 1.1.6
250
+ *
251
+ * @param array $headers_old Header mapping stored data.
252
+ * @param array $headers_data Header mapping data.
253
+ * @return array Filtered header mapping data.
254
+ */
255
+ public static function get_header_mapping( $headers_old = array(), $headers_data = array() ) {
256
+
257
+ // Set menu location by menu slug.
258
+ if ( isset( $headers_data['menus'] ) && ! empty( $headers_data['menus'] ) ) {
259
+ foreach ( $headers_data['menus'] as $header_option_name => $menu_data ) {
260
+ $term = get_term_by( 'slug', $menu_data['slug'], 'nav_menu' );
261
+ if ( is_object( $term ) ) {
262
+ $headers_old[ $header_option_name ] = $term->term_id;
263
+ }
264
+ }
265
+ }
266
+
267
+ // Set image ID & URL after importing these on website.
268
+ if ( isset( $headers_data['images'] ) && ! empty( $headers_data['images'] ) ) {
269
+ foreach ( $headers_data['images'] as $key => $image_data ) {
270
+ if ( isset( $image_data['image'] ) && ! empty( $image_data['image'] ) ) {
271
+ $downloaded_image = Astra_Sites_Image_Importer::get_instance()->import( $image_data['image'] );
272
+
273
+ $headers_old[ $image_data['key_map']['url'] ] = $downloaded_image['url'];
274
+ $headers_old[ $image_data['key_map']['id'] ] = $downloaded_image['id'];
275
+ }
276
+ }
277
+ }
278
+
279
+ return $headers_old;
280
+ }
281
+
282
+ /**
283
+ * Clear Cache
284
+ *
285
+ * @since 1.2.3
286
+ * @return void
287
+ */
288
+ function clear_cache() {
289
+ if ( is_callable( 'Astra_Minify::refresh_assets' ) ) {
290
+ Astra_Minify::refresh_assets();
291
+ }
292
+ }
293
+ }
294
+
295
+ /**
296
+ * Kicking this off by calling 'get_instance()' method
297
+ */
298
+ Astra_Sites_Compatibility_Astra_Pro::get_instance();
299
+
300
+ endif;
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 = get_option( 'elementor_cpt_support', array( 'page', 'post' ) );
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 = get_option( 'elementor_cpt_support', array( 'page', 'post' ) );
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,146 +1,165 @@
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_ids = Astra_Sites_Batch_Processing::get_pages( array( 'page' ) );
91
- if ( empty( $post_ids ) && ! is_array( $post_ids ) ) {
92
- return;
93
- }
94
-
95
- foreach ( $post_ids as $post_id ) {
96
- $this->import_single_post( $post_id );
97
- }
98
- }
99
-
100
- /**
101
- * Update post meta.
102
- *
103
- * @param integer $post_id Post ID.
104
- * @return void
105
- */
106
- public function import_single_post( $post_id = 0 ) {
107
-
108
- $ids_mapping = get_option( 'astra_sites_wpforms_ids_mapping', array() );
109
-
110
- // Empty mapping? Then return.
111
- if ( empty( $ids_mapping ) ) {
112
- return;
113
- }
114
-
115
- // Post content.
116
- $content = get_post_field( 'post_content', $post_id );
117
-
118
- // Replace ID's.
119
- foreach ( $ids_mapping as $old_id => $new_id ) {
120
- $content = str_replace( '[wpforms id="' . $old_id, '[wpforms id="' . $new_id, $content );
121
- }
122
-
123
- // # Tweak
124
- // Gutenberg break block markup from render. Because the '&' is updated in database with '&amp;' and it
125
- // expects as 'u0026amp;'. So, Converted '&amp;' with 'u0026amp;'.
126
- //
127
- // @todo This affect for normal page content too. Detect only Gutenberg pages and process only on it.
128
- $content = str_replace( '&amp;', "\u0026amp;", $content );
129
-
130
- // Update content.
131
- wp_update_post(
132
- array(
133
- 'ID' => $post_id,
134
- 'post_content' => $content,
135
- )
136
- );
137
- }
138
-
139
- }
140
-
141
- /**
142
- * Kicking this off by calling 'get_instance()' method
143
- */
144
- Astra_Sites_Batch_Processing_Gutenberg::get_instance();
145
-
146
- 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_ids = Astra_Sites_Batch_Processing::get_pages( array( 'page' ) );
91
+ if ( empty( $post_ids ) && ! is_array( $post_ids ) ) {
92
+ return;
93
+ }
94
+
95
+ foreach ( $post_ids as $post_id ) {
96
+ $this->import_single_post( $post_id );
97
+ }
98
+ }
99
+
100
+ /**
101
+ * Update post meta.
102
+ *
103
+ * @param integer $post_id Post ID.
104
+ * @return void
105
+ */
106
+ public function import_single_post( $post_id = 0 ) {
107
+
108
+ $ids_mapping = get_option( 'astra_sites_wpforms_ids_mapping', array() );
109
+
110
+ // Post content.
111
+ $content = get_post_field( 'post_content', $post_id );
112
+
113
+ if ( ! empty( $ids_mapping ) ) {
114
+ // Replace ID's.
115
+ foreach ( $ids_mapping as $old_id => $new_id ) {
116
+ $content = str_replace( '[wpforms id="' . $old_id, '[wpforms id="' . $new_id, $content );
117
+ }
118
+ }
119
+
120
+ // This replaces the category ID in UAG Post blocks.
121
+ $site_options = get_option( 'astra_sites_import_data', array() );
122
+
123
+ if ( isset( $site_options['astra-site-taxonomy-mapping'] ) ) {
124
+
125
+ $tax_mapping = $site_options['astra-site-taxonomy-mapping'];
126
+
127
+ if ( isset( $tax_mapping['post'] ) ) {
128
+
129
+ $catogory_mapping = ( isset( $tax_mapping['post']['category'] ) ) ? $tax_mapping['post']['category'] : array();
130
+
131
+ if ( is_array( $catogory_mapping ) ) {
132
+
133
+ foreach ( $catogory_mapping as $key => $value ) {
134
+
135
+ $this_site_term = get_term_by( 'slug', $value['slug'], 'category' );
136
+ $content = str_replace( '"categories":"' . $value['id'], '"categories":"' . $this_site_term->term_id, $content );
137
+ }
138
+ }
139
+ }
140
+ }
141
+
142
+ // # Tweak
143
+ // Gutenberg break block markup from render. Because the '&' is updated in database with '&amp;' and it
144
+ // expects as 'u0026amp;'. So, Converted '&amp;' with 'u0026amp;'.
145
+ //
146
+ // @todo This affect for normal page content too. Detect only Gutenberg pages and process only on it.
147
+ $content = str_replace( '&amp;', "\u0026amp;", $content );
148
+
149
+ // Update content.
150
+ wp_update_post(
151
+ array(
152
+ 'ID' => $post_id,
153
+ 'post_content' => $content,
154
+ )
155
+ );
156
+ }
157
+
158
+ }
159
+
160
+ /**
161
+ * Kicking this off by calling 'get_instance()' method
162
+ */
163
+ Astra_Sites_Batch_Processing_Gutenberg::get_instance();
164
+
165
+ endif;
inc/importers/batch-processing/class-astra-sites-batch-processing-misc.php CHANGED
@@ -1,137 +1,137 @@
1
- <?php
2
- /**
3
- * Misc batch import tasks.
4
- *
5
- * @package Astra Sites
6
- * @since 1.1.6
7
- */
8
-
9
- if ( ! class_exists( 'Astra_Sites_Batch_Processing_Misc' ) ) :
10
-
11
- /**
12
- * Astra_Sites_Batch_Processing_Misc
13
- *
14
- * @since 1.1.6
15
- */
16
- class Astra_Sites_Batch_Processing_Misc {
17
-
18
- /**
19
- * Instance
20
- *
21
- * @since 1.1.6
22
- * @access private
23
- * @var object Class object.
24
- */
25
- private static $instance;
26
-
27
- /**
28
- * Initiator
29
- *
30
- * @since 1.1.6
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.1.6
45
- */
46
- public function __construct() {}
47
-
48
- /**
49
- * Import
50
- *
51
- * @since 1.1.6
52
- * @return void
53
- */
54
- public function import() {
55
-
56
- Astra_Sites_Importer_Log::add( '---- Processing MISC ----' );
57
- self::fix_nav_menus();
58
- }
59
-
60
- /**
61
- * Import Module Images.
62
- *
63
- * @return object
64
- */
65
- public static function fix_nav_menus() {
66
- // Not found site data, then return.
67
- $demo_data = get_option( 'astra_sites_import_data', array() );
68
- if ( ! isset( $demo_data['astra-post-data-mapping'] ) ) {
69
- return;
70
- }
71
-
72
- // Not found/empty XML URL, then return.
73
- $xml_url = ( isset( $demo_data['astra-site-wxr-path'] ) ) ? esc_url( $demo_data['astra-site-wxr-path'] ) : '';
74
- if ( empty( $xml_url ) ) {
75
- return;
76
- }
77
-
78
- // Not empty site URL, then return.
79
- $site_url = strpos( $xml_url, '/wp-content' );
80
- if ( false === $site_url ) {
81
- return;
82
- }
83
-
84
- // Get remote site URL.
85
- $site_url = substr( $xml_url, 0, $site_url );
86
-
87
- $post_ids = self::get_menu_post_ids();
88
- if ( is_array( $post_ids ) ) {
89
- foreach ( $post_ids as $post_id ) {
90
- Astra_Sites_Importer_Log::add( 'Post ID: ' . $post_id );
91
- $menu_url = get_post_meta( $post_id, '_menu_item_url', true );
92
-
93
- if ( $menu_url ) {
94
- $menu_url = str_replace( $site_url, site_url(), $menu_url );
95
- update_post_meta( $post_id, '_menu_item_url', $menu_url );
96
- }
97
- }
98
- }
99
- }
100
-
101
- /**
102
- * Get all post id's
103
- *
104
- * @since 1.1.6
105
- *
106
- * @return array
107
- */
108
- public static function get_menu_post_ids() {
109
-
110
- $args = array(
111
- 'post_type' => 'nav_menu_item',
112
-
113
- // Query performance optimization.
114
- 'fields' => 'ids',
115
- 'no_found_rows' => true,
116
- 'post_status' => 'any',
117
- );
118
-
119
- $query = new WP_Query( $args );
120
-
121
- // Have posts?
122
- if ( $query->have_posts() ) :
123
-
124
- return $query->posts;
125
-
126
- endif;
127
- return null;
128
- }
129
-
130
- }
131
-
132
- /**
133
- * Kicking this off by calling 'get_instance()' method
134
- */
135
- Astra_Sites_Batch_Processing_Misc::get_instance();
136
-
137
- endif;
1
+ <?php
2
+ /**
3
+ * Misc batch import tasks.
4
+ *
5
+ * @package Astra Sites
6
+ * @since 1.1.6
7
+ */
8
+
9
+ if ( ! class_exists( 'Astra_Sites_Batch_Processing_Misc' ) ) :
10
+
11
+ /**
12
+ * Astra_Sites_Batch_Processing_Misc
13
+ *
14
+ * @since 1.1.6
15
+ */
16
+ class Astra_Sites_Batch_Processing_Misc {
17
+
18
+ /**
19
+ * Instance
20
+ *
21
+ * @since 1.1.6
22
+ * @access private
23
+ * @var object Class object.
24
+ */
25
+ private static $instance;
26
+
27
+ /**
28
+ * Initiator
29
+ *
30
+ * @since 1.1.6
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.1.6
45
+ */
46
+ public function __construct() {}
47
+
48
+ /**
49
+ * Import
50
+ *
51
+ * @since 1.1.6
52
+ * @return void
53
+ */
54
+ public function import() {
55
+
56
+ Astra_Sites_Importer_Log::add( '---- Processing MISC ----' );
57
+ self::fix_nav_menus();
58
+ }
59
+
60
+ /**
61
+ * Import Module Images.
62
+ *
63
+ * @return object
64
+ */
65
+ public static function fix_nav_menus() {
66
+ // Not found site data, then return.
67
+ $demo_data = get_option( 'astra_sites_import_data', array() );
68
+ if ( ! isset( $demo_data['astra-post-data-mapping'] ) ) {
69
+ return;
70
+ }
71
+
72
+ // Not found/empty XML URL, then return.
73
+ $xml_url = ( isset( $demo_data['astra-site-wxr-path'] ) ) ? esc_url( $demo_data['astra-site-wxr-path'] ) : '';
74
+ if ( empty( $xml_url ) ) {
75
+ return;
76
+ }
77
+
78
+ // Not empty site URL, then return.
79
+ $site_url = strpos( $xml_url, '/wp-content' );
80
+ if ( false === $site_url ) {
81
+ return;
82
+ }
83
+
84
+ // Get remote site URL.
85
+ $site_url = substr( $xml_url, 0, $site_url );
86
+
87
+ $post_ids = self::get_menu_post_ids();
88
+ if ( is_array( $post_ids ) ) {
89
+ foreach ( $post_ids as $post_id ) {
90
+ Astra_Sites_Importer_Log::add( 'Post ID: ' . $post_id );
91
+ $menu_url = get_post_meta( $post_id, '_menu_item_url', true );
92
+
93
+ if ( $menu_url ) {
94
+ $menu_url = str_replace( $site_url, site_url(), $menu_url );
95
+ update_post_meta( $post_id, '_menu_item_url', $menu_url );
96
+ }
97
+ }
98
+ }
99
+ }
100
+
101
+ /**
102
+ * Get all post id's
103
+ *
104
+ * @since 1.1.6
105
+ *
106
+ * @return array
107
+ */
108
+ public static function get_menu_post_ids() {
109
+
110
+ $args = array(
111
+ 'post_type' => 'nav_menu_item',
112
+
113
+ // Query performance optimization.
114
+ 'fields' => 'ids',
115
+ 'no_found_rows' => true,
116
+ 'post_status' => 'any',
117
+ );
118
+
119
+ $query = new WP_Query( $args );
120
+
121
+ // Have posts?
122
+ if ( $query->have_posts() ) :
123
+
124
+ return $query->posts;
125
+
126
+ endif;
127
+ return null;
128
+ }
129
+
130
+ }
131
+
132
+ /**
133
+ * Kicking this off by calling 'get_instance()' method
134
+ */
135
+ Astra_Sites_Batch_Processing_Misc::get_instance();
136
+
137
+ endif;
inc/importers/batch-processing/class-astra-sites-batch-processing-widgets.php CHANGED
@@ -1,97 +1,97 @@
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_Widgets' ) ) :
10
-
11
- /**
12
- * Astra_Sites_Batch_Processing_Widgets
13
- *
14
- * @since 1.0.14
15
- */
16
- class Astra_Sites_Batch_Processing_Widgets {
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
- if ( ! isset( self::$instance ) ) {
35
- self::$instance = new self;
36
- }
37
- return self::$instance;
38
- }
39
-
40
- /**
41
- * Constructor
42
- *
43
- * @since 1.0.14
44
- */
45
- public function __construct() {
46
- }
47
-
48
- /**
49
- * Import
50
- *
51
- * @since 1.0.14
52
- * @return void
53
- */
54
- public function import() {
55
- $this->widget_media_image();
56
- }
57
-
58
- /**
59
- * Widget Media Image
60
- *
61
- * @since 1.0.14
62
- * @return void
63
- */
64
- public function widget_media_image() {
65
-
66
- $data = get_option( 'widget_media_image', null );
67
-
68
- Astra_Sites_Importer_Log::add( '---- Processing Images from Widgets -----' );
69
- foreach ( $data as $key => $value ) {
70
-
71
- if (
72
- isset( $value['url'] ) &&
73
- isset( $value['attachment_id'] )
74
- ) {
75
-
76
- $image = array(
77
- 'url' => $value['url'],
78
- 'id' => $value['attachment_id'],
79
- );
80
-
81
- $downloaded_image = Astra_Sites_Image_Importer::get_instance()->import( $image );
82
-
83
- $data[ $key ]['url'] = $downloaded_image['url'];
84
- $data[ $key ]['attachment_id'] = $downloaded_image['id'];
85
- }
86
- }
87
-
88
- update_option( 'widget_media_image', $data );
89
- }
90
- }
91
-
92
- /**
93
- * Kicking this off by calling 'get_instance()' method
94
- */
95
- Astra_Sites_Batch_Processing_Widgets::get_instance();
96
-
97
- 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_Widgets' ) ) :
10
+
11
+ /**
12
+ * Astra_Sites_Batch_Processing_Widgets
13
+ *
14
+ * @since 1.0.14
15
+ */
16
+ class Astra_Sites_Batch_Processing_Widgets {
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
+ if ( ! isset( self::$instance ) ) {
35
+ self::$instance = new self;
36
+ }
37
+ return self::$instance;
38
+ }
39
+
40
+ /**
41
+ * Constructor
42
+ *
43
+ * @since 1.0.14
44
+ */
45
+ public function __construct() {
46
+ }
47
+
48
+ /**
49
+ * Import
50
+ *
51
+ * @since 1.0.14
52
+ * @return void
53
+ */
54
+ public function import() {
55
+ $this->widget_media_image();
56
+ }
57
+
58
+ /**
59
+ * Widget Media Image
60
+ *
61
+ * @since 1.0.14
62
+ * @return void
63
+ */
64
+ public function widget_media_image() {
65
+
66
+ $data = get_option( 'widget_media_image', null );
67
+
68
+ Astra_Sites_Importer_Log::add( '---- Processing Images from Widgets -----' );
69
+ foreach ( $data as $key => $value ) {
70
+
71
+ if (
72
+ isset( $value['url'] ) &&
73
+ isset( $value['attachment_id'] )
74
+ ) {
75
+
76
+ $image = array(
77
+ 'url' => $value['url'],
78
+ 'id' => $value['attachment_id'],
79
+ );
80
+
81
+ $downloaded_image = Astra_Sites_Image_Importer::get_instance()->import( $image );
82
+
83
+ $data[ $key ]['url'] = $downloaded_image['url'];
84
+ $data[ $key ]['attachment_id'] = $downloaded_image['id'];
85
+ }
86
+ }
87
+
88
+ update_option( 'widget_media_image', $data );
89
+ }
90
+ }
91
+
92
+ /**
93
+ * Kicking this off by calling 'get_instance()' method
94
+ */
95
+ Astra_Sites_Batch_Processing_Widgets::get_instance();
96
+
97
+ endif;
inc/importers/batch-processing/class-astra-sites-batch-processing.php CHANGED
@@ -1,210 +1,210 @@
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
-
205
- /**
206
- * Kicking this off by calling 'get_instance()' method
207
- */
208
- Astra_Sites_Batch_Processing::get_instance();
209
-
210
- 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
+
205
+ /**
206
+ * Kicking this off by calling 'get_instance()' method
207
+ */
208
+ Astra_Sites_Batch_Processing::get_instance();
209
+
210
+ endif;
inc/importers/batch-processing/helpers/class-astra-sites-image-importer.php CHANGED
@@ -1,243 +1,243 @@
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
-
238
- /**
239
- * Kicking this off by calling 'get_instance()' method
240
- */
241
- Astra_Sites_Image_Importer::get_instance();
242
-
243
- 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
+
238
+ /**
239
+ * Kicking this off by calling 'get_instance()' method
240
+ */
241
+ Astra_Sites_Image_Importer::get_instance();
242
+
243
+ endif;
inc/importers/batch-processing/helpers/class-wp-background-process-astra.php CHANGED
@@ -1,69 +1,69 @@
1
- <?php
2
- /**
3
- * Image Background Process
4
- *
5
- * @package Astra Sites
6
- * @since 1.0.11
7
- */
8
-
9
- if ( class_exists( 'WP_Background_Process' ) ) :
10
-
11
- /**
12
- * Image Background Process
13
- *
14
- * @since 1.0.11
15
- */
16
- class WP_Background_Process_Astra extends WP_Background_Process {
17
-
18
- /**
19
- * Image Process
20
- *
21
- * @var string
22
- */
23
- protected $action = 'image_process';
24
-
25
- /**
26
- * Task
27
- *
28
- * Override this method to perform any actions required on each
29
- * queue item. Return the modified item for further processing
30
- * in the next pass through. Or, return false to remove the
31
- * item from the queue.
32
- *
33
- * @since 1.0.11
34
- *
35
- * @param object $process Queue item object.
36
- * @return mixed
37
- */
38
- protected function task( $process ) {
39
-
40
- if ( method_exists( $process, 'import' ) ) {
41
- $process->import();
42
- }
43
-
44
- return false;
45
- }
46
-
47
- /**
48
- * Complete
49
- *
50
- * Override if applicable, but ensure that the below actions are
51
- * performed, or, call parent::complete().
52
- *
53
- * @since 1.0.11
54
- */
55
- protected function complete() {
56
-
57
- parent::complete();
58
-
59
- Astra_Sites_Importer_Log::add( 'Batch Process Complete!' );
60
-
61
- // Delete Log file.
62
- delete_option( 'astra_sites_recent_import_log_file' );
63
-
64
- do_action( 'astra_sites_image_import_complete' );
65
- }
66
-
67
- }
68
-
69
- endif;
1
+ <?php
2
+ /**
3
+ * Image Background Process
4
+ *
5
+ * @package Astra Sites
6
+ * @since 1.0.11
7
+ */
8
+
9
+ if ( class_exists( 'WP_Background_Process' ) ) :
10
+
11
+ /**
12
+ * Image Background Process
13
+ *
14
+ * @since 1.0.11
15
+ */
16
+ class WP_Background_Process_Astra extends WP_Background_Process {
17
+
18
+ /**
19
+ * Image Process
20
+ *
21
+ * @var string
22
+ */
23
+ protected $action = 'image_process';
24
+
25
+ /**
26
+ * Task
27
+ *
28
+ * Override this method to perform any actions required on each
29
+ * queue item. Return the modified item for further processing
30
+ * in the next pass through. Or, return false to remove the
31
+ * item from the queue.
32
+ *
33
+ * @since 1.0.11
34
+ *
35
+ * @param object $process Queue item object.
36
+ * @return mixed
37
+ */
38
+ protected function task( $process ) {
39
+
40
+ if ( method_exists( $process, 'import' ) ) {
41
+ $process->import();
42
+ }
43
+
44
+ return false;
45
+ }
46
+
47
+ /**
48
+ * Complete
49
+ *
50
+ * Override if applicable, but ensure that the below actions are
51
+ * performed, or, call parent::complete().
52
+ *
53
+ * @since 1.0.11
54
+ */
55
+ protected function complete() {
56
+
57
+ parent::complete();
58
+
59
+ Astra_Sites_Importer_Log::add( 'Batch Process Complete!' );
60
+
61
+ // Delete Log file.
62
+ delete_option( 'astra_sites_recent_import_log_file' );
63
+
64
+ do_action( 'astra_sites_image_import_complete' );
65
+ }
66
+
67
+ }
68
+
69
+ endif;
inc/importers/class-astra-site-options-import.php CHANGED
@@ -1,289 +1,289 @@
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
- }
110
-
111
- /**
112
- * Import site options.
113
- *
114
- * @since 1.0.2 Updated option if exist in defined option array 'site_options()'.
115
- *
116
- * @since 1.0.0
117
- *
118
- * @param (Array) $options Array of site options to be imported from the demo.
119
- */
120
- public function import_options( $options = array() ) {
121
-
122
- if ( ! isset( $options ) ) {
123
- return;
124
- }
125
-
126
- foreach ( $options as $option_name => $option_value ) {
127
-
128
- // Is option exist in defined array site_options()?
129
- if ( null !== $option_value ) {
130
-
131
- // Is option exist in defined array site_options()?
132
- if ( in_array( $option_name, self::site_options() ) ) {
133
-
134
- switch ( $option_name ) {
135
-
136
- // Set WooCommerce page ID by page Title.
137
- case 'woocommerce_shop_page_title':
138
- case 'woocommerce_cart_page_title':
139
- case 'woocommerce_checkout_page_title':
140
- case 'woocommerce_myaccount_page_title':
141
- case 'woocommerce_edit_address_page_title':
142
- case 'woocommerce_view_order_page_title':
143
- case 'woocommerce_change_password_page_title':
144
- case 'woocommerce_logout_page_title':
145
- $this->update_woocommerce_page_id_by_option_value( $option_name, $option_value );
146
- break;
147
-
148
- case 'page_for_posts':
149
- case 'page_on_front':
150
- $this->update_page_id_by_option_value( $option_name, $option_value );
151
- break;
152
-
153
- // nav menu locations.
154
- case 'nav_menu_locations':
155
- $this->set_nav_menu_locations( $option_value );
156
- break;
157
-
158
- // import WooCommerce category images.
159
- case 'woocommerce_product_cat':
160
- $this->set_woocommerce_product_cat( $option_value );
161
- break;
162
-
163
- // insert logo.
164
- case 'custom_logo':
165
- $this->insert_logo( $option_value );
166
- break;
167
-
168
- default:
169
- update_option( $option_name, $option_value );
170
- break;
171
- }
172
- }
173
- }
174
- }
175
- }
176
-
177
- /**
178
- * Update post option
179
- *
180
- * @since 1.0.2
181
- *
182
- * @param string $option_name Option name.
183
- * @param mixed $option_value Option value.
184
- * @return void
185
- */
186
- private function update_page_id_by_option_value( $option_name, $option_value ) {
187
- $page = get_page_by_title( $option_value );
188
- if ( is_object( $page ) ) {
189
- update_option( $option_name, $page->ID );
190
- }
191
- }
192
-
193
- /**
194
- * Update WooCommerce page ids.
195
- *
196
- * @since 1.1.6
197
- *
198
- * @param string $option_name Option name.
199
- * @param mixed $option_value Option value.
200
- * @return void
201
- */
202
- private function update_woocommerce_page_id_by_option_value( $option_name, $option_value ) {
203
- $option_name = str_replace( '_title', '_id', $option_name );
204
- $this->update_page_id_by_option_value( $option_name, $option_value );
205
- }
206
-
207
- /**
208
- * In WP nav menu is stored as ( 'menu_location' => 'menu_id' );
209
- * In export we send 'menu_slug' like ( 'menu_location' => 'menu_slug' );
210
- * In import we set 'menu_id' from menu slug like ( 'menu_location' => 'menu_id' );
211
- *
212
- * @since 1.0.0
213
- * @param array $nav_menu_locations Array of nav menu locations.
214
- */
215
- private function set_nav_menu_locations( $nav_menu_locations = array() ) {
216
-
217
- $menu_locations = array();
218
-
219
- // Update menu locations.
220
- if ( isset( $nav_menu_locations ) ) {
221
-
222
- foreach ( $nav_menu_locations as $menu => $value ) {
223
-
224
- $term = get_term_by( 'slug', $value, 'nav_menu' );
225
-
226
- if ( is_object( $term ) ) {
227
- $menu_locations[ $menu ] = $term->term_id;
228
- }
229
- }
230
-
231
- set_theme_mod( 'nav_menu_locations', $menu_locations );
232
- }
233
- }
234
-
235
- /**
236
- * Set WooCommerce category images.
237
- *
238
- * @since 1.1.4
239
- *
240
- * @param array $cats Array of categories.
241
- */
242
- private function set_woocommerce_product_cat( $cats = array() ) {
243
-
244
- $menu_locations = array();
245
-
246
- if ( isset( $cats ) ) {
247
-
248
- foreach ( $cats as $key => $cat ) {
249
-
250
- if ( ! empty( $cat['slug'] ) && ! empty( $cat['thumbnail_src'] ) ) {
251
-
252
- $image = (object) Astra_Sites_Helper::_sideload_image( $cat['thumbnail_src'] );
253
-
254
- if ( ! is_wp_error( $image ) ) {
255
-
256
- if ( isset( $image->attachment_id ) && ! empty( $image->attachment_id ) ) {
257
-
258
- $term = get_term_by( 'slug', $cat['slug'], 'product_cat' );
259
-
260
- if ( is_object( $term ) ) {
261
- update_term_meta( $term->term_id, 'thumbnail_id', $image->attachment_id );
262
- }
263
- }
264
- }
265
- }
266
- }
267
- }
268
- }
269
-
270
- /**
271
- * Insert Logo By URL
272
- *
273
- * @since 1.0.0
274
- * @param string $image_url Logo URL.
275
- * @return void
276
- */
277
- private function insert_logo( $image_url = '' ) {
278
-
279
- $data = (object) Astra_Sites_Helper::_sideload_image( $image_url );
280
-
281
- if ( ! is_wp_error( $data ) ) {
282
-
283
- if ( isset( $data->attachment_id ) && ! empty( $data->attachment_id ) ) {
284
- set_theme_mod( 'custom_logo', $data->attachment_id );
285
- }
286
- }
287
- }
288
-
289
- }
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
+ }
110
+
111
+ /**
112
+ * Import site options.
113
+ *
114
+ * @since 1.0.2 Updated option if exist in defined option array 'site_options()'.
115
+ *
116
+ * @since 1.0.0
117
+ *
118
+ * @param (Array) $options Array of site options to be imported from the demo.
119
+ */
120
+ public function import_options( $options = array() ) {
121
+
122
+ if ( ! isset( $options ) ) {
123
+ return;
124
+ }
125
+
126
+ foreach ( $options as $option_name => $option_value ) {
127
+
128
+ // Is option exist in defined array site_options()?
129
+ if ( null !== $option_value ) {
130
+
131
+ // Is option exist in defined array site_options()?
132
+ if ( in_array( $option_name, self::site_options(), true ) ) {
133
+
134
+ switch ( $option_name ) {
135
+
136
+ // Set WooCommerce page ID by page Title.
137
+ case 'woocommerce_shop_page_title':
138
+ case 'woocommerce_cart_page_title':
139
+ case 'woocommerce_checkout_page_title':
140
+ case 'woocommerce_myaccount_page_title':
141
+ case 'woocommerce_edit_address_page_title':
142
+ case 'woocommerce_view_order_page_title':
143
+ case 'woocommerce_change_password_page_title':
144
+ case 'woocommerce_logout_page_title':
145
+ $this->update_woocommerce_page_id_by_option_value( $option_name, $option_value );
146
+ break;
147
+
148
+ case 'page_for_posts':
149
+ case 'page_on_front':
150
+ $this->update_page_id_by_option_value( $option_name, $option_value );
151
+ break;
152
+
153
+ // nav menu locations.
154
+ case 'nav_menu_locations':
155
+ $this->set_nav_menu_locations( $option_value );
156
+ break;
157
+
158
+ // import WooCommerce category images.
159
+ case 'woocommerce_product_cat':
160
+ $this->set_woocommerce_product_cat( $option_value );
161
+ break;
162
+
163
+ // insert logo.
164
+ case 'custom_logo':
165
+ $this->insert_logo( $option_value );
166
+ break;
167
+
168
+ default:
169
+ update_option( $option_name, $option_value );
170
+ break;
171
+ }
172
+ }
173
+ }
174
+ }
175
+ }
176
+
177
+ /**
178
+ * Update post option
179
+ *
180
+ * @since 1.0.2
181
+ *
182
+ * @param string $option_name Option name.
183
+ * @param mixed $option_value Option value.
184
+ * @return void
185
+ */
186
+ private function update_page_id_by_option_value( $option_name, $option_value ) {
187
+ $page = get_page_by_title( $option_value );
188
+ if ( is_object( $page ) ) {
189
+ update_option( $option_name, $page->ID );
190
+ }
191
+ }
192
+
193
+ /**
194
+ * Update WooCommerce page ids.
195
+ *
196
+ * @since 1.1.6
197
+ *
198
+ * @param string $option_name Option name.
199
+ * @param mixed $option_value Option value.
200
+ * @return void
201
+ */
202
+ private function update_woocommerce_page_id_by_option_value( $option_name, $option_value ) {
203
+ $option_name = str_replace( '_title', '_id', $option_name );
204
+ $this->update_page_id_by_option_value( $option_name, $option_value );
205
+ }
206
+
207
+ /**
208
+ * In WP nav menu is stored as ( 'menu_location' => 'menu_id' );
209
+ * In export we send 'menu_slug' like ( 'menu_location' => 'menu_slug' );
210
+ * In import we set 'menu_id' from menu slug like ( 'menu_location' => 'menu_id' );
211
+ *
212
+ * @since 1.0.0
213
+ * @param array $nav_menu_locations Array of nav menu locations.
214
+ */
215
+ private function set_nav_menu_locations( $nav_menu_locations = array() ) {
216
+
217
+ $menu_locations = array();
218
+
219
+ // Update menu locations.
220
+ if ( isset( $nav_menu_locations ) ) {
221
+
222
+ foreach ( $nav_menu_locations as $menu => $value ) {
223
+
224
+ $term = get_term_by( 'slug', $value, 'nav_menu' );
225
+
226
+ if ( is_object( $term ) ) {
227
+ $menu_locations[ $menu ] = $term->term_id;
228
+ }
229
+ }
230
+
231
+ set_theme_mod( 'nav_menu_locations', $menu_locations );
232
+ }
233
+ }
234
+
235
+ /**
236
+ * Set WooCommerce category images.
237
+ *
238
+ * @since 1.1.4
239
+ *
240
+ * @param array $cats Array of categories.
241
+ */
242
+ private function set_woocommerce_product_cat( $cats = array() ) {
243
+
244
+ $menu_locations = array();
245
+
246
+ if ( isset( $cats ) ) {
247
+
248
+ foreach ( $cats as $key => $cat ) {
249
+
250
+ if ( ! empty( $cat['slug'] ) && ! empty( $cat['thumbnail_src'] ) ) {
251
+
252
+ $image = (object) Astra_Sites_Helper::_sideload_image( $cat['thumbnail_src'] );
253
+
254
+ if ( ! is_wp_error( $image ) ) {
255
+
256
+ if ( isset( $image->attachment_id ) && ! empty( $image->attachment_id ) ) {
257
+
258
+ $term = get_term_by( 'slug', $cat['slug'], 'product_cat' );
259
+
260
+ if ( is_object( $term ) ) {
261
+ update_term_meta( $term->term_id, 'thumbnail_id', $image->attachment_id );
262
+ }
263
+ }
264
+ }
265
+ }
266
+ }
267
+ }
268
+ }
269
+
270
+ /**
271
+ * Insert Logo By URL
272
+ *
273
+ * @since 1.0.0
274
+ * @param string $image_url Logo URL.
275
+ * @return void
276
+ */
277
+ private function insert_logo( $image_url = '' ) {
278
+
279
+ $data = (object) Astra_Sites_Helper::_sideload_image( $image_url );
280
+
281
+ if ( ! is_wp_error( $data ) ) {
282
+
283
+ if ( isset( $data->attachment_id ) && ! empty( $data->attachment_id ) ) {
284
+ set_theme_mod( 'custom_logo', $data->attachment_id );
285
+ }
286
+ }
287
+ }
288
+
289
+ }
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 );
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|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|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();
inc/includes/admin-page.php CHANGED
@@ -1,420 +1,420 @@
1
- <?php
2
- /**
3
- * Shortcode Markup
4
- *
5
- * TMPL - Single Demo Preview
6
- * TMPL - No more demos
7
- * TMPL - Filters
8
- * TMPL - List
9
- *
10
- * @package Astra Sites
11
- * @since 1.0.0
12
- */
13
-
14
- defined( 'ABSPATH' ) or exit;
15
- ?>
16
-
17
- <div class="wrap" id="astra-sites-admin">
18
-
19
- <div id="astra-sites-filters">
20
-
21
- <?php if ( apply_filters( 'astra_sites_show_filters', true ) ) { ?>
22
- <div class="wp-filter hide-if-no-js">
23
- <div class="section-left">
24
-
25
- <!-- All Filters -->
26
- <div class="filter-count">
27
- <span class="count"></span>
28
- </div>
29
- <div class="filters-wrap" style="display: none;">
30
- <div id="astra-site-page-builder"></div>
31
- </div>
32
- <div class="filters-wrap">
33
- <div id="astra-site-category"></div>
34
- </div>
35
-
36
- </div>
37
-
38
- <div class="section-right">
39
-
40
- <div class="search-form">
41
- <label class="screen-reader-text" for="wp-filter-search-input"><?php _e( 'Search Sites', 'astra-sites' ); ?> </label>
42
- <input placeholder="<?php _e( 'Search Sites...', 'astra-sites' ); ?>" type="search" aria-describedby="live-search-desc" id="wp-filter-search-input" class="wp-filter-search">
43
- </div>
44
-
45
- </div>
46
- </div>
47
- <?php } ?>
48
-
49
- </div>
50
-
51
- <?php do_action( 'astra_sites_before_site_grid' ); ?>
52
-
53
- <div class="theme-browser rendered">
54
- <div id="astra-sites" class="themes wp-clearfix"></div>
55
- </div>
56
-
57
- <div class="spinner-wrap">
58
- <span class="spinner"></span>
59
- </div>
60
-
61
- <?php do_action( 'astra_sites_after_site_grid' ); ?>
62
-
63
- </div>
64
-
65
- <?php
66
- /**
67
- * TMPL - Pro Site Description
68
- */
69
- ?>
70
- <script type="text/template" id="tmpl-astra-sites-pro-site-description">
71
- <p><?php _e( 'Liked this demo?', 'astra-sites' ); ?></p>
72
- <p>
73
- <?php
74
- /* translators: %s is pricing page link */
75
- printf( __( 'It is a premium website demo which is available only with the Agency Bundles <a href="%s" target="_blank">Buy Now!</a>', 'astra-sites' ), 'https://wpastra.com/pricing/' );
76
- ?>
77
- </p>
78
- <p>
79
- <?php
80
- /* translators: %s is article link */
81
- printf( __( 'Already own an Agency Bundle? Read an article to know how you can <a href="%s" target="_blank">import a premium website demo</a>.', 'astra-sites' ), 'https://wpastra.com/docs/import-astra-agency-website-demos/' );
82
- ?>
83
- </p>
84
- </script>
85
-
86
- <?php
87
- /**
88
- * TMPL - Pro Site Description for Inactive license
89
- */
90
- ?>
91
- <script type="text/template" id="tmpl-astra-sites-pro-inactive-site-description">
92
- <p><?php _e( 'You are just 2 minutes away from importing this demo!', 'astra-sites' ); ?></p>
93
- <p><?php _e( 'It is a premium website demo and you need to activate the license to access it.', 'astra-sites' ); ?></p>
94
- <p>
95
- <?php
96
- /* translators: %s is article link */
97
- printf( __( 'Learn how you can <a href="%s" target="_blank">activate the license</a> of the Astra Premium Sites plugin.', 'astra-sites' ), 'https://wpastra.com/docs/activate-license-for-astra-premium-sites-plugin/' );
98
- ?>
99
- </p>
100
- </script>
101
-
102
- <?php
103
- /**
104
- * TMPL - Single Demo Preview
105
- */
106
- ?>
107
- <script type="text/template" id="tmpl-astra-site-select-page-builder">
108
- <div class="select-page-builder">
109
- <div class="note-wrap">
110
- <h3>
111
- <span class="up-arrow dashicons dashicons-editor-break"></span>
112
- <div class="note"><?php _e( 'Select Your Favorite Page Builder', 'astra-sites' ); ?></div>
113
- </h3>
114
- </div>
115
- <img src="<?php echo esc_url( ASTRA_SITES_URI . 'inc/assets/images/sites-screenshot.jpg' ); ?>" alt="<?php _e( 'Sites List..', 'astra-sites' ); ?>" title="<?php _e( 'Sites List..', 'astra-sites' ); ?>" />
116
- </div>
117
- </script>
118
-
119
- <?php
120
- /**
121
- * TMPL - Single Demo Preview
122
- */
123
- ?>
124
- <script type="text/template" id="tmpl-astra-site-preview">
125
- <div class="astra-sites-preview theme-install-overlay wp-full-overlay expanded">
126
- <div class="wp-full-overlay-sidebar">
127
- <div class="wp-full-overlay-header"
128
- data-demo-id="{{{data.id}}}"
129
- data-demo-type="{{{data.astra_demo_type}}}"
130
- data-demo-url="{{{data.astra_demo_url}}}"
131
- data-demo-api="{{{data.demo_api}}}"
132
- data-demo-name="{{{data.demo_name}}}"
133
- data-demo-slug="{{{data.slug}}}"
134
- data-screenshot="{{{data.screenshot}}}"
135
- data-content="{{{data.content}}}"
136
- data-required-plugins="{{data.required_plugins}}">
137
- <input type="hidden" class="astra-site-options" value="{{data.astra_site_options}}" >
138
- <input type="hidden" class="astra-enabled-extensions" value="{{data.astra_enabled_extensions}}" >
139
- <button class="close-full-overlay"><span class="screen-reader-text"><?php esc_html_e( 'Close', 'astra-sites' ); ?></span></button>
140
- <button class="previous-theme"><span class="screen-reader-text"><?php esc_html_e( 'Previous', 'astra-sites' ); ?></span></button>
141
- <button class="next-theme"><span class="screen-reader-text"><?php esc_html_e( 'Next', 'astra-sites' ); ?></span></button>
142
- <!-- <a class="button hide-if-no-customize astra-site-import" href="#" data-import="disabled"><?php esc_html_e( 'Import Site', 'astra-sites' ); ?></a> -->
143
- <a class="button hide-if-no-customize button-primary astra-demo-import" href="#" data-import="disabled"><?php esc_html_e( 'Import Site', 'astra-sites' ); ?></a>
144
-
145
- </div>
146
- <div class="wp-full-overlay-sidebar-content">
147
- <div class="install-theme-info">
148
-
149
- <span class="site-type {{{data.astra_demo_type}}}">{{{data.astra_demo_type}}}</span>
150
- <h3 class="theme-name">{{{data.demo_name}}}</h3>
151
-
152
- <# if ( data.screenshot.length ) { #>
153
- <div class="theme-screenshot-wrap">
154
- <img class="theme-screenshot" src="{{{data.screenshot}}}" alt="">
155
- </div>
156
- <# } #>
157
-
158
- <div class="theme-details">
159
- {{{data.content}}}
160
- </div>
161
- <a href="#" class="theme-details-read-more"><?php _e( 'Read more', 'astra-sites' ); ?> &hellip;</a>
162
-
163
- <div class="astra-sites-advanced-options-wrap">
164
-
165
- <div class="astra-sites-advanced-options">
166
-
167
- <ul class="astra-site-contents">
168
- <li class="astra-sites-import-plugins">
169
- <input type="checkbox" name="plugins" checked="checked" class="disabled checkbox" readonly>
170
- <strong><?php _e( 'Install Required Plugins', 'astra-sites' ); ?></strong>
171
- <span class="astra-sites-tooltip-icon" data-tip-id="astra-sites-tooltip-plugins-settings"><span class="dashicons dashicons-editor-help"></span></span>
172
- <div class="astra-sites-tooltip-message" id="astra-sites-tooltip-plugins-settings" style="display: none;">
173
- <ul class="required-plugins-list"><span class="spinner is-active"></span></ul>
174
- </div>
175
- </li>
176
- <li class="astra-sites-import-customizer">
177
- <label>
178
- <input type="checkbox" name="customizer" checked="checked" class="checkbox">
179
- <strong>Import Customizer Settings</strong>
180
- <span class="astra-sites-tooltip-icon" data-tip-id="astra-sites-tooltip-customizer-settings"><span class="dashicons dashicons-editor-help"></span></span>
181
- <div class="astra-sites-tooltip-message" id="astra-sites-tooltip-customizer-settings" style="display: none;">
182
- <p><?php _e( 'Customizer is what gives a design to the website; and selecting this option replaces your current design with a new one.', 'astra-sites' ); ?></p>
183
- <p><?php _e( 'Backup of current customizer settings will be stored in "wp-content/astra-sites" directory, just in case if you want to restore it later.', 'astra-sites' ); ?></p>
184
- </div>
185
- </label>
186
- </li>
187
- <li class="astra-sites-import-xml">
188
- <label>
189
- <input type="checkbox" name="xml" checked="checked" class="checkbox">
190
- <strong>Import Content</strong>
191
- </label>
192
- <span class="astra-sites-tooltip-icon" data-tip-id="astra-sites-tooltip-site-content"><span class="dashicons dashicons-editor-help"></span></span>
193
- <div class="astra-sites-tooltip-message" id="astra-sites-tooltip-site-content" style="display: none;"><p><?php _e( 'Selecting this option will import dummy pages, posts, images and menus. If you do not want to import dummy content, please uncheck this option.', 'astra-sites' ); ?></p></div>
194
- </li>
195
- <li class="astra-sites-import-widgets">
196
- <label>
197
- <input type="checkbox" name="widgets" checked="checked" class="checkbox">
198
- <strong>Import Widgets</strong>
199
- </label>
200
- </li>
201
- </ul>
202
- </div>
203
-
204
- <ul>
205
- <li class="astra-sites-reset-data">
206
- <label>
207
- <input type="checkbox" name="reset" class="checkbox">
208
- <strong>Delete Previously Imported Site</strong>
209
- <div class="astra-sites-tooltip-message" id="astra-sites-tooltip-reset-data" style="display: none;"><p><?php _e( 'WARNING: Selecting this option will delete data from your current website. Choose this option only if this is intended.', 'astra-sites' ); ?></p></div>
210
- </label>
211
- </li>
212
- </ul>
213
-
214
- <!-- <p><a href="#" class="astra-sites-advanced-options-button"><?php _e( 'Advanced Options', 'astra-sites' ); ?></a></p> -->
215
-
216
- </div>
217
-
218
- <!-- <div class="astra-sites-advanced-options">
219
- <h4><?php _e( 'Required Plugins', 'astra-sites' ); ?> </h4>
220
- <div class="required-plugins"></div>
221
- </div> -->
222
- </div>
223
- </div>
224
-
225
- <div class="wp-full-overlay-footer">
226
- <div class="footer-import-button-wrap">
227
- <a class="button button-hero hide-if-no-customize button-primary astra-demo-import" href="#" data-import="disabled">
228
- <?php esc_html_e( 'Import Site', 'astra-sites' ); ?>
229
- <span class="percent"></span>
230
- </a>
231
- <div class="astra-site-import-process-wrap" style="display: none;">
232
- <progress class="astra-site-import-process" max="100" value="0"></progress>
233
- </div>
234
- <!-- <a class="button button-hero hide-if-no-customize astra-site-import" href="#">
235
- <?php esc_html_e( 'Import Site', 'astra-sites' ); ?>
236
- </a> -->
237
- </div>
238
- <button type="button" class="collapse-sidebar button" aria-expanded="true"
239
- aria-label="Collapse Sidebar">
240
- <span class="collapse-sidebar-arrow"></span>
241
- <span class="collapse-sidebar-label"><?php esc_html_e( 'Collapse', 'astra-sites' ); ?></span>
242
- </button>
243
-
244
- <div class="devices-wrapper">
245
- <div class="devices">
246
- <button type="button" class="preview-desktop active" aria-pressed="true" data-device="desktop">
247
- <span class="screen-reader-text"><?php _e( 'Enter desktop preview mode', 'astra-sites' ); ?></span>
248
- </button>
249
- <button type="button" class="preview-tablet" aria-pressed="false" data-device="tablet">
250
- <span class="screen-reader-text"><?php _e( 'Enter tablet preview mode', 'astra-sites' ); ?></span>
251
- </button>
252
- <button type="button" class="preview-mobile" aria-pressed="false" data-device="mobile">
253
- <span class="screen-reader-text"><?php _e( 'Enter mobile preview mode', 'astra-sites' ); ?></span>
254
- </button>
255
- </div>
256
- </div>
257
-
258
- </div>
259
- </div>
260
- <div class="wp-full-overlay-main">
261
- <iframe src="{{{data.astra_demo_url}}}" title="<?php esc_attr_e( 'Preview', 'astra-sites' ); ?>"></iframe>
262
- <div class="astra-sites-result-preview" style="display: none;">
263
- <div class="inner">
264
- <h2><?php _e( 'We\'re building your website.', 'astra-sites' ); ?></h2>
265
- <p><?php _e( 'The process can take anywhere between 2 to 10 minutes depending on the size of the website and speed of connection.', 'astra-sites' ); ?></p>
266
- <p><?php _e( 'Please do not close this browser window until the site is imported completely.', 'astra-sites' ); ?></p>
267
- <div class="current-importing-status-wrap">
268
- <div class="current-importing-status">
269
- <div class="current-importing-status-title"></div>
270
- <div class="current-importing-status-description"></div>
271
- </div>
272
- </div>
273
- </div>
274
- </div>
275
- </div>
276
- </div>
277
- </script>
278
-
279
- <?php
280
- /**
281
- * TMPL - No more demos
282
- */
283
- ?>
284
- <script type="text/template" id="tmpl-astra-site-api-request-failed">
285
- <div class="no-themes">
286
- <?php
287
-
288
- /* translators: %1$s & %2$s are a Demo API URL */
289
- printf( __( '<p> It seems the demo data server, <i><a href="%1$s">%2$s</a></i> is unreachable from your site.</p>', 'astra-sites' ), esc_url( Astra_Sites::$api_url ), esc_url( Astra_Sites::$api_url ) );
290
-
291
- _e( '<p class="left-margin"> 1. Sometimes, simple page reload fixes any temporary issues. No kidding!</p>', 'astra-sites' );
292
-
293
- _e( '<p class="left-margin"> 2. If that does not work, you will need to talk to your server administrator and check if demo server is being blocked by the firewall!</p>', 'astra-sites' );
294
-
295
- /* translators: %1$s is a support link */
296
- printf( __( '<p>If that does not help, please open up a <a href="%1$s" target="_blank">Support Ticket</a> and we will be glad take a closer look for you.</p>', 'astra-sites' ), esc_url( 'https://wpastra.com/support/?utm_source=demo-import-panel&utm_campaign=astra-sites&utm_medium=api-request-failed' ) );
297
- ?>
298
- </div>
299
- </script>
300
-
301
- <?php
302
- /**
303
- * TMPL - Site Down
304
- */
305
- ?>
306
- <script type="text/template" id="tmpl-astra-site-down">
307
- <div class="postbox astra-site-down">
308
- <h2><?php _e( 'Under Maintenance..', 'astra-sites' ); ?></h2>
309
- <p><?php _e( 'If you are seeing this message, most likely our servers are under routine maintenance and we will be back shortly. ', 'astra-sites' ); ?></p>
310
- <p><?php _e( 'In rare case, it is possible your website is having trouble connecting with ours. If you need help, please feel free to get in touch with us from our website.', 'astra-sites' ); ?></p>
311
- </div>
312
- </script>
313
-
314
- <?php
315
- /**
316
- * TMPL - Filters
317
- */
318
- ?>
319
- <script type="text/template" id="tmpl-astra-site-filters">
320
-
321
- <# if ( data ) { #>
322
-
323
- <ul class="{{ data.args.wrapper_class }} {{ data.args.class }}">
324
-
325
- <# if ( data.args.show_all ) { #>
326
- <li>
327
- <a href="#" data-group="all"> All </a>
328
- </li>
329
- <# } #>
330
-
331
- <# for ( key in data.items ) { #>
332
- <# if ( data.items[ key ].count ) { #>
333
- <li>
334
- <a href="#" data-group='{{ data.items[ key ].id }}' class="{{ data.items[ key ].name }}">
335
- {{ data.items[ key ].name }}
336
- </a>
337
- </li>
338
- <# } #>
339
- <# } #>
340
-
341
- </ul>
342
- <# } #>
343
- </script>
344
-
345
- <?php
346
- /**
347
- * TMPL - List
348
- */
349
- ?>
350
- <script type="text/template" id="tmpl-astra-sites-list">
351
-
352
- <# if ( data.items.length ) { #>
353
- <# for ( key in data.items ) { #>
354
-
355
- <div class="theme astra-theme site-single {{ data.items[ key ].status }}" tabindex="0" aria-describedby="astra-theme-action astra-theme-name"
356
- data-demo-id="{{{ data.items[ key ].id }}}"
357
- data-demo-type="{{{ data.items[ key ]['astra-site-type'] }}}"
358
- data-demo-url="{{{ data.items[ key ]['astra-site-url'] }}}"
359
- data-demo-api="{{{ data.items[ key ]['_links']['self'][0]['href'] }}}"
360
- data-demo-name="{{{ data.items[ key ].title.rendered }}}"
361
- data-demo-slug="{{{ data.items[ key ].slug }}}"
362
- data-screenshot="{{{ data.items[ key ]['featured-image-url'] }}}"
363
- data-content="{{{ data.items[ key ].content.rendered }}}"
364
- data-required-plugins="{{ JSON.stringify( data.items[ key ]['required-plugins'] ) }}"
365
- data-groups=["{{ data.items[ key ].tags }}"]>
366
- <input type="hidden" class="astra-site-options" value="{{ JSON.stringify(data.items[ key ]['astra-site-options-data'] ) }}" />
367
- <input type="hidden" class="astra-enabled-extensions" value="{{ JSON.stringify(data.items[ key ]['astra-enabled-extensions'] ) }}" />
368
-
369
- <div class="inner">
370
- <span class="site-preview" data-href="{{ data.items[ key ]['astra-site-url'] }}?TB_iframe=true&width=600&height=550" data-title="{{ data.items[ key ].title.rendered }}">
371
- <div class="theme-screenshot" style="background-image: url('{{ data.items[ key ]['featured-image-url'] }}');"></div>
372
- </span>
373
- <# if ( data.items[ key ]['astra-site-type'] ) { #>
374
- <# var type = ( data.items[ key ]['astra-site-type'] !== 'premium' ) ? ( data.items[ key ]['astra-site-type'] ) : 'agency'; #>
375
- <span class="site-type {{data.items[ key ]['astra-site-type']}}">{{ type }}</span>
376
- <# } #>
377
- <# if ( data.items[ key ].status ) { #>
378
- <span class="status {{data.items[ key ].status}}">{{data.items[ key ].status}}</span>
379
- <# } #>
380
- <div class="theme-id-container">
381
- <h3 class="theme-name" id="astra-theme-name"> {{{ data.items[ key ].title.rendered }}} </h3>
382
- <div class="theme-actions">
383
- <button class="button-primary button preview install-theme-preview"><?php esc_html_e( 'Preview', 'astra-sites' ); ?></button>
384
- </div>
385
- </div>
386
- </div>
387
- </div>
388
- <# } #>
389
- <# } else { #>
390
- <p class="no-themes" style="display:block;">
391
- <?php _e( 'No Demos found, Try a different search.', 'astra-sites' ); ?>
392
- <span class="description">
393
- <?php
394
- /* translators: %1$s External Link */
395
- printf( __( 'Don\'t see a site that you would like to import?<br><a target="_blank" href="%1$s">Please suggest us!</a>', 'astra-sites' ), esc_url( 'https://wpastra.com/sites-suggestions/?utm_source=demo-import-panel&utm_campaign=astra-sites&utm_medium=suggestions' ) );
396
- ?>
397
- </span>
398
- </p>
399
- <# } #>
400
- </script>
401
-
402
- <?php
403
- /**
404
- * TMPL - List
405
- */
406
- ?>
407
- <script type="text/template" id="tmpl-astra-sites-suggestions">
408
- <div class="theme astra-theme site-single astra-sites-suggestions">
409
- <div class="inner">
410
- <p>
411
- <?php
412
- /* translators: %1$s External Link */
413
- printf( __( 'Don\'t see a site that you would like to import?<br><a target="_blank" href="%1$s">Please suggest us!</a>', 'astra-sites' ), esc_url( 'https://wpastra.com/sites-suggestions/?utm_source=demo-import-panel&utm_campaign=astra-sites&utm_medium=suggestions' ) );
414
- ?>
415
- </p>
416
- </div>
417
- </div>
418
- </script>
419
- <?php
420
- wp_print_admin_notice_templates();
1
+ <?php
2
+ /**
3
+ * Shortcode Markup
4
+ *
5
+ * TMPL - Single Demo Preview
6
+ * TMPL - No more demos
7
+ * TMPL - Filters
8
+ * TMPL - List
9
+ *
10
+ * @package Astra Sites
11
+ * @since 1.0.0
12
+ */
13
+
14
+ defined( 'ABSPATH' ) or exit;
15
+ ?>
16
+
17
+ <div class="wrap" id="astra-sites-admin">
18
+
19
+ <div id="astra-sites-filters">
20
+
21
+ <?php if ( apply_filters( 'astra_sites_show_filters', true ) ) { ?>
22
+ <div class="wp-filter hide-if-no-js">
23
+ <div class="section-left">
24
+
25
+ <!-- All Filters -->
26
+ <div class="filter-count">
27
+ <span class="count"></span>
28
+ </div>
29
+ <div class="filters-wrap" style="display: none;">
30
+ <div id="astra-site-page-builder"></div>
31
+ </div>
32
+ <div class="filters-wrap">
33
+ <div id="astra-site-category"></div>
34
+ </div>
35
+
36
+ </div>
37
+
38
+ <div class="section-right">
39
+
40
+ <div class="search-form">
41
+ <label class="screen-reader-text" for="wp-filter-search-input"><?php _e( 'Search Sites', 'astra-sites' ); ?> </label>
42
+ <input placeholder="<?php _e( 'Search Sites...', 'astra-sites' ); ?>" type="search" aria-describedby="live-search-desc" id="wp-filter-search-input" class="wp-filter-search">
43
+ </div>
44
+
45
+ </div>
46
+ </div>
47
+ <?php } ?>
48
+
49
+ </div>
50
+
51
+ <?php do_action( 'astra_sites_before_site_grid' ); ?>
52
+
53
+ <div class="theme-browser rendered">
54
+ <div id="astra-sites" class="themes wp-clearfix"></div>
55
+ </div>
56
+
57
+ <div class="spinner-wrap">
58
+ <span class="spinner"></span>
59
+ </div>
60
+
61
+ <?php do_action( 'astra_sites_after_site_grid' ); ?>
62
+
63
+ </div>
64
+
65
+ <?php
66
+ /**
67
+ * TMPL - Pro Site Description
68
+ */
69
+ ?>
70
+ <script type="text/template" id="tmpl-astra-sites-pro-site-description">
71
+ <p><?php _e( 'Liked this demo?', 'astra-sites' ); ?></p>
72
+ <p>
73
+ <?php
74
+ /* translators: %s is pricing page link */
75
+ printf( __( 'It is a premium website demo which is available only with the Agency Bundles <a href="%s" target="_blank">Buy Now!</a>', 'astra-sites' ), 'https://wpastra.com/pricing/' );
76
+ ?>
77
+ </p>
78
+ <p>
79
+ <?php
80
+ /* translators: %s is article link */
81
+ printf( __( 'Already own an Agency Bundle? Read an article to know how you can <a href="%s" target="_blank">import a premium website demo</a>.', 'astra-sites' ), 'https://wpastra.com/docs/import-astra-agency-website-demos/' );
82
+ ?>
83
+ </p>
84
+ </script>
85
+
86
+ <?php
87
+ /**
88
+ * TMPL - Pro Site Description for Inactive license
89
+ */
90
+ ?>
91
+ <script type="text/template" id="tmpl-astra-sites-pro-inactive-site-description">
92
+ <p><?php _e( 'You are just 2 minutes away from importing this demo!', 'astra-sites' ); ?></p>
93
+ <p><?php _e( 'It is a premium website demo and you need to activate the license to access it.', 'astra-sites' ); ?></p>
94
+ <p>
95
+ <?php
96
+ /* translators: %s is article link */
97
+ printf( __( 'Learn how you can <a href="%s" target="_blank">activate the license</a> of the Astra Premium Sites plugin.', 'astra-sites' ), 'https://wpastra.com/docs/activate-license-for-astra-premium-sites-plugin/' );
98
+ ?>
99
+ </p>
100
+ </script>
101
+
102
+ <?php
103
+ /**
104
+ * TMPL - Single Demo Preview
105
+ */
106
+ ?>
107
+ <script type="text/template" id="tmpl-astra-site-select-page-builder">
108
+ <div class="select-page-builder">
109
+ <div class="note-wrap">
110
+ <h3>
111
+ <span class="up-arrow dashicons dashicons-editor-break"></span>
112
+ <div class="note"><?php _e( 'Select Your Favorite Page Builder', 'astra-sites' ); ?></div>
113
+ </h3>
114
+ </div>
115
+ <img src="<?php echo esc_url( ASTRA_SITES_URI . 'inc/assets/images/sites-screenshot.jpg' ); ?>" alt="<?php _e( 'Sites List..', 'astra-sites' ); ?>" title="<?php _e( 'Sites List..', 'astra-sites' ); ?>" />
116
+ </div>
117
+ </script>
118
+
119
+ <?php
120
+ /**
121
+ * TMPL - Single Demo Preview
122
+ */
123
+ ?>
124
+ <script type="text/template" id="tmpl-astra-site-preview">
125
+ <div class="astra-sites-preview theme-install-overlay wp-full-overlay expanded">
126
+ <div class="wp-full-overlay-sidebar">
127
+ <div class="wp-full-overlay-header"
128
+ data-demo-id="{{{data.id}}}"
129
+ data-demo-type="{{{data.astra_demo_type}}}"
130
+ data-demo-url="{{{data.astra_demo_url}}}"
131
+ data-demo-api="{{{data.demo_api}}}"
132
+ data-demo-name="{{{data.demo_name}}}"
133
+ data-demo-slug="{{{data.slug}}}"
134
+ data-screenshot="{{{data.screenshot}}}"
135
+ data-content="{{{data.content}}}"
136
+ data-required-plugins="{{data.required_plugins}}">
137
+ <input type="hidden" class="astra-site-options" value="{{data.astra_site_options}}" >
138
+ <input type="hidden" class="astra-enabled-extensions" value="{{data.astra_enabled_extensions}}" >
139
+ <button class="close-full-overlay"><span class="screen-reader-text"><?php esc_html_e( 'Close', 'astra-sites' ); ?></span></button>
140
+ <button class="previous-theme"><span class="screen-reader-text"><?php esc_html_e( 'Previous', 'astra-sites' ); ?></span></button>
141
+ <button class="next-theme"><span class="screen-reader-text"><?php esc_html_e( 'Next', 'astra-sites' ); ?></span></button>
142
+ <!-- <a class="button hide-if-no-customize astra-site-import" href="#" data-import="disabled"><?php esc_html_e( 'Import Site', 'astra-sites' ); ?></a> -->
143
+ <a class="button hide-if-no-customize button-primary astra-demo-import" href="#" data-import="disabled"><?php esc_html_e( 'Import Site', 'astra-sites' ); ?></a>
144
+
145
+ </div>
146
+ <div class="wp-full-overlay-sidebar-content">
147
+ <div class="install-theme-info">
148
+
149
+ <span class="site-type {{{data.astra_demo_type}}}">{{{data.astra_demo_type}}}</span>
150
+ <h3 class="theme-name">{{{data.demo_name}}}</h3>
151
+
152
+ <# if ( data.screenshot.length ) { #>
153
+ <div class="theme-screenshot-wrap">
154
+ <img class="theme-screenshot" src="{{{data.screenshot}}}" alt="">
155
+ </div>
156
+ <# } #>
157
+
158
+ <div class="theme-details">
159
+ {{{data.content}}}
160
+ </div>
161
+ <a href="#" class="theme-details-read-more"><?php _e( 'Read more', 'astra-sites' ); ?> &hellip;</a>
162
+
163
+ <div class="astra-sites-advanced-options-wrap">
164
+
165
+ <div class="astra-sites-advanced-options">
166
+
167
+ <ul class="astra-site-contents">
168
+ <li class="astra-sites-import-plugins">
169
+ <input type="checkbox" name="plugins" checked="checked" class="disabled checkbox" readonly>
170
+ <strong><?php _e( 'Install Required Plugins', 'astra-sites' ); ?></strong>
171
+ <span class="astra-sites-tooltip-icon" data-tip-id="astra-sites-tooltip-plugins-settings"><span class="dashicons dashicons-editor-help"></span></span>
172
+ <div class="astra-sites-tooltip-message" id="astra-sites-tooltip-plugins-settings" style="display: none;">
173
+ <ul class="required-plugins-list"><span class="spinner is-active"></span></ul>
174
+ </div>
175
+ </li>
176
+ <li class="astra-sites-import-customizer">
177
+ <label>
178
+ <input type="checkbox" name="customizer" checked="checked" class="checkbox">
179
+ <strong>Import Customizer Settings</strong>
180
+ <span class="astra-sites-tooltip-icon" data-tip-id="astra-sites-tooltip-customizer-settings"><span class="dashicons dashicons-editor-help"></span></span>
181
+ <div class="astra-sites-tooltip-message" id="astra-sites-tooltip-customizer-settings" style="display: none;">
182
+ <p><?php _e( 'Customizer is what gives a design to the website; and selecting this option replaces your current design with a new one.', 'astra-sites' ); ?></p>
183
+ <p><?php _e( 'Backup of current customizer settings will be stored in "wp-content/astra-sites" directory, just in case if you want to restore it later.', 'astra-sites' ); ?></p>
184
+ </div>
185
+ </label>
186
+ </li>
187
+ <li class="astra-sites-import-xml">
188
+ <label>
189
+ <input type="checkbox" name="xml" checked="checked" class="checkbox">
190
+ <strong>Import Content</strong>
191
+ </label>
192
+ <span class="astra-sites-tooltip-icon" data-tip-id="astra-sites-tooltip-site-content"><span class="dashicons dashicons-editor-help"></span></span>
193
+ <div class="astra-sites-tooltip-message" id="astra-sites-tooltip-site-content" style="display: none;"><p><?php _e( 'Selecting this option will import dummy pages, posts, images and menus. If you do not want to import dummy content, please uncheck this option.', 'astra-sites' ); ?></p></div>
194
+ </li>
195
+ <li class="astra-sites-import-widgets">
196
+ <label>
197
+ <input type="checkbox" name="widgets" checked="checked" class="checkbox">
198
+ <strong>Import Widgets</strong>
199
+ </label>
200
+ </li>
201
+ </ul>
202
+ </div>
203
+
204
+ <ul>
205
+ <li class="astra-sites-reset-data">
206
+ <label>
207
+ <input type="checkbox" name="reset" class="checkbox">
208
+ <strong>Delete Previously Imported Site</strong>
209
+ <div class="astra-sites-tooltip-message" id="astra-sites-tooltip-reset-data" style="display: none;"><p><?php _e( 'WARNING: Selecting this option will delete data from your current website. Choose this option only if this is intended.', 'astra-sites' ); ?></p></div>
210
+ </label>
211
+ </li>
212
+ </ul>
213
+
214
+ <!-- <p><a href="#" class="astra-sites-advanced-options-button"><?php _e( 'Advanced Options', 'astra-sites' ); ?></a></p> -->
215
+
216
+ </div>
217
+
218
+ <!-- <div class="astra-sites-advanced-options">
219
+ <h4><?php _e( 'Required Plugins', 'astra-sites' ); ?> </h4>
220
+ <div class="required-plugins"></div>
221
+ </div> -->
222
+ </div>
223
+ </div>
224
+
225
+ <div class="wp-full-overlay-footer">
226
+ <div class="footer-import-button-wrap">
227
+ <a class="button button-hero hide-if-no-customize button-primary astra-demo-import" href="#" data-import="disabled">
228
+ <?php esc_html_e( 'Import Site', 'astra-sites' ); ?>
229
+ <span class="percent"></span>
230
+ </a>
231
+ <div class="astra-site-import-process-wrap" style="display: none;">
232
+ <progress class="astra-site-import-process" max="100" value="0"></progress>
233
+ </div>
234
+ <!-- <a class="button button-hero hide-if-no-customize astra-site-import" href="#">
235
+ <?php esc_html_e( 'Import Site', 'astra-sites' ); ?>
236
+ </a> -->
237
+ </div>
238
+ <button type="button" class="collapse-sidebar button" aria-expanded="true"
239
+ aria-label="Collapse Sidebar">
240
+ <span class="collapse-sidebar-arrow"></span>
241
+ <span class="collapse-sidebar-label"><?php esc_html_e( 'Collapse', 'astra-sites' ); ?></span>
242
+ </button>
243
+
244
+ <div class="devices-wrapper">
245
+ <div class="devices">
246
+ <button type="button" class="preview-desktop active" aria-pressed="true" data-device="desktop">
247
+ <span class="screen-reader-text"><?php _e( 'Enter desktop preview mode', 'astra-sites' ); ?></span>
248
+ </button>
249
+ <button type="button" class="preview-tablet" aria-pressed="false" data-device="tablet">
250
+ <span class="screen-reader-text"><?php _e( 'Enter tablet preview mode', 'astra-sites' ); ?></span>
251
+ </button>
252
+ <button type="button" class="preview-mobile" aria-pressed="false" data-device="mobile">
253
+ <span class="screen-reader-text"><?php _e( 'Enter mobile preview mode', 'astra-sites' ); ?></span>
254
+ </button>
255
+ </div>
256
+ </div>
257
+
258
+ </div>
259
+ </div>
260
+ <div class="wp-full-overlay-main">
261
+ <iframe src="{{{data.astra_demo_url}}}" title="<?php esc_attr_e( 'Preview', 'astra-sites' ); ?>"></iframe>
262
+ <div class="astra-sites-result-preview" style="display: none;">
263
+ <div class="inner">
264
+ <h2><?php _e( 'We\'re building your website.', 'astra-sites' ); ?></h2>
265
+ <p><?php _e( 'The process can take anywhere between 2 to 10 minutes depending on the size of the website and speed of connection.', 'astra-sites' ); ?></p>
266
+ <p><?php _e( 'Please do not close this browser window until the site is imported completely.', 'astra-sites' ); ?></p>
267
+ <div class="current-importing-status-wrap">
268
+ <div class="current-importing-status">
269
+ <div class="current-importing-status-title"></div>
270
+ <div class="current-importing-status-description"></div>
271
+ </div>
272
+ </div>
273
+ </div>
274
+ </div>
275
+ </div>
276
+ </div>
277
+ </script>
278
+
279
+ <?php
280
+ /**
281
+ * TMPL - No more demos
282
+ */
283
+ ?>
284
+ <script type="text/template" id="tmpl-astra-site-api-request-failed">
285
+ <div class="no-themes">
286
+ <?php
287
+
288
+ /* translators: %1$s & %2$s are a Demo API URL */
289
+ printf( __( '<p> It seems the demo data server, <i><a href="%1$s">%2$s</a></i> is unreachable from your site.</p>', 'astra-sites' ), esc_url( Astra_Sites::$api_url ), esc_url( Astra_Sites::$api_url ) );
290
+
291
+ _e( '<p class="left-margin"> 1. Sometimes, simple page reload fixes any temporary issues. No kidding!</p>', 'astra-sites' );
292
+
293
+ _e( '<p class="left-margin"> 2. If that does not work, you will need to talk to your server administrator and check if demo server is being blocked by the firewall!</p>', 'astra-sites' );
294
+
295
+ /* translators: %1$s is a support link */
296
+ printf( __( '<p>If that does not help, please open up a <a href="%1$s" target="_blank">Support Ticket</a> and we will be glad take a closer look for you.</p>', 'astra-sites' ), esc_url( 'https://wpastra.com/support/?utm_source=demo-import-panel&utm_campaign=astra-sites&utm_medium=api-request-failed' ) );
297
+ ?>
298
+ </div>
299
+ </script>
300
+
301
+ <?php
302
+ /**
303
+ * TMPL - Site Down
304
+ */
305
+ ?>
306
+ <script type="text/template" id="tmpl-astra-site-down">
307
+ <div class="postbox astra-site-down">
308
+ <h2><?php _e( 'Under Maintenance..', 'astra-sites' ); ?></h2>
309
+ <p><?php _e( 'If you are seeing this message, most likely our servers are under routine maintenance and we will be back shortly. ', 'astra-sites' ); ?></p>
310
+ <p><?php _e( 'In rare case, it is possible your website is having trouble connecting with ours. If you need help, please feel free to get in touch with us from our website.', 'astra-sites' ); ?></p>
311
+ </div>
312
+ </script>
313
+
314
+ <?php
315
+ /**
316
+ * TMPL - Filters
317
+ */
318
+ ?>
319
+ <script type="text/template" id="tmpl-astra-site-filters">
320
+
321
+ <# if ( data ) { #>
322
+
323
+ <ul class="{{ data.args.wrapper_class }} {{ data.args.class }}">
324
+
325
+ <# if ( data.args.show_all ) { #>
326
+ <li>
327
+ <a href="#" data-group="all"> All </a>
328
+ </li>
329
+ <# } #>
330
+
331
+ <# for ( key in data.items ) { #>
332
+ <# if ( data.items[ key ].count ) { #>
333
+ <li>
334
+ <a href="#" data-group='{{ data.items[ key ].id }}' class="{{ data.items[ key ].name }}">
335
+ {{ data.items[ key ].name }}
336
+ </a>
337
+ </li>
338
+ <# } #>
339
+ <# } #>
340
+
341
+ </ul>
342
+ <# } #>
343
+ </script>
344
+
345
+ <?php
346
+ /**
347
+ * TMPL - List
348
+ */
349
+ ?>
350
+ <script type="text/template" id="tmpl-astra-sites-list">
351
+
352
+ <# if ( data.items.length ) { #>
353
+ <# for ( key in data.items ) { #>
354
+
355
+ <div class="theme astra-theme site-single {{ data.items[ key ].status }}" tabindex="0" aria-describedby="astra-theme-action astra-theme-name"
356
+ data-demo-id="{{{ data.items[ key ].id }}}"
357
+ data-demo-type="{{{ data.items[ key ]['astra-site-type'] }}}"
358
+ data-demo-url="{{{ data.items[ key ]['astra-site-url'] }}}"
359
+ data-demo-api="{{{ data.items[ key ]['_links']['self'][0]['href'] }}}"
360
+ data-demo-name="{{{ data.items[ key ].title.rendered }}}"
361
+ data-demo-slug="{{{ data.items[ key ].slug }}}"
362
+ data-screenshot="{{{ data.items[ key ]['featured-image-url'] }}}"
363
+ data-content="{{{ data.items[ key ].content.rendered }}}"
364
+ data-required-plugins="{{ JSON.stringify( data.items[ key ]['required-plugins'] ) }}"
365
+ data-groups=["{{ data.items[ key ].tags }}"]>
366
+ <input type="hidden" class="astra-site-options" value="{{ JSON.stringify(data.items[ key ]['astra-site-options-data'] ) }}" />
367
+ <input type="hidden" class="astra-enabled-extensions" value="{{ JSON.stringify(data.items[ key ]['astra-enabled-extensions'] ) }}" />
368
+
369
+ <div class="inner">
370
+ <span class="site-preview" data-href="{{ data.items[ key ]['astra-site-url'] }}?TB_iframe=true&width=600&height=550" data-title="{{ data.items[ key ].title.rendered }}">
371
+ <div class="theme-screenshot" style="background-image: url('{{ data.items[ key ]['featured-image-url'] }}');"></div>
372
+ </span>
373
+ <# if ( data.items[ key ]['astra-site-type'] ) { #>
374
+ <# var type = ( data.items[ key ]['astra-site-type'] !== 'premium' ) ? ( data.items[ key ]['astra-site-type'] ) : 'agency'; #>
375
+ <span class="site-type {{data.items[ key ]['astra-site-type']}}">{{ type }}</span>
376
+ <# } #>
377
+ <# if ( data.items[ key ].status ) { #>
378
+ <span class="status {{data.items[ key ].status}}">{{data.items[ key ].status}}</span>
379
+ <# } #>
380
+ <div class="theme-id-container">
381
+ <h3 class="theme-name" id="astra-theme-name"> {{{ data.items[ key ].title.rendered }}} </h3>
382
+ <div class="theme-actions">
383
+ <button class="button-primary button preview install-theme-preview"><?php esc_html_e( 'Preview', 'astra-sites' ); ?></button>
384
+ </div>
385
+ </div>
386
+ </div>
387
+ </div>
388
+ <# } #>
389
+ <# } else { #>
390
+ <p class="no-themes" style="display:block;">
391
+ <?php _e( 'No Demos found, Try a different search.', 'astra-sites' ); ?>
392
+ <span class="description">
393
+ <?php
394
+ /* translators: %1$s External Link */
395
+ printf( __( 'Don\'t see a site that you would like to import?<br><a target="_blank" href="%1$s">Please suggest us!</a>', 'astra-sites' ), esc_url( 'https://wpastra.com/sites-suggestions/?utm_source=demo-import-panel&utm_campaign=astra-sites&utm_medium=suggestions' ) );
396
+ ?>
397
+ </span>
398
+ </p>
399
+ <# } #>
400
+ </script>
401
+
402
+ <?php
403
+ /**
404
+ * TMPL - List
405
+ */
406
+ ?>
407
+ <script type="text/template" id="tmpl-astra-sites-suggestions">
408
+ <div class="theme astra-theme site-single astra-sites-suggestions">
409
+ <div class="inner">
410
+ <p>
411
+ <?php
412
+ /* translators: %1$s External Link */
413
+ printf( __( 'Don\'t see a site that you would like to import?<br><a target="_blank" href="%1$s">Please suggest us!</a>', 'astra-sites' ), esc_url( 'https://wpastra.com/sites-suggestions/?utm_source=demo-import-panel&utm_campaign=astra-sites&utm_medium=suggestions' ) );
414
+ ?>
415
+ </p>
416
+ </div>
417
+ </div>
418
+ </script>
419
+ <?php
420
+ wp_print_admin_notice_templates();
inc/lib/astra-notices/class-astra-notices.php CHANGED
@@ -1,334 +1,334 @@
1
- <?php
2
- /**
3
- * Astra Sites Notices
4
- *
5
- * Closing notice on click on `astra-notice-close` class.
6
- *
7
- * If notice has the data attribute `data-repeat-notice-after="%2$s"` then notice close for that SPECIFIC TIME.
8
- * If notice has NO data attribute `data-repeat-notice-after="%2$s"` then notice close for the CURRENT USER FOREVER.
9
- *
10
- * > Create custom close notice link in the notice markup. E.g.
11
- * `<a href="#" data-repeat-notice-after="<?php echo MONTH_IN_SECONDS; ?>" class="astra-notice-close">`
12
- * It close the notice for 30 days.
13
- *
14
- * @package Astra Sites
15
- * @since 1.4.0
16
- */
17
-
18
- if ( ! class_exists( 'Astra_Notices' ) ) :
19
-
20
- /**
21
- * Astra_Notices
22
- *
23
- * @since 1.4.0
24
- */
25
- class Astra_Notices {
26
-
27
- /**
28
- * Notices
29
- *
30
- * @access private
31
- * @var array Notices.
32
- * @since 1.4.0
33
- */
34
- private static $version = '1.1.3';
35
-
36
- /**
37
- * Notices
38
- *
39
- * @access private
40
- * @var array Notices.
41
- * @since 1.4.0
42
- */
43
- private static $notices = array();
44
-
45
- /**
46
- * Instance
47
- *
48
- * @access private
49
- * @var object Class object.
50
- * @since 1.4.0
51
- */
52
- private static $instance;
53
-
54
- /**
55
- * Initiator
56
- *
57
- * @since 1.4.0
58
- * @return object initialized object of class.
59
- */
60
- public static function get_instance() {
61
- if ( ! isset( self::$instance ) ) {
62
- self::$instance = new self;
63
- }
64
- return self::$instance;
65
- }
66
-
67
- /**
68
- * Constructor
69
- *
70
- * @since 1.4.0
71
- */
72
- public function __construct() {
73
- add_action( 'admin_notices', array( $this, 'show_notices' ), 30 );
74
- add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
75
- add_action( 'wp_ajax_astra-notice-dismiss', array( $this, 'dismiss_notice' ) );
76
- add_filter( 'wp_kses_allowed_html', array( $this, 'add_data_attributes' ), 10, 2 );
77
- }
78
-
79
- /**
80
- * Filters and Returns a list of allowed tags and attributes for a given context.
81
- *
82
- * @param Array $allowedposttags Array of allowed tags.
83
- * @param String $context Context type (explicit).
84
- * @since 1.4.0
85
- * @return Array
86
- */
87
- public function add_data_attributes( $allowedposttags, $context ) {
88
- $allowedposttags['a']['data-repeat-notice-after'] = true;
89
-
90
- return $allowedposttags;
91
- }
92
-
93
- /**
94
- * Add Notice.
95
- *
96
- * @since 1.4.0
97
- * @param array $args Notice arguments.
98
- * @return void
99
- */
100
- public static function add_notice( $args = array() ) {
101
- self::$notices[] = $args;
102
- }
103
-
104
- /**
105
- * Dismiss Notice.
106
- *
107
- * @since 1.4.0
108
- * @return void
109
- */
110
- public function dismiss_notice() {
111
- $notice_id = ( isset( $_POST['notice_id'] ) ) ? sanitize_key( $_POST['notice_id'] ) : '';
112
- $repeat_notice_after = ( isset( $_POST['repeat_notice_after'] ) ) ? absint( $_POST['repeat_notice_after'] ) : '';
113
-
114
- // Valid inputs?
115
- if ( ! empty( $notice_id ) ) {
116
-
117
- if ( ! empty( $repeat_notice_after ) ) {
118
- set_transient( $notice_id, true, $repeat_notice_after );
119
- } else {
120
- update_user_meta( get_current_user_id(), $notice_id, 'notice-dismissed' );
121
- }
122
-
123
- wp_send_json_success();
124
- }
125
-
126
- wp_send_json_error();
127
- }
128
-
129
- /**
130
- * Enqueue Scripts.
131
- *
132
- * @since 1.4.0
133
- * @return void
134
- */
135
- public function enqueue_scripts() {
136
- wp_register_script( 'astra-notices', self::_get_uri() . 'notices.js', array( 'jquery' ), self::$version, true );
137
- }
138
-
139
- /**
140
- * Rating priority sort
141
- *
142
- * @since 1.5.2
143
- * @param array $array1 array one.
144
- * @param array $array2 array two.
145
- * @return array
146
- */
147
- public function sort_notices( $array1, $array2 ) {
148
- if ( ! isset( $array1['priority'] ) ) {
149
- $array1['priority'] = 10;
150
- }
151
- if ( ! isset( $array2['priority'] ) ) {
152
- $array2['priority'] = 10;
153
- }
154
-
155
- return $array1['priority'] - $array2['priority'];
156
- }
157
-
158
- /**
159
- * Notice Types
160
- *
161
- * @since 1.4.0
162
- * @return void
163
- */
164
- public function show_notices() {
165
-
166
- $defaults = array(
167
- 'id' => '', // Optional, Notice ID. If empty it set `astra-notices-id-<$array-index>`.
168
- 'type' => 'info', // Optional, Notice type. Default `info`. Expected [info, warning, notice, error].
169
- 'message' => '', // Optional, Message.
170
- 'show_if' => true, // Optional, Show notice on custom condition. E.g. 'show_if' => if( is_admin() ) ? true, false, .
171
- 'repeat-notice-after' => '', // Optional, Dismiss-able notice time. It'll auto show after given time.
172
- 'display-notice-after' => false, // Optional, Dismiss-able notice time. It'll auto show after given time.
173
- 'class' => '', // Optional, Additional notice wrapper class.
174
- 'priority' => 10, // Priority of the notice.
175
- 'display-with-other-notices' => true, // Should the notice be displayed if other notices are being displayed from Astra_Notices.
176
- );
177
-
178
- // Count for the notices that are rendered.
179
- $notices_displayed = 0;
180
-
181
- // sort the array with priority.
182
- usort( self::$notices, array( $this, 'sort_notices' ) );
183
-
184
- foreach ( self::$notices as $key => $notice ) {
185
-
186
- $notice = wp_parse_args( $notice, $defaults );
187
-
188
- $notice['id'] = self::get_notice_id( $notice, $key );
189
-
190
- $notice['classes'] = self::get_wrap_classes( $notice );
191
-
192
- // Notices visible after transient expire.
193
- if ( isset( $notice['show_if'] ) && true === $notice['show_if'] ) {
194
-
195
- // don't display the notice if it is not supposed to be displayed with other notices.
196
- if ( 0 !== $notices_displayed && false === $notice['display-with-other-notices'] ) {
197
- continue;
198
- }
199
-
200
- if ( self::is_expired( $notice ) ) {
201
-
202
- self::markup( $notice );
203
- ++$notices_displayed;
204
- }
205
- }
206
- }
207
-
208
- }
209
-
210
- /**
211
- * Markup Notice.
212
- *
213
- * @since 1.4.0
214
- * @param array $notice Notice markup.
215
- * @return void
216
- */
217
- public static function markup( $notice = array() ) {
218
-
219
- wp_enqueue_script( 'astra-notices' );
220
-
221
- do_action( "astra_notice_before_markup_{$notice['id']}" );
222
-
223
- ?>
224
- <div id="<?php echo esc_attr( $notice['id'] ); ?>" class="<?php echo esc_attr( $notice['classes'] ); ?>" data-repeat-notice-after="<?php echo esc_attr( $notice['repeat-notice-after'] ); ?>">
225
- <div class="notice-container">
226
- <?php do_action( "astra_notice_inside_markup_{$notice['id']}" ); ?>
227
- <?php echo wp_kses_post( $notice['message'] ); ?>
228
- </div>
229
- </div>
230
- <?php
231
-
232
- do_action( "astra_notice_after_markup_{$notice['id']}" );
233
-
234
- }
235
-
236
- /**
237
- * Notice classes.
238
- *
239
- * @since 1.4.0
240
- *
241
- * @param array $notice Notice arguments.
242
- * @return array Notice wrapper classes.
243
- */
244
- private static function get_wrap_classes( $notice ) {
245
- $classes = array( 'astra-notice', 'notice', 'is-dismissible' );
246
- $classes[] = $notice['class'];
247
- if ( isset( $notice['type'] ) && '' !== $notice['type'] ) {
248
- $classes[] = 'notice-' . $notice['type'];
249
- }
250
-
251
- return esc_attr( implode( ' ', $classes ) );
252
- }
253
-
254
- /**
255
- * Get Notice ID.
256
- *
257
- * @since 1.4.0
258
- *
259
- * @param array $notice Notice arguments.
260
- * @param int $key Notice array index.
261
- * @return string Notice id.
262
- */
263
- private static function get_notice_id( $notice, $key ) {
264
- if ( isset( $notice['id'] ) && ! empty( $notice['id'] ) ) {
265
- return $notice['id'];
266
- }
267
-
268
- return 'astra-notices-id-' . $key;
269
- }
270
-
271
- /**
272
- * Is notice expired?
273
- *
274
- * @since 1.4.0
275
- *
276
- * @param array $notice Notice arguments.
277
- * @return boolean
278
- */
279
- private static function is_expired( $notice ) {
280
- $transient_status = get_transient( $notice['id'] );
281
-
282
- if ( false === $transient_status ) {
283
-
284
- if ( isset( $notice['display-notice-after'] ) && false !== $notice['display-notice-after'] ) {
285
-
286
- if ( 'delayed-notice' !== get_user_meta( get_current_user_id(), $notice['id'], true ) &&
287
- 'notice-dismissed' !== get_user_meta( get_current_user_id(), $notice['id'], true ) ) {
288
- set_transient( $notice['id'], 'delayed-notice', $notice['display-notice-after'] );
289
- update_user_meta( get_current_user_id(), $notice['id'], 'delayed-notice' );
290
-
291
- return false;
292
- }
293
- }
294
-
295
- // Check the user meta status if current notice is dismissed or delay completed.
296
- $meta_status = get_user_meta( get_current_user_id(), $notice['id'], true );
297
-
298
- if ( empty( $meta_status ) || 'delayed-notice' === $meta_status ) {
299
- return true;
300
- }
301
- }
302
-
303
- return false;
304
- }
305
-
306
- /**
307
- * Get URI
308
- *
309
- * @return mixed URL.
310
- */
311
- public static function _get_uri() {
312
- $path = wp_normalize_path( dirname( __FILE__ ) );
313
- $theme_dir = wp_normalize_path( get_template_directory() );
314
- $plugin_dir = wp_normalize_path( WP_PLUGIN_DIR );
315
-
316
- if ( strpos( $path, $theme_dir ) !== false ) {
317
- return trailingslashit( get_template_directory_uri() . str_replace( $theme_dir, '', $path ) );
318
- } elseif ( strpos( $path, $plugin_dir ) !== false ) {
319
- return plugin_dir_url( __FILE__ );
320
- } elseif ( strpos( $path, dirname( plugin_basename( __FILE__ ) ) ) !== false ) {
321
- return plugin_dir_url( __FILE__ );
322
- }
323
-
324
- return;
325
- }
326
-
327
- }
328
-
329
- /**
330
- * Kicking this off by calling 'get_instance()' method
331
- */
332
- Astra_Notices::get_instance();
333
-
334
- endif;
1
+ <?php
2
+ /**
3
+ * Astra Sites Notices
4
+ *
5
+ * Closing notice on click on `astra-notice-close` class.
6
+ *
7
+ * If notice has the data attribute `data-repeat-notice-after="%2$s"` then notice close for that SPECIFIC TIME.
8
+ * If notice has NO data attribute `data-repeat-notice-after="%2$s"` then notice close for the CURRENT USER FOREVER.
9
+ *
10
+ * > Create custom close notice link in the notice markup. E.g.
11
+ * `<a href="#" data-repeat-notice-after="<?php echo MONTH_IN_SECONDS; ?>" class="astra-notice-close">`
12
+ * It close the notice for 30 days.
13
+ *
14
+ * @package Astra Sites
15
+ * @since 1.4.0
16
+ */
17
+
18
+ if ( ! class_exists( 'Astra_Notices' ) ) :
19
+
20
+ /**
21
+ * Astra_Notices
22
+ *
23
+ * @since 1.4.0
24
+ */
25
+ class Astra_Notices {
26
+
27
+ /**
28
+ * Notices
29
+ *
30
+ * @access private
31
+ * @var array Notices.
32
+ * @since 1.4.0
33
+ */
34
+ private static $version = '1.1.3';
35
+
36
+ /**
37
+ * Notices
38
+ *
39
+ * @access private
40
+ * @var array Notices.
41
+ * @since 1.4.0
42
+ */
43
+ private static $notices = array();
44
+
45
+ /**
46
+ * Instance
47
+ *
48
+ * @access private
49
+ * @var object Class object.
50
+ * @since 1.4.0
51
+ */
52
+ private static $instance;
53
+
54
+ /**
55
+ * Initiator
56
+ *
57
+ * @since 1.4.0
58
+ * @return object initialized object of class.
59
+ */
60
+ public static function get_instance() {
61
+ if ( ! isset( self::$instance ) ) {
62
+ self::$instance = new self;
63
+ }
64
+ return self::$instance;
65
+ }
66
+
67
+ /**
68
+ * Constructor
69
+ *
70
+ * @since 1.4.0
71
+ */
72
+ public function __construct() {
73
+ add_action( 'admin_notices', array( $this, 'show_notices' ), 30 );
74
+ add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
75
+ add_action( 'wp_ajax_astra-notice-dismiss', array( $this, 'dismiss_notice' ) );
76
+ add_filter( 'wp_kses_allowed_html', array( $this, 'add_data_attributes' ), 10, 2 );
77
+ }
78
+
79
+ /**
80
+ * Filters and Returns a list of allowed tags and attributes for a given context.
81
+ *
82
+ * @param Array $allowedposttags Array of allowed tags.
83
+ * @param String $context Context type (explicit).
84
+ * @since 1.4.0
85
+ * @return Array
86
+ */
87
+ public function add_data_attributes( $allowedposttags, $context ) {
88
+ $allowedposttags['a']['data-repeat-notice-after'] = true;
89
+
90
+ return $allowedposttags;
91
+ }
92
+
93
+ /**
94
+ * Add Notice.
95
+ *
96
+ * @since 1.4.0
97
+ * @param array $args Notice arguments.
98
+ * @return void
99
+ */
100
+ public static function add_notice( $args = array() ) {
101
+ self::$notices[] = $args;
102
+ }
103
+
104
+ /**
105
+ * Dismiss Notice.
106
+ *
107
+ * @since 1.4.0
108
+ * @return void
109
+ */
110
+ public function dismiss_notice() {
111
+ $notice_id = ( isset( $_POST['notice_id'] ) ) ? sanitize_key( $_POST['notice_id'] ) : '';
112
+ $repeat_notice_after = ( isset( $_POST['repeat_notice_after'] ) ) ? absint( $_POST['repeat_notice_after'] ) : '';
113
+
114
+ // Valid inputs?
115
+ if ( ! empty( $notice_id ) ) {
116
+
117
+ if ( ! empty( $repeat_notice_after ) ) {
118
+ set_transient( $notice_id, true, $repeat_notice_after );
119
+ } else {
120
+ update_user_meta( get_current_user_id(), $notice_id, 'notice-dismissed' );
121
+ }
122
+
123
+ wp_send_json_success();
124
+ }
125
+
126
+ wp_send_json_error();
127
+ }
128
+
129
+ /**
130
+ * Enqueue Scripts.
131
+ *
132
+ * @since 1.4.0
133
+ * @return void
134
+ */
135
+ public function enqueue_scripts() {
136
+ wp_register_script( 'astra-notices', self::_get_uri() . 'notices.js', array( 'jquery' ), self::$version, true );
137
+ }
138
+
139
+ /**
140
+ * Rating priority sort
141
+ *
142
+ * @since 1.5.2
143
+ * @param array $array1 array one.
144
+ * @param array $array2 array two.
145
+ * @return array
146
+ */
147
+ public function sort_notices( $array1, $array2 ) {
148
+ if ( ! isset( $array1['priority'] ) ) {
149
+ $array1['priority'] = 10;
150
+ }
151
+ if ( ! isset( $array2['priority'] ) ) {
152
+ $array2['priority'] = 10;
153
+ }
154
+
155
+ return $array1['priority'] - $array2['priority'];
156
+ }
157
+
158
+ /**
159
+ * Notice Types
160
+ *
161
+ * @since 1.4.0
162
+ * @return void
163
+ */
164
+ public function show_notices() {
165
+
166
+ $defaults = array(
167
+ 'id' => '', // Optional, Notice ID. If empty it set `astra-notices-id-<$array-index>`.
168
+ 'type' => 'info', // Optional, Notice type. Default `info`. Expected [info, warning, notice, error].
169
+ 'message' => '', // Optional, Message.
170
+ 'show_if' => true, // Optional, Show notice on custom condition. E.g. 'show_if' => if( is_admin() ) ? true, false, .
171
+ 'repeat-notice-after' => '', // Optional, Dismiss-able notice time. It'll auto show after given time.
172
+ 'display-notice-after' => false, // Optional, Dismiss-able notice time. It'll auto show after given time.
173
+ 'class' => '', // Optional, Additional notice wrapper class.
174
+ 'priority' => 10, // Priority of the notice.
175
+ 'display-with-other-notices' => true, // Should the notice be displayed if other notices are being displayed from Astra_Notices.
176
+ );
177
+
178
+ // Count for the notices that are rendered.
179
+ $notices_displayed = 0;
180
+
181
+ // sort the array with priority.
182
+ usort( self::$notices, array( $this, 'sort_notices' ) );
183
+
184
+ foreach ( self::$notices as $key => $notice ) {
185
+
186
+ $notice = wp_parse_args( $notice, $defaults );
187
+
188
+ $notice['id'] = self::get_notice_id( $notice, $key );
189
+
190
+ $notice['classes'] = self::get_wrap_classes( $notice );
191
+
192
+ // Notices visible after transient expire.
193
+ if ( isset( $notice['show_if'] ) && true === $notice['show_if'] ) {
194
+
195
+ // don't display the notice if it is not supposed to be displayed with other notices.
196
+ if ( 0 !== $notices_displayed && false === $notice['display-with-other-notices'] ) {
197
+ continue;
198
+ }
199
+
200
+ if ( self::is_expired( $notice ) ) {
201
+
202
+ self::markup( $notice );
203
+ ++$notices_displayed;
204
+ }
205
+ }
206
+ }
207
+
208
+ }
209
+
210
+ /**
211
+ * Markup Notice.
212
+ *
213
+ * @since 1.4.0
214
+ * @param array $notice Notice markup.
215
+ * @return void
216
+ */
217
+ public static function markup( $notice = array() ) {
218
+
219
+ wp_enqueue_script( 'astra-notices' );
220
+
221
+ do_action( "astra_notice_before_markup_{$notice['id']}" );
222
+
223
+ ?>
224
+ <div id="<?php echo esc_attr( $notice['id'] ); ?>" class="<?php echo esc_attr( $notice['classes'] ); ?>" data-repeat-notice-after="<?php echo esc_attr( $notice['repeat-notice-after'] ); ?>">
225
+ <div class="notice-container">
226
+ <?php do_action( "astra_notice_inside_markup_{$notice['id']}" ); ?>
227
+ <?php echo wp_kses_post( $notice['message'] ); ?>
228
+ </div>
229
+ </div>
230
+ <?php
231
+
232
+ do_action( "astra_notice_after_markup_{$notice['id']}" );
233
+
234
+ }
235
+
236
+ /**
237
+ * Notice classes.
238
+ *
239
+ * @since 1.4.0
240
+ *
241
+ * @param array $notice Notice arguments.
242
+ * @return array Notice wrapper classes.
243
+ */
244
+ private static function get_wrap_classes( $notice ) {
245
+ $classes = array( 'astra-notice', 'notice', 'is-dismissible' );
246
+ $classes[] = $notice['class'];
247
+ if ( isset( $notice['type'] ) && '' !== $notice['type'] ) {
248
+ $classes[] = 'notice-' . $notice['type'];
249
+ }
250
+
251
+ return esc_attr( implode( ' ', $classes ) );
252
+ }
253
+
254
+ /**
255
+ * Get Notice ID.
256
+ *
257
+ * @since 1.4.0
258
+ *
259
+ * @param array $notice Notice arguments.
260
+ * @param int $key Notice array index.
261
+ * @return string Notice id.
262
+ */
263
+ private static function get_notice_id( $notice, $key ) {
264
+ if ( isset( $notice['id'] ) && ! empty( $notice['id'] ) ) {
265
+ return $notice['id'];
266
+ }
267
+
268
+ return 'astra-notices-id-' . $key;
269
+ }
270
+
271
+ /**
272
+ * Is notice expired?
273
+ *
274
+ * @since 1.4.0
275
+ *
276
+ * @param array $notice Notice arguments.
277
+ * @return boolean
278
+ */
279
+ private static function is_expired( $notice ) {
280
+ $transient_status = get_transient( $notice['id'] );
281
+
282
+ if ( false === $transient_status ) {
283
+
284
+ if ( isset( $notice['display-notice-after'] ) && false !== $notice['display-notice-after'] ) {
285
+
286
+ if ( 'delayed-notice' !== get_user_meta( get_current_user_id(), $notice['id'], true ) &&
287
+ 'notice-dismissed' !== get_user_meta( get_current_user_id(), $notice['id'], true ) ) {
288
+ set_transient( $notice['id'], 'delayed-notice', $notice['display-notice-after'] );
289
+ update_user_meta( get_current_user_id(), $notice['id'], 'delayed-notice' );
290
+
291
+ return false;
292
+ }
293
+ }
294
+
295
+ // Check the user meta status if current notice is dismissed or delay completed.
296
+ $meta_status = get_user_meta( get_current_user_id(), $notice['id'], true );
297
+
298
+ if ( empty( $meta_status ) || 'delayed-notice' === $meta_status ) {
299
+ return true;
300
+ }
301
+ }
302
+
303
+ return false;
304
+ }
305
+
306
+ /**
307
+ * Get URI
308
+ *
309
+ * @return mixed URL.
310
+ */
311
+ public static function _get_uri() {
312
+ $path = wp_normalize_path( dirname( __FILE__ ) );
313
+ $theme_dir = wp_normalize_path( get_template_directory() );
314
+ $plugin_dir = wp_normalize_path( WP_PLUGIN_DIR );
315
+
316
+ if ( strpos( $path, $theme_dir ) !== false ) {
317
+ return trailingslashit( get_template_directory_uri() . str_replace( $theme_dir, '', $path ) );
318
+ } elseif ( strpos( $path, $plugin_dir ) !== false ) {
319
+ return plugin_dir_url( __FILE__ );
320
+ } elseif ( strpos( $path, dirname( plugin_basename( __FILE__ ) ) ) !== false ) {
321
+ return plugin_dir_url( __FILE__ );
322
+ }
323
+
324
+ return;
325
+ }
326
+
327
+ }
328
+
329
+ /**
330
+ * Kicking this off by calling 'get_instance()' method
331
+ */
332
+ Astra_Notices::get_instance();
333
+
334
+ endif;
languages/astra-sites.pot CHANGED
@@ -3,9 +3,9 @@
3
  msgid ""
4
  msgstr ""
5
  "Project-Id-Version: Astra Starter Sites – Elementor, Beaver Builder & "
6
- "Gutenberg Templates 1.3.5\n"
7
  "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/astra-sites\n"
8
- "POT-Creation-Date: 2019-04-18 06:55:00+00:00\n"
9
  "MIME-Version: 1.0\n"
10
  "Content-Type: text/plain; charset=utf-8\n"
11
  "Content-Transfer-Encoding: 8bit\n"
@@ -23,27 +23,27 @@ msgstr ""
23
  "X-Poedit-SearchPath-0: .\n"
24
  "X-Poedit-Bookmarks: \n"
25
  "X-Textdomain-Support: yes\n"
26
- "X-Generator: grunt-wp-i18n1.0.0\n"
27
 
28
  #: astra-sites.php:18
29
  msgid "Astra Sites"
30
  msgstr ""
31
 
32
- #: inc/classes/class-astra-sites-importer-log.php:254
33
  msgid "Enabled"
34
  msgstr ""
35
 
36
- #: inc/classes/class-astra-sites-importer-log.php:257
37
  msgid "Disabled"
38
  msgstr ""
39
 
40
- #: inc/classes/class-astra-sites-importer-log.php:342
41
- #: inc/classes/class-astra-sites-importer-log.php:399
42
  msgid "Yes"
43
  msgstr ""
44
 
45
- #: inc/classes/class-astra-sites-importer-log.php:345
46
- #: inc/classes/class-astra-sites-importer-log.php:402
47
  msgid "No"
48
  msgstr ""
49
 
@@ -177,39 +177,39 @@ msgstr ""
177
  msgid "See Library"
178
  msgstr ""
179
 
180
- #: inc/classes/class-astra-sites.php:263
181
  msgid "Installed! Activating.."
182
  msgstr ""
183
 
184
- #: inc/classes/class-astra-sites.php:264
185
  msgid "Activating.."
186
  msgstr ""
187
 
188
- #: inc/classes/class-astra-sites.php:265
189
  msgid "Activated! Reloading.."
190
  msgstr ""
191
 
192
- #: inc/classes/class-astra-sites.php:266
193
  msgid "Installing.."
194
  msgstr ""
195
 
196
- #: inc/classes/class-astra-sites.php:299
197
  msgid "Page Builder"
198
  msgstr ""
199
 
200
- #: inc/classes/class-astra-sites.php:304
201
  msgid "Categories"
202
  msgstr ""
203
 
204
- #: inc/classes/class-astra-sites.php:345
205
  msgid "Get Agency Bundle"
206
  msgstr ""
207
 
208
- #: inc/classes/class-astra-sites.php:347
209
  msgid "Upgrade"
210
  msgstr ""
211
 
212
- #: inc/classes/class-astra-sites.php:354
213
  #. translators: %s are HTML tags.
214
  msgid ""
215
  "%1$sRequired XMLReader PHP extension is missing on your server!%2$sAstra "
@@ -218,201 +218,201 @@ msgid ""
218
  "XMLReader PHP extension."
219
  msgstr ""
220
 
221
- #: inc/classes/class-astra-sites.php:355
222
  msgid ""
223
  "Warning! Astra Site Import process is not complete. Don't close the window "
224
  "until import process complete. Do you still want to leave the window?"
225
  msgstr ""
226
 
227
- #: inc/classes/class-astra-sites.php:356
228
  msgid "Error!"
229
  msgstr ""
230
 
231
- #: inc/classes/class-astra-sites.php:357
232
  msgid "Error! Read Possibilities."
233
  msgstr ""
234
 
235
- #: inc/classes/class-astra-sites.php:359
236
  msgid "Done! View Site"
237
  msgstr ""
238
 
239
- #: inc/classes/class-astra-sites.php:360
240
  msgid "Activating"
241
  msgstr ""
242
 
243
- #: inc/classes/class-astra-sites.php:361
244
  msgid "Active"
245
  msgstr ""
246
 
247
- #: inc/classes/class-astra-sites.php:362
248
  msgid "Import failed."
249
  msgstr ""
250
 
251
- #: inc/classes/class-astra-sites.php:363
252
  msgid "Import failed. See error log."
253
  msgstr ""
254
 
255
- #: inc/classes/class-astra-sites.php:364
256
  msgid "Import This Site"
257
  msgstr ""
258
 
259
- #: inc/classes/class-astra-sites.php:365 inc/classes/class-astra-sites.php:381
260
  msgid "Importing.."
261
  msgstr ""
262
 
263
- #: inc/classes/class-astra-sites.php:366 inc/includes/admin-page.php:161
264
  msgid "Read more"
265
  msgstr ""
266
 
267
- #: inc/classes/class-astra-sites.php:367
268
  msgid "Hide"
269
  msgstr ""
270
 
271
- #: inc/classes/class-astra-sites.php:368
272
  msgid "There was a problem receiving a response from server."
273
  msgstr ""
274
 
275
- #: inc/classes/class-astra-sites.php:369 inc/includes/admin-page.php:391
276
  msgid "No Demos found, Try a different search."
277
  msgstr ""
278
 
279
- #: inc/classes/class-astra-sites.php:372
280
  msgid "Installing plugin "
281
  msgstr ""
282
 
283
- #: inc/classes/class-astra-sites.php:373
284
  msgid "Plugin installed!"
285
  msgstr ""
286
 
287
- #: inc/classes/class-astra-sites.php:374
288
  msgid "Activating plugin "
289
  msgstr ""
290
 
291
- #: inc/classes/class-astra-sites.php:375
292
  msgid "Plugin activated "
293
  msgstr ""
294
 
295
- #: inc/classes/class-astra-sites.php:376
296
  msgid "Bulk plugin activation..."
297
  msgstr ""
298
 
299
- #: inc/classes/class-astra-sites.php:377
300
  msgid "Plugin activate - "
301
  msgstr ""
302
 
303
- #: inc/classes/class-astra-sites.php:378
304
  msgid "Error! While activating plugin - "
305
  msgstr ""
306
 
307
- #: inc/classes/class-astra-sites.php:379
308
  msgid "Bulk plugin installation..."
309
  msgstr ""
310
 
311
- #: inc/classes/class-astra-sites.php:380
312
  msgid "Site API "
313
  msgstr ""
314
 
315
- #: inc/classes/class-astra-sites.php:382
316
  msgid "Processing requests..."
317
  msgstr ""
318
 
319
- #: inc/classes/class-astra-sites.php:383
320
  msgid "Importing \"Customizer Settings\"..."
321
  msgstr ""
322
 
323
- #: inc/classes/class-astra-sites.php:384
324
  msgid "Imported customizer settings!"
325
  msgstr ""
326
 
327
- #: inc/classes/class-astra-sites.php:385
328
  msgid "Importing \"Contact Forms\"..."
329
  msgstr ""
330
 
331
- #: inc/classes/class-astra-sites.php:386
332
  msgid "Imported Contact Forms!"
333
  msgstr ""
334
 
335
- #: inc/classes/class-astra-sites.php:387
336
  msgid "Preparing \"XML\" Data..."
337
  msgstr ""
338
 
339
- #: inc/classes/class-astra-sites.php:388
340
  msgid "Set XML data!"
341
  msgstr ""
342
 
343
- #: inc/classes/class-astra-sites.php:389
344
  msgid "Importing \"XML\"..."
345
  msgstr ""
346
 
347
- #: inc/classes/class-astra-sites.php:390
348
  msgid "Imported XML!"
349
  msgstr ""
350
 
351
- #: inc/classes/class-astra-sites.php:391
352
  msgid "Importing \"Options\"..."
353
  msgstr ""
354
 
355
- #: inc/classes/class-astra-sites.php:392
356
  msgid "Imported Options!"
357
  msgstr ""
358
 
359
- #: inc/classes/class-astra-sites.php:393
360
  msgid "Importing \"Widgets\"..."
361
  msgstr ""
362
 
363
- #: inc/classes/class-astra-sites.php:394
364
  msgid "Imported Widgets!"
365
  msgstr ""
366
 
367
- #: inc/classes/class-astra-sites.php:396
368
  msgid "View site: "
369
  msgstr ""
370
 
371
- #: inc/classes/class-astra-sites.php:397
372
  msgid "Getting Site Information.."
373
  msgstr ""
374
 
375
- #: inc/classes/class-astra-sites.php:398
376
  msgid "Importing Customizer Settings.."
377
  msgstr ""
378
 
379
- #: inc/classes/class-astra-sites.php:399
380
  msgid "Importing Contact Forms.."
381
  msgstr ""
382
 
383
- #: inc/classes/class-astra-sites.php:400
384
  msgid "Setting up import data.."
385
  msgstr ""
386
 
387
- #: inc/classes/class-astra-sites.php:401
388
  msgid "Importing Content.."
389
  msgstr ""
390
 
391
- #: inc/classes/class-astra-sites.php:402
392
  msgid "Importing Site Options.."
393
  msgstr ""
394
 
395
- #: inc/classes/class-astra-sites.php:403
396
  msgid "Importing Widgets.."
397
  msgstr ""
398
 
399
- #: inc/classes/class-astra-sites.php:404
400
  msgid "Import Complete.."
401
  msgstr ""
402
 
403
- #: inc/classes/class-astra-sites.php:405
404
  msgid "Previewing "
405
  msgstr ""
406
 
407
- #: inc/classes/class-astra-sites.php:406
408
  msgid "See Error Log &rarr;"
409
  msgstr ""
410
 
411
- #: inc/classes/class-astra-sites.php:440
412
  msgid "No plugin specified"
413
  msgstr ""
414
 
415
- #: inc/classes/class-astra-sites.php:469
416
  msgid "Plugin Activated"
417
  msgstr ""
418
 
@@ -816,13 +816,13 @@ msgstr ""
816
  msgid "http://www.brainstormforce.com"
817
  msgstr ""
818
 
819
- #: inc/classes/class-astra-sites-importer-log.php:275
820
  #. translators: %1$s Memory Limit, %2$s Recommended memory limit.
821
  msgctxt "Recommended Memory Limit"
822
  msgid "Current memory limit %1$s. We recommend setting memory to at least %2$s."
823
  msgstr ""
824
 
825
- #: inc/classes/class-astra-sites-importer-log.php:356
826
  msgctxt "PHP Version"
827
  msgid "We recommend to use php 5.4 or higher"
828
  msgstr ""
3
  msgid ""
4
  msgstr ""
5
  "Project-Id-Version: Astra Starter Sites – Elementor, Beaver Builder & "
6
+ "Gutenberg Templates 1.3.6\n"
7
  "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/astra-sites\n"
8
+ "POT-Creation-Date: 2019-04-19 10:24:46+00:00\n"
9
  "MIME-Version: 1.0\n"
10
  "Content-Type: text/plain; charset=utf-8\n"
11
  "Content-Transfer-Encoding: 8bit\n"
23
  "X-Poedit-SearchPath-0: .\n"
24
  "X-Poedit-Bookmarks: \n"
25
  "X-Textdomain-Support: yes\n"
26
+ "X-Generator: grunt-wp-i18n 1.0.3\n"
27
 
28
  #: astra-sites.php:18
29
  msgid "Astra Sites"
30
  msgstr ""
31
 
32
+ #: inc/classes/class-astra-sites-importer-log.php:255
33
  msgid "Enabled"
34
  msgstr ""
35
 
36
+ #: inc/classes/class-astra-sites-importer-log.php:258
37
  msgid "Disabled"
38
  msgstr ""
39
 
40
+ #: inc/classes/class-astra-sites-importer-log.php:343
41
+ #: inc/classes/class-astra-sites-importer-log.php:400
42
  msgid "Yes"
43
  msgstr ""
44
 
45
+ #: inc/classes/class-astra-sites-importer-log.php:346
46
+ #: inc/classes/class-astra-sites-importer-log.php:403
47
  msgid "No"
48
  msgstr ""
49
 
177
  msgid "See Library"
178
  msgstr ""
179
 
180
+ #: inc/classes/class-astra-sites.php:262
181
  msgid "Installed! Activating.."
182
  msgstr ""
183
 
184
+ #: inc/classes/class-astra-sites.php:263
185
  msgid "Activating.."
186
  msgstr ""
187
 
188
+ #: inc/classes/class-astra-sites.php:264
189
  msgid "Activated! Reloading.."
190
  msgstr ""
191
 
192
+ #: inc/classes/class-astra-sites.php:265
193
  msgid "Installing.."
194
  msgstr ""
195
 
196
+ #: inc/classes/class-astra-sites.php:298
197
  msgid "Page Builder"
198
  msgstr ""
199
 
200
+ #: inc/classes/class-astra-sites.php:303
201
  msgid "Categories"
202
  msgstr ""
203
 
204
+ #: inc/classes/class-astra-sites.php:344
205
  msgid "Get Agency Bundle"
206
  msgstr ""
207
 
208
+ #: inc/classes/class-astra-sites.php:346
209
  msgid "Upgrade"
210
  msgstr ""
211
 
212
+ #: inc/classes/class-astra-sites.php:353
213
  #. translators: %s are HTML tags.
214
  msgid ""
215
  "%1$sRequired XMLReader PHP extension is missing on your server!%2$sAstra "
218
  "XMLReader PHP extension."
219
  msgstr ""
220
 
221
+ #: inc/classes/class-astra-sites.php:354
222
  msgid ""
223
  "Warning! Astra Site Import process is not complete. Don't close the window "
224
  "until import process complete. Do you still want to leave the window?"
225
  msgstr ""
226
 
227
+ #: inc/classes/class-astra-sites.php:355
228
  msgid "Error!"
229
  msgstr ""
230
 
231
+ #: inc/classes/class-astra-sites.php:356
232
  msgid "Error! Read Possibilities."
233
  msgstr ""
234
 
235
+ #: inc/classes/class-astra-sites.php:358
236
  msgid "Done! View Site"
237
  msgstr ""
238
 
239
+ #: inc/classes/class-astra-sites.php:359
240
  msgid "Activating"
241
  msgstr ""
242
 
243
+ #: inc/classes/class-astra-sites.php:360
244
  msgid "Active"
245
  msgstr ""
246
 
247
+ #: inc/classes/class-astra-sites.php:361
248
  msgid "Import failed."
249
  msgstr ""
250
 
251
+ #: inc/classes/class-astra-sites.php:362
252
  msgid "Import failed. See error log."
253
  msgstr ""
254
 
255
+ #: inc/classes/class-astra-sites.php:363
256
  msgid "Import This Site"
257
  msgstr ""
258
 
259
+ #: inc/classes/class-astra-sites.php:364 inc/classes/class-astra-sites.php:380
260
  msgid "Importing.."
261
  msgstr ""
262
 
263
+ #: inc/classes/class-astra-sites.php:365 inc/includes/admin-page.php:161
264
  msgid "Read more"
265
  msgstr ""
266
 
267
+ #: inc/classes/class-astra-sites.php:366
268
  msgid "Hide"
269
  msgstr ""
270
 
271
+ #: inc/classes/class-astra-sites.php:367
272
  msgid "There was a problem receiving a response from server."
273
  msgstr ""
274
 
275
+ #: inc/classes/class-astra-sites.php:368 inc/includes/admin-page.php:391
276
  msgid "No Demos found, Try a different search."
277
  msgstr ""
278
 
279
+ #: inc/classes/class-astra-sites.php:371
280
  msgid "Installing plugin "
281
  msgstr ""
282
 
283
+ #: inc/classes/class-astra-sites.php:372
284
  msgid "Plugin installed!"
285
  msgstr ""
286
 
287
+ #: inc/classes/class-astra-sites.php:373
288
  msgid "Activating plugin "
289
  msgstr ""
290
 
291
+ #: inc/classes/class-astra-sites.php:374
292
  msgid "Plugin activated "
293
  msgstr ""
294
 
295
+ #: inc/classes/class-astra-sites.php:375
296
  msgid "Bulk plugin activation..."
297
  msgstr ""
298
 
299
+ #: inc/classes/class-astra-sites.php:376
300
  msgid "Plugin activate - "
301
  msgstr ""
302
 
303
+ #: inc/classes/class-astra-sites.php:377
304
  msgid "Error! While activating plugin - "
305
  msgstr ""
306
 
307
+ #: inc/classes/class-astra-sites.php:378
308
  msgid "Bulk plugin installation..."
309
  msgstr ""
310
 
311
+ #: inc/classes/class-astra-sites.php:379
312
  msgid "Site API "
313
  msgstr ""
314
 
315
+ #: inc/classes/class-astra-sites.php:381
316
  msgid "Processing requests..."
317
  msgstr ""
318
 
319
+ #: inc/classes/class-astra-sites.php:382
320
  msgid "Importing \"Customizer Settings\"..."
321
  msgstr ""
322
 
323
+ #: inc/classes/class-astra-sites.php:383
324
  msgid "Imported customizer settings!"
325
  msgstr ""
326
 
327
+ #: inc/classes/class-astra-sites.php:384
328
  msgid "Importing \"Contact Forms\"..."
329
  msgstr ""
330
 
331
+ #: inc/classes/class-astra-sites.php:385
332
  msgid "Imported Contact Forms!"
333
  msgstr ""
334
 
335
+ #: inc/classes/class-astra-sites.php:386
336
  msgid "Preparing \"XML\" Data..."
337
  msgstr ""
338
 
339
+ #: inc/classes/class-astra-sites.php:387
340
  msgid "Set XML data!"
341
  msgstr ""
342
 
343
+ #: inc/classes/class-astra-sites.php:388
344
  msgid "Importing \"XML\"..."
345
  msgstr ""
346
 
347
+ #: inc/classes/class-astra-sites.php:389
348
  msgid "Imported XML!"
349
  msgstr ""
350
 
351
+ #: inc/classes/class-astra-sites.php:390
352
  msgid "Importing \"Options\"..."
353
  msgstr ""
354
 
355
+ #: inc/classes/class-astra-sites.php:391
356
  msgid "Imported Options!"
357
  msgstr ""
358
 
359
+ #: inc/classes/class-astra-sites.php:392
360
  msgid "Importing \"Widgets\"..."
361
  msgstr ""
362
 
363
+ #: inc/classes/class-astra-sites.php:393
364
  msgid "Imported Widgets!"
365
  msgstr ""
366
 
367
+ #: inc/classes/class-astra-sites.php:395
368
  msgid "View site: "
369
  msgstr ""
370
 
371
+ #: inc/classes/class-astra-sites.php:396
372
  msgid "Getting Site Information.."
373
  msgstr ""
374
 
375
+ #: inc/classes/class-astra-sites.php:397
376
  msgid "Importing Customizer Settings.."
377
  msgstr ""
378
 
379
+ #: inc/classes/class-astra-sites.php:398
380
  msgid "Importing Contact Forms.."
381
  msgstr ""
382
 
383
+ #: inc/classes/class-astra-sites.php:399
384
  msgid "Setting up import data.."
385
  msgstr ""
386
 
387
+ #: inc/classes/class-astra-sites.php:400
388
  msgid "Importing Content.."
389
  msgstr ""
390
 
391
+ #: inc/classes/class-astra-sites.php:401
392
  msgid "Importing Site Options.."
393
  msgstr ""
394
 
395
+ #: inc/classes/class-astra-sites.php:402
396
  msgid "Importing Widgets.."
397
  msgstr ""
398
 
399
+ #: inc/classes/class-astra-sites.php:403
400
  msgid "Import Complete.."
401
  msgstr ""
402
 
403
+ #: inc/classes/class-astra-sites.php:404
404
  msgid "Previewing "
405
  msgstr ""
406
 
407
+ #: inc/classes/class-astra-sites.php:405
408
  msgid "See Error Log &rarr;"
409
  msgstr ""
410
 
411
+ #: inc/classes/class-astra-sites.php:439
412
  msgid "No plugin specified"
413
  msgstr ""
414
 
415
+ #: inc/classes/class-astra-sites.php:468
416
  msgid "Plugin Activated"
417
  msgstr ""
418
 
816
  msgid "http://www.brainstormforce.com"
817
  msgstr ""
818
 
819
+ #: inc/classes/class-astra-sites-importer-log.php:276
820
  #. translators: %1$s Memory Limit, %2$s Recommended memory limit.
821
  msgctxt "Recommended Memory Limit"
822
  msgid "Current memory limit %1$s. We recommend setting memory to at least %2$s."
823
  msgstr ""
824
 
825
+ #: inc/classes/class-astra-sites-importer-log.php:357
826
  msgctxt "PHP Version"
827
  msgid "We recommend to use php 5.4 or higher"
828
  msgstr ""
readme.txt CHANGED
@@ -4,8 +4,8 @@ Donate link: https://wpastra.com/pro/
4
  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.1
8
- Stable tag: 1.3.5
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
@@ -117,6 +117,10 @@ We are open to suggestions and would love to work on topics that our users are l
117
 
118
  == Changelog ==
119
 
 
 
 
 
120
  v1.3.5 - 18-April-2019
121
  - Improvement: Updated page builder selection screen UI.
122
  - Improvement: Showing import process on separate window. In which we can see all the current import process.
4
  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.1.1
8
+ Stable tag: 1.3.6
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
117
 
118
  == Changelog ==
119
 
120
+ v1.3.6 - 19-April-2019
121
+ - Fix: After Import UAG - Post Grid categories do not retain issue fixed
122
+ - Fix: Premium Sites not importing due to invalid URL error.
123
+
124
  v1.3.5 - 18-April-2019
125
  - Improvement: Updated page builder selection screen UI.
126
  - Improvement: Showing import process on separate window. In which we can see all the current import process.