Advanced Import : One Click Import for WordPress or Theme Demo Data - Version 1.2.5

Version Description

  • 2020-11-11 =
  • Updated : Hook attributes, control each demo import. Now developer can provide user template kit separately. View Example : CosmosWP Template kits
  • Updated : PHPCS
  • Updated : Some minor design
  • Updated : Minor changes
Download this release

Release Info

Developer addonspress
Plugin Icon 128x128 Advanced Import : One Click Import for WordPress or Theme Demo Data
Version 1.2.5
Comparing to
See all releases

Code changes from version 1.2.4 to 1.2.5

admin/class-advanced-import-admin.php CHANGED
@@ -1,2507 +1,2515 @@
1
- <?php
2
- if ( ! defined( 'ABSPATH' ) ) {
3
- exit;
4
- }
5
- /**
6
- * The admin-specific functionality of the plugin.
7
- *
8
- * @link https://addonspress.com/
9
- * @since 1.0.0
10
- *
11
- * @package Advanced_Import
12
- * @subpackage Advanced_Import/admin
13
- */
14
-
15
- /**
16
- * The admin-specific functionality of the plugin.
17
- *
18
- * Defines the plugin name, version, and two examples hooks for how to
19
- * enqueue the admin-specific stylesheet and JavaScript.
20
- *
21
- * @package Advanced_Import
22
- * @subpackage Advanced_Import/admin
23
- * @author Addons Press <addonspress.com>
24
- */
25
- class Advanced_Import_Admin {
26
-
27
- /**
28
- * The Name of this plugin.
29
- *
30
- * @since 1.0.0
31
- * @access private
32
- * @var string $plugin_name The ID of this plugin.
33
- */
34
- private $plugin_name;
35
-
36
- /**
37
- * The version of this plugin.
38
- *
39
- * @since 1.0.0
40
- * @access private
41
- * @var string $version The current version of this plugin.
42
- */
43
- private $version;
44
-
45
- /**
46
- * The Current theme name
47
- *
48
- * @since 1.0.0
49
- * @access public
50
- * @var string $theme_name The Current theme name.
51
- */
52
- public $theme_name = '';
53
-
54
- /**
55
- * Current step
56
- *
57
- * @since 1.0.0
58
- * @access protected
59
- * @var string $step Current step.
60
- */
61
- protected $step = '';
62
-
63
- /**
64
- * Array of steps
65
- *
66
- * @since 1.0.0
67
- * @access public
68
- * @var array $steps Array of steps.
69
- */
70
- protected $steps = array();
71
-
72
- /**
73
- * Demo lists
74
- *
75
- * @since 1.0.0
76
- * @access public
77
- * @var array $demo_lists Array of demo lists.
78
- */
79
- protected $demo_lists = array();
80
-
81
- /**
82
- * Demo lists
83
- *
84
- * @since 1.0.0
85
- * @access public
86
- * @var array $demo_lists Array of demo lists.
87
- */
88
- protected $is_pro_active = false;
89
-
90
- /**
91
- * Array of delayed post for late process
92
- *
93
- * @since 1.0.0
94
- * @access public
95
- * @var array $delay_posts Array of delayed post for late process.
96
- */
97
- private $delay_posts = array();
98
-
99
- /**
100
- * Store logs and errors
101
- *
102
- * @since 1.0.0
103
- * @access public
104
- * @var array $logs Store logs and errors.
105
- */
106
- public $logs = array();
107
-
108
-
109
- /**
110
- * Store errors
111
- *
112
- * @since 1.0.0
113
- * @access public
114
- * @var array $errors Store errors.
115
- */
116
- public $errors = array();
117
-
118
-
119
- /**
120
- * current added Menu hook_suffix
121
- *
122
- * @since 1.0.0
123
- * @access public
124
- * @var array $logs Store logs and errors.
125
- */
126
- public $hook_suffix;
127
-
128
- /**
129
- * Slug of the import page
130
- *
131
- * @since 1.0.0
132
- * @access public
133
- * @var string $logs Store logs and errors.
134
- */
135
- private $current_template_type;
136
-
137
- /**
138
- * Slug of the import page
139
- *
140
- * @since 1.0.0
141
- * @access public
142
- * @var string $logs Store logs and errors.
143
- */
144
- private $current_template_url;
145
-
146
- /**
147
- * Initialize the class and set its properties.
148
- *
149
- * @since 1.0.0
150
- */
151
- public function __construct( ) {}
152
-
153
- /**
154
- * Main Advanced_Import_Admin Instance
155
- * Initialize the class and set its properties.
156
- *
157
- * @since 1.0.0
158
- * @return object $instance Advanced_Import_Admin Instance
159
- */
160
- public static function instance() {
161
-
162
- // Store the instance locally to avoid private static replication
163
- static $instance = null;
164
-
165
- // Only run these methods if they haven't been ran previously
166
- if ( null === $instance ) {
167
- $instance = new Advanced_Import_Admin;
168
- $instance->plugin_name = ADVANCED_IMPORT_PLUGIN_NAME;
169
- $instance->version = ADVANCED_IMPORT_VERSION;
170
-
171
- /*page slug using theme name */
172
- $instance->theme_name = sanitize_key( get_option('template') );
173
-
174
- }
175
-
176
- // Always return the instance
177
- return $instance;
178
- }
179
-
180
- /**
181
- * Check if template is available to import
182
- *
183
- * @since 1.0.8
184
- * @param array $item current array of demo list
185
- * @return boolean
186
- */
187
- public function is_template_available( $item ){
188
- $is_available = false;
189
-
190
- /*if pro active everything is available*/
191
- if( $this->is_pro_active ){
192
- $is_available = true;
193
- }
194
- /*if is_pro not set the $item is available*/
195
- elseif( !isset($item['is_pro'] ) ){
196
- $is_available = true;/*template available since */
197
- }
198
- /*if is_pro not set but it is false, it will be free and avialable*/
199
- elseif( isset( $item['is_pro'] ) && !$item['is_pro'] ){
200
- $is_available = true;
201
- }
202
-
203
- return (boolean) apply_filters( 'advanced_import_is_template_available', $is_available );
204
- }
205
-
206
- /**
207
- * Return Template Button
208
- *
209
- * @since 1.0.8
210
- * @param array $item current array of demo list
211
- * @return string
212
- */
213
- public function template_button( $item ){
214
- /*Start buffering*/
215
- ob_start();
216
-
217
- if( $this->is_template_available($item)){
218
- $plugins = isset( $item['plugins'] ) && is_array( $item['plugins'] )?' data-plugins="'.esc_attr(json_encode($item['plugins'])).'"':'';
219
- ?>
220
- <a class="button ai-demo-import ai-item-import is-button is-default is-primary is-large button-primary" href="#" aria-label="<?php esc_attr_e( 'Import', 'advanced-import' )?>" <?php echo $plugins;?>>
221
- <span class="dashicons dashicons-download"></span><?php esc_html_e( 'Import', 'advanced-import' );?>
222
- </a>
223
- <?php
224
- }
225
- else{
226
- ?>
227
- <a class="button is-button is-default is-primary is-large button-primary"
228
- href="<?php echo esc_url( isset($item['pro_url'])?$item['pro_url']:'#' );?>"
229
- target="_blank"
230
- aria-label="<?php esc_attr_e( 'View Pro', 'advanced-import' )?>">
231
- <span class="dashicons dashicons-awards"></span><?php esc_html_e( 'View Pro', 'advanced-import' );?>
232
- </a>
233
- <?php
234
- }
235
- /*removes the buffer (without printing it), and returns its content.*/
236
- $render_button = ob_get_clean();
237
-
238
- $render_button = apply_filters( 'advanced_import_template_import_button', $render_button );
239
- return $render_button;
240
-
241
- }
242
-
243
- /**
244
- * Register the stylesheets for the admin area.
245
- *
246
- * @since 1.0.0
247
- */
248
- public function enqueue_styles( $hook_suffix ) {
249
- if ( !is_array($this->hook_suffix) || !in_array( $hook_suffix, $this->hook_suffix )){
250
- return;
251
- }
252
- wp_enqueue_style( $this->plugin_name, ADVANCED_IMPORT_URL . 'assets/css/advanced-import-admin' . ADVANCED_IMPORT_SCRIPT_PREFIX . '.css',array( 'wp-admin', 'dashicons' ), $this->version, 'all' );
253
- wp_enqueue_media();
254
- }
255
-
256
- /**
257
- * Register the JavaScript for the admin area.
258
- *
259
- * @since 1.0.0
260
- */
261
- public function enqueue_scripts( $hook_suffix ) {
262
- if ( !is_array($this->hook_suffix) || !in_array( $hook_suffix, $this->hook_suffix )){
263
- return;
264
- }
265
-
266
- //Isotope Js
267
- wp_enqueue_script(
268
- 'isotope', // Handle.
269
- ADVANCED_IMPORT_URL . '/assets/library/isotope/isotope.pkgd' . ADVANCED_IMPORT_SCRIPT_PREFIX . '.js',
270
- array('jquery'), // Dependencies, defined above.
271
- '3.0.6', // Version: File modification time.
272
- true // Enqueue the script in the footer.
273
- );
274
-
275
- //Isotope Js
276
- wp_enqueue_script(
277
- 'sweetalert2', // Handle.
278
- ADVANCED_IMPORT_URL . '/assets/library/sweetalert2/sweetalert2.all' . ADVANCED_IMPORT_SCRIPT_PREFIX . '.js',
279
- array('jquery'), // Dependencies, defined above.
280
- '3.0.6', // Version: File modification time.
281
- true // Enqueue the script in the footer.
282
- );
283
-
284
- wp_enqueue_script( $this->plugin_name, ADVANCED_IMPORT_URL . 'assets/js/advanced-import-admin' . ADVANCED_IMPORT_SCRIPT_PREFIX . '.js', array( 'jquery','masonry'), $this->version, true );
285
- wp_localize_script( $this->plugin_name, 'advanced_import_object', array(
286
- 'ajaxurl' => admin_url( 'admin-ajax.php' ),
287
- 'wpnonce' => wp_create_nonce( 'advanced_import_nonce' ),
288
- 'text' => array(
289
- 'failed' => esc_html__('Failed','advanced-import'),
290
- 'error' => esc_html__('Error','advanced-import'),
291
- 'skip' => esc_html__( 'Skipping','advanced-import' ),
292
- 'confirmImport' => array(
293
- 'title' => esc_html__( 'Advanced Import! Just a step away','advanced-import' ),
294
- 'html' => sprintf(
295
-
296
- __( 'Importing demo data is the easiest way to setup your theme. It will allow you to quickly edit everything instead of creating content from scratch. Also, read following points before importing the demo: %1$s %2$s %3$s %4$s', 'advanced-import' ),
297
-
298
- '<ol><li class="warning">' . __( 'It is highly recommended to import demo on fresh WordPress installation to exactly replicate the theme demo. If no important data on your site, you can reset it from Reset Wizard at the top', 'advanced-import' ) . '</li>',
299
-
300
- '<li>' . __( 'No existing posts, pages, categories, images, custom post types or any other data will be deleted or modified.', 'advanced-import' ) . '</li>',
301
-
302
- '<li>' . __( 'It will install the plugins required for demo and activate them. Also posts, pages, images, widgets, & other data will get imported.', 'advanced-import' ) . '</li>',
303
-
304
- '<li>' . __( 'Please click on the Import button and wait, it will take some time to import the data.', 'advanced-import' ) . '</li></ol>'
305
-
306
- ),
307
- 'confirmButtonText' => esc_html__( 'Yes, Import Demo!','advanced-import' ),
308
- 'cancelButtonText' => esc_html__( 'Cancel','advanced-import' ),
309
- ),
310
- 'confirmReset' => array(
311
- 'title' => esc_html__( 'Are you sure?','advanced-import' ),
312
- 'text' => __( "You won't be able to revert this!",'advanced-import' ),
313
- 'confirmButtonText' => esc_html__( 'Yes, Reset','advanced-import' ),
314
- 'cancelButtonText' => esc_html__( 'Cancel','advanced-import' ),
315
- ),
316
- 'resetSuccess' => array(
317
- 'title' => esc_html__( 'Reset Successful','advanced-import' ),
318
- 'confirmButtonText' => esc_html__( 'Ok','advanced-import' ),
319
- ),
320
- 'failedImport' => array(
321
- 'code' => __( "Error Code:",'advanced-import' ),
322
- 'text' => __( "Contact theme author or try again",'advanced-import' ),
323
- ),
324
- 'successImport' => array(
325
- 'confirmButtonText' => esc_html__( 'Visit My Site','advanced-import' ),
326
- 'cancelButtonText' => esc_html__( 'Okay','advanced-import' ),
327
- )
328
- ),
329
- ) );
330
- }
331
-
332
- /**
333
- * @return array
334
- */
335
- public function mime_types( $mimes ) {
336
- $add_mimes = array(
337
- 'json' => 'text/plain'
338
- );
339
-
340
- return array_merge( $mimes, $add_mimes );
341
- }
342
-
343
- /**
344
- * Determine if the user already has theme content installed.
345
- * @access public
346
- */
347
- public function is_possible_upgrade() {
348
- return false;
349
- }
350
-
351
- /**
352
- * Add admin menus
353
- * @access public
354
- */
355
- public function import_menu() {
356
- $this->hook_suffix[] = add_theme_page( esc_html__( 'Demo Import ','advanced-import' ), esc_html__( 'Demo Import' ), 'manage_options', 'advanced-import', array( $this, 'demo_import_screen' ) );
357
- $this->hook_suffix[] = add_management_page( esc_html__( 'Advanced Import', 'advanced-import' ), esc_html__( 'Advanced Import', 'advanced-import' ), 'manage_options', 'advanced-import-tool', array( $this, 'demo_import_screen' ) );
358
-
359
- }
360
-
361
- /**
362
- * Show the setup
363
- * @access public
364
- * @return void
365
- */
366
- public function demo_import_screen() {
367
- do_action('advanced_import_before_demo_import_screen');
368
-
369
- $this->step = isset( $_GET['step'] ) ? sanitize_key( $_GET['step'] ) : current( array_keys( $this->steps ) );
370
-
371
-
372
- echo '<div class="ai-body">';
373
-
374
- $this->get_header();
375
-
376
- echo '<div class="ai-content">';
377
- echo '<div class="ai-content-blocker hidden">';
378
- echo '<div class="ai-notification-title"><p>'.esc_html__( 'Processing... Please do not refresh this page or do not go to other url!' ,'advanced-import').'</p></div>';
379
- echo '<div id="ai-demo-popup"></div>';
380
- echo '</div>';
381
- $this->init_demo_import();
382
- echo '</div>';
383
- echo '</div>';/*ai-body*/
384
- do_action('advanced_import_after_demo_import_screen');
385
-
386
- }
387
-
388
- /**
389
- * get header of setup
390
- * @access public
391
- * @return void
392
- */
393
- public function get_header(){
394
- global $pagenow;
395
-
396
- $welcome_msg = "<div class='ai-header'>";
397
- $welcome_msg .= "<h1>".sprintf( esc_html__( 'Welcome to the Advanced Import for %s.','advanced-import' ), wp_get_theme() )."</h1>";
398
- if( $pagenow != 'tools.php' ){
399
- $welcome_msg .= " <p>".sprintf( esc_html__( 'Thank you for choosing the %s theme. This quick demo import setup will help you configure your new website like theme demo. It will install the required WordPress plugins, default content and tell you a little about Help &amp; Support options. It should only take less than 5 minutes.','advanced-import' ), wp_get_theme() )."</p>";
400
- }
401
- $welcome_msg .= "</div>";
402
- echo advanced_import_allowed_html( apply_filters('advanced_import_welcome_message', $welcome_msg ) );
403
-
404
- if ( get_theme_mod( 'advanced_import_setup_complete', false ) && $pagenow != 'tools.php' ) {
405
- ?>
406
- <p><?php esc_html_e( 'It looks like you have already run the demo import for this theme.','advanced-import' ); ?></p>
407
- <?php
408
- }
409
- }
410
-
411
- /**
412
- * Handle the demo content upload and called to process
413
- * Ajax callback
414
- *
415
- * @return void
416
- */
417
- function upload_zip() {
418
- if ( isset( $_FILES[ 'ai-upload-zip-archive' ][ 'name' ] ) && ! empty( $_FILES[ 'ai-upload-zip-archive' ][ 'name' ] ) ) {
419
- /*check for security*/
420
- if ( ! current_user_can( 'upload_files' ) ) {
421
- wp_send_json_error(
422
- array(
423
- 'message' => esc_html__( 'Sorry, you are not allowed to install demo on this site.','advanced-import' )
424
- )
425
- );
426
- }
427
- check_admin_referer( 'advanced-import' );
428
-
429
- /*file process*/
430
- require_once( ABSPATH . 'wp-admin/includes/file.php' );
431
- WP_Filesystem();
432
- global $wp_filesystem;
433
- $wp_filesystem->rmdir( ADVANCED_IMPORT_TEMP, true );
434
- $upload_zip_archive = $_FILES[ 'ai-upload-zip-archive' ];
435
- $unzipfile = unzip_file( $upload_zip_archive['tmp_name'], ADVANCED_IMPORT_TEMP );
436
- if ( is_wp_error( $unzipfile ) ) {
437
- wp_send_json_error(
438
- array(
439
- 'message' => esc_html__( 'Error on unzipping, Please try again','advanced-import')
440
- )
441
- );
442
- }
443
- /*(check) Zip should contain json file and uploads folder only*/
444
- $dirlist = $wp_filesystem->dirlist( ADVANCED_IMPORT_TEMP );
445
- foreach ( (array) $dirlist as $filename => $fileinfo ) {
446
- if( $fileinfo['type'] == 'd'){
447
- if( $filename == 'uploads' ){
448
- continue;
449
- }
450
- else{
451
- $wp_filesystem->rmdir( ADVANCED_IMPORT_TEMP, true );
452
- wp_send_json_error(
453
- array(
454
- 'message' => esc_html__( 'Invalid Zip File','advanced-import' )
455
- )
456
- );
457
- }
458
- }
459
- else{
460
- $filetype = wp_check_filetype($filename);
461
- if( empty( $filetype['ext'] ) || $filetype['ext'] != 'json'){
462
- $wp_filesystem->rmdir( ADVANCED_IMPORT_TEMP, true );
463
- wp_send_json_error(
464
- array(
465
- 'message' => esc_html__( 'Invalid Zip File','advanced-import' )
466
- )
467
- );
468
- }
469
- }
470
-
471
- }
472
- wp_send_json_success(
473
- array(
474
- 'message' => esc_html__( 'Success','advanced-import' )
475
- )
476
- );
477
- }
478
- wp_send_json_error(
479
- array(
480
- 'message' => esc_html__( 'No Zip File Found','advanced-import' )
481
- )
482
- );
483
- }
484
-
485
- /**
486
- * Download Zip file/ Move it to temp import folder
487
- * Ajax callback
488
- *
489
- * @return mixed
490
- */
491
- function demo_download_and_unzip() {
492
-
493
- /*check for security*/
494
- if ( ! current_user_can( 'upload_files' ) ) {
495
- wp_send_json_error(
496
- array(
497
- 'message' => esc_html__( 'Sorry, you are not allowed to install demo on this site.','advanced-import' )
498
- )
499
- );
500
- }
501
- check_admin_referer( 'advanced-import' );
502
-
503
- /*get file and what should do*/
504
- $demo_file = is_array( $_POST['demo_file'] )? (array) $_POST['demo_file'] : sanitize_text_field( $_POST['demo_file'] );
505
- $demo_file_type = sanitize_text_field( $_POST['demo_file_type'] );
506
-
507
- /*from file*/
508
- if( $demo_file_type == 'file' ){
509
- require_once( ABSPATH . 'wp-admin/includes/file.php' );
510
- WP_Filesystem();
511
- global $wp_filesystem;
512
- $wp_filesystem->rmdir( ADVANCED_IMPORT_TEMP, true );
513
- $unzipfile = unzip_file( $demo_file, ADVANCED_IMPORT_TEMP );
514
- if ( is_wp_error( $unzipfile ) ) {
515
- wp_send_json_error(
516
- array(
517
- 'message' => esc_html__( 'Error on unzipping, Please try again','advanced-import')
518
- )
519
- );
520
- }
521
- /*(check) Zip should contain json file and uploads folder only*/
522
- $dirlist = $wp_filesystem->dirlist( ADVANCED_IMPORT_TEMP );
523
- foreach ( (array) $dirlist as $filename => $fileinfo ) {
524
- if( $fileinfo['type'] == 'd'){
525
- if( $filename == 'uploads' ){
526
- continue;
527
- }
528
- else{
529
- $wp_filesystem->rmdir( ADVANCED_IMPORT_TEMP, true );
530
- wp_send_json_error(
531
- array(
532
- 'message' => esc_html__( 'Invalid Zip File','advanced-import' )
533
- )
534
- );
535
- }
536
- }
537
- else{
538
- $filetype = wp_check_filetype($filename);
539
- if( empty( $filetype['ext'] ) || $filetype['ext'] != 'json'){
540
- $wp_filesystem->rmdir( ADVANCED_IMPORT_TEMP, true );
541
- wp_send_json_error(
542
- array(
543
- 'message' => esc_html__( 'Invalid Zip File','advanced-import' )
544
- )
545
- );
546
- }
547
- }
548
-
549
- }
550
- wp_send_json_success(
551
- array(
552
- 'message' => esc_html__( 'Success','advanced-import' )
553
- )
554
- );
555
- }
556
- elseif ( $demo_file_type == 'url' ){
557
-
558
- /*finally fetch the file from remote*/
559
- $response = wp_remote_get( $demo_file );
560
-
561
- if ( is_array( $response ) && ! empty( $response['body'] ) && $response['response']['code'] == '200' ) {
562
- require_once( ABSPATH . 'wp-admin/includes/file.php' );
563
- WP_Filesystem();
564
- global $wp_filesystem;
565
- $file_permission = 0777;
566
- if ( !file_exists( ADVANCED_IMPORT_TEMP_ZIP ) ) {
567
- $wp_filesystem->mkdir(ADVANCED_IMPORT_TEMP_ZIP, $file_permission, true);
568
- }
569
- $temp_import_zip = trailingslashit(ADVANCED_IMPORT_TEMP_ZIP ). "temp-import.zip";
570
- $wp_filesystem->put_contents( $temp_import_zip, $response['body'],0777 );
571
-
572
- }
573
- else {
574
- /*required to download file failed.*/
575
- wp_send_json_error(
576
- array(
577
- 'error' => 1,
578
- 'message' => esc_html__( 'Remote server did not respond, Contact to Theme Author','advanced-import' )
579
- )
580
- );
581
- }
582
-
583
- $file_size = filesize( $temp_import_zip );
584
-
585
- /*if file size is 0*/
586
- if ( 0 == $file_size ) {
587
- $wp_filesystem->rmdir( ADVANCED_IMPORT_TEMP_ZIP, true );
588
- wp_send_json_error(
589
- array(
590
- 'error' => 1,
591
- 'message' => esc_html__( 'Zero size file downloaded, Contact to Theme Author','advanced-import' )
592
- )
593
- );
594
- }
595
-
596
- /*if file is too large*/
597
- if ( ! empty( $max_size ) && $file_size > $max_size ) {
598
- $wp_filesystem->rmdir( ADVANCED_IMPORT_TEMP_ZIP, true );
599
- wp_send_json_error(
600
- array(
601
- 'error' => 1,
602
- 'message' => sprintf( esc_html__( 'Remote file is too large, limit is %s','advanced-import' ), size_format( $max_size ) )
603
- )
604
- );
605
- }
606
-
607
- /*if we are here then unzip file*/
608
- $unzipfile = unzip_file( $temp_import_zip, ADVANCED_IMPORT_TEMP );
609
- if ( is_wp_error( $unzipfile ) ) {
610
- wp_send_json_error(
611
- array(
612
- 'error' => 1,
613
- 'message' => esc_html__( 'Error on unzipping, Please try again','advanced-import')
614
- )
615
- );
616
- }
617
- $wp_filesystem->rmdir( ADVANCED_IMPORT_TEMP_ZIP, true );
618
-
619
- /*(check) Zip should contain json file and uploads folder only*/
620
- $dirlist = $wp_filesystem->dirlist( ADVANCED_IMPORT_TEMP );
621
- foreach ( (array) $dirlist as $filename => $fileinfo ) {
622
- if( $fileinfo['type'] == 'd'){
623
- if( $filename == 'uploads' ){
624
- continue;
625
- }
626
- else{
627
- $wp_filesystem->rmdir( ADVANCED_IMPORT_TEMP, true );
628
- wp_send_json_error(
629
- array(
630
- 'message' => esc_html__( 'Invalid Zip File','advanced-import' )
631
- )
632
- );
633
- }
634
- }
635
- else{
636
- $filetype = wp_check_filetype($filename);
637
- if( empty( $filetype['ext'] ) || $filetype['ext'] != 'json'){
638
- $wp_filesystem->rmdir( ADVANCED_IMPORT_TEMP, true );
639
- wp_send_json_error(
640
- array(
641
- 'message' => esc_html__( 'Invalid Zip File','advanced-import' )
642
- )
643
- );
644
- }
645
- }
646
-
647
- }
648
- wp_send_json_success(
649
- array(
650
- 'message' => esc_html__( 'Success','advanced-import' )
651
- )
652
- );
653
-
654
- }
655
- else{
656
- wp_send_json_error(
657
- array(
658
- 'error' => 1,
659
- 'message' => esc_html__( 'File not allowed','advanced-import' )
660
- )
661
- );
662
- }
663
- }
664
-
665
- /**
666
- * List Demo List
667
- *
668
- * @return void
669
- */
670
- public function demo_list( $demo_lists, $total_demo ){
671
- ?>
672
- <div class="ai-filter-header">
673
- <div class="ai-filter-tabs">
674
- <ul class="ai-types ai-filter-group" data-filter-group="secondary">
675
- <li class="ai-filter-btn-active ai-filter-btn" data-filter="*">
676
- <?php esc_html_e( 'All', 'advanced-import' ); ?>
677
- <span class="ai-count"></span>
678
- </li>
679
- <?php
680
- $types = array_column($demo_lists, 'type');
681
- $unique_types = array_unique( $types );
682
- foreach ( $unique_types as $cat_index => $single_type ){
683
- ?>
684
- <li class="ai-filter-btn" data-filter=".<?php echo strtolower( esc_attr($single_type) );?>">
685
- <?php echo ucfirst( esc_html($single_type) );?>
686
- <span class="ai-count"></span>
687
-
688
- </li>
689
- <?php
690
- }
691
- ?>
692
- </ul>
693
- <div class="ai-search-control">
694
- <input id="ai-filter-search-input" class="ai-search-filter" type="text" placeholder="<?php esc_attr_e('Search...','advanced-import')?>">
695
- </div>
696
- <ul class="ai-form-type">
697
- <li class="ai-form-file-import">
698
- <?php esc_html_e( 'Upload zip', 'advanced-import' ); ?>
699
- </li>
700
- </ul>
701
- </div>
702
- </div>
703
- <div class="ai-filter-content" id="ai-filter-content">
704
- <div class="ai-actions ai-sidebar">
705
- <div class="ai-import-available-categories">
706
- <h3><?php esc_html_e( 'Categories', 'advanced-import' ); ?></h3>
707
- <ul class="ai-import-available-categories-lists ai-filter-group" data-filter-group="primary">
708
- <li class="ai-filter-btn-active ai-filter-btn" data-filter="*">
709
- <?php esc_html_e( 'All Categories', 'advanced-import' ); ?>
710
- <span class="ai-count"></span>
711
- </li>
712
- <?php
713
- $categories = array_column($demo_lists, 'categories');
714
- $unique_categories = array();
715
- if( is_array( $categories) && !empty( $categories )){
716
- foreach ( $categories as $demo_index => $demo_cats ){
717
- foreach ( $demo_cats as $cat_index => $single_cat ){
718
- if (in_array($single_cat, $unique_categories)){
719
- continue;
720
- }
721
- $unique_categories[] = $single_cat;
722
- ?>
723
- <li class="ai-filter-btn" data-filter=".<?php echo strtolower( esc_attr($single_cat) );?>">
724
- <?php echo ucfirst( esc_html($single_cat) );?>
725
- <span class="ai-count"></span>
726
- </li>
727
- <?php
728
- }
729
- }
730
- }
731
- ?>
732
- </ul>
733
- </div>
734
-
735
- </div>
736
- <div class="ai-filter-content-wrapper">
737
- <?php
738
- foreach ( $demo_lists as $key => $demo_list ){
739
-
740
- /*Check for required fields*/
741
- if( !isset( $demo_list['title'] ) || !isset( $demo_list['screenshot_url'] ) || !isset( $demo_list['demo_url']) ){
742
- continue;
743
- }
744
-
745
- $template_url = isset( $demo_list['template_url'] )?$demo_list['template_url']:'';
746
- if( is_array( $template_url )){
747
- $data_template = 'data-template_url="'.esc_attr(json_encode($template_url)).'"';
748
- $data_template_type = 'data-template_type="array"';
749
- }
750
- elseif ($template_url){
751
- $data_template = 'data-template_url="'.esc_attr($template_url).'"';
752
- if ( is_file( $template_url ) && filesize( $template_url ) > 0 ) {
753
- $data_template_type = 'data-template_type="file"';
754
- }
755
- else{
756
- $data_template_type = 'data-template_type="url"';
757
- }
758
- }
759
- else{
760
- $data_template = 'data-template_url="'.esc_attr(json_encode($template_url)).'"';
761
- $data_template_type = 'data-template_type="array"';
762
- }
763
- ?>
764
- <div aria-label="<?php echo esc_attr( $demo_list['title'])?>"
765
- class="ai-item <?php
766
- echo isset( $demo_list['categories'] )?esc_attr(implode(" ",$demo_list['categories'])):'';
767
- echo isset( $demo_list['type'] )?' '.esc_attr($demo_list['type']):'';
768
- echo $this->is_template_available($demo_list)?'':' ai-pro-item'?>"
769
- <?php echo $this->is_template_available($demo_list)?$data_template.' '.$data_template_type:'';?>
770
- >
771
- <?php
772
- wp_nonce_field( 'advanced-import' );
773
- ?>
774
- <div class="ai-item-preview">
775
- <div class="ai-item-screenshot">
776
- <img src="<?php echo esc_url( $demo_list['screenshot_url'])?>">
777
-
778
- </div>
779
- <h4 class="ai-author-info"><?php esc_html_e( 'Author: ', 'advanced-import' ) ?><?php echo esc_html( isset($demo_list['author'])?$demo_list['author']:wp_get_theme()->get( 'Author' ))?></h4>
780
- <div class="ai-details"><?php esc_html_e( 'Details', 'advanced-import' ) ?></div>
781
- <?php
782
- if( isset( $demo_list['is_pro'] ) && $demo_list['is_pro'] ){
783
- ?>
784
- <span class="ai-premium-label"><?php esc_html_e( 'Premium', 'advanced-import' ) ?></span>
785
- <?php
786
- }
787
- ?>
788
- </div>
789
- <div class="ai-item-footer">
790
- <div class="ai-item-footer_meta">
791
- <h3 class="theme-name"><?php echo esc_html( $demo_list['title'])?></h3>
792
- <div class="ai-item-footer-actions">
793
- <a class="button ai-item-demo-link" href="<?php echo esc_url( $demo_list['demo_url'])?>" target="_blank">
794
- <span class="dashicons dashicons-visibility"></span><?php esc_html_e( 'Preview', 'advanced-import' );?>
795
- </a>
796
- <?php
797
- echo $this->template_button( $demo_list );
798
- ?>
799
- </div>
800
- <?php
801
- $keywords = isset( $demo_list['keywords'] )? $demo_list['keywords']:array();
802
- If( !empty( $keywords )){
803
- echo '<ul class="ai-keywords hidden">';
804
- foreach ( $keywords as $cat_index => $single_keywords ){
805
- ?>
806
- <li class="<?php echo strtolower( esc_attr($single_keywords) );?>"><?php echo ucfirst( esc_html($single_keywords) );?></li>
807
- <?php
808
- }
809
- echo '</ul>';
810
- }
811
- ?>
812
-
813
- </div>
814
-
815
- </div>
816
- </div>
817
- <?php
818
- }
819
- ?>
820
- </div>
821
- </div>
822
- <?php
823
- }
824
- /**
825
- * List Demo Form
826
- *
827
- * @return void
828
- */
829
-
830
- public function demo_import_form( $total_demo = 0 ){
831
- ?>
832
- <div class="ai-form <?php echo $total_demo > 0?'hidden':''?>">
833
- <form action="" method="post" enctype="multipart/form-data" id="ai-upload-zip-form">
834
- <h3 class="media-title"><?php esc_html_e( 'Upload a zip file containing demo content', 'advanced-import' ); ?> </h3>
835
- <div class="input-file"><input type="file" name="ai-upload-zip-archive" id="ai-upload-zip-archive" size="50" /></div>
836
- <p>
837
- <?php
838
- wp_nonce_field( 'advanced-import' );
839
- printf( __( 'Maximum upload file size: %s','advanced-import' ), size_format( wp_max_upload_size() ) );
840
- ?>
841
- </p>
842
- <div id='ai-empty-file' class="error hidden">
843
- <p>
844
- <?php esc_html_e('Select File and Try Again!','advanced-import')?>
845
- </p>
846
- </div>
847
- <p class="ai-form-import-actions step">
848
- <button class="button-primary button button-large button-upload-demo" type="submit">
849
- <?php esc_html_e( 'Upload Demo Zip','advanced-import' ); ?>
850
- </button>
851
- <a href="<?php echo esc_url( wp_get_referer() && ! strpos( wp_get_referer(), 'update.php' ) ? wp_get_referer() : admin_url( '' ) ); ?>" class="button button-large">
852
- <?php esc_html_e( 'Not right now','advanced-import' ); ?>
853
- </a>
854
- </p>
855
- <div id='ai-ajax-install-result'></div>
856
- </form>
857
- </div>
858
- <?php
859
- }
860
-
861
- /**
862
- * 1st step of demo import view
863
- * Upload Zip file
864
- * Demo List
865
- */
866
- public function init_demo_import(){
867
-
868
- global $pagenow;
869
- $total_demo = 0;
870
- if( $pagenow != 'tools.php' ){
871
- $this->demo_lists = apply_filters( 'advanced_import_demo_lists',array() );
872
- $this->is_pro_active = apply_filters( 'advanced_import_is_pro_active', $this->is_pro_active);
873
- $demo_lists = $this->demo_lists;
874
-
875
- $total_demo = count( $demo_lists );
876
- if( $total_demo >= 1 ){
877
- $this->demo_list( $demo_lists, $total_demo );
878
- }
879
- }
880
-
881
- $this->demo_import_form($total_demo);
882
- }
883
-
884
- /**
885
- * 2nd step Plugin Installation step View
886
- * return void || boolean
887
- */
888
- public function plugin_screen() {
889
-
890
- /*check for security*/
891
- if ( ! current_user_can( 'upload_files' ) ) {
892
- wp_send_json_error(
893
- array(
894
- 'message' => esc_html__( 'Sorry, you are not allowed to install demo on this site.','advanced-import' )
895
- )
896
- );
897
- }
898
-
899
- check_admin_referer( 'advanced-import' );
900
-
901
- /*delete_transient(); for safety*/
902
- delete_transient('content.json');
903
- delete_transient('widgets.json');
904
- delete_transient('options.json');
905
-
906
- do_action('advanced_import_before_plugin_screen');
907
- ?>
908
- <div class="ai-notification-title">
909
- <p><?php esc_html_e( 'Your website needs a few essential plugins. We are installing them...','advanced-import' ); ?></p>
910
- </div>
911
- <ul class="ai-plugins-wrap hidden">
912
- <?php
913
- $recommended_plugins = (array) $_POST['recommendedPlugins'];
914
- if ( count( $recommended_plugins ) ) {
915
- foreach ( $recommended_plugins as $index => $recommended_plugin ) { ?>
916
- <li data-slug="<?php echo esc_attr( $recommended_plugin['slug'] ); ?>" data-main_file ="<?php echo esc_attr( isset($recommended_plugin['main_file'])?$recommended_plugin['main_file']: $recommended_plugin['slug'].'.php'); ?>">
917
- <?php echo esc_html( $recommended_plugin['name'] ); ?>
918
- </li>
919
- <?php
920
- }
921
- }
922
- else{
923
- ?>
924
- <li id="ai-no-recommended-plugins"><?php esc_html_e( 'No Recommended Plugins','advanced-import' ); ?></li>
925
- <?php
926
- }
927
- ?>
928
- </ul>
929
- <?php
930
- do_action('advanced_import_after_plugin_screen');
931
- exit;
932
- }
933
-
934
- /**
935
- * 3rd steps helper functions
936
- * Get json from json file
937
- *
938
- * @param string $file
939
- * @return mixed
940
- */
941
- public function get_json_data_from_file( $file ) {
942
-
943
- if( get_transient ($file)){
944
- return get_transient ($file);
945
- }
946
-
947
- If( $this->current_template_type == 'array'){
948
- $type = strtok($file, '.');
949
- if( isset( $this->current_template_url[$type])){
950
- $request = wp_remote_get($this->current_template_url[$type]);
951
- $response = wp_remote_retrieve_body( $request );
952
- $result = json_decode( $response, true );
953
- set_transient($file, $result, 1000 );
954
- return $result;
955
- }
956
- return array();
957
- }
958
-
959
- if ( is_file( ADVANCED_IMPORT_TEMP . basename( $file ) ) ) {
960
- require_once( ABSPATH . 'wp-admin/includes/file.php' );
961
- WP_Filesystem();
962
- global $wp_filesystem;
963
- $file_name = ADVANCED_IMPORT_TEMP . basename( $file );
964
- if ( file_exists( $file_name ) ) {
965
- $result = json_decode( $wp_filesystem->get_contents( $file_name ), true );
966
- set_transient($file, $result, 1000 );
967
- return $result;
968
- }
969
- }
970
- return array();
971
- }
972
-
973
- public function get_main_content_json( ) {
974
- return $this->get_json_data_from_file( 'content.json' );
975
- }
976
- public function get_widgets_json(){
977
- return $this->get_json_data_from_file( 'widgets.json' );
978
- }
979
-
980
- public function get_theme_options_json( ) {
981
- return $this->get_json_data_from_file( 'options.json' );
982
- }
983
-
984
- /*
985
- * return array
986
- */
987
- private function advanced_import_setup_content_steps() {
988
-
989
- $content = array();
990
-
991
- /*check if there is files*/
992
- $content_data = $this->get_main_content_json();
993
- foreach ( $content_data as $post_type => $post_data ) {
994
- if ( count( $post_data ) ) {
995
- $first = current( $post_data );
996
- $post_type_title = ! empty( $first['type_title'] ) ? $first['type_title'] : ucwords( $post_type ) . 's';
997
- $content[ $post_type ] = array(
998
- 'title' => $post_type_title,
999
- 'description' => sprintf( esc_html__( 'This will create default %s as seen in the demo.','advanced-import' ), $post_type_title ),
1000
- 'pending' => esc_html__( 'Pending.','advanced-import'),
1001
- 'installing' => esc_html__( 'Installing.','advanced-import' ),
1002
- 'success' => esc_html__( 'Success.','advanced-import' ),
1003
- 'install_callback' => array( $this, 'import_content_post_type_data' ),
1004
- 'checked' => $this->is_possible_upgrade() ? 0 : 1,
1005
- // dont check if already have content installed.
1006
- );
1007
- }
1008
- }
1009
- /*array adjustment
1010
- TODO : Remove it after adjustment on Advanced Import
1011
- */
1012
- /*Put post 3nd last*/
1013
- $post = isset( $content['post'] ) ? $content['post'] : array();
1014
- if ( $post ) {
1015
- unset( $content['post'] );
1016
- $content['post'] = $post;
1017
- }
1018
- /*Put page 2nd last*/
1019
- $page = isset( $content['page'] ) ? $content['page'] : array();
1020
- if ( $page ) {
1021
- unset( $content['page'] );
1022
- $content['page'] = $page;
1023
-
1024
- }
1025
- /*Put nav last*/
1026
- $nav = isset( $content['nav_menu_item'] ) ? $content['nav_menu_item'] : array();
1027
- if ( $nav ) {
1028
- unset( $content['nav_menu_item'] );
1029
- $content['nav_menu_item'] = $nav;
1030
- }
1031
- /*check if there is files*/
1032
- $widget_data = $this->get_widgets_json();
1033
- if( !empty( $widget_data ) ){
1034
- $content['widgets'] = array(
1035
- 'title' => esc_html__( 'Widgets','advanced-import' ),
1036
- 'description' => esc_html__( 'Insert default sidebar widgets as seen in the demo.','advanced-import' ),
1037
- 'pending' => esc_html__( 'Pending.','advanced-import' ),
1038
- 'installing' => esc_html__( 'Installing Default Widgets.','advanced-import' ),
1039
- 'success' => esc_html__( 'Success.' ,'advanced-import'),
1040
- 'install_callback' => array( $this, 'import_content_widgets_data' ),
1041
- 'checked' => $this->is_possible_upgrade() ? 0 : 1,
1042
- // dont check if already have content installed.
1043
- );
1044
- }
1045
- $options_data = $this->get_theme_options_json();
1046
- if( !empty( $options_data ) ){
1047
- $content['settings'] = array(
1048
- 'title' => esc_html__( 'Settings','advanced-import' ),
1049
- 'description' => esc_html__( 'Configure default settings.','advanced-import' ),
1050
- 'pending' => esc_html__( 'Pending.','advanced-import' ),
1051
- 'installing' => esc_html__( 'Installing Default Settings.' ,'advanced-import'),
1052
- 'success' => esc_html__( 'Success.','advanced-import' ),
1053
- 'install_callback' => array( $this, 'import_menu_and_options' ),
1054
- 'checked' => $this->is_possible_upgrade() ? 0 : 1,
1055
- // dont check if already have content installed.
1056
- );
1057
- }
1058
- $content = apply_filters( $this->theme_name . '_theme_view_setup_step_content', $content );
1059
-
1060
- return $content;
1061
-
1062
- }
1063
-
1064
- /**
1065
- * 3rd Step Step for content, widget, setting import
1066
- * Page setup
1067
- */
1068
- public function content_screen() {
1069
-
1070
- /*check for security*/
1071
- if ( ! current_user_can( 'upload_files' ) ) {
1072
- wp_send_json_error(
1073
- array(
1074
- 'message' => esc_html__( 'Sorry, you are not allowed to install demo on this site.','advanced-import' )
1075
- )
1076
- );
1077
- }
1078
- check_admin_referer( 'advanced-import' );
1079
-
1080
- if( isset($_POST['template_url'] )){
1081
- $this->current_template_url = is_array( $_POST['template_url'] )? (array) $_POST['template_url'] : sanitize_text_field( $_POST['template_url'] );
1082
- $this->current_template_type = sanitize_text_field( $_POST['template_type'] );
1083
- }
1084
-
1085
- do_action('advanced_import_before_content_screen');
1086
-
1087
- ?>
1088
- <div class="ai-notification-title">
1089
- <p>
1090
- <?php
1091
- esc_html_e( 'It\'s time to insert some demo content for your new WordPress Site. Once inserted, this content can be managed from the WordPress admin dashboard. ' )
1092
- ?>
1093
- </p>
1094
- </div>
1095
-
1096
- <table class="ai-pages hidden">
1097
- <thead>
1098
- <tr>
1099
- <th class="check"></th>
1100
- <th class="item"><?php esc_html_e( 'Item','advanced-import'); ?></th>
1101
- <th class="description"><?php esc_html_e( 'Description','advanced-import' ); ?></th>
1102
- <th class="status"><?php esc_html_e( 'Status','advanced-import' ); ?></th>
1103
- </tr>
1104
- </thead>
1105
- <tbody>
1106
- <?php
1107
- $setup_content_steps = $this->advanced_import_setup_content_steps();
1108
- foreach ( $setup_content_steps as $slug => $default ) { ?>
1109
- <tr class="ai-available-content" data-content="<?php echo esc_attr( $slug ); ?>">
1110
- <td>
1111
- <input type="checkbox" name="import_content[<?php echo esc_attr( $slug ); ?>]" class="ai-available-content" id="import_content_<?php echo esc_attr( $slug ); ?>" value="1" <?php echo ( ! isset( $default['checked'] ) || $default['checked'] ) ? ' checked' : ''; ?>>
1112
- </td>
1113
- <td>
1114
- <label for="import_content_<?php echo esc_attr( $slug ); ?>">
1115
- <?php echo esc_html( $default['title'] ); ?>
1116
- </label>
1117
- </td>
1118
- <td class="description">
1119
- <?php echo esc_html( $default['description'] ); ?>
1120
- </td>
1121
- <td class="status">
1122
- <span>
1123
- <?php echo esc_html( $default['pending'] ); ?>
1124
- </span>
1125
- </td>
1126
- </tr>
1127
- <?php } ?>
1128
- </tbody>
1129
- </table>
1130
- <?php
1131
- do_action('advanced_import_after_content_screen');
1132
-
1133
- exit;
1134
- }
1135
-
1136
- /*import ajax content
1137
- * return JSON
1138
- */
1139
- public function import_content() {
1140
-
1141
- /*check for security*/
1142
- if ( ! current_user_can( 'upload_files' ) ) {
1143
- wp_send_json_error(
1144
- array(
1145
- 'message' => esc_html__( 'Sorry, you are not allowed to install demo on this site.','advanced-import' )
1146
- )
1147
- );
1148
- }
1149
- if( isset($_POST['template_url'] )){
1150
- $this->current_template_url = is_array( $_POST['template_url'] )? (array) $_POST['template_url'] : sanitize_text_field( $_POST['template_url'] );
1151
- $this->current_template_type = sanitize_text_field ( $_POST['template_type'] );
1152
- }
1153
-
1154
- /*Move to Trash default page and post*/
1155
- $sample_page = get_page_by_title('Sample Page', OBJECT, 'page');
1156
- $hello_world_post = get_page_by_title('Hello world!', OBJECT, 'post');
1157
- if( is_object( $sample_page ) ) {
1158
- wp_trash_post( $sample_page->ID );
1159
- }
1160
- if( is_object( $hello_world_post ) ) {
1161
- wp_trash_post( $hello_world_post->ID );
1162
- }
1163
-
1164
- $content_slug = isset( $_POST['content'] )? sanitize_title( $_POST['content'] ): '';
1165
-
1166
- $content = $this->advanced_import_setup_content_steps();
1167
-
1168
- /*check for security again*/
1169
- if ( ! check_ajax_referer( 'advanced_import_nonce', 'wpnonce' ) || empty( $content_slug ) || !isset( $content[ $content_slug ] ) ) {
1170
- wp_send_json_error(
1171
- array(
1172
- 'error' => 1,
1173
- 'message' => esc_html__( 'No content Found','advanced-import' )
1174
- )
1175
- );
1176
- }
1177
-
1178
- $json = false;
1179
- $this_content = $content[ $content_slug ];
1180
-
1181
- if ( isset( $_POST['proceed'] ) ) {
1182
-
1183
- /*install the content*/
1184
- $this->log( esc_html__( 'Starting import for ','advanced-import') . $content_slug );
1185
-
1186
- /*init delayed posts from transient.*/
1187
- $this->delay_posts = get_transient( 'delayed_posts' );
1188
- if ( ! is_array( $this->delay_posts ) ) {
1189
- $this->delay_posts = array();
1190
- }
1191
-
1192
- if ( ! empty( $this_content['install_callback'] ) ) {
1193
- /* install_callback includes following functions
1194
- * import_content_post_type_data
1195
- * import_content_widgets_data
1196
- * import_menu_and_options
1197
- * */
1198
- if ( $result = call_user_func( $this_content['install_callback'] ) ) {
1199
-
1200
- $this->log( esc_html__( 'Finish writing ','advanced-import' ) . count( $this->delay_posts, COUNT_RECURSIVE ) . esc_html__(' delayed posts to transient ','advanced-import') );
1201
- set_transient( 'delayed_posts', $this->delay_posts, 60 * 60 * 24 );
1202
-
1203
- /*if there is retry, retry it
1204
- or finish it*/
1205
- if ( is_array( $result ) && isset( $result['retry'] ) ) {
1206
- /*we split the stuff up again.*/
1207
- $json = array(
1208
- 'url' => admin_url( 'admin-ajax.php' ),
1209
- 'action' => 'import_content',
1210
- 'proceed' => 'true',
1211
- 'retry' => time(),
1212
- 'retry_count' => $result['retry_count'],
1213
- 'content' => $content_slug,
1214
- '_wpnonce' => wp_create_nonce( 'advanced_import_nonce' ),
1215
- 'message' => $this_content['installing'],
1216
- 'logs' => $this->logs,
1217
- 'errors' => $this->errors,
1218
- 'template_url' => $this->current_template_url,
1219
- 'template_type' => $this->current_template_type,
1220
-
1221
- );
1222
- }
1223
- else {
1224
- $json = array(
1225
- 'done' => 1,
1226
- 'message' => $this_content['success'],
1227
- 'debug' => $result,
1228
- 'logs' => $this->logs,
1229
- 'errors' => $this->errors,
1230
- );
1231
- }
1232
- }
1233
- }
1234
- }
1235
- else {
1236
-
1237
- $json = array(
1238
- 'url' => admin_url( 'admin-ajax.php' ),
1239
- 'action' => 'import_content',
1240
- 'proceed' => 'true',
1241
- 'content' => $content_slug,
1242
- '_wpnonce' => wp_create_nonce( 'advanced_import_nonce' ),
1243
- 'message' => $this_content['installing'],
1244
- 'logs' => $this->logs,
1245
- 'errors' => $this->errors,
1246
- 'template_url' => $this->current_template_url,
1247
- 'template_type' => $this->current_template_type,
1248
- );
1249
- }
1250
-
1251
- if ( $json ) {
1252
- $json['hash'] = md5( serialize( $json ) ); /*used for checking if duplicates happen, move to next plugin*/
1253
- wp_send_json( $json );
1254
- }
1255
- else {
1256
- wp_send_json_error( array(
1257
- 'message' => esc_html__( 'Error','advanced-import' ),
1258
- 'logs' => $this->logs,
1259
- 'errors' => $this->errors,
1260
- ) );
1261
- }
1262
- exit;
1263
- }
1264
-
1265
- /* callback function to importing post type
1266
- * all post type is imported from here
1267
- * return mix
1268
- * */
1269
- private function import_content_post_type_data() {
1270
- $post_type = ! empty( $_POST['content'] ) ? sanitize_text_field( $_POST['content'] ) : false;
1271
- $all_data = $this->get_main_content_json();
1272
- if ( ! $post_type || ! isset( $all_data[ $post_type ] ) ) {
1273
- return false;
1274
- }
1275
-
1276
- /*Import 10 posts at a time*/
1277
- $limit = 10 + ( isset( $_REQUEST['retry_count'] ) ? (int) $_REQUEST['retry_count'] : 0 );
1278
-
1279
- $limit = apply_filters('advanced_import_limit_at_time', $limit );
1280
- $x = 0;
1281
- foreach ( $all_data[ $post_type ] as $post_data ) {
1282
-
1283
- $this->process_import_single_post( $post_type, $post_data );
1284
-
1285
- if ( $x ++ > $limit ) {
1286
- return array(
1287
- 'retry' => 1,
1288
- 'retry_count' => $limit
1289
- );
1290
- }
1291
- }
1292
-
1293
- /*processed delayed posts*/
1294
- $this->process_delayed_posts();
1295
-
1296
- /*process child posts*/
1297
- $this->processpost_orphans();
1298
-
1299
- return true;
1300
-
1301
- }
1302
-
1303
- /*set and get transient imported_term_ids
1304
- return mix*/
1305
- private function imported_term_id( $original_term_id, $new_term_id = false ) {
1306
- $terms = get_transient( 'imported_term_ids' );
1307
- if ( ! is_array( $terms ) ) {
1308
- $terms = array();
1309
- }
1310
- if ( $new_term_id ) {
1311
- if ( ! isset( $terms[ $original_term_id ] ) ) {
1312
- $this->log( esc_html__('Insert old TERM ID ','advanced-import') . $original_term_id .esc_html__(' as new TERM ID: ' ,'advanced-import'). $new_term_id );
1313
- }
1314
- else if ( $terms[ $original_term_id ] != $new_term_id ) {
1315
- $this->error( 'Replacement OLD TERM ID ' . $original_term_id . ' overwritten by new TERM ID: ' . $new_term_id );
1316
- }
1317
- $terms[ $original_term_id ] = $new_term_id;
1318
- set_transient( 'imported_term_ids', $terms, 60 * 60 * 24 );
1319
- }
1320
- else if ( $original_term_id && isset( $terms[ $original_term_id ] ) ) {
1321
- return $terms[ $original_term_id ];
1322
- }
1323
-
1324
- return false;
1325
- }
1326
-
1327
- /*set and get imported_post_ids
1328
- return mix*/
1329
- public function imported_post_id( $original_id = false, $new_id = false ) {
1330
- if ( is_array( $original_id ) || is_object( $original_id ) ) {
1331
- return false;
1332
- }
1333
- $post_ids = get_transient( 'imported_post_ids' );
1334
- if ( ! is_array( $post_ids ) ) {
1335
- $post_ids = array();
1336
- }
1337
- if ( $new_id ) {
1338
- if ( ! isset( $post_ids[ $original_id ] ) ) {
1339
- $this->log( esc_html__('Insert old ID ','advanced-import') . $original_id . esc_html__(' as new ID: ','advanced-import') . $new_id );
1340
- }
1341
- else if ( $post_ids[ $original_id ] != $new_id ) {
1342
- $this->error( esc_html__('Replacement OLD ID ','advanced-import'). $original_id . ' overwritten by new ID: ' . $new_id );
1343
- }
1344
- $post_ids[ $original_id ] = $new_id;
1345
- set_transient( 'imported_post_ids', $post_ids, 60 * 60 * 24 );
1346
- }
1347
- else if ( $original_id && isset( $post_ids[ $original_id ] ) ) {
1348
- return $post_ids[ $original_id ];
1349
- }
1350
- else if ( $original_id === false ) {
1351
- return $post_ids;
1352
- }
1353
- return false;
1354
- }
1355
-
1356
- /*set and get post_orphans/post parent
1357
- if parent is not already imported the child will be orphan
1358
- return mix*/
1359
- private function post_orphans( $original_id = false, $missing_parent_id = false ) {
1360
- $post_ids = get_transient( 'post_orphans' );
1361
- if ( ! is_array( $post_ids ) ) {
1362
- $post_ids = array();
1363
- }
1364
- if ( $missing_parent_id ) {
1365
- $post_ids[ $original_id ] = $missing_parent_id;
1366
- set_transient( 'post_orphans', $post_ids, 60 * 60 * 24 );
1367
- }
1368
- else if ( $original_id && isset( $post_ids[ $original_id ] ) ) {
1369
- return $post_ids[ $original_id ];
1370
- }
1371
- else if ( $original_id === false ) {
1372
- return $post_ids;
1373
- }
1374
- return false;
1375
- }
1376
-
1377
-
1378
- /*set delayed post for later process*/
1379
- private function delay_post_process( $post_type, $post_data ) {
1380
- if ( ! isset( $this->delay_posts[$post_type] ) ) {
1381
- $this->delay_posts[ $post_type ] = array();
1382
- }
1383
- $this->delay_posts[ $post_type ][ $post_data['post_id'] ] = $post_data;
1384
- }
1385
-
1386
-
1387
- /*Important Function
1388
- Import single Post/Content
1389
- */
1390
- private function process_import_single_post( $post_type, $post_data, $delayed = 0 ) {
1391
-
1392
- $this->log( esc_html__('Processing ','advanced-import' ) .$post_type.' '.$post_data['post_id'] );
1393
- $original_post_data = $post_data;
1394
-
1395
- /*if there is not post type return false*/
1396
- if ( ! post_type_exists( $post_type ) ) {
1397
- return false;
1398
- }
1399
-
1400
- /*if it is aready imported return*/
1401
- if ( $this->imported_post_id( $post_data['post_id'] ) ) {
1402
- return true; /*already done*/
1403
- }
1404
-
1405
- /*set post_name id for empty post name/title*/
1406
- if ( empty( $post_data['post_title'] ) && empty( $post_data['post_name'] ) ) {
1407
- $post_data['post_name'] = $post_data['post_id'];
1408
- }
1409
-
1410
- /*set post_type on $post_data*/
1411
- $post_data['post_type'] = $post_type;
1412
-
1413
- /*post_orphans/post parent management */
1414
- $post_parent = isset( $post_data['post_parent'] )?absint( $post_data['post_parent'] ):false;
1415
- if ( $post_parent ) {
1416
- /*if we already know the parent, map it to the new local imported ID*/
1417
- if ( $this->imported_post_id( $post_parent ) ) {
1418
- $post_data['post_parent'] = $this->imported_post_id( $post_parent );
1419
- }
1420
- else {
1421
- /*if there is not parent imported, child will be orphans*/
1422
- $this->post_orphans( absint( $post_data['post_id'] ), $post_parent );
1423
- $post_data['post_parent'] = 0;
1424
- }
1425
- }
1426
-
1427
- /*check if already exists by post_name*/
1428
- if ( empty( $post_data['post_title'] ) && ! empty( $post_data['post_name'] ) ) {
1429
- global $wpdb;
1430
- $sql = "
1431
- SELECT ID, post_name, post_parent, post_type
1432
- FROM $wpdb->posts
1433
- WHERE post_name = %s
1434
- AND post_type = %s
1435
- ";
1436
- $pages = $wpdb->get_results( $wpdb->prepare( $sql, array(
1437
- $post_data['post_name'],
1438
- $post_type,
1439
- ) ), OBJECT_K );
1440
-
1441
- $foundid = 0;
1442
- foreach ( (array) $pages as $page ) {
1443
- if ( $page->post_name == $post_data['post_name'] && empty( $page->post_title ) ) {
1444
- $foundid = $page->ID;
1445
- }
1446
- }
1447
-
1448
- /*if we have found id by post_name, imported_post_id and return*/
1449
- if ( $foundid ) {
1450
- $this->imported_post_id( $post_data['post_id'], $foundid );
1451
- return true;
1452
- }
1453
- }
1454
-
1455
- /*check if already exists by post_name and post_title*/
1456
- /*don't use post_exists because it will dupe up on media with same name but different slug*/
1457
- if ( ! empty( $post_data['post_title'] ) && ! empty( $post_data['post_name'] ) ) {
1458
- global $wpdb;
1459
- $sql = "
1460
- SELECT ID, post_name, post_parent, post_type
1461
- FROM $wpdb->posts
1462
- WHERE post_name = %s
1463
- AND post_title = %s
1464
- AND post_type = %s
1465
- ";
1466
- $pages = $wpdb->get_results( $wpdb->prepare( $sql, array(
1467
- $post_data['post_name'],
1468
- $post_data['post_title'],
1469
- $post_type,
1470
- ) ), OBJECT_K );
1471
-
1472
- $foundid = 0;
1473
- foreach ( (array) $pages as $page ) {
1474
- if ( $page->post_name == $post_data['post_name'] ) {
1475
- $foundid = $page->ID;
1476
- }
1477
- }
1478
-
1479
- /*if we have found id by post_name and post_title, imported_post_id and return*/
1480
- if ( $foundid ) {
1481
- $this->imported_post_id( $post_data['post_id'], $foundid );
1482
- return true;
1483
- }
1484
- }
1485
-
1486
- /*
1487
- * todo it may not required
1488
- * backwards compat with old import format.*/
1489
- if ( isset( $post_data['meta'] ) ) {
1490
- foreach ( $post_data['meta'] as $key => $meta ) {
1491
- if(is_array($meta) && count($meta) == 1){
1492
- $single_meta = current($meta);
1493
- if(!is_array($single_meta)){
1494
- $post_data['meta'][$key] = $single_meta;
1495
- }
1496
- }
1497
- }
1498
- }
1499
-
1500
- /*finally process*/
1501
- switch ( $post_type ) {
1502
-
1503
- /*case attachment*/
1504
- case 'attachment':
1505
-
1506
- /*import media via url*/
1507
- if ( isset( $post_data['guid'] ) && ! empty( $post_data['guid'] ) ) {
1508
-
1509
- /*check if this has already been imported.*/
1510
- $old_guid = $post_data['guid'];
1511
- if ( $this->imported_post_id( $old_guid ) ) {
1512
- return true; /*already done*/
1513
- }
1514
-
1515
- // ignore post parent, we haven't imported those yet.
1516
- // $file_data = wp_remote_get($post_data['guid']);
1517
- $remote_url = $post_data['guid'];
1518
-
1519
- $post_data['upload_date'] = date( 'Y/m', strtotime( $post_data['post_date_gmt'] ) );
1520
-
1521
- if ( isset( $post_data['meta'] ) ) {
1522
- foreach ( $post_data['meta'] as $key => $meta ) {
1523
- if ( $key == '_wp_attached_file' ) {
1524
- foreach ( (array) $meta as $meta_val ) {
1525
- if ( preg_match( '%^[0-9]{4}/[0-9]{2}%', $meta_val, $matches ) ) {
1526
- $post_data['upload_date'] = $matches[0];
1527
- }
1528
- }
1529
- }
1530
- }
1531
- }
1532
-
1533
- /*upload the file*/
1534
- $upload = $this->import_image_and_file( $remote_url, $post_data );
1535
-
1536
- /*if error on upload*/
1537
- if ( ! is_array( $upload ) || is_wp_error( $upload ) ) {
1538
- /*todo: error*/
1539
- return false;
1540
- }
1541
-
1542
- /*check file type, if file type not found return false*/
1543
- if ( $info = wp_check_filetype( $upload['file'] ) ) {
1544
- $post_data['post_mime_type'] = $info['type'];
1545
- }
1546
- else {
1547
- return false;
1548
- }
1549
-
1550
- /*set guid file url*/
1551
- $post_data['guid'] = $upload['url'];
1552
-
1553
- /*
1554
- * insert attachment
1555
- *https://developer.wordpress.org/reference/functions/wp_insert_attachment/
1556
- * */
1557
- $attach_id = wp_insert_attachment( $post_data, $upload['file'] );
1558
- if( $attach_id ) {
1559
-
1560
- /*update meta*/
1561
- if ( ! empty( $post_data['meta'] ) ) {
1562
- foreach ( $post_data['meta'] as $meta_key => $meta_val ) {
1563
- if( $meta_key != '_wp_attached_file' && !empty( $meta_val ) ) {
1564
- update_post_meta( $attach_id, $meta_key, $meta_val );
1565
- }
1566
- }
1567
- }
1568
- /* Update metadata for an attachment.*/
1569
- wp_update_attachment_metadata( $attach_id, wp_generate_attachment_metadata( $attach_id, $upload['file'] ) );
1570
-
1571
- /*remap resized image URLs, works by stripping the extension and remapping the URL stub.*/
1572
- if ( preg_match( '!^image/!', $info['type'] ) ) {
1573
- $parts = pathinfo( $remote_url );
1574
- $name = basename( $parts['basename'], ".{$parts['extension']}" ); // PATHINFO_FILENAME in PHP 5.2
1575
-
1576
- $parts_new = pathinfo( $upload['url'] );
1577
- $name_new = basename( $parts_new['basename'], ".{$parts_new['extension']}" );
1578
-
1579
- $this->imported_post_id( $parts['dirname'] . '/' . $name, $parts_new['dirname'] . '/' . $name_new );
1580
- }
1581
- $this->imported_post_id( $post_data['post_id'], $attach_id );
1582
- }
1583
- }
1584
- break;
1585
-
1586
- default:
1587
-
1588
- /*Process Post Meta*/
1589
- if ( ! empty( $post_data['meta'] ) && is_array( $post_data['meta'] ) ) {
1590
-
1591
- /*fix for double json encoded stuff*/
1592
- foreach ( $post_data['meta'] as $meta_key => $meta_val ) {
1593
- if ( is_string( $meta_val ) && strlen( $meta_val ) && $meta_val[0] == '[' ) {
1594
- $test_json = @json_decode( $meta_val, true );
1595
- if ( is_array( $test_json ) ) {
1596
- $post_data['meta'][ $meta_key ] = $test_json;
1597
- }
1598
- }
1599
- }
1600
-
1601
- array_walk_recursive( $post_data['meta'], array( advanced_import_elementor(), 'elementor_id_import' ) );
1602
-
1603
- /*todo gutenberg and page builders*/
1604
-
1605
- /*replace menu data
1606
- work out what we're replacing. a tax, page, term etc..*/
1607
- //
1608
- if( isset( $post_data['meta']['_menu_item_menu_item_parent'] ) && 0 != $post_data['meta']['_menu_item_menu_item_parent'] ) {
1609
- $new_parent_id = $this->imported_post_id( $post_data['meta']['_menu_item_menu_item_parent'] );
1610
- if( !$new_parent_id ) {
1611
- if ( $delayed ) {
1612
- /*already delayed, unable to find this meta value, skip inserting it*/
1613
- $this->error( esc_html__('Unable to find replacement. Continue anyway.... content will most likely break..','advanced-import') );
1614
- }
1615
- else {
1616
- /*not found , delay it*/
1617
- $this->error( esc_html__('Unable to find replacement. Delaying....','advanced-import') );
1618
- $this->delay_post_process( $post_type, $original_post_data );
1619
- return false;
1620
- }
1621
- }
1622
- $post_data['meta']['_menu_item_menu_item_parent'] = $new_parent_id;
1623
- }
1624
-
1625
- /*if _menu_item_type*/
1626
- if( isset( $post_data['meta'][ '_menu_item_type' ] ) ){
1627
-
1628
- switch( $post_data['meta'][ '_menu_item_type' ] ){
1629
- case 'post_type':
1630
- if( !empty( $post_data['meta']['_menu_item_object_id'] ) ) {
1631
- $new_parent_id = $this->imported_post_id( $post_data['meta']['_menu_item_object_id'] );
1632
- if( !$new_parent_id ) {
1633
- if ( $delayed ) {
1634
- /*already delayed, unable to find this meta value, skip inserting it*/
1635
- $this->error( esc_html__('Unable to find replacement. Continue anyway.... content will most likely break..','advanced-import') );
1636
- }
1637
- else {
1638
- /*not found , delay it*/
1639
- $this->error( esc_html__('Unable to find replacement. Delaying....','advanced-import') );
1640
- $this->delay_post_process( $post_type, $original_post_data );
1641
- return false;
1642
- }
1643
- }
1644
- $post_data['meta']['_menu_item_object_id'] = $new_parent_id;
1645
- }
1646
- break;
1647
-
1648
- case 'taxonomy':
1649
- if( !empty( $post_data['meta']['_menu_item_object_id'] ) ) {
1650
- $new_parent_id = $this->imported_term_id( $post_data['meta']['_menu_item_object_id'] );
1651
- if(!$new_parent_id) {
1652
- if ( $delayed ) {
1653
- /*already delayed, unable to find this meta value, skip inserting it*/
1654
- $this->error( esc_html__('Unable to find replacement. Continue anyway.... content will most likely break..','advanced-import') );
1655
- }
1656
- else {
1657
- /*not found , delay it*/
1658
- $this->error( esc_html__('Unable to find replacement. Delaying....','advanced-import') );
1659
- $this->delay_post_process( $post_type, $original_post_data );
1660
- return false;
1661
- }
1662
- }
1663
- $post_data['meta']['_menu_item_object_id'] = $new_parent_id;
1664
- }
1665
- break;
1666
- }
1667
- }
1668
- }
1669
-
1670
- /*post content parser
1671
- for shortcode post id replacement*/
1672
- $post_data['post_content'] = $this->parse_shortcode_meta_content( $post_data['post_content'] );
1673
-
1674
- $replace_tax_id_keys = array(
1675
- 'taxonomies',
1676
- );
1677
- foreach ( $replace_tax_id_keys as $replace_key ) {
1678
- if ( preg_match_all( '# ' . $replace_key . '="(\d+)"#', $post_data['post_content'], $matches ) ) {
1679
- foreach ( $matches[0] as $match_id => $string ) {
1680
- $new_id = $this->imported_term_id( $matches[1][ $match_id ] );
1681
- if ( $new_id ) {
1682
- $post_data['post_content'] = str_replace( $string, ' ' . $replace_key . '="' . $new_id . '"', $post_data['post_content'] );
1683
- }
1684
- else {
1685
- $this->error( esc_html__('Unable to find TAXONOMY replacement for ','advanced-import' ) . $replace_key . '="' . $matches[1][ $match_id ]. esc_html__('in content.','advanced-import') );
1686
- if ( $delayed ) {
1687
- /*already delayed, unable to find this meta value, skip inserting it*/
1688
- $this->error( esc_html__('Unable to find replacement. Continue anyway.... content will most likely break..','advanced-import') );
1689
- }
1690
- else {
1691
- /*not found , delay it*/
1692
- $this->delay_post_process( $post_type, $original_post_data );
1693
- return false;
1694
- }
1695
- }
1696
- }
1697
- }
1698
- }
1699
-
1700
- /*do further filter if you need*/
1701
- $post_data = apply_filters('advanced_import_post_data',$post_data );
1702
-
1703
- /*finally insert post data*/
1704
- $post_id = wp_insert_post( $post_data, true );
1705
- if ( ! is_wp_error( $post_id ) ) {
1706
-
1707
- /*set id on imported_post_id*/
1708
- $this->imported_post_id( $post_data['post_id'], $post_id );
1709
-
1710
- /*add/update post meta*/
1711
- if ( ! empty( $post_data['meta'] ) ) {
1712
- foreach ( $post_data['meta'] as $meta_key => $meta_val ) {
1713
- /*if the post has a featured image, take note of this in case of remap*/
1714
- if ( '_thumbnail_id' == $meta_key ) {
1715
- /*find this inserted id and use that instead.*/
1716
- $inserted_id = $this->imported_post_id( intval( $meta_val ) );
1717
- if ( $inserted_id ) {
1718
- $meta_val = $inserted_id;
1719
- }
1720
- }
1721
- /*update meta*/
1722
- update_post_meta( $post_id, $meta_key, $meta_val );
1723
- }
1724
- }
1725
-
1726
- if ( ! empty( $post_data['terms'] ) ) {
1727
- $terms_to_set = array();
1728
- foreach ( $post_data['terms'] as $term_slug => $terms ) {
1729
- foreach ( $terms as $term ) {
1730
- $taxonomy = $term['taxonomy'];
1731
- if ( taxonomy_exists( $taxonomy ) ) {
1732
- $term_exists = term_exists( $term['slug'], $taxonomy );
1733
- $term_id = is_array( $term_exists ) ? $term_exists['term_id'] : $term_exists;
1734
- if ( ! $term_id ) {
1735
- if ( ! empty( $term['parent'] ) ) {
1736
- /*see if we have imported this yet?*/
1737
- $term['parent'] = $this->imported_term_id( $term['parent'] );
1738
- }
1739
- $term_id_tax_id = wp_insert_term( $term['name'], $taxonomy, $term );
1740
- if ( ! is_wp_error( $term_id_tax_id ) ) {
1741
- $term_id = $term_id_tax_id['term_id'];
1742
- }
1743
- else {
1744
- // todo - error
1745
- continue;
1746
- }
1747
- }
1748
- /*set term_id on imported_term_id*/
1749
- $this->imported_term_id( $term['term_id'], $term_id );
1750
-
1751
- /*add the term meta.*/
1752
- if( $term_id && !empty( $term['meta'] ) && is_array( $term['meta'] ) ){
1753
- foreach( $term['meta'] as $meta_key => $meta_val ){
1754
- // we have to replace certain meta_key/meta_val
1755
- // e.g. thumbnail id from woocommerce product categories.
1756
- switch( $meta_key ){
1757
- case 'thumbnail_id':
1758
- if( $new_meta_val = $this->imported_post_id($meta_val) ){
1759
- /*use this new id.*/
1760
- $meta_val = $new_meta_val;
1761
- }
1762
- break;
1763
- }
1764
- update_term_meta( $term_id, $meta_key, $meta_val );
1765
- }
1766
- }
1767
- $terms_to_set[ $taxonomy ][] = intval( $term_id );
1768
- }
1769
- }
1770
- }
1771
- foreach ( $terms_to_set as $tax => $ids ) {
1772
- wp_set_post_terms( $post_id, $ids, $tax );
1773
- }
1774
-
1775
- if ( (isset( $post_data['meta']['_elementor_data'] ) && !empty($post_data['meta']['_elementor_data'])) ||
1776
- (isset($post_data['meta']['_elementor_css']) && !!empty($post_data['meta']['_elementor_css']))
1777
- ) {
1778
- advanced_import_elementor()->elementor_post( $post_id );
1779
- }
1780
-
1781
- /*Gutentor*/
1782
- $post = get_post( $post_id );
1783
- $content = $post->post_content;
1784
- if ( preg_match_all( '/data-gpid="(.*?)\" /', $content, $matches ) ) {
1785
- foreach ( $matches[0] as $match_id => $string ) {
1786
- $content = str_replace( $matches[0][$match_id], 'data-gpid="' . $post_id . '" ', $content );
1787
- }
1788
- }
1789
- $post->post_content = $content;
1790
- wp_update_post( $post );
1791
- }
1792
-
1793
- }
1794
- break;
1795
- }
1796
-
1797
- return true;
1798
- }
1799
-
1800
- /*Shortcode/Meta/Post Ids fixed start*/
1801
-
1802
- /*
1803
- * since 1.2.3
1804
- * return the difference in length between two strings
1805
- * */
1806
- public function strlen_diff( $a, $b ) {
1807
- return strlen( $b ) - strlen( $a );
1808
- }
1809
-
1810
-
1811
- /*
1812
- * since 1.2.3
1813
- * helper function to parse url, shortcode, post ids form provided content
1814
- * * currently uses on meta and post content
1815
- * */
1816
- public function parse_shortcode_meta_content( $content ){
1817
- /*we have to format the post content. rewriting images and gallery stuff*/
1818
- $replace = $this->imported_post_id();
1819
-
1820
- /*filters urls for replace*/
1821
- $urls_replace = array();
1822
- foreach ( $replace as $key => $val ) {
1823
- if ( $key && $val && ! is_numeric( $key ) && ! is_numeric( $val ) ) {
1824
- $urls_replace[ $key ] = $val;
1825
- }
1826
- }
1827
- /*replace image/file urls*/
1828
- if ( $urls_replace ) {
1829
- uksort( $urls_replace, array( &$this, 'strlen_diff' ) );
1830
- foreach ( $urls_replace as $from_url => $to_url ) {
1831
- $content = str_replace( $from_url, $to_url, $content );
1832
- }
1833
- }
1834
-
1835
- /*gallery fixed*/
1836
- if ( preg_match_all( '#\[gallery[^\]]*\]#', $content, $matches ) ) {
1837
- foreach ( $matches[0] as $match_id => $string ) {
1838
- if ( preg_match( '#ids="([^"]+)"#', $string, $ids_matches ) ) {
1839
- $ids = explode( ',', $ids_matches[1] );
1840
- foreach ( $ids as $key => $val ) {
1841
- $new_id = $val ? $this->imported_post_id( $val ) : false;
1842
- if ( ! $new_id ) {
1843
- unset( $ids[ $key ] );
1844
- }
1845
- else {
1846
- $ids[ $key ] = $new_id;
1847
- }
1848
- }
1849
- $new_ids = implode( ',', $ids );
1850
- $content = str_replace( $ids_matches[0], 'ids="' . $new_ids . '"', $content );
1851
- }
1852
- }
1853
- }
1854
-
1855
- /*contact form 7 id fixes.*/
1856
- if ( preg_match_all( '#\[contact-form-7[^\]]*\]#', $content, $matches ) ) {
1857
- foreach ( $matches[0] as $match_id => $string ) {
1858
- if ( preg_match( '#id="(\d+)"#', $string, $id_match ) ) {
1859
- $new_id = $this->imported_post_id( $id_match[1] );
1860
- if ( $new_id ) {
1861
- $content = str_replace( $id_match[0], 'id="' . $new_id . '"', $content );
1862
- }
1863
- else {
1864
- /*no imported ID found. remove this entry.*/
1865
- $content = str_replace( $matches[0], '(insert contact form here)', $content );
1866
- }
1867
- }
1868
- }
1869
- }
1870
-
1871
- /*Gutentor*/
1872
- if ( preg_match_all( '/\"pTaxTerm"(.*?)\]/', $content, $matches ) ) {
1873
- foreach ( $matches[0] as $match_id => $string ) {
1874
- if ( preg_match_all( '/\"value":(.*?)\}/', $string, $matches1 ) ) {
1875
- foreach ( $matches1[0] as $match_id1 => $string1 ) {
1876
- $new_id = $this->imported_term_id( $matches1[1][$match_id1] );
1877
- $content = str_replace( $string1, '"value":' . $new_id . '}', $content );
1878
- }
1879
- }
1880
- }
1881
- }
1882
- if ( preg_match_all( '/\"e14TaxTerm"(.*?)\]/', $content, $matches ) ) {
1883
- foreach ( $matches[0] as $match_id => $string ) {
1884
- if ( preg_match_all( '/\"value":(.*?)\}/', $string, $matches1 ) ) {
1885
- foreach ( $matches1[0] as $match_id1 => $string1 ) {
1886
- $new_id = $this->imported_term_id( $matches1[1][$match_id1] );
1887
- $content = str_replace( $string1, '"value":' . $new_id . '}', $content );
1888
- }
1889
- }
1890
- }
1891
- }
1892
- if ( preg_match_all( '/data-gpid="(.*?)\" /', $content, $matches ) ) {
1893
- foreach ( $matches[0] as $match_id => $string ) {
1894
- $new_id = $this->imported_post_id( $matches[1][$match_id] );
1895
- $content = str_replace( $matches[0][$match_id], 'data-gpid="' . $new_id . '" ', $content );
1896
- }
1897
- }
1898
- if ( preg_match_all( '/\"p4PostId"(.*?)\,/', $content, $matches ) ) {
1899
- foreach ( $matches[0] as $match_id => $string ) {
1900
- $new_id = $this->imported_post_id( $matches[1][$match_id] );
1901
- $content = str_replace( $matches[0][$match_id], '"p4PostId":' . $new_id . ',', $content );
1902
- }
1903
- }
1904
- return $content;
1905
- }
1906
- /*Shortcode/Meta/Post Ids fixed end*/
1907
-
1908
- /*update parent page id for child page*/
1909
- private function processpost_orphans() {
1910
-
1911
- /*get post orphans to find it parent*/
1912
- $orphans = $this->post_orphans();
1913
- foreach ( $orphans as $original_post_id => $original_post_parent_id ) {
1914
- if ( $original_post_parent_id ) {
1915
- if ( $this->imported_post_id( $original_post_id ) && $this->imported_post_id( $original_post_parent_id ) ) {
1916
- $post_data = array();
1917
- $post_data['ID'] = $this->imported_post_id( $original_post_id );
1918
- $post_data['post_parent'] = $this->imported_post_id( $original_post_parent_id );
1919
- wp_update_post( $post_data );
1920
- $this->post_orphans( $original_post_id, 0 ); /*ignore future*/
1921
- }
1922
- }
1923
- }
1924
- }
1925
-
1926
- /*Process delayed post
1927
- */
1928
- private function process_delayed_posts( $last_delay = false ) {
1929
-
1930
- $this->log( esc_html__('Processing ','advanced-import'). count( $this->delay_posts, COUNT_RECURSIVE ) . esc_html__('delayed posts','advanced-import') );
1931
- for ( $x = 1; $x < 4; $x ++ ) {
1932
- foreach ( $this->delay_posts as $delayed_post_type => $delayed_post_data_s ) {
1933
- foreach ( $delayed_post_data_s as $delayed_post_id => $delayed_post_data ) {
1934
-
1935
- /*already processed*/
1936
- if ( $this->imported_post_id( $delayed_post_data['post_id'] ) ) {
1937
- $this->log( $x . esc_html__('- Successfully processed ','advanced-import') . $delayed_post_type . esc_html__(' ID ','advanced-import') . $delayed_post_data['post_id'] . esc_html__(' previously.','advanced-import') );
1938
-
1939
- /*already processed, remove it from delay_posts*/
1940
- unset( $this->delay_posts[ $delayed_post_type ][ $delayed_post_id ] );
1941
- $this->log( esc_html__(' ( ','advanced-import') . count( $this->delay_posts, COUNT_RECURSIVE ) . esc_html__(' delayed posts remain ) ','advanced-import') );
1942
- }
1943
- /*Process it*/
1944
- else if ( $this->process_import_single_post( $delayed_post_type, $delayed_post_data, $last_delay ) ) {
1945
- $this->log( $x . esc_html__(' - Successfully found delayed replacement for ','advanced-import') . $delayed_post_type . esc_html__(' ID ','advanced-import') . $delayed_post_data['post_id'] );
1946
-
1947
- /*successfully processed, remove it from delay_posts*/
1948
- unset( $this->delay_posts[ $delayed_post_type ][ $delayed_post_id ] );
1949
- $this->log( esc_html__(' ( ','advanced-import') . count( $this->delay_posts, COUNT_RECURSIVE ) .esc_html__(' delayed posts remain ) ','advanced-import') );
1950
- }
1951
- else{
1952
- $this->log( $x . esc_html__(' - Not found delayed replacement for ','advanced-import') . $delayed_post_type .esc_html__(' ID ' ,'advanced-import'). $delayed_post_data['post_id'] );
1953
- }
1954
- }
1955
- }
1956
- }
1957
- }
1958
-
1959
- /*Get file from url , download it and add to local*/
1960
- private function import_image_and_file( $url, $post ) {
1961
-
1962
- /*extract the file name and extension from the url*/
1963
- $file_name = basename( $url );
1964
- $local_file = ADVANCED_IMPORT_TEMP_UPLOADS. $file_name;
1965
- $upload = false;
1966
-
1967
- /*if file is already on local, return file information
1968
- It means media is on local, while exporting media*/
1969
- if ( is_file( $local_file ) && filesize( $local_file ) > 0 ) {
1970
- require_once( ABSPATH . 'wp-admin/includes/file.php' );
1971
- WP_Filesystem();
1972
- global $wp_filesystem;
1973
- $file_data = $wp_filesystem->get_contents( $local_file );
1974
- $upload = wp_upload_bits( $file_name, 0, $file_data, $post['upload_date'] );
1975
- if ( $upload['error'] ) {
1976
- return new WP_Error( 'upload_dir_error', $upload['error'] );
1977
- }
1978
- }
1979
-
1980
- /*if there is no file on local or error on local file need to fetch it*/
1981
- if ( ! $upload || $upload['error'] ) {
1982
-
1983
- /*get placeholder file in the upload dir with a unique, sanitized filename*/
1984
- $upload = wp_upload_bits( $file_name, 0, '', $post['upload_date'] );
1985
- if ( $upload['error'] ) {
1986
- return new WP_Error( 'upload_dir_error', $upload['error'] );
1987
- }
1988
-
1989
- $max_size = (int) apply_filters( 'import_attachment_size_limit', 0 );
1990
-
1991
- /*finally fetch the file from remote*/
1992
- $response = wp_remote_get( $url );
1993
- if ( is_array( $response ) && ! empty( $response['body'] ) && $response['response']['code'] == '200' ) {
1994
- require_once( ABSPATH . 'wp-admin/includes/file.php' );
1995
- $headers = $response['headers'];
1996
- WP_Filesystem();
1997
- global $wp_filesystem;
1998
- $wp_filesystem->put_contents( $upload['file'], $response['body'] );
1999
- }
2000
- else {
2001
- /*required to download file failed.*/
2002
- wp_delete_file( $upload['file'] );
2003
- return new WP_Error( 'import_file_error', esc_html__( 'Remote server did not respond' ,'advanced-import') );
2004
- }
2005
-
2006
- $file_size = filesize( $upload['file'] );
2007
-
2008
- /*check for size*/
2009
- if ( isset( $headers['content-length'] ) && $file_size != $headers['content-length'] ) {
2010
- wp_delete_file( $upload['file'] );
2011
- return new WP_Error( 'import_file_error', esc_html__( 'Remote file is incorrect size','advanced-import' ) );
2012
- }
2013
-
2014
- /*if file size is 0*/
2015
- if ( 0 == $file_size ) {
2016
- wp_delete_file( $upload['file'] );
2017
- return new WP_Error( 'import_file_error', esc_html__( 'Zero size file downloaded','advanced-import' ) );
2018
- }
2019
-
2020
- /*if file is too large*/
2021
- if ( ! empty( $max_size ) && $file_size > $max_size ) {
2022
- wp_delete_file( $upload['file'] );
2023
- return new WP_Error( 'import_file_error', sprintf( esc_html__( 'Remote file is too large, limit is %s','advanced-import' ), size_format( $max_size ) ) );
2024
- }
2025
- }
2026
-
2027
- /*keep track of the old and new urls so we can substitute them later*/
2028
- $this->imported_post_id( $url, $upload['url'] );
2029
- $this->imported_post_id( $post['guid'], $upload['url'] );
2030
-
2031
- /*keep track of the destination if the remote url is redirected somewhere else*/
2032
- if ( isset( $headers['x-final-location'] ) && $headers['x-final-location'] != $url ) {
2033
- $this->imported_post_id( $headers['x-final-location'], $upload['url'] );
2034
- }
2035
- return $upload;
2036
- }
2037
-
2038
- /*Replace necessary ID by Local imported ID
2039
- 'Posts IDS : page_id','post_id','image_id','selectpage','page_on_front','page_for_posts'
2040
- 'Terms IDS : 'cat_id','nav_menu'
2041
- */
2042
- private function replace_old_id_to_new( $option_value, $index_key = false ){
2043
-
2044
- /*Post IDS*/
2045
- $replace_post_ids = apply_filters('advanced_import_replace_post_ids',
2046
- array(
2047
- 'page_id',
2048
- 'post_id',
2049
- 'image_id',
2050
- 'selectpage',
2051
- 'page_on_front',
2052
- 'page_for_posts',
2053
- 'first_page_id',
2054
- 'second_page_id',
2055
- /*woocommerce pages*/
2056
- 'woocommerce_shop_page_id',
2057
- 'woocommerce_cart_page_id',
2058
- 'woocommerce_checkout_page_id',
2059
- 'woocommerce_pay_page_id',
2060
- 'woocommerce_thanks_page_id',
2061
- 'woocommerce_myaccount_page_id',
2062
- 'woocommerce_edit_address_page_id',
2063
- 'woocommerce_view_order_page_id',
2064
- 'woocommerce_terms_page_id',
2065
- /*gutentor*/
2066
- 'wp_block_id'
2067
- )
2068
- );
2069
-
2070
- /*Terms IDS*/
2071
- $replace_term_ids = apply_filters('advanced_import_replace_term_ids',
2072
- array(
2073
- 'cat_id',
2074
- 'nav_menu',
2075
- 'online_shop_featured_cats',
2076
- 'online_shop_wc_product_cat',
2077
- 'online_shop_wc_product_tag',
2078
- ) );
2079
-
2080
- /*replace terms in keys*/
2081
-
2082
- if( is_array( $option_value ) ){
2083
- foreach ( $option_value as $key => $replace_old_value ){
2084
-
2085
- if( is_array( $replace_old_value) && !is_null( $replace_old_value )){
2086
- $option_value[$key] = $this->replace_old_id_to_new( $replace_old_value );
2087
- }
2088
- elseif ( $this->isJson( $replace_old_value ) && is_string( $replace_old_value ) && !is_null( $replace_old_value ) ){
2089
- $value_array = json_decode( $replace_old_value, true );
2090
- if( is_array( $value_array ) ){
2091
- $option_value[$key]= json_encode( $this->replace_old_id_to_new( $value_array ) );
2092
- }
2093
- else{
2094
- if ( in_array( $key, $replace_post_ids ) && $key !== 0 ) {
2095
- $new_id = $this->imported_post_id( $replace_old_value );
2096
- if ( $new_id ) {
2097
- $option_value[$key] = $new_id;
2098
- }
2099
- }
2100
- elseif ( in_array( $key, $replace_term_ids ) && $key !== 0 ) {
2101
- $new_id = $this->imported_term_id( $replace_old_value );
2102
- if ( $new_id ) {
2103
- $option_value[$key] = $new_id;
2104
- }
2105
- }
2106
- else{
2107
- $option_value[$key] = $replace_old_value;
2108
- }
2109
- }
2110
- }
2111
- else{
2112
-
2113
- if ( in_array( $key, $replace_post_ids ) && $key !== 0) {
2114
-
2115
- $new_id = $this->imported_post_id( $replace_old_value );
2116
- if ( ! $new_id ) {
2117
- /**/
2118
- } else {
2119
- $option_value[$key] = $new_id;
2120
- }
2121
- }
2122
- elseif ( in_array( $key, $replace_term_ids ) && $key !== 0 ) {
2123
- $new_id = $this->imported_term_id( $replace_old_value );
2124
- if ( $new_id ) {
2125
- $option_value[$key] = $new_id;
2126
- }
2127
- }
2128
- else{
2129
- $option_value[$key] = $replace_old_value;
2130
- }
2131
- }
2132
- }
2133
- }
2134
- elseif ( is_numeric( $option_value ) && $index_key ){
2135
-
2136
- if ( in_array( $index_key, $replace_post_ids ) && $index_key !== 0) {
2137
-
2138
- $new_id = $this->imported_post_id( $option_value );
2139
- if ( ! $new_id ) {
2140
- /**/
2141
- } else {
2142
- $option_value = $new_id;
2143
- }
2144
- }
2145
- elseif ( in_array( $index_key, $replace_term_ids ) && $index_key !== 0 ) {
2146
- $new_id = $this->imported_term_id( $option_value );
2147
- if ( $new_id ) {
2148
- $option_value = $new_id;
2149
- }
2150
- }
2151
- }
2152
-
2153
- return $option_value;
2154
- }
2155
-
2156
- /* callback function to importing widgets data
2157
- * all widgets data is imported from here
2158
- * return mix
2159
- * */
2160
- private function import_content_widgets_data() {
2161
- $import_widget_data = $this->get_widgets_json();
2162
- $import_widget_positions = $import_widget_data['widget_positions'];
2163
- $import_widget_options = $import_widget_data['widget_options'];
2164
-
2165
- /* get sidebars_widgets */
2166
- $widget_positions = get_option( 'sidebars_widgets' );
2167
- if ( ! is_array( $widget_positions ) ) {
2168
- $widget_positions = array();
2169
- }
2170
-
2171
- foreach ( $import_widget_options as $widget_name => $widget_options ) {
2172
-
2173
- /*replace $widget_options elements with updated imported entries.*/
2174
- foreach ( $widget_options as $widget_option_id => $widget_option ) {
2175
- $widget_options[$widget_option_id]= $this->replace_old_id_to_new( $widget_option, $widget_option_id );
2176
- }
2177
- $existing_options = get_option( 'widget_' . $widget_name, array() );
2178
- if ( ! is_array( $existing_options ) ) {
2179
- $existing_options = array();
2180
- }
2181
- $new_options = $widget_options + $existing_options ;
2182
-
2183
- $new_options = apply_filters('advanced_import_new_options', $new_options );
2184
-
2185
- update_option( 'widget_' . $widget_name, $new_options );
2186
- }
2187
-
2188
- $sidebars_widgets = array_merge( $widget_positions, $import_widget_positions );
2189
- $sidebars_widgets = apply_filters('advanced_import_sidebars_widgets', $sidebars_widgets,$this );
2190
- update_option( 'sidebars_widgets', $sidebars_widgets);
2191
-
2192
- return true;
2193
-
2194
- }
2195
-
2196
- /*check if string is json*/
2197
- function isJson( $string ) {
2198
- $test_json = @json_decode( $string, true );
2199
- if ( is_array( $test_json ) ) {
2200
- return true;
2201
- }
2202
- return false;
2203
- }
2204
-
2205
- /* callback function to importing menus and options data
2206
- * all menus and import data is imported from here
2207
- * return mix
2208
- * */
2209
- public function import_menu_and_options() {
2210
-
2211
- /*final wrap up of delayed posts.*/
2212
- $this->process_delayed_posts( true );
2213
-
2214
- /*it includes options and menu data*/
2215
- $theme_options = $this->get_theme_options_json();
2216
-
2217
- /*options data*/
2218
- $custom_options = $theme_options['options'];
2219
-
2220
- /*menu data*/
2221
- $menu_ids = $theme_options['menu'];
2222
-
2223
- /*we also want to update the widget area manager options.*/
2224
- if( is_array( $custom_options )){
2225
- foreach ( $custom_options as $option => $value ) {
2226
- /*replace old entries with updated imported entries.*/
2227
- $value= $this->replace_old_id_to_new( $value, $option );
2228
-
2229
- /*we have to update widget page numbers with imported page numbers.*/
2230
- if (
2231
- preg_match( '#(wam__position_)(\d+)_#', $option, $matches ) ||
2232
- preg_match( '#(wam__area_)(\d+)_#', $option, $matches )
2233
- ) {
2234
- $new_page_id = $this->imported_post_id( $matches[2] );
2235
- if ( $new_page_id ) {
2236
- // we have a new page id for this one. import the new setting value.
2237
- $option = str_replace( $matches[1] . $matches[2] . '_', $matches[1] . $new_page_id . '_', $option );
2238
- }
2239
- }
2240
- if ( $value && ! empty( $value['custom_logo'] ) ) {
2241
- $new_logo_id = $this->imported_post_id( $value['custom_logo'] );
2242
- if ( $new_logo_id ) {
2243
- $value['custom_logo'] = $new_logo_id;
2244
- }
2245
- }
2246
- update_option( $option, $value );
2247
- }
2248
- }
2249
-
2250
- /*Options completed
2251
- Menu Start*/
2252
- $save = array();
2253
- foreach ( $menu_ids as $menu_id => $term_id ) {
2254
- $new_term_id = $this->imported_term_id( $term_id );
2255
- if ( $new_term_id ) {
2256
- $save[ $menu_id ] = $new_term_id;
2257
- }
2258
- }
2259
-
2260
- if ( $save ) {
2261
- set_theme_mod( 'nav_menu_locations', array_map( 'absint', $save ) );
2262
- }
2263
-
2264
- global $wp_rewrite;
2265
- $wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
2266
- update_option( 'rewrite_rules', false );
2267
- $wp_rewrite->flush_rules( true );
2268
-
2269
- return true;
2270
- }
2271
-
2272
- public function log( $message ) {
2273
- $this->logs[] = $message;
2274
- }
2275
-
2276
-
2277
- public function error( $message ) {
2278
- $this->logs[] = esc_html__('ERROR!!!! ' ,'advanced-import'). $message;
2279
- }
2280
-
2281
- /* callback function to completed
2282
- * Show Completed Message
2283
- * */
2284
- public function complete_screen() {
2285
-
2286
- /*check for security*/
2287
- if ( ! current_user_can( 'upload_files' ) ) {
2288
- wp_send_json_error(
2289
- array(
2290
- 'message' => esc_html__( 'Sorry, you are not allowed to install demo on this site.','advanced-import' )
2291
- )
2292
- );
2293
- }
2294
-
2295
- require_once( ABSPATH . 'wp-admin/includes/file.php' );
2296
- WP_Filesystem();
2297
- global $wp_filesystem;
2298
- $wp_filesystem->rmdir( ADVANCED_IMPORT_TEMP, true );
2299
-
2300
- set_theme_mod('advanced_import_setup_complete', time() );
2301
- /*delete_transient();*/
2302
- delete_transient('content.json');
2303
- delete_transient('widgets.json');
2304
- delete_transient('options.json');
2305
-
2306
- $message = '<div class="ai-notification-title">';
2307
- $message .= '<p>'.esc_html__( "Your Website is Ready!" ,'advanced-import').'</p>';
2308
- $message .= '<p class="ai-actions-buttons">'.sprintf( esc_html__( ' %sVisit your Site%s ','advanced-import' ),'<a target="_blank" href="'.esc_url(home_url('/')).'">','</a>').'</p>';
2309
- $message .= '<p>'.sprintf( esc_html__( 'Congratulations! All Data is imported successfully. From %s WordPress dashboard%s you can make changes and modify any of the default content to suit your needs.','advanced-import' ),'<a href="'.esc_url(admin_url()).'">','</a>').'</p>';
2310
- $message .= '</div>';
2311
-
2312
- apply_filters('advanced_import_complete_message', $message);
2313
-
2314
- do_action('advanced_import_before_complete_screen');
2315
- echo $message;
2316
- do_action('advanced_import_after_complete_screen');
2317
- exit;
2318
- }
2319
-
2320
-
2321
- /* callback function for wp_ajax_install_plugin
2322
- * Install plugin
2323
- * */
2324
- function install_plugin() {
2325
-
2326
- /*check for security*/
2327
- if ( ! current_user_can( 'install_plugins' ) ) {
2328
- $status['errorMessage'] = __( 'Sorry, you are not allowed to install plugins on this site.', 'advanced-import' );
2329
- wp_send_json_error( $status );
2330
- }
2331
-
2332
- if ( empty( $_POST['plugin'] ) || empty( $_POST['slug'] ) ) {
2333
- wp_send_json_error(
2334
- array(
2335
- 'slug' => '',
2336
- 'errorCode' => 'no_plugin_specified',
2337
- 'errorMessage' => __( 'No plugin specified.', 'advanced-import' ),
2338
- )
2339
- );
2340
- }
2341
-
2342
- $slug = sanitize_key( wp_unslash( $_POST['slug'] ) );
2343
- $plugin = plugin_basename( sanitize_text_field( wp_unslash( $_POST['plugin'] ) ) );
2344
-
2345
- if ( is_plugin_active_for_network( $plugin ) || is_plugin_active( $plugin ) ) {
2346
- // Plugin is activated
2347
- wp_send_json_success();
2348
-
2349
- }
2350
- $status = array(
2351
- 'install' => 'plugin',
2352
- 'slug' => sanitize_key( wp_unslash( $_POST['slug'] ) ),
2353
- );
2354
-
2355
- include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
2356
- include_once ABSPATH . 'wp-admin/includes/plugin-install.php';
2357
-
2358
- // Looks like a plugin is installed, but not active.
2359
- if ( file_exists( WP_PLUGIN_DIR . '/' . $slug ) ) {
2360
- $plugin_data = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin );
2361
- $status['plugin'] = $plugin;
2362
- $status['pluginName'] = $plugin_data['Name'];
2363
-
2364
- if ( current_user_can( 'activate_plugin', $plugin ) && is_plugin_inactive( $plugin ) ) {
2365
- $result = activate_plugin( $plugin );
2366
-
2367
- if ( is_wp_error( $result ) ) {
2368
- $status['errorCode'] = $result->get_error_code();
2369
- $status['errorMessage'] = $result->get_error_message();
2370
- wp_send_json_error( $status );
2371
- }
2372
-
2373
- wp_send_json_success( $status );
2374
- }
2375
- }
2376
-
2377
- $api = plugins_api(
2378
- 'plugin_information',
2379
- array(
2380
- 'slug' => sanitize_key( wp_unslash( $_POST['slug'] ) ),
2381
- 'fields' => array(
2382
- 'sections' => false,
2383
- ),
2384
- )
2385
- );
2386
-
2387
- if ( is_wp_error( $api ) ) {
2388
- $status['errorMessage'] = $api->get_error_message();
2389
- wp_send_json_error( $status );
2390
- }
2391
-
2392
- $status['pluginName'] = $api->name;
2393
-
2394
- $skin = new WP_Ajax_Upgrader_Skin();
2395
- $upgrader = new Plugin_Upgrader( $skin );
2396
- $result = $upgrader->install( $api->download_link );
2397
-
2398
- if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
2399
- $status['debug'] = $skin->get_upgrade_messages();
2400
- }
2401
-
2402
- if ( is_wp_error( $result ) ) {
2403
- $status['errorCode'] = $result->get_error_code();
2404
- $status['errorMessage'] = $result->get_error_message();
2405
- wp_send_json_error( $status );
2406
- } elseif ( is_wp_error( $skin->result ) ) {
2407
- $status['errorCode'] = $skin->result->get_error_code();
2408
- $status['errorMessage'] = $skin->result->get_error_message();
2409
- wp_send_json_error( $status );
2410
- } elseif ( $skin->get_errors()->get_error_code() ) {
2411
- $status['errorMessage'] = $skin->get_error_messages();
2412
- wp_send_json_error( $status );
2413
- } elseif ( is_null( $result ) ) {
2414
- require_once( ABSPATH . 'wp-admin/includes/file.php' );
2415
- WP_Filesystem();
2416
- global $wp_filesystem;
2417
-
2418
- $status['errorCode'] = 'unable_to_connect_to_filesystem';
2419
- $status['errorMessage'] = __( 'Unable to connect to the filesystem. Please confirm your credentials.', 'advanced-import' );
2420
-
2421
- // Pass through the error from WP_Filesystem if one was raised.
2422
- if ( $wp_filesystem instanceof WP_Filesystem_Base && is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->get_error_code() ) {
2423
- $status['errorMessage'] = esc_html( $wp_filesystem->errors->get_error_message() );
2424
- }
2425
-
2426
- wp_send_json_error( $status );
2427
- }
2428
-
2429
- $install_status = install_plugin_install_status( $api );
2430
-
2431
- if ( current_user_can( 'activate_plugin', $install_status['file'] ) && is_plugin_inactive( $install_status['file'] ) ) {
2432
- $result = activate_plugin( $install_status['file'] );
2433
-
2434
- if ( is_wp_error( $result ) ) {
2435
- $status['errorCode'] = $result->get_error_code();
2436
- $status['errorMessage'] = $result->get_error_message();
2437
- wp_send_json_error( $status );
2438
- }
2439
- }
2440
-
2441
- wp_send_json_success( $status );
2442
- }
2443
-
2444
- /* callback function to current_screen
2445
- * Add help Text
2446
- * @param $screen object screen
2447
- * */
2448
- public function help_tabs($screen) {
2449
- if ( !is_array($this->hook_suffix) || !in_array( $screen->base, $this->hook_suffix )){
2450
- return;
2451
- }
2452
- $current_url = advanced_import_current_url();
2453
-
2454
- $screen->add_help_tab(
2455
- array(
2456
- 'id' => 'ai_help_tab_info',
2457
- 'title' => __( 'Information', 'advanced-import' ),
2458
- 'content' =>
2459
- '<h2>' . __( 'Information', 'advanced-import' ) . '</h2>' .
2460
- '<p>' . sprintf(
2461
- __( 'Export you content via, <a href="%s" target="_blank">Advanced Export</a>. You can import export content, widget, customizer and media files too.', 'advanced-import' ),
2462
- 'https://wordpress.org/plugins/advanced-export/'
2463
- ) . '</p>' .
2464
- '<p>' . sprintf(
2465
- __( 'The zip file exported via <a href="%1$s" target="_blank">Advanced Export</a>. can be imported from this plugin <a href="%2$s">Advanced Import</a>.', 'advanced-import' ),
2466
- 'https://wordpress.org/support/plugin/advanced-export',
2467
- 'https://wordpress.org/support/plugin/advanced-import'
2468
- ) . '</p>' .
2469
- '<p><a href="' . 'https://wordpress.org/support/plugin/advanced-import' . '" class="button button-primary" target="_blank">' . __( 'Community forum', 'advanced-import' ) . '</a> <a href="' . 'https://www.addonspress.com/' . '" class="button" target="_blank">' . __( 'Author', 'advanced-import' ) . '</a></p>',
2470
- )
2471
- );
2472
-
2473
- $reset_url = wp_nonce_url(
2474
- add_query_arg( 'ai_reset_wordpress', 'true', $current_url ),
2475
- 'ai_reset_wordpress',
2476
- 'ai_reset_wordpress_nonce'
2477
- );
2478
- $screen->add_help_tab(
2479
- array(
2480
- 'id' => 'ai_help_tab_reset',
2481
- 'title' => __( 'Reset wizard', 'advanced-import' ),
2482
- 'content' =>
2483
- '<h2>'.__( '<strong>WordPress Reset</strong>', 'advanced-import' ).'</h2>'.
2484
- '<p>'.__( 'If no important data on your site. You can reset the WordPress back to default again!', 'advanced-import' ).'</p>'.
2485
- '<p class="submit"><a href="'.esc_url( $reset_url ).'" class="button button-primary ai-wp-reset">'. __( 'Run the Reset Wizard', 'advanced-import' ).'</a></p>' )
2486
- );
2487
-
2488
- $screen->set_help_sidebar(
2489
- '<p><strong>' . __( 'More information:', 'advanced-import' ) . '</strong></p>' .
2490
- '<p><a href="' . 'https://wordpress.org/plugins/advanced-export/' . '" target="_blank">' . __( 'Advanced Export', 'advanced-import' ) . '</a></p>' .
2491
- '<p><a href="' . 'https://wordpress.org/plugins/advanced-import/' . '" target="_blank">' . __( 'Advanced Import', 'advanced-import' ) . '</a></p>'
2492
- );
2493
- }
2494
- }
2495
-
2496
- /**
2497
- * Begins execution of the plugin.
2498
- *
2499
- * Since everything within the plugin is registered via hooks,
2500
- * then kicking off the plugin from this point in the file does
2501
- * not affect the page life cycle.
2502
- *
2503
- * @since 1.0.0
2504
- */
2505
- function advanced_import_admin( ) {
2506
- return Advanced_Import_Admin::instance();
2507
- }
 
 
 
 
 
 
 
 
1
+ <?php // phpcs:ignore WordPress.Files.FileName
2
+ /**
3
+ * Advanced Import Admin class
4
+ *
5
+ * Collection of admin hooks
6
+ *
7
+ * @package Advanced_Import
8
+ * @since 1.0.0
9
+ */
10
+
11
+ if ( ! defined( 'ABSPATH' ) ) {
12
+ exit;
13
+ }
14
+
15
+ /**
16
+ * The admin-specific functionality of the plugin.
17
+ *
18
+ * Defines the plugin name, version, and two examples hooks for how to
19
+ * enqueue the admin-specific stylesheet and JavaScript.
20
+ *
21
+ * @package Advanced_Import
22
+ * @subpackage Advanced_Import/admin
23
+ * @author Addons Press <addonspress.com>
24
+ */
25
+ class Advanced_Import_Admin {
26
+
27
+ /**
28
+ * The Name of this plugin.
29
+ *
30
+ * @since 1.0.0
31
+ * @access private
32
+ * @var string $plugin_name The ID of this plugin.
33
+ */
34
+ private $plugin_name;
35
+
36
+ /**
37
+ * The version of this plugin.
38
+ *
39
+ * @since 1.0.0
40
+ * @access private
41
+ * @var string $version The current version of this plugin.
42
+ */
43
+ private $version;
44
+
45
+ /**
46
+ * The Current theme name
47
+ *
48
+ * @since 1.0.0
49
+ * @access public
50
+ * @var string $theme_name The Current theme name.
51
+ */
52
+ public $theme_name = '';
53
+
54
+ /**
55
+ * Current step
56
+ *
57
+ * @since 1.0.0
58
+ * @access protected
59
+ * @var string $step Current step.
60
+ */
61
+ protected $step = '';
62
+
63
+ /**
64
+ * Array of steps
65
+ *
66
+ * @since 1.0.0
67
+ * @access public
68
+ * @var array $steps Array of steps.
69
+ */
70
+ protected $steps = array();
71
+
72
+ /**
73
+ * Demo lists
74
+ *
75
+ * @since 1.0.0
76
+ * @access public
77
+ * @var array $demo_lists Array of demo lists.
78
+ */
79
+ protected $demo_lists = array();
80
+
81
+ /**
82
+ * Demo lists
83
+ *
84
+ * @since 1.0.0
85
+ * @access public
86
+ * @var array $demo_lists Array of demo lists.
87
+ */
88
+ protected $is_pro_active = false;
89
+
90
+ /**
91
+ * Array of delayed post for late process
92
+ *
93
+ * @since 1.0.0
94
+ * @access public
95
+ * @var array $delay_posts Array of delayed post for late process.
96
+ */
97
+ private $delay_posts = array();
98
+
99
+ /**
100
+ * Store logs and errors
101
+ *
102
+ * @since 1.0.0
103
+ * @access public
104
+ * @var array $logs Store logs and errors.
105
+ */
106
+ public $logs = array();
107
+
108
+ /**
109
+ * Store errors
110
+ *
111
+ * @since 1.0.0
112
+ * @access public
113
+ * @var array $errors Store errors.
114
+ */
115
+ public $errors = array();
116
+
117
+ /**
118
+ * Current added Menu hook_suffix
119
+ *
120
+ * @since 1.0.0
121
+ * @access public
122
+ * @var array $logs Store logs and errors.
123
+ */
124
+ public $hook_suffix;
125
+
126
+ /**
127
+ * Slug of the import page
128
+ *
129
+ * @since 1.0.0
130
+ * @access public
131
+ * @var string $logs Store logs and errors.
132
+ */
133
+ private $current_template_type;
134
+
135
+ /**
136
+ * Slug of the import page
137
+ *
138
+ * @since 1.0.0
139
+ * @access public
140
+ * @var string $logs Store logs and errors.
141
+ */
142
+ private $current_template_url;
143
+
144
+ /**
145
+ * Initialize the class and set its properties.
146
+ *
147
+ * @since 1.0.0
148
+ */
149
+ public function __construct() {}
150
+
151
+ /**
152
+ * Main Advanced_Import_Admin Instance
153
+ * Initialize the class and set its properties.
154
+ *
155
+ * @since 1.0.0
156
+ * @return object $instance Advanced_Import_Admin Instance
157
+ */
158
+ public static function instance() {
159
+
160
+ // Store the instance locally to avoid private static replication.
161
+ static $instance = null;
162
+
163
+ // Only run these methods if they haven't been ran previously.
164
+ if ( null === $instance ) {
165
+ $instance = new Advanced_Import_Admin();
166
+ $instance->plugin_name = ADVANCED_IMPORT_PLUGIN_NAME;
167
+ $instance->version = ADVANCED_IMPORT_VERSION;
168
+
169
+ /*page slug using theme name */
170
+ $instance->theme_name = sanitize_key( get_option( 'template' ) );
171
+
172
+ }
173
+
174
+ // Always return the instance.
175
+ return $instance;
176
+ }
177
+
178
+ /**
179
+ * Check if template is available to import
180
+ *
181
+ * @since 1.0.8
182
+ * @param array $item current array of demo list.
183
+ * @return boolean
184
+ */
185
+ public function is_template_available( $item ) {
186
+ $is_available = false;
187
+
188
+ /*if pro active everything is available*/
189
+ if ( $this->is_pro_active ) {
190
+ $is_available = true;
191
+ } elseif ( ! isset( $item['is_pro'] ) ) {/*if is_pro not set the $item is available*/
192
+ $is_available = true;/*template available since */
193
+ } elseif ( isset( $item['is_pro'] ) && ! $item['is_pro'] ) {/*if is_pro not set but it is false, it will be free and avialable*/
194
+ $is_available = true;
195
+ }
196
+
197
+ return (bool) apply_filters( 'advanced_import_is_template_available', $is_available, $item );
198
+ }
199
+
200
+ /**
201
+ * Return Template Button
202
+ *
203
+ * @since 1.0.8
204
+ * @param array $item current array of demo list.
205
+ * @return string
206
+ */
207
+ public function template_button( $item ) {
208
+ /*Start buffering*/
209
+ ob_start();
210
+
211
+ if ( $this->is_template_available( $item ) ) {
212
+ $plugins = isset( $item['plugins'] ) && is_array( $item['plugins'] ) ? ' data-plugins="' . esc_attr( wp_json_encode( $item['plugins'] ) ) . '"' : '';
213
+ ?>
214
+ <a class="button ai-demo-import ai-item-import is-button is-default is-primary is-large button-primary" href="#" aria-label="<?php esc_attr_e( 'Import', 'advanced-import' ); ?>" <?php echo $plugins; ?>>
215
+ <span class="dashicons dashicons-download"></span><?php esc_html_e( 'Import', 'advanced-import' ); ?>
216
+ </a>
217
+ <?php
218
+ } else {
219
+ ?>
220
+ <a class="button is-button is-default is-primary is-large button-primary"
221
+ href="<?php echo esc_url( isset( $item['pro_url'] ) ? $item['pro_url'] : '#' ); ?>"
222
+ target="_blank"
223
+ aria-label="<?php esc_attr_e( 'View Pro', 'advanced-import' ); ?>">
224
+ <span class="dashicons dashicons-awards"></span><?php esc_html_e( 'View Pro', 'advanced-import' ); ?>
225
+ </a>
226
+ <?php
227
+ }
228
+
229
+ /*removes the buffer (without printing it), and returns its content.*/
230
+ $render_button = ob_get_clean();
231
+
232
+ $render_button = apply_filters( 'advanced_import_template_import_button', $render_button, $item );
233
+ return $render_button;
234
+
235
+ }
236
+
237
+ /**
238
+ * Register the stylesheets for the admin area.
239
+ *
240
+ * @since 1.0.8
241
+ * @param string $hook_suffix current hook.
242
+ * @return void
243
+ */
244
+ public function enqueue_styles( $hook_suffix ) {
245
+ if ( ! is_array( $this->hook_suffix ) || ! in_array( $hook_suffix, $this->hook_suffix ) ) {
246
+ return;
247
+ }
248
+ wp_enqueue_style( $this->plugin_name, ADVANCED_IMPORT_URL . 'assets/css/advanced-import-admin' . ADVANCED_IMPORT_SCRIPT_PREFIX . '.css', array( 'wp-admin', 'dashicons' ), $this->version, 'all' );
249
+ wp_enqueue_media();
250
+ }
251
+
252
+ /**
253
+ * Register the JavaScript for the admin area.
254
+ *
255
+ * @since 1.0.8
256
+ * @param string $hook_suffix current hook.
257
+ * @return void
258
+ */
259
+ public function enqueue_scripts( $hook_suffix ) {
260
+ if ( ! is_array( $this->hook_suffix ) || ! in_array( $hook_suffix, $this->hook_suffix ) ) {
261
+ return;
262
+ }
263
+
264
+ // Isotope Js.
265
+ wp_enqueue_script(
266
+ 'isotope', // Handle.
267
+ ADVANCED_IMPORT_URL . '/assets/library/isotope/isotope.pkgd' . ADVANCED_IMPORT_SCRIPT_PREFIX . '.js',
268
+ array( 'jquery' ), // Dependencies, defined above.
269
+ '3.0.6', // Version: File modification time.
270
+ true // Enqueue the script in the footer.
271
+ );
272
+
273
+ // sweetalert2 Js.
274
+ wp_enqueue_script(
275
+ 'sweetalert2', // Handle.
276
+ ADVANCED_IMPORT_URL . '/assets/library/sweetalert2/sweetalert2.all' . ADVANCED_IMPORT_SCRIPT_PREFIX . '.js',
277
+ array( 'jquery' ), // Dependencies, defined above.
278
+ '3.0.6', // Version: File modification time.
279
+ true // Enqueue the script in the footer.
280
+ );
281
+
282
+ wp_enqueue_script( $this->plugin_name, ADVANCED_IMPORT_URL . 'assets/js/advanced-import-admin' . ADVANCED_IMPORT_SCRIPT_PREFIX . '.js', array( 'jquery', 'masonry' ), $this->version, true );
283
+ wp_localize_script(
284
+ $this->plugin_name,
285
+ 'advanced_import_object',
286
+ array(
287
+ 'ajaxurl' => admin_url( 'admin-ajax.php' ),
288
+ 'wpnonce' => wp_create_nonce( 'advanced_import_nonce' ),
289
+ 'text' => array(
290
+ 'failed' => esc_html__( 'Failed', 'advanced-import' ),
291
+ 'error' => esc_html__( 'Error', 'advanced-import' ),
292
+ 'skip' => esc_html__( 'Skipping', 'advanced-import' ),
293
+ 'confirmImport' => array(
294
+ 'title' => esc_html__( 'Advanced Import! Just a step away', 'advanced-import' ),
295
+ 'html' => sprintf(
296
+ /* translators: 1: message 1, 2: message 2., 3: message 3., 4: message 4. */
297
+ __( 'Importing demo data is the easiest way to setup your theme. It will allow you to quickly edit everything instead of creating content from scratch. Also, read following points before importing the demo: %1$s %2$s %3$s %4$s', 'advanced-import' ),
298
+ '<ol><li class="warning">' . __( 'It is highly recommended to import demo on fresh WordPress installation to exactly replicate the theme demo. If no important data on your site, you can reset it from Reset Wizard at the top', 'advanced-import' ) . '</li>',
299
+ '<li>' . __( 'No existing posts, pages, categories, images, custom post types or any other data will be deleted or modified.', 'advanced-import' ) . '</li>',
300
+ '<li>' . __( 'It will install the plugins required for demo and activate them. Also posts, pages, images, widgets, & other data will get imported.', 'advanced-import' ) . '</li>',
301
+ '<li>' . __( 'Please click on the Import button and wait, it will take some time to import the data.', 'advanced-import' ) . '</li></ol>'
302
+ ),
303
+ 'confirmButtonText' => esc_html__( 'Yes, Import Demo!', 'advanced-import' ),
304
+ 'cancelButtonText' => esc_html__( 'Cancel', 'advanced-import' ),
305
+ ),
306
+ 'confirmReset' => array(
307
+ 'title' => esc_html__( 'Are you sure?', 'advanced-import' ),
308
+ 'text' => __( "You won't be able to revert this!", 'advanced-import' ),
309
+ 'confirmButtonText' => esc_html__( 'Yes, Reset', 'advanced-import' ),
310
+ 'cancelButtonText' => esc_html__( 'Cancel', 'advanced-import' ),
311
+ ),
312
+ 'resetSuccess' => array(
313
+ 'title' => esc_html__( 'Reset Successful', 'advanced-import' ),
314
+ 'confirmButtonText' => esc_html__( 'Ok', 'advanced-import' ),
315
+ ),
316
+ 'failedImport' => array(
317
+ 'code' => __( 'Error Code:', 'advanced-import' ),
318
+ 'text' => __( 'Contact theme author or try again', 'advanced-import' ),
319
+ ),
320
+ 'successImport' => array(
321
+ 'confirmButtonText' => esc_html__( 'Visit My Site', 'advanced-import' ),
322
+ 'cancelButtonText' => esc_html__( 'Okay', 'advanced-import' ),
323
+ ),
324
+ ),
325
+ )
326
+ );
327
+ }
328
+
329
+ /**
330
+ * Adding new mime types.
331
+ *
332
+ * @access public
333
+ * @since 1.0.0
334
+ * @param array $mimes existing mime types.
335
+ * @return array
336
+ */
337
+ public function mime_types( $mimes ) {
338
+ $add_mimes = array(
339
+ 'json' => 'text/plain',
340
+ );
341
+
342
+ return array_merge( $mimes, $add_mimes );
343
+ }
344
+
345
+ /**
346
+ * Determine if the user already has theme content installed.
347
+ *
348
+ * @access public
349
+ */
350
+ public function is_possible_upgrade() {
351
+ return false;
352
+ }
353
+
354
+ /**
355
+ * Add admin menus
356
+ *
357
+ * @access public
358
+ */
359
+ public function import_menu() {
360
+ $this->hook_suffix[] = add_theme_page( esc_html__( 'Demo Import ', 'advanced-import' ), esc_html__( 'Demo Import' ), 'manage_options', 'advanced-import', array( $this, 'demo_import_screen' ) );
361
+ $this->hook_suffix[] = add_management_page( esc_html__( 'Advanced Import', 'advanced-import' ), esc_html__( 'Advanced Import', 'advanced-import' ), 'manage_options', 'advanced-import-tool', array( $this, 'demo_import_screen' ) );
362
+
363
+ }
364
+
365
+ /**
366
+ * Show the setup
367
+ *
368
+ * @access public
369
+ * @return void
370
+ */
371
+ public function demo_import_screen() {
372
+ do_action( 'advanced_import_before_demo_import_screen' );
373
+
374
+ $this->step = isset( $_GET['step'] ) ? sanitize_key( $_GET['step'] ) : current( array_keys( $this->steps ) );
375
+
376
+ echo '<div class="ai-body">';
377
+
378
+ $this->get_header();
379
+
380
+ echo '<div class="ai-content">';
381
+ echo '<div class="ai-content-blocker hidden">';
382
+ echo '<div class="ai-notification-title"><p>' . esc_html__( 'Processing... Please do not refresh this page or do not go to other url!', 'advanced-import' ) . '</p></div>';
383
+ echo '<div id="ai-demo-popup"></div>';
384
+ echo '</div>';
385
+ $this->init_demo_import();
386
+ echo '</div>';
387
+ echo '</div>';/*ai-body*/
388
+ do_action( 'advanced_import_after_demo_import_screen' );
389
+
390
+ }
391
+
392
+ /**
393
+ * Get header of setup
394
+ *
395
+ * @access public
396
+ * @return void
397
+ */
398
+ public function get_header() {
399
+ global $pagenow;
400
+
401
+ $welcome_msg = "<div class='ai-header'>";
402
+ /* translators: 1: current theme */
403
+ $welcome_msg .= '<h1>' . sprintf( esc_html__( 'Welcome to the Advanced Import for %s.', 'advanced-import' ), wp_get_theme() ) . '</h1>';
404
+ if ( $pagenow != 'tools.php' ) {
405
+ /* translators: 1: current theme */
406
+ $welcome_msg .= ' <p>' . sprintf( esc_html__( 'Thank you for choosing the %s theme. This quick demo import setup will help you configure your new website like theme demo. It will install the required WordPress plugins, default content and tell you a little about Help &amp; Support options. It should only take less than 5 minutes.', 'advanced-import' ), wp_get_theme() ) . '</p>';
407
+ }
408
+ $welcome_msg .= '</div>';
409
+ echo advanced_import_allowed_html( apply_filters( 'advanced_import_welcome_message', $welcome_msg ) );
410
+
411
+ if ( get_theme_mod( 'advanced_import_setup_complete', false ) && $pagenow != 'tools.php' ) {
412
+ ?>
413
+ <p><?php esc_html_e( 'It looks like you have already run the demo import for this theme.', 'advanced-import' ); ?></p>
414
+ <?php
415
+ }
416
+ }
417
+
418
+ /**
419
+ * Handle the demo content upload and called to process
420
+ * Ajax callback
421
+ *
422
+ * @return void
423
+ */
424
+ public function upload_zip() {
425
+ if ( isset( $_FILES['ai-upload-zip-archive']['name'] ) && ! empty( $_FILES['ai-upload-zip-archive']['name'] ) ) {
426
+ /*check for security*/
427
+ if ( ! current_user_can( 'upload_files' ) ) {
428
+ wp_send_json_error(
429
+ array(
430
+ 'message' => esc_html__( 'Sorry, you are not allowed to install demo on this site.', 'advanced-import' ),
431
+ )
432
+ );
433
+ }
434
+ check_admin_referer( 'advanced-import' );
435
+
436
+ /*file process*/
437
+ require_once ABSPATH . 'wp-admin/includes/file.php';
438
+ WP_Filesystem();
439
+ global $wp_filesystem;
440
+ $wp_filesystem->rmdir( ADVANCED_IMPORT_TEMP, true );
441
+ $upload_zip_archive = $_FILES['ai-upload-zip-archive'];
442
+ $unzipfile = unzip_file( $upload_zip_archive['tmp_name'], ADVANCED_IMPORT_TEMP );
443
+ if ( is_wp_error( $unzipfile ) ) {
444
+ wp_send_json_error(
445
+ array(
446
+ 'message' => esc_html__( 'Error on unzipping, Please try again', 'advanced-import' ),
447
+ )
448
+ );
449
+ }
450
+ /*(check) Zip should contain json file and uploads folder only*/
451
+ $dirlist = $wp_filesystem->dirlist( ADVANCED_IMPORT_TEMP );
452
+ foreach ( (array) $dirlist as $filename => $fileinfo ) {
453
+ if ( $fileinfo['type'] == 'd' ) {
454
+ if ( $filename == 'uploads' ) {
455
+ continue;
456
+ } else {
457
+ $wp_filesystem->rmdir( ADVANCED_IMPORT_TEMP, true );
458
+ wp_send_json_error(
459
+ array(
460
+ 'message' => esc_html__( 'Invalid Zip File', 'advanced-import' ),
461
+ )
462
+ );
463
+ }
464
+ } else {
465
+ $filetype = wp_check_filetype( $filename );
466
+ if ( empty( $filetype['ext'] ) || $filetype['ext'] != 'json' ) {
467
+ $wp_filesystem->rmdir( ADVANCED_IMPORT_TEMP, true );
468
+ wp_send_json_error(
469
+ array(
470
+ 'message' => esc_html__( 'Invalid Zip File', 'advanced-import' ),
471
+ )
472
+ );
473
+ }
474
+ }
475
+ }
476
+ wp_send_json_success(
477
+ array(
478
+ 'message' => esc_html__( 'Success', 'advanced-import' ),
479
+ )
480
+ );
481
+ }
482
+ wp_send_json_error(
483
+ array(
484
+ 'message' => esc_html__( 'No Zip File Found', 'advanced-import' ),
485
+ )
486
+ );
487
+ }
488
+
489
+ /**
490
+ * Download Zip file/ Move it to temp import folder
491
+ * Ajax callback
492
+ *
493
+ * @return mixed
494
+ */
495
+ public function demo_download_and_unzip() {
496
+
497
+ /*check for security*/
498
+ if ( ! current_user_can( 'upload_files' ) ) {
499
+ wp_send_json_error(
500
+ array(
501
+ 'message' => esc_html__( 'Sorry, you are not allowed to install demo on this site.', 'advanced-import' ),
502
+ )
503
+ );
504
+ }
505
+ check_admin_referer( 'advanced-import' );
506
+
507
+ /*get file and what should do*/
508
+ $demo_file = is_array( $_POST['demo_file'] ) ? (array) $_POST['demo_file'] : sanitize_text_field( $_POST['demo_file'] );
509
+ $demo_file_type = sanitize_text_field( $_POST['demo_file_type'] );
510
+
511
+ /*from file*/
512
+ if ( $demo_file_type == 'file' ) {
513
+ require_once ABSPATH . 'wp-admin/includes/file.php';
514
+ WP_Filesystem();
515
+ global $wp_filesystem;
516
+ $wp_filesystem->rmdir( ADVANCED_IMPORT_TEMP, true );
517
+ $unzipfile = unzip_file( $demo_file, ADVANCED_IMPORT_TEMP );
518
+ if ( is_wp_error( $unzipfile ) ) {
519
+ wp_send_json_error(
520
+ array(
521
+ 'message' => esc_html__( 'Error on unzipping, Please try again', 'advanced-import' ),
522
+ )
523
+ );
524
+ }
525
+ /*(check) Zip should contain json file and uploads folder only*/
526
+ $dirlist = $wp_filesystem->dirlist( ADVANCED_IMPORT_TEMP );
527
+ foreach ( (array) $dirlist as $filename => $fileinfo ) {
528
+ if ( $fileinfo['type'] == 'd' ) {
529
+ if ( $filename == 'uploads' ) {
530
+ continue;
531
+ } else {
532
+ $wp_filesystem->rmdir( ADVANCED_IMPORT_TEMP, true );
533
+ wp_send_json_error(
534
+ array(
535
+ 'message' => esc_html__( 'Invalid Zip File', 'advanced-import' ),
536
+ )
537
+ );
538
+ }
539
+ } else {
540
+ $filetype = wp_check_filetype( $filename );
541
+ if ( empty( $filetype['ext'] ) || $filetype['ext'] != 'json' ) {
542
+ $wp_filesystem->rmdir( ADVANCED_IMPORT_TEMP, true );
543
+ wp_send_json_error(
544
+ array(
545
+ 'message' => esc_html__( 'Invalid Zip File', 'advanced-import' ),
546
+ )
547
+ );
548
+ }
549
+ }
550
+ }
551
+ wp_send_json_success(
552
+ array(
553
+ 'message' => esc_html__( 'Success', 'advanced-import' ),
554
+ )
555
+ );
556
+ } elseif ( $demo_file_type == 'url' ) {
557
+
558
+ /*finally fetch the file from remote*/
559
+ $response = wp_remote_get( $demo_file );
560
+
561
+ if ( is_array( $response ) && ! empty( $response['body'] ) && $response['response']['code'] == '200' ) {
562
+ require_once ABSPATH . 'wp-admin/includes/file.php';
563
+ WP_Filesystem();
564
+ global $wp_filesystem;
565
+ $file_permission = 0777;
566
+ if ( ! file_exists( ADVANCED_IMPORT_TEMP_ZIP ) ) {
567
+ $wp_filesystem->mkdir( ADVANCED_IMPORT_TEMP_ZIP, $file_permission, true );
568
+ }
569
+ $temp_import_zip = trailingslashit( ADVANCED_IMPORT_TEMP_ZIP ) . 'temp-import.zip';
570
+ $wp_filesystem->put_contents( $temp_import_zip, $response['body'], 0777 );
571
+
572
+ } else {
573
+ /*required to download file failed.*/
574
+ wp_send_json_error(
575
+ array(
576
+ 'error' => 1,
577
+ 'message' => esc_html__( 'Remote server did not respond, Contact to Theme Author', 'advanced-import' ),
578
+ )
579
+ );
580
+ }
581
+
582
+ $file_size = filesize( $temp_import_zip );
583
+
584
+ /*if file size is 0*/
585
+ if ( 0 == $file_size ) {
586
+ $wp_filesystem->rmdir( ADVANCED_IMPORT_TEMP_ZIP, true );
587
+ wp_send_json_error(
588
+ array(
589
+ 'error' => 1,
590
+ 'message' => esc_html__( 'Zero size file downloaded, Contact to Theme Author', 'advanced-import' ),
591
+ )
592
+ );
593
+ }
594
+
595
+ /*if file is too large*/
596
+ if ( ! empty( $max_size ) && $file_size > $max_size ) {
597
+ $wp_filesystem->rmdir( ADVANCED_IMPORT_TEMP_ZIP, true );
598
+ wp_send_json_error(
599
+ array(
600
+ 'error' => 1,
601
+ 'message' => sprintf( esc_html__( 'Remote file is too large, limit is %s', 'advanced-import' ), size_format( $max_size ) ),
602
+ )
603
+ );
604
+ }
605
+
606
+ /*if we are here then unzip file*/
607
+ $unzipfile = unzip_file( $temp_import_zip, ADVANCED_IMPORT_TEMP );
608
+ if ( is_wp_error( $unzipfile ) ) {
609
+ wp_send_json_error(
610
+ array(
611
+ 'error' => 1,
612
+ 'message' => esc_html__( 'Error on unzipping, Please try again', 'advanced-import' ),
613
+ )
614
+ );
615
+ }
616
+ $wp_filesystem->rmdir( ADVANCED_IMPORT_TEMP_ZIP, true );
617
+
618
+ /*(check) Zip should contain json file and uploads folder only*/
619
+ $dirlist = $wp_filesystem->dirlist( ADVANCED_IMPORT_TEMP );
620
+ foreach ( (array) $dirlist as $filename => $fileinfo ) {
621
+ if ( $fileinfo['type'] == 'd' ) {
622
+ if ( $filename == 'uploads' ) {
623
+ continue;
624
+ } else {
625
+ $wp_filesystem->rmdir( ADVANCED_IMPORT_TEMP, true );
626
+ wp_send_json_error(
627
+ array(
628
+ 'message' => esc_html__( 'Invalid Zip File', 'advanced-import' ),
629
+ )
630
+ );
631
+ }
632
+ } else {
633
+ $filetype = wp_check_filetype( $filename );
634
+ if ( empty( $filetype['ext'] ) || $filetype['ext'] != 'json' ) {
635
+ $wp_filesystem->rmdir( ADVANCED_IMPORT_TEMP, true );
636
+ wp_send_json_error(
637
+ array(
638
+ 'message' => esc_html__( 'Invalid Zip File', 'advanced-import' ),
639
+ )
640
+ );
641
+ }
642
+ }
643
+ }
644
+ wp_send_json_success(
645
+ array(
646
+ 'message' => esc_html__( 'Success', 'advanced-import' ),
647
+ )
648
+ );
649
+
650
+ } else {
651
+ wp_send_json_error(
652
+ array(
653
+ 'error' => 1,
654
+ 'message' => esc_html__( 'File not allowed', 'advanced-import' ),
655
+ )
656
+ );
657
+ }
658
+ }
659
+
660
+ /**
661
+ * List Demo List
662
+ *
663
+ * @return void
664
+ */
665
+ public function demo_list( $demo_lists, $total_demo ) {
666
+ ?>
667
+ <div class="ai-filter-header">
668
+ <div class="ai-filter-tabs">
669
+ <ul class="ai-types ai-filter-group" data-filter-group="secondary">
670
+ <li class="ai-filter-btn-active ai-filter-btn" data-filter="*">
671
+ <?php esc_html_e( 'All', 'advanced-import' ); ?>
672
+ <span class="ai-count"></span>
673
+ </li>
674
+ <?php
675
+ $types = array_column( $demo_lists, 'type' );
676
+ $unique_types = array_unique( $types );
677
+ foreach ( $unique_types as $cat_index => $single_type ) {
678
+ ?>
679
+ <li class="ai-filter-btn" data-filter=".<?php echo strtolower( esc_attr( $single_type ) ); ?>">
680
+ <?php echo ucfirst( esc_html( $single_type ) ); ?>
681
+ <span class="ai-count"></span>
682
+
683
+ </li>
684
+ <?php
685
+ }
686
+ ?>
687
+ </ul>
688
+ <div class="ai-search-control">
689
+ <input id="ai-filter-search-input" class="ai-search-filter" type="text" placeholder="<?php esc_attr_e( 'Search...', 'advanced-import' ); ?>">
690
+ </div>
691
+ <ul class="ai-form-type">
692
+ <li class="ai-form-file-import">
693
+ <?php esc_html_e( 'Upload zip', 'advanced-import' ); ?>
694
+ </li>
695
+ </ul>
696
+ </div>
697
+ </div>
698
+ <div class="ai-filter-content" id="ai-filter-content">
699
+ <div class="ai-actions ai-sidebar">
700
+ <div class="ai-import-available-categories">
701
+ <h3><?php esc_html_e( 'Categories', 'advanced-import' ); ?></h3>
702
+ <ul class="ai-import-available-categories-lists ai-filter-group" data-filter-group="primary">
703
+ <li class="ai-filter-btn-active ai-filter-btn" data-filter="*">
704
+ <?php esc_html_e( 'All Categories', 'advanced-import' ); ?>
705
+ <span class="ai-count"></span>
706
+ </li>
707
+ <?php
708
+ $categories = array_column( $demo_lists, 'categories' );
709
+ $unique_categories = array();
710
+ if ( is_array( $categories ) && ! empty( $categories ) ) {
711
+ foreach ( $categories as $demo_index => $demo_cats ) {
712
+ foreach ( $demo_cats as $cat_index => $single_cat ) {
713
+ if ( in_array( $single_cat, $unique_categories ) ) {
714
+ continue;
715
+ }
716
+ $unique_categories[] = $single_cat;
717
+ ?>
718
+ <li class="ai-filter-btn" data-filter=".<?php echo strtolower( esc_attr( $single_cat ) ); ?>">
719
+ <?php echo ucfirst( esc_html( $single_cat ) ); ?>
720
+ <span class="ai-count"></span>
721
+ </li>
722
+ <?php
723
+ }
724
+ }
725
+ }
726
+ ?>
727
+ </ul>
728
+ </div>
729
+
730
+ </div>
731
+ <div class="ai-filter-content-wrapper">
732
+ <?php
733
+ foreach ( $demo_lists as $key => $demo_list ) {
734
+
735
+ /*Check for required fields*/
736
+ if ( ! isset( $demo_list['title'] ) || ! isset( $demo_list['screenshot_url'] ) || ! isset( $demo_list['demo_url'] ) ) {
737
+ continue;
738
+ }
739
+
740
+ $template_url = isset( $demo_list['template_url'] ) ? $demo_list['template_url'] : '';
741
+ if ( is_array( $template_url ) ) {
742
+ $data_template = 'data-template_url="' . esc_attr( wp_json_encode( $template_url ) ) . '"';
743
+ $data_template_type = 'data-template_type="array"';
744
+ } elseif ( $template_url ) {
745
+ $data_template = 'data-template_url="' . esc_attr( $template_url ) . '"';
746
+ if ( is_file( $template_url ) && filesize( $template_url ) > 0 ) {
747
+ $data_template_type = 'data-template_type="file"';
748
+ } else {
749
+ $data_template_type = 'data-template_type="url"';
750
+ }
751
+ } else {
752
+ $data_template = 'data-template_url="' . esc_attr( wp_json_encode( $template_url ) ) . '"';
753
+ $data_template_type = 'data-template_type="array"';
754
+ }
755
+ ?>
756
+ <div aria-label="<?php echo esc_attr( $demo_list['title'] ); ?>"
757
+ class="ai-item
758
+ <?php
759
+ echo isset( $demo_list['categories'] ) ? esc_attr( implode( ' ', $demo_list['categories'] ) ) : '';
760
+ echo isset( $demo_list['type'] ) ? ' ' . esc_attr( $demo_list['type'] ) : '';
761
+ echo $this->is_template_available( $demo_list ) ? '' : ' ai-pro-item'
762
+ ?>
763
+ "
764
+ <?php echo $this->is_template_available( $demo_list ) ? $data_template . ' ' . $data_template_type : ''; ?>
765
+ >
766
+ <?php
767
+ wp_nonce_field( 'advanced-import' );
768
+ ?>
769
+ <div class="ai-item-preview">
770
+ <div class="ai-item-screenshot">
771
+ <img src="<?php echo esc_url( $demo_list['screenshot_url'] ); ?>">
772
+
773
+ </div>
774
+ <h4 class="ai-author-info"><?php esc_html_e( 'Author: ', 'advanced-import' ); ?><?php echo esc_html( isset( $demo_list['author'] ) ? $demo_list['author'] : wp_get_theme()->get( 'Author' ) ); ?></h4>
775
+ <div class="ai-details"><?php esc_html_e( 'Details', 'advanced-import' ); ?></div>
776
+ <?php
777
+ if ( isset( $demo_list['is_pro'] ) && $demo_list['is_pro'] ) {
778
+ ?>
779
+ <span class="ai-premium-label"><?php esc_html_e( 'Premium', 'advanced-import' ); ?></span>
780
+ <?php
781
+ }
782
+ ?>
783
+ </div>
784
+ <div class="ai-item-footer">
785
+ <div class="ai-item-footer_meta">
786
+ <h3 class="theme-name"><?php echo esc_html( $demo_list['title'] ); ?></h3>
787
+ <div class="ai-item-footer-actions">
788
+ <a class="button ai-item-demo-link" href="<?php echo esc_url( $demo_list['demo_url'] ); ?>" target="_blank">
789
+ <span class="dashicons dashicons-visibility"></span><?php esc_html_e( 'Preview', 'advanced-import' ); ?>
790
+ </a>
791
+ <?php
792
+ echo $this->template_button( $demo_list );
793
+ ?>
794
+ </div>
795
+ <?php
796
+ $keywords = isset( $demo_list['keywords'] ) ? $demo_list['keywords'] : array();
797
+ if ( ! empty( $keywords ) ) {
798
+ echo '<ul class="ai-keywords hidden">';
799
+ foreach ( $keywords as $cat_index => $single_keywords ) {
800
+ ?>
801
+ <li class="<?php echo strtolower( esc_attr( $single_keywords ) ); ?>"><?php echo ucfirst( esc_html( $single_keywords ) ); ?></li>
802
+ <?php
803
+ }
804
+ echo '</ul>';
805
+ }
806
+ ?>
807
+
808
+ </div>
809
+
810
+ </div>
811
+ </div>
812
+ <?php
813
+ }
814
+ ?>
815
+ </div>
816
+ </div>
817
+ <?php
818
+ }
819
+
820
+ /**
821
+ * List Demo Form
822
+ *
823
+ * @return void
824
+ */
825
+
826
+ public function demo_import_form( $total_demo = 0 ) {
827
+ ?>
828
+ <div class="ai-form <?php echo $total_demo > 0 ? 'hidden' : ''; ?>">
829
+ <form action="" method="post" enctype="multipart/form-data" id="ai-upload-zip-form">
830
+ <h3 class="media-title"><?php esc_html_e( 'Upload a zip file containing demo content', 'advanced-import' ); ?> </h3>
831
+ <div class="input-file"><input type="file" name="ai-upload-zip-archive" id="ai-upload-zip-archive" size="50" /></div>
832
+ <p>
833
+ <?php
834
+ wp_nonce_field( 'advanced-import' );
835
+ printf( __( 'Maximum upload file size: %s', 'advanced-import' ), size_format( wp_max_upload_size() ) );
836
+ ?>
837
+ </p>
838
+ <div id='ai-empty-file' class="error hidden">
839
+ <p>
840
+ <?php esc_html_e( 'Select File and Try Again!', 'advanced-import' ); ?>
841
+ </p>
842
+ </div>
843
+ <p class="ai-form-import-actions step">
844
+ <button class="button-primary button button-large button-upload-demo" type="submit">
845
+ <?php esc_html_e( 'Upload Demo Zip', 'advanced-import' ); ?>
846
+ </button>
847
+ <a href="<?php echo esc_url( wp_get_referer() && ! strpos( wp_get_referer(), 'update.php' ) ? wp_get_referer() : admin_url( '' ) ); ?>" class="button button-large">
848
+ <?php esc_html_e( 'Not right now', 'advanced-import' ); ?>
849
+ </a>
850
+ </p>
851
+ <div id='ai-ajax-install-result'></div>
852
+ </form>
853
+ </div>
854
+ <?php
855
+ }
856
+
857
+ /**
858
+ * 1st step of demo import view
859
+ * Upload Zip file
860
+ * Demo List
861
+ */
862
+ public function init_demo_import() {
863
+
864
+ global $pagenow;
865
+ $total_demo = 0;
866
+ if ( $pagenow != 'tools.php' ) {
867
+ $this->demo_lists = apply_filters( 'advanced_import_demo_lists', array() );
868
+ $this->is_pro_active = apply_filters( 'advanced_import_is_pro_active', $this->is_pro_active );
869
+ $demo_lists = $this->demo_lists;
870
+
871
+ $total_demo = count( $demo_lists );
872
+ if ( $total_demo >= 1 ) {
873
+ $this->demo_list( $demo_lists, $total_demo );
874
+ }
875
+ }
876
+
877
+ $this->demo_import_form( $total_demo );
878
+ }
879
+
880
+ /**
881
+ * 2nd step Plugin Installation step View
882
+ * return void || boolean
883
+ */
884
+ public function plugin_screen() {
885
+
886
+ /*check for security*/
887
+ if ( ! current_user_can( 'upload_files' ) ) {
888
+ wp_send_json_error(
889
+ array(
890
+ 'message' => esc_html__( 'Sorry, you are not allowed to install demo on this site.', 'advanced-import' ),
891
+ )
892
+ );
893
+ }
894
+
895
+ check_admin_referer( 'advanced-import' );
896
+
897
+ /*for safety.*/
898
+ delete_transient( 'content.json' );
899
+ delete_transient( 'widgets.json' );
900
+ delete_transient( 'options.json' );
901
+
902
+ do_action( 'advanced_import_before_plugin_screen' );
903
+ ?>
904
+ <div class="ai-notification-title">
905
+ <p><?php esc_html_e( 'Your website needs a few essential plugins. We are installing them...', 'advanced-import' ); ?></p>
906
+ </div>
907
+ <ul class="ai-plugins-wrap hidden">
908
+ <?php
909
+ $recommended_plugins = (array) $_POST['recommendedPlugins'];
910
+ if ( count( $recommended_plugins ) ) {
911
+ foreach ( $recommended_plugins as $index => $recommended_plugin ) {
912
+ ?>
913
+ <li data-slug="<?php echo esc_attr( $recommended_plugin['slug'] ); ?>" data-main_file ="<?php echo esc_attr( isset( $recommended_plugin['main_file'] ) ? $recommended_plugin['main_file'] : $recommended_plugin['slug'] . '.php' ); ?>">
914
+ <?php echo esc_html( $recommended_plugin['name'] ); ?>
915
+ </li>
916
+ <?php
917
+ }
918
+ } else {
919
+ ?>
920
+ <li id="ai-no-recommended-plugins"><?php esc_html_e( 'No Recommended Plugins', 'advanced-import' ); ?></li>
921
+ <?php
922
+ }
923
+ ?>
924
+ </ul>
925
+ <?php
926
+ do_action( 'advanced_import_after_plugin_screen' );
927
+ exit;
928
+ }
929
+
930
+ /**
931
+ * 3rd steps helper functions
932
+ * Get json from json file
933
+ *
934
+ * @param string $file file url.
935
+ * @return mixed
936
+ */
937
+ public function get_json_data_from_file( $file ) {
938
+
939
+ if ( get_transient( $file ) ) {
940
+ return get_transient( $file );
941
+ }
942
+
943
+ if ( $this->current_template_type == 'array' ) {
944
+ $type = strtok( $file, '.' );
945
+ if ( isset( $this->current_template_url[ $type ] ) ) {
946
+ $request = wp_remote_get( $this->current_template_url[ $type ] );
947
+ $response = wp_remote_retrieve_body( $request );
948
+ $result = json_decode( $response, true );
949
+ set_transient( $file, $result, 1000 );
950
+ return $result;
951
+ }
952
+ return array();
953
+ }
954
+
955
+ if ( is_file( ADVANCED_IMPORT_TEMP . basename( $file ) ) ) {
956
+ require_once ABSPATH . 'wp-admin/includes/file.php';
957
+ WP_Filesystem();
958
+ global $wp_filesystem;
959
+ $file_name = ADVANCED_IMPORT_TEMP . basename( $file );
960
+ if ( file_exists( $file_name ) ) {
961
+ $result = json_decode( $wp_filesystem->get_contents( $file_name ), true );
962
+ set_transient( $file, $result, 1000 );
963
+ return $result;
964
+ }
965
+ }
966
+ return array();
967
+ }
968
+
969
+ public function get_main_content_json() {
970
+ return $this->get_json_data_from_file( 'content.json' );
971
+ }
972
+ public function get_widgets_json() {
973
+ return $this->get_json_data_from_file( 'widgets.json' );
974
+ }
975
+
976
+ public function get_theme_options_json() {
977
+ return $this->get_json_data_from_file( 'options.json' );
978
+ }
979
+
980
+ /*
981
+ * return array
982
+ */
983
+ private function advanced_import_setup_content_steps() {
984
+
985
+ $content = array();
986
+
987
+ /*check if there is files*/
988
+ $content_data = $this->get_main_content_json();
989
+ foreach ( $content_data as $post_type => $post_data ) {
990
+ if ( count( $post_data ) ) {
991
+ $first = current( $post_data );
992
+ $post_type_title = ! empty( $first['type_title'] ) ? $first['type_title'] : ucwords( $post_type ) . 's';
993
+ $content[ $post_type ] = array(
994
+ 'title' => $post_type_title,
995
+ 'description' => sprintf( esc_html__( 'This will create default %s as seen in the demo.', 'advanced-import' ), $post_type_title ),
996
+ 'pending' => esc_html__( 'Pending.', 'advanced-import' ),
997
+ 'installing' => esc_html__( 'Installing.', 'advanced-import' ),
998
+ 'success' => esc_html__( 'Success.', 'advanced-import' ),
999
+ 'install_callback' => array( $this, 'import_content_post_type_data' ),
1000
+ 'checked' => $this->is_possible_upgrade() ? 0 : 1,
1001
+ // dont check if already have content installed.
1002
+ );
1003
+ }
1004
+ }
1005
+ /*
1006
+ array adjustment
1007
+ TODO : Remove it after adjustment on Advanced Import
1008
+ */
1009
+ /*Put post 3nd last*/
1010
+ $post = isset( $content['post'] ) ? $content['post'] : array();
1011
+ if ( $post ) {
1012
+ unset( $content['post'] );
1013
+ $content['post'] = $post;
1014
+ }
1015
+ /*Put page 2nd last*/
1016
+ $page = isset( $content['page'] ) ? $content['page'] : array();
1017
+ if ( $page ) {
1018
+ unset( $content['page'] );
1019
+ $content['page'] = $page;
1020
+
1021
+ }
1022
+ /*Put nav last*/
1023
+ $nav = isset( $content['nav_menu_item'] ) ? $content['nav_menu_item'] : array();
1024
+ if ( $nav ) {
1025
+ unset( $content['nav_menu_item'] );
1026
+ $content['nav_menu_item'] = $nav;
1027
+ }
1028
+ /*check if there is files*/
1029
+ $widget_data = $this->get_widgets_json();
1030
+ if ( ! empty( $widget_data ) ) {
1031
+ $content['widgets'] = array(
1032
+ 'title' => esc_html__( 'Widgets', 'advanced-import' ),
1033
+ 'description' => esc_html__( 'Insert default sidebar widgets as seen in the demo.', 'advanced-import' ),
1034
+ 'pending' => esc_html__( 'Pending.', 'advanced-import' ),
1035
+ 'installing' => esc_html__( 'Installing Default Widgets.', 'advanced-import' ),
1036
+ 'success' => esc_html__( 'Success.', 'advanced-import' ),
1037
+ 'install_callback' => array( $this, 'import_content_widgets_data' ),
1038
+ 'checked' => $this->is_possible_upgrade() ? 0 : 1,
1039
+ // dont check if already have content installed.
1040
+ );
1041
+ }
1042
+ $options_data = $this->get_theme_options_json();
1043
+ if ( ! empty( $options_data ) ) {
1044
+ $content['settings'] = array(
1045
+ 'title' => esc_html__( 'Settings', 'advanced-import' ),
1046
+ 'description' => esc_html__( 'Configure default settings.', 'advanced-import' ),
1047
+ 'pending' => esc_html__( 'Pending.', 'advanced-import' ),
1048
+ 'installing' => esc_html__( 'Installing Default Settings.', 'advanced-import' ),
1049
+ 'success' => esc_html__( 'Success.', 'advanced-import' ),
1050
+ 'install_callback' => array( $this, 'import_menu_and_options' ),
1051
+ 'checked' => $this->is_possible_upgrade() ? 0 : 1,
1052
+ // dont check if already have content installed.
1053
+ );
1054
+ }
1055
+ $content = apply_filters( $this->theme_name . '_theme_view_setup_step_content', $content );
1056
+
1057
+ return $content;
1058
+
1059
+ }
1060
+
1061
+ /**
1062
+ * 3rd Step Step for content, widget, setting import
1063
+ * Page setup
1064
+ */
1065
+ public function content_screen() {
1066
+
1067
+ /*check for security*/
1068
+ if ( ! current_user_can( 'upload_files' ) ) {
1069
+ wp_send_json_error(
1070
+ array(
1071
+ 'message' => esc_html__( 'Sorry, you are not allowed to install demo on this site.', 'advanced-import' ),
1072
+ )
1073
+ );
1074
+ }
1075
+ check_admin_referer( 'advanced-import' );
1076
+
1077
+ if ( isset( $_POST['template_url'] ) ) {
1078
+ $this->current_template_url = is_array( $_POST['template_url'] ) ? (array) $_POST['template_url'] : sanitize_text_field( $_POST['template_url'] );
1079
+ $this->current_template_type = sanitize_text_field( $_POST['template_type'] );
1080
+ }
1081
+
1082
+ do_action( 'advanced_import_before_content_screen' );
1083
+
1084
+ ?>
1085
+ <div class="ai-notification-title">
1086
+ <p>
1087
+ <?php
1088
+ esc_html_e( 'It\'s time to insert some demo content for your new WordPress Site. Once inserted, this content can be managed from the WordPress admin dashboard. ' )
1089
+ ?>
1090
+ </p>
1091
+ </div>
1092
+
1093
+ <table class="ai-pages hidden">
1094
+ <thead>
1095
+ <tr>
1096
+ <th class="check"></th>
1097
+ <th class="item"><?php esc_html_e( 'Item', 'advanced-import' ); ?></th>
1098
+ <th class="description"><?php esc_html_e( 'Description', 'advanced-import' ); ?></th>
1099
+ <th class="status"><?php esc_html_e( 'Status', 'advanced-import' ); ?></th>
1100
+ </tr>
1101
+ </thead>
1102
+ <tbody>
1103
+ <?php
1104
+ $setup_content_steps = $this->advanced_import_setup_content_steps();
1105
+ foreach ( $setup_content_steps as $slug => $default ) {
1106
+ ?>
1107
+ <tr class="ai-available-content" data-content="<?php echo esc_attr( $slug ); ?>">
1108
+ <td>
1109
+ <input type="checkbox" name="import_content[<?php echo esc_attr( $slug ); ?>]" class="ai-available-content" id="import_content_<?php echo esc_attr( $slug ); ?>" value="1" <?php echo ( ! isset( $default['checked'] ) || $default['checked'] ) ? ' checked' : ''; ?>>
1110
+ </td>
1111
+ <td>
1112
+ <label for="import_content_<?php echo esc_attr( $slug ); ?>">
1113
+ <?php echo esc_html( $default['title'] ); ?>
1114
+ </label>
1115
+ </td>
1116
+ <td class="description">
1117
+ <?php echo esc_html( $default['description'] ); ?>
1118
+ </td>
1119
+ <td class="status">
1120
+ <span>
1121
+ <?php echo esc_html( $default['pending'] ); ?>
1122
+ </span>
1123
+ </td>
1124
+ </tr>
1125
+ <?php } ?>
1126
+ </tbody>
1127
+ </table>
1128
+ <?php
1129
+ do_action( 'advanced_import_after_content_screen' );
1130
+
1131
+ exit;
1132
+ }
1133
+
1134
+ /*
1135
+ * import ajax content
1136
+ * return JSON
1137
+ */
1138
+ public function import_content() {
1139
+
1140
+ /*check for security*/
1141
+ if ( ! current_user_can( 'upload_files' ) ) {
1142
+ wp_send_json_error(
1143
+ array(
1144
+ 'message' => esc_html__( 'Sorry, you are not allowed to install demo on this site.', 'advanced-import' ),
1145
+ )
1146
+ );
1147
+ }
1148
+ if ( isset( $_POST['template_url'] ) ) {
1149
+ $this->current_template_url = is_array( $_POST['template_url'] ) ? (array) $_POST['template_url'] : sanitize_text_field( $_POST['template_url'] );
1150
+ $this->current_template_type = sanitize_text_field( $_POST['template_type'] );
1151
+ }
1152
+
1153
+ /*Move to Trash default page and post*/
1154
+ $sample_page = get_page_by_title( 'Sample Page', OBJECT, 'page' );
1155
+ $hello_world_post = get_page_by_title( 'Hello world!', OBJECT, 'post' );
1156
+ if ( is_object( $sample_page ) ) {
1157
+ wp_trash_post( $sample_page->ID );
1158
+ }
1159
+ if ( is_object( $hello_world_post ) ) {
1160
+ wp_trash_post( $hello_world_post->ID );
1161
+ }
1162
+
1163
+ $content_slug = isset( $_POST['content'] ) ? sanitize_title( $_POST['content'] ) : '';
1164
+
1165
+ $content = $this->advanced_import_setup_content_steps();
1166
+
1167
+ /*check for security again*/
1168
+ if ( ! check_ajax_referer( 'advanced_import_nonce', 'wpnonce' ) || empty( $content_slug ) || ! isset( $content[ $content_slug ] ) ) {
1169
+ wp_send_json_error(
1170
+ array(
1171
+ 'error' => 1,
1172
+ 'message' => esc_html__( 'No content Found', 'advanced-import' ),
1173
+ )
1174
+ );
1175
+ }
1176
+
1177
+ $json = false;
1178
+ $this_content = $content[ $content_slug ];
1179
+
1180
+ if ( isset( $_POST['proceed'] ) ) {
1181
+
1182
+ /*install the content*/
1183
+ $this->log( esc_html__( 'Starting import for ', 'advanced-import' ) . $content_slug );
1184
+
1185
+ /*init delayed posts from transient.*/
1186
+ $this->delay_posts = get_transient( 'delayed_posts' );
1187
+ if ( ! is_array( $this->delay_posts ) ) {
1188
+ $this->delay_posts = array();
1189
+ }
1190
+
1191
+ if ( ! empty( $this_content['install_callback'] ) ) {
1192
+ /*
1193
+ install_callback includes following functions
1194
+ * import_content_post_type_data
1195
+ * import_content_widgets_data
1196
+ * import_menu_and_options
1197
+ * */
1198
+ if ( $result = call_user_func( $this_content['install_callback'] ) ) {
1199
+
1200
+ $this->log( esc_html__( 'Finish writing ', 'advanced-import' ) . count( $this->delay_posts, COUNT_RECURSIVE ) . esc_html__( ' delayed posts to transient ', 'advanced-import' ) );
1201
+ set_transient( 'delayed_posts', $this->delay_posts, 60 * 60 * 24 );
1202
+
1203
+ /*
1204
+ if there is retry, retry it
1205
+ or finish it*/
1206
+ if ( is_array( $result ) && isset( $result['retry'] ) ) {
1207
+ /*we split the stuff up again.*/
1208
+ $json = array(
1209
+ 'url' => admin_url( 'admin-ajax.php' ),
1210
+ 'action' => 'import_content',
1211
+ 'proceed' => 'true',
1212
+ 'retry' => time(),
1213
+ 'retry_count' => $result['retry_count'],
1214
+ 'content' => $content_slug,
1215
+ '_wpnonce' => wp_create_nonce( 'advanced_import_nonce' ),
1216
+ 'message' => $this_content['installing'],
1217
+ 'logs' => $this->logs,
1218
+ 'errors' => $this->errors,
1219
+ 'template_url' => $this->current_template_url,
1220
+ 'template_type' => $this->current_template_type,
1221
+
1222
+ );
1223
+ } else {
1224
+ $json = array(
1225
+ 'done' => 1,
1226
+ 'message' => $this_content['success'],
1227
+ 'debug' => $result,
1228
+ 'logs' => $this->logs,
1229
+ 'errors' => $this->errors,
1230
+ );
1231
+ }
1232
+ }
1233
+ }
1234
+ } else {
1235
+
1236
+ $json = array(
1237
+ 'url' => admin_url( 'admin-ajax.php' ),
1238
+ 'action' => 'import_content',
1239
+ 'proceed' => 'true',
1240
+ 'content' => $content_slug,
1241
+ '_wpnonce' => wp_create_nonce( 'advanced_import_nonce' ),
1242
+ 'message' => $this_content['installing'],
1243
+ 'logs' => $this->logs,
1244
+ 'errors' => $this->errors,
1245
+ 'template_url' => $this->current_template_url,
1246
+ 'template_type' => $this->current_template_type,
1247
+ );
1248
+ }
1249
+
1250
+ if ( $json ) {
1251
+ $json['hash'] = md5( serialize( $json ) ); /*used for checking if duplicates happen, move to next plugin*/
1252
+ wp_send_json( $json );
1253
+ } else {
1254
+ wp_send_json_error(
1255
+ array(
1256
+ 'message' => esc_html__( 'Error', 'advanced-import' ),
1257
+ 'logs' => $this->logs,
1258
+ 'errors' => $this->errors,
1259
+ )
1260
+ );
1261
+ }
1262
+ exit;
1263
+ }
1264
+
1265
+ /*
1266
+ callback function to importing post type
1267
+ * all post type is imported from here
1268
+ * return mix
1269
+ * */
1270
+ private function import_content_post_type_data() {
1271
+ $post_type = ! empty( $_POST['content'] ) ? sanitize_text_field( $_POST['content'] ) : false;
1272
+ $all_data = $this->get_main_content_json();
1273
+ if ( ! $post_type || ! isset( $all_data[ $post_type ] ) ) {
1274
+ return false;
1275
+ }
1276
+
1277
+ /*Import 10 posts at a time*/
1278
+ $limit = 10 + ( isset( $_REQUEST['retry_count'] ) ? (int) $_REQUEST['retry_count'] : 0 );
1279
+
1280
+ $limit = apply_filters( 'advanced_import_limit_at_time', $limit );
1281
+ $x = 0;
1282
+ foreach ( $all_data[ $post_type ] as $post_data ) {
1283
+
1284
+ $this->process_import_single_post( $post_type, $post_data );
1285
+
1286
+ if ( $x ++ > $limit ) {
1287
+ return array(
1288
+ 'retry' => 1,
1289
+ 'retry_count' => $limit,
1290
+ );
1291
+ }
1292
+ }
1293
+
1294
+ /*processed delayed posts*/
1295
+ $this->process_delayed_posts();
1296
+
1297
+ /*process child posts*/
1298
+ $this->processpost_orphans();
1299
+
1300
+ return true;
1301
+
1302
+ }
1303
+
1304
+ /*
1305
+ set and get transient imported_term_ids
1306
+ return mix*/
1307
+ public function imported_term_id( $original_term_id, $new_term_id = false ) {
1308
+ $terms = get_transient( 'imported_term_ids' );
1309
+ if ( ! is_array( $terms ) ) {
1310
+ $terms = array();
1311
+ }
1312
+ if ( $new_term_id ) {
1313
+ if ( ! isset( $terms[ $original_term_id ] ) ) {
1314
+ $this->log( esc_html__( 'Insert old TERM ID ', 'advanced-import' ) . $original_term_id . esc_html__( ' as new TERM ID: ', 'advanced-import' ) . $new_term_id );
1315
+ } elseif ( $terms[ $original_term_id ] != $new_term_id ) {
1316
+ $this->error( 'Replacement OLD TERM ID ' . $original_term_id . ' overwritten by new TERM ID: ' . $new_term_id );
1317
+ }
1318
+ $terms[ $original_term_id ] = $new_term_id;
1319
+ set_transient( 'imported_term_ids', $terms, 60 * 60 * 24 );
1320
+ } elseif ( $original_term_id && isset( $terms[ $original_term_id ] ) ) {
1321
+ return $terms[ $original_term_id ];
1322
+ }
1323
+
1324
+ return false;
1325
+ }
1326
+
1327
+ /*
1328
+ set and get imported_post_ids
1329
+ return mix*/
1330
+ public function imported_post_id( $original_id = false, $new_id = false ) {
1331
+ if ( is_array( $original_id ) || is_object( $original_id ) ) {
1332
+ return false;
1333
+ }
1334
+ $post_ids = get_transient( 'imported_post_ids' );
1335
+ if ( ! is_array( $post_ids ) ) {
1336
+ $post_ids = array();
1337
+ }
1338
+ if ( $new_id ) {
1339
+ if ( ! isset( $post_ids[ $original_id ] ) ) {
1340
+ $this->log( esc_html__( 'Insert old ID ', 'advanced-import' ) . $original_id . esc_html__( ' as new ID: ', 'advanced-import' ) . $new_id );
1341
+ } elseif ( $post_ids[ $original_id ] != $new_id ) {
1342
+ $this->error( esc_html__( 'Replacement OLD ID ', 'advanced-import' ) . $original_id . ' overwritten by new ID: ' . $new_id );
1343
+ }
1344
+ $post_ids[ $original_id ] = $new_id;
1345
+ set_transient( 'imported_post_ids', $post_ids, 60 * 60 * 24 );
1346
+ } elseif ( $original_id && isset( $post_ids[ $original_id ] ) ) {
1347
+ return $post_ids[ $original_id ];
1348
+ } elseif ( $original_id === false ) {
1349
+ return $post_ids;
1350
+ }
1351
+ return false;
1352
+ }
1353
+
1354
+ /*
1355
+ set and get post_orphans/post parent
1356
+ if parent is not already imported the child will be orphan
1357
+ return mix*/
1358
+ private function post_orphans( $original_id = false, $missing_parent_id = false ) {
1359
+ $post_ids = get_transient( 'post_orphans' );
1360
+ if ( ! is_array( $post_ids ) ) {
1361
+ $post_ids = array();
1362
+ }
1363
+ if ( $missing_parent_id ) {
1364
+ $post_ids[ $original_id ] = $missing_parent_id;
1365
+ set_transient( 'post_orphans', $post_ids, 60 * 60 * 24 );
1366
+ } elseif ( $original_id && isset( $post_ids[ $original_id ] ) ) {
1367
+ return $post_ids[ $original_id ];
1368
+ } elseif ( $original_id === false ) {
1369
+ return $post_ids;
1370
+ }
1371
+ return false;
1372
+ }
1373
+
1374
+
1375
+ /*set delayed post for later process*/
1376
+ private function delay_post_process( $post_type, $post_data ) {
1377
+ if ( ! isset( $this->delay_posts[ $post_type ] ) ) {
1378
+ $this->delay_posts[ $post_type ] = array();
1379
+ }
1380
+ $this->delay_posts[ $post_type ][ $post_data['post_id'] ] = $post_data;
1381
+ }
1382
+
1383
+
1384
+ /*
1385
+ Important Function
1386
+ Import single Post/Content
1387
+ */
1388
+ private function process_import_single_post( $post_type, $post_data, $delayed = 0 ) {
1389
+
1390
+ $this->log( esc_html__( 'Processing ', 'advanced-import' ) . $post_type . ' ' . $post_data['post_id'] );
1391
+ $original_post_data = $post_data;
1392
+
1393
+ /*if there is not post type return false*/
1394
+ if ( ! post_type_exists( $post_type ) ) {
1395
+ return false;
1396
+ }
1397
+
1398
+ /*if it is aready imported return*/
1399
+ if ( $this->imported_post_id( $post_data['post_id'] ) ) {
1400
+ return true; /*already done*/
1401
+ }
1402
+
1403
+ /*set post_name id for empty post name/title*/
1404
+ if ( empty( $post_data['post_title'] ) && empty( $post_data['post_name'] ) ) {
1405
+ $post_data['post_name'] = $post_data['post_id'];
1406
+ }
1407
+
1408
+ /*set post_type on $post_data*/
1409
+ $post_data['post_type'] = $post_type;
1410
+
1411
+ /*post_orphans/post parent management */
1412
+ $post_parent = isset( $post_data['post_parent'] ) ? absint( $post_data['post_parent'] ) : false;
1413
+ if ( $post_parent ) {
1414
+ /*if we already know the parent, map it to the new local imported ID*/
1415
+ if ( $this->imported_post_id( $post_parent ) ) {
1416
+ $post_data['post_parent'] = $this->imported_post_id( $post_parent );
1417
+ } else {
1418
+ /*if there is not parent imported, child will be orphans*/
1419
+ $this->post_orphans( absint( $post_data['post_id'] ), $post_parent );
1420
+ $post_data['post_parent'] = 0;
1421
+ }
1422
+ }
1423
+
1424
+ /*check if already exists by post_name*/
1425
+ if ( empty( $post_data['post_title'] ) && ! empty( $post_data['post_name'] ) ) {
1426
+ global $wpdb;
1427
+ $sql = "
1428
+ SELECT ID, post_name, post_parent, post_type
1429
+ FROM $wpdb->posts
1430
+ WHERE post_name = %s
1431
+ AND post_type = %s
1432
+ ";
1433
+ $pages = $wpdb->get_results(
1434
+ $wpdb->prepare(
1435
+ $sql,
1436
+ array(
1437
+ $post_data['post_name'],
1438
+ $post_type,
1439
+ )
1440
+ ),
1441
+ OBJECT_K
1442
+ );
1443
+
1444
+ $foundid = 0;
1445
+ foreach ( (array) $pages as $page ) {
1446
+ if ( $page->post_name == $post_data['post_name'] && empty( $page->post_title ) ) {
1447
+ $foundid = $page->ID;
1448
+ }
1449
+ }
1450
+
1451
+ /*if we have found id by post_name, imported_post_id and return*/
1452
+ if ( $foundid ) {
1453
+ $this->imported_post_id( $post_data['post_id'], $foundid );
1454
+ return true;
1455
+ }
1456
+ }
1457
+
1458
+ /*
1459
+ check if already exists by post_name and post_title*/
1460
+ /*don't use post_exists because it will dupe up on media with same name but different slug*/
1461
+ if ( ! empty( $post_data['post_title'] ) && ! empty( $post_data['post_name'] ) ) {
1462
+ global $wpdb;
1463
+ $sql = "
1464
+ SELECT ID, post_name, post_parent, post_type
1465
+ FROM $wpdb->posts
1466
+ WHERE post_name = %s
1467
+ AND post_title = %s
1468
+ AND post_type = %s
1469
+ ";
1470
+ $pages = $wpdb->get_results(
1471
+ $wpdb->prepare(
1472
+ $sql,
1473
+ array(
1474
+ $post_data['post_name'],
1475
+ $post_data['post_title'],
1476
+ $post_type,
1477
+ )
1478
+ ),
1479
+ OBJECT_K
1480
+ );
1481
+
1482
+ $foundid = 0;
1483
+ foreach ( (array) $pages as $page ) {
1484
+ if ( $page->post_name == $post_data['post_name'] ) {
1485
+ $foundid = $page->ID;
1486
+ }
1487
+ }
1488
+
1489
+ /*if we have found id by post_name and post_title, imported_post_id and return*/
1490
+ if ( $foundid ) {
1491
+ $this->imported_post_id( $post_data['post_id'], $foundid );
1492
+ return true;
1493
+ }
1494
+ }
1495
+
1496
+ /*
1497
+ * todo it may not required
1498
+ * backwards compat with old import format.*/
1499
+ if ( isset( $post_data['meta'] ) ) {
1500
+ foreach ( $post_data['meta'] as $key => $meta ) {
1501
+ if ( is_array( $meta ) && count( $meta ) == 1 ) {
1502
+ $single_meta = current( $meta );
1503
+ if ( ! is_array( $single_meta ) ) {
1504
+ $post_data['meta'][ $key ] = $single_meta;
1505
+ }
1506
+ }
1507
+ }
1508
+ }
1509
+
1510
+ /*finally process*/
1511
+ switch ( $post_type ) {
1512
+
1513
+ /*case attachment*/
1514
+ case 'attachment':
1515
+ /*import media via url*/
1516
+ if ( isset( $post_data['guid'] ) && ! empty( $post_data['guid'] ) ) {
1517
+
1518
+ /*check if this has already been imported.*/
1519
+ $old_guid = $post_data['guid'];
1520
+ if ( $this->imported_post_id( $old_guid ) ) {
1521
+ return true; /*already done*/
1522
+ }
1523
+
1524
+ // ignore post parent, we haven't imported those yet.
1525
+ // $file_data = wp_remote_get($post_data['guid']);
1526
+ $remote_url = $post_data['guid'];
1527
+
1528
+ $post_data['upload_date'] = date( 'Y/m', strtotime( $post_data['post_date_gmt'] ) );
1529
+
1530
+ if ( isset( $post_data['meta'] ) ) {
1531
+ foreach ( $post_data['meta'] as $key => $meta ) {
1532
+ if ( $key == '_wp_attached_file' ) {
1533
+ foreach ( (array) $meta as $meta_val ) {
1534
+ if ( preg_match( '%^[0-9]{4}/[0-9]{2}%', $meta_val, $matches ) ) {
1535
+ $post_data['upload_date'] = $matches[0];
1536
+ }
1537
+ }
1538
+ }
1539
+ }
1540
+ }
1541
+
1542
+ /*upload the file*/
1543
+ $upload = $this->import_image_and_file( $remote_url, $post_data );
1544
+
1545
+ /*if error on upload*/
1546
+ if ( ! is_array( $upload ) || is_wp_error( $upload ) ) {
1547
+ /*todo: error*/
1548
+ return false;
1549
+ }
1550
+
1551
+ /*check file type, if file type not found return false*/
1552
+ if ( $info = wp_check_filetype( $upload['file'] ) ) {
1553
+ $post_data['post_mime_type'] = $info['type'];
1554
+ } else {
1555
+ return false;
1556
+ }
1557
+
1558
+ /*set guid file url*/
1559
+ $post_data['guid'] = $upload['url'];
1560
+
1561
+ /*
1562
+ * insert attachment
1563
+ *https://developer.wordpress.org/reference/functions/wp_insert_attachment/
1564
+ * */
1565
+ $attach_id = wp_insert_attachment( $post_data, $upload['file'] );
1566
+ if ( $attach_id ) {
1567
+
1568
+ /*update meta*/
1569
+ if ( ! empty( $post_data['meta'] ) ) {
1570
+ foreach ( $post_data['meta'] as $meta_key => $meta_val ) {
1571
+ if ( $meta_key != '_wp_attached_file' && ! empty( $meta_val ) ) {
1572
+ update_post_meta( $attach_id, $meta_key, $meta_val );
1573
+ }
1574
+ }
1575
+ }
1576
+ /* Update metadata for an attachment.*/
1577
+ wp_update_attachment_metadata( $attach_id, wp_generate_attachment_metadata( $attach_id, $upload['file'] ) );
1578
+
1579
+ /*remap resized image URLs, works by stripping the extension and remapping the URL stub.*/
1580
+ if ( preg_match( '!^image/!', $info['type'] ) ) {
1581
+ $parts = pathinfo( $remote_url );
1582
+ $name = basename( $parts['basename'], ".{$parts['extension']}" ); // PATHINFO_FILENAME in PHP 5.2
1583
+
1584
+ $parts_new = pathinfo( $upload['url'] );
1585
+ $name_new = basename( $parts_new['basename'], ".{$parts_new['extension']}" );
1586
+
1587
+ $this->imported_post_id( $parts['dirname'] . '/' . $name, $parts_new['dirname'] . '/' . $name_new );
1588
+ }
1589
+ $this->imported_post_id( $post_data['post_id'], $attach_id );
1590
+ }
1591
+ }
1592
+ break;
1593
+
1594
+ default:
1595
+ /*Process Post Meta*/
1596
+ if ( ! empty( $post_data['meta'] ) && is_array( $post_data['meta'] ) ) {
1597
+
1598
+ /*fix for double json encoded stuff*/
1599
+ foreach ( $post_data['meta'] as $meta_key => $meta_val ) {
1600
+ if ( is_string( $meta_val ) && strlen( $meta_val ) && $meta_val[0] == '[' ) {
1601
+ $test_json = @json_decode( $meta_val, true );
1602
+ if ( is_array( $test_json ) ) {
1603
+ $post_data['meta'][ $meta_key ] = $test_json;
1604
+ }
1605
+ }
1606
+ }
1607
+
1608
+ array_walk_recursive( $post_data['meta'], array( advanced_import_elementor(), 'elementor_id_import' ) );
1609
+
1610
+ /*todo gutenberg and page builders*/
1611
+
1612
+ /*
1613
+ replace menu data
1614
+ work out what we're replacing. a tax, page, term etc..*/
1615
+ if ( isset( $post_data['meta']['_menu_item_menu_item_parent'] ) && 0 != $post_data['meta']['_menu_item_menu_item_parent'] ) {
1616
+ $new_parent_id = $this->imported_post_id( $post_data['meta']['_menu_item_menu_item_parent'] );
1617
+ if ( ! $new_parent_id ) {
1618
+ if ( $delayed ) {
1619
+ /*already delayed, unable to find this meta value, skip inserting it*/
1620
+ $this->error( esc_html__( 'Unable to find replacement. Continue anyway.... content will most likely break..', 'advanced-import' ) );
1621
+ } else {
1622
+ /*not found , delay it*/
1623
+ $this->error( esc_html__( 'Unable to find replacement. Delaying....', 'advanced-import' ) );
1624
+ $this->delay_post_process( $post_type, $original_post_data );
1625
+ return false;
1626
+ }
1627
+ }
1628
+ $post_data['meta']['_menu_item_menu_item_parent'] = $new_parent_id;
1629
+ }
1630
+
1631
+ /*if _menu_item_type*/
1632
+ if ( isset( $post_data['meta']['_menu_item_type'] ) ) {
1633
+
1634
+ switch ( $post_data['meta']['_menu_item_type'] ) {
1635
+ case 'post_type':
1636
+ if ( ! empty( $post_data['meta']['_menu_item_object_id'] ) ) {
1637
+ $new_parent_id = $this->imported_post_id( $post_data['meta']['_menu_item_object_id'] );
1638
+ if ( ! $new_parent_id ) {
1639
+ if ( $delayed ) {
1640
+ /*already delayed, unable to find this meta value, skip inserting it*/
1641
+ $this->error( esc_html__( 'Unable to find replacement. Continue anyway.... content will most likely break..', 'advanced-import' ) );
1642
+ } else {
1643
+ /*not found , delay it*/
1644
+ $this->error( esc_html__( 'Unable to find replacement. Delaying....', 'advanced-import' ) );
1645
+ $this->delay_post_process( $post_type, $original_post_data );
1646
+ return false;
1647
+ }
1648
+ }
1649
+ $post_data['meta']['_menu_item_object_id'] = $new_parent_id;
1650
+ }
1651
+ break;
1652
+
1653
+ case 'taxonomy':
1654
+ if ( ! empty( $post_data['meta']['_menu_item_object_id'] ) ) {
1655
+ $new_parent_id = $this->imported_term_id( $post_data['meta']['_menu_item_object_id'] );
1656
+ if ( ! $new_parent_id ) {
1657
+ if ( $delayed ) {
1658
+ /*already delayed, unable to find this meta value, skip inserting it*/
1659
+ $this->error( esc_html__( 'Unable to find replacement. Continue anyway.... content will most likely break..', 'advanced-import' ) );
1660
+ } else {
1661
+ /*not found , delay it*/
1662
+ $this->error( esc_html__( 'Unable to find replacement. Delaying....', 'advanced-import' ) );
1663
+ $this->delay_post_process( $post_type, $original_post_data );
1664
+ return false;
1665
+ }
1666
+ }
1667
+ $post_data['meta']['_menu_item_object_id'] = $new_parent_id;
1668
+ }
1669
+ break;
1670
+ }
1671
+ }
1672
+ }
1673
+
1674
+ /*
1675
+ post content parser
1676
+ for shortcode post id replacement*/
1677
+ $post_data['post_content'] = $this->parse_shortcode_meta_content( $post_data['post_content'] );
1678
+
1679
+ $replace_tax_id_keys = array(
1680
+ 'taxonomies',
1681
+ );
1682
+ foreach ( $replace_tax_id_keys as $replace_key ) {
1683
+ if ( preg_match_all( '# ' . $replace_key . '="(\d+)"#', $post_data['post_content'], $matches ) ) {
1684
+ foreach ( $matches[0] as $match_id => $string ) {
1685
+ $new_id = $this->imported_term_id( $matches[1][ $match_id ] );
1686
+ if ( $new_id ) {
1687
+ $post_data['post_content'] = str_replace( $string, ' ' . $replace_key . '="' . $new_id . '"', $post_data['post_content'] );
1688
+ } else {
1689
+ $this->error( esc_html__( 'Unable to find TAXONOMY replacement for ', 'advanced-import' ) . $replace_key . '="' . $matches[1][ $match_id ] . esc_html__( 'in content.', 'advanced-import' ) );
1690
+ if ( $delayed ) {
1691
+ /*already delayed, unable to find this meta value, skip inserting it*/
1692
+ $this->error( esc_html__( 'Unable to find replacement. Continue anyway.... content will most likely break..', 'advanced-import' ) );
1693
+ } else {
1694
+ /*not found , delay it*/
1695
+ $this->delay_post_process( $post_type, $original_post_data );
1696
+ return false;
1697
+ }
1698
+ }
1699
+ }
1700
+ }
1701
+ }
1702
+
1703
+ /*do further filter if you need*/
1704
+ $post_data = apply_filters( 'advanced_import_post_data', $post_data );
1705
+
1706
+ /*finally insert post data*/
1707
+ $post_id = wp_insert_post( $post_data, true );
1708
+ if ( ! is_wp_error( $post_id ) ) {
1709
+
1710
+ /*set id on imported_post_id*/
1711
+ $this->imported_post_id( $post_data['post_id'], $post_id );
1712
+
1713
+ /*add/update post meta*/
1714
+ if ( ! empty( $post_data['meta'] ) ) {
1715
+ foreach ( $post_data['meta'] as $meta_key => $meta_val ) {
1716
+ /*if the post has a featured image, take note of this in case of remap*/
1717
+ if ( '_thumbnail_id' == $meta_key ) {
1718
+ /*find this inserted id and use that instead.*/
1719
+ $inserted_id = $this->imported_post_id( intval( $meta_val ) );
1720
+ if ( $inserted_id ) {
1721
+ $meta_val = $inserted_id;
1722
+ }
1723
+ }
1724
+ /*update meta*/
1725
+ update_post_meta( $post_id, $meta_key, $meta_val );
1726
+ }
1727
+ }
1728
+
1729
+ if ( ! empty( $post_data['terms'] ) ) {
1730
+ $terms_to_set = array();
1731
+ foreach ( $post_data['terms'] as $term_slug => $terms ) {
1732
+ foreach ( $terms as $term ) {
1733
+ $taxonomy = $term['taxonomy'];
1734
+ if ( taxonomy_exists( $taxonomy ) ) {
1735
+ $term_exists = term_exists( $term['slug'], $taxonomy );
1736
+ $term_id = is_array( $term_exists ) ? $term_exists['term_id'] : $term_exists;
1737
+ if ( ! $term_id ) {
1738
+ if ( ! empty( $term['parent'] ) ) {
1739
+ /*see if we have imported this yet?*/
1740
+ $term['parent'] = $this->imported_term_id( $term['parent'] );
1741
+ }
1742
+ $term_id_tax_id = wp_insert_term( $term['name'], $taxonomy, $term );
1743
+ if ( ! is_wp_error( $term_id_tax_id ) ) {
1744
+ $term_id = $term_id_tax_id['term_id'];
1745
+ } else {
1746
+ // todo - error
1747
+ continue;
1748
+ }
1749
+ }
1750
+ /*set term_id on imported_term_id*/
1751
+ $this->imported_term_id( $term['term_id'], $term_id );
1752
+
1753
+ /*add the term meta.*/
1754
+ if ( $term_id && ! empty( $term['meta'] ) && is_array( $term['meta'] ) ) {
1755
+ foreach ( $term['meta'] as $meta_key => $meta_val ) {
1756
+ // we have to replace certain meta_key/meta_val
1757
+ // e.g. thumbnail id from woocommerce product categories.
1758
+ switch ( $meta_key ) {
1759
+ case 'thumbnail_id':
1760
+ if ( $new_meta_val = $this->imported_post_id( $meta_val ) ) {
1761
+ /*use this new id.*/
1762
+ $meta_val = $new_meta_val;
1763
+ }
1764
+ break;
1765
+ }
1766
+ update_term_meta( $term_id, $meta_key, $meta_val );
1767
+ }
1768
+ }
1769
+ $terms_to_set[ $taxonomy ][] = intval( $term_id );
1770
+ }
1771
+ }
1772
+ }
1773
+ foreach ( $terms_to_set as $tax => $ids ) {
1774
+ wp_set_post_terms( $post_id, $ids, $tax );
1775
+ }
1776
+
1777
+ if ( ( isset( $post_data['meta']['_elementor_data'] ) && ! empty( $post_data['meta']['_elementor_data'] ) ) ||
1778
+ ( isset( $post_data['meta']['_elementor_css'] ) && ! ! empty( $post_data['meta']['_elementor_css'] ) )
1779
+ ) {
1780
+ advanced_import_elementor()->elementor_post( $post_id );
1781
+ }
1782
+
1783
+ /*Gutentor*/
1784
+ $post = get_post( $post_id );
1785
+ $content = $post->post_content;
1786
+ if ( preg_match_all( '/data-gpid="(.*?)\" /', $content, $matches ) ) {
1787
+ foreach ( $matches[0] as $match_id => $string ) {
1788
+ $content = str_replace( $matches[0][ $match_id ], 'data-gpid="' . $post_id . '" ', $content );
1789
+ }
1790
+ }
1791
+ $post->post_content = $content;
1792
+ wp_update_post( $post );
1793
+ }
1794
+ }
1795
+ break;
1796
+ }
1797
+
1798
+ return true;
1799
+ }
1800
+
1801
+ /*Shortcode/Meta/Post Ids fixed start*/
1802
+
1803
+ /*
1804
+ * since 1.2.3
1805
+ * return the difference in length between two strings
1806
+ * */
1807
+ public function strlen_diff( $a, $b ) {
1808
+ return strlen( $b ) - strlen( $a );
1809
+ }
1810
+
1811
+
1812
+ /*
1813
+ * since 1.2.3
1814
+ * helper function to parse url, shortcode, post ids form provided content
1815
+ * * currently uses on meta and post content
1816
+ * */
1817
+ public function parse_shortcode_meta_content( $content ) {
1818
+ /*we have to format the post content. rewriting images and gallery stuff*/
1819
+ $replace = $this->imported_post_id();
1820
+
1821
+ /*filters urls for replace*/
1822
+ $urls_replace = array();
1823
+ foreach ( $replace as $key => $val ) {
1824
+ if ( $key && $val && ! is_numeric( $key ) && ! is_numeric( $val ) ) {
1825
+ $urls_replace[ $key ] = $val;
1826
+ }
1827
+ }
1828
+ /*replace image/file urls*/
1829
+ if ( $urls_replace ) {
1830
+ uksort( $urls_replace, array( &$this, 'strlen_diff' ) );
1831
+ foreach ( $urls_replace as $from_url => $to_url ) {
1832
+ $content = str_replace( $from_url, $to_url, $content );
1833
+ }
1834
+ }
1835
+
1836
+ /*gallery fixed*/
1837
+ if ( preg_match_all( '#\[gallery[^\]]*\]#', $content, $matches ) ) {
1838
+ foreach ( $matches[0] as $match_id => $string ) {
1839
+ if ( preg_match( '#ids="([^"]+)"#', $string, $ids_matches ) ) {
1840
+ $ids = explode( ',', $ids_matches[1] );
1841
+ foreach ( $ids as $key => $val ) {
1842
+ $new_id = $val ? $this->imported_post_id( $val ) : false;
1843
+ if ( ! $new_id ) {
1844
+ unset( $ids[ $key ] );
1845
+ } else {
1846
+ $ids[ $key ] = $new_id;
1847
+ }
1848
+ }
1849
+ $new_ids = implode( ',', $ids );
1850
+ $content = str_replace( $ids_matches[0], 'ids="' . $new_ids . '"', $content );
1851
+ }
1852
+ }
1853
+ }
1854
+
1855
+ /*contact form 7 id fixes.*/
1856
+ if ( preg_match_all( '#\[contact-form-7[^\]]*\]#', $content, $matches ) ) {
1857
+ foreach ( $matches[0] as $match_id => $string ) {
1858
+ if ( preg_match( '#id="(\d+)"#', $string, $id_match ) ) {
1859
+ $new_id = $this->imported_post_id( $id_match[1] );
1860
+ if ( $new_id ) {
1861
+ $content = str_replace( $id_match[0], 'id="' . $new_id . '"', $content );
1862
+ } else {
1863
+ /*no imported ID found. remove this entry.*/
1864
+ $content = str_replace( $matches[0], '(insert contact form here)', $content );
1865
+ }
1866
+ }
1867
+ }
1868
+ }
1869
+
1870
+ /*Gutentor*/
1871
+ if ( preg_match_all( '/\"pTaxTerm"(.*?)\]/', $content, $matches ) ) {
1872
+ foreach ( $matches[0] as $match_id => $string ) {
1873
+ if ( preg_match_all( '/\"value":(.*?)\}/', $string, $matches1 ) ) {
1874
+ foreach ( $matches1[0] as $match_id1 => $string1 ) {
1875
+ $new_id = $this->imported_term_id( $matches1[1][ $match_id1 ] );
1876
+ $content = str_replace( $string1, '"value":' . $new_id . '}', $content );
1877
+ }
1878
+ }
1879
+ }
1880
+ }
1881
+ if ( preg_match_all( '/\"e14TaxTerm"(.*?)\]/', $content, $matches ) ) {
1882
+ foreach ( $matches[0] as $match_id => $string ) {
1883
+ if ( preg_match_all( '/\"value":(.*?)\}/', $string, $matches1 ) ) {
1884
+ foreach ( $matches1[0] as $match_id1 => $string1 ) {
1885
+ $new_id = $this->imported_term_id( $matches1[1][ $match_id1 ] );
1886
+ $content = str_replace( $string1, '"value":' . $new_id . '}', $content );
1887
+ }
1888
+ }
1889
+ }
1890
+ }
1891
+ if ( preg_match_all( '/data-gpid="(.*?)\" /', $content, $matches ) ) {
1892
+ foreach ( $matches[0] as $match_id => $string ) {
1893
+ $new_id = $this->imported_post_id( $matches[1][ $match_id ] );
1894
+ $content = str_replace( $matches[0][ $match_id ], 'data-gpid="' . $new_id . '" ', $content );
1895
+ }
1896
+ }
1897
+ if ( preg_match_all( '/\"p4PostId"(.*?)\,/', $content, $matches ) ) {
1898
+ foreach ( $matches[0] as $match_id => $string ) {
1899
+ $new_id = $this->imported_post_id( $matches[1][ $match_id ] );
1900
+ $content = str_replace( $matches[0][ $match_id ], '"p4PostId":' . $new_id . ',', $content );
1901
+ }
1902
+ }
1903
+ return $content;
1904
+ }
1905
+ /*Shortcode/Meta/Post Ids fixed end*/
1906
+
1907
+ /*update parent page id for child page*/
1908
+ private function processpost_orphans() {
1909
+
1910
+ /*get post orphans to find it parent*/
1911
+ $orphans = $this->post_orphans();
1912
+ foreach ( $orphans as $original_post_id => $original_post_parent_id ) {
1913
+ if ( $original_post_parent_id ) {
1914
+ if ( $this->imported_post_id( $original_post_id ) && $this->imported_post_id( $original_post_parent_id ) ) {
1915
+ $post_data = array();
1916
+ $post_data['ID'] = $this->imported_post_id( $original_post_id );
1917
+ $post_data['post_parent'] = $this->imported_post_id( $original_post_parent_id );
1918
+ wp_update_post( $post_data );
1919
+ $this->post_orphans( $original_post_id, 0 ); /*ignore future*/
1920
+ }
1921
+ }
1922
+ }
1923
+ }
1924
+
1925
+ /*
1926
+ Process delayed post
1927
+ */
1928
+ private function process_delayed_posts( $last_delay = false ) {
1929
+
1930
+ $this->log( esc_html__( 'Processing ', 'advanced-import' ) . count( $this->delay_posts, COUNT_RECURSIVE ) . esc_html__( 'delayed posts', 'advanced-import' ) );
1931
+ for ( $x = 1; $x < 4; $x ++ ) {
1932
+ foreach ( $this->delay_posts as $delayed_post_type => $delayed_post_data_s ) {
1933
+ foreach ( $delayed_post_data_s as $delayed_post_id => $delayed_post_data ) {
1934
+
1935
+ /*already processed*/
1936
+ if ( $this->imported_post_id( $delayed_post_data['post_id'] ) ) {
1937
+ $this->log( $x . esc_html__( '- Successfully processed ', 'advanced-import' ) . $delayed_post_type . esc_html__( ' ID ', 'advanced-import' ) . $delayed_post_data['post_id'] . esc_html__( ' previously.', 'advanced-import' ) );
1938
+
1939
+ /*already processed, remove it from delay_posts*/
1940
+ unset( $this->delay_posts[ $delayed_post_type ][ $delayed_post_id ] );
1941
+ $this->log( esc_html__( ' ( ', 'advanced-import' ) . count( $this->delay_posts, COUNT_RECURSIVE ) . esc_html__( ' delayed posts remain ) ', 'advanced-import' ) );
1942
+ }
1943
+ /*Process it*/
1944
+ elseif ( $this->process_import_single_post( $delayed_post_type, $delayed_post_data, $last_delay ) ) {
1945
+ $this->log( $x . esc_html__( ' - Successfully found delayed replacement for ', 'advanced-import' ) . $delayed_post_type . esc_html__( ' ID ', 'advanced-import' ) . $delayed_post_data['post_id'] );
1946
+
1947
+ /*successfully processed, remove it from delay_posts*/
1948
+ unset( $this->delay_posts[ $delayed_post_type ][ $delayed_post_id ] );
1949
+ $this->log( esc_html__( ' ( ', 'advanced-import' ) . count( $this->delay_posts, COUNT_RECURSIVE ) . esc_html__( ' delayed posts remain ) ', 'advanced-import' ) );
1950
+ } else {
1951
+ $this->log( $x . esc_html__( ' - Not found delayed replacement for ', 'advanced-import' ) . $delayed_post_type . esc_html__( ' ID ', 'advanced-import' ) . $delayed_post_data['post_id'] );
1952
+ }
1953
+ }
1954
+ }
1955
+ }
1956
+ }
1957
+
1958
+ /*Get file from url , download it and add to local*/
1959
+ private function import_image_and_file( $url, $post ) {
1960
+
1961
+ /*extract the file name and extension from the url*/
1962
+ $file_name = basename( $url );
1963
+ $local_file = ADVANCED_IMPORT_TEMP_UPLOADS . $file_name;
1964
+ $upload = false;
1965
+
1966
+ /*
1967
+ if file is already on local, return file information
1968
+ It means media is on local, while exporting media*/
1969
+ if ( is_file( $local_file ) && filesize( $local_file ) > 0 ) {
1970
+ require_once ABSPATH . 'wp-admin/includes/file.php';
1971
+ WP_Filesystem();
1972
+ global $wp_filesystem;
1973
+ $file_data = $wp_filesystem->get_contents( $local_file );
1974
+ $upload = wp_upload_bits( $file_name, 0, $file_data, $post['upload_date'] );
1975
+ if ( $upload['error'] ) {
1976
+ return new WP_Error( 'upload_dir_error', $upload['error'] );
1977
+ }
1978
+ }
1979
+
1980
+ /*if there is no file on local or error on local file need to fetch it*/
1981
+ if ( ! $upload || $upload['error'] ) {
1982
+
1983
+ /*get placeholder file in the upload dir with a unique, sanitized filename*/
1984
+ $upload = wp_upload_bits( $file_name, 0, '', $post['upload_date'] );
1985
+ if ( $upload['error'] ) {
1986
+ return new WP_Error( 'upload_dir_error', $upload['error'] );
1987
+ }
1988
+
1989
+ $max_size = (int) apply_filters( 'import_attachment_size_limit', 0 );
1990
+
1991
+ /*finally fetch the file from remote*/
1992
+ $response = wp_remote_get( $url );
1993
+ if ( is_array( $response ) && ! empty( $response['body'] ) && $response['response']['code'] == '200' ) {
1994
+ require_once ABSPATH . 'wp-admin/includes/file.php';
1995
+ $headers = $response['headers'];
1996
+ WP_Filesystem();
1997
+ global $wp_filesystem;
1998
+ $wp_filesystem->put_contents( $upload['file'], $response['body'] );
1999
+ } else {
2000
+ /*required to download file failed.*/
2001
+ wp_delete_file( $upload['file'] );
2002
+ return new WP_Error( 'import_file_error', esc_html__( 'Remote server did not respond', 'advanced-import' ) );
2003
+ }
2004
+
2005
+ $file_size = filesize( $upload['file'] );
2006
+
2007
+ /*check for size*/
2008
+ if ( isset( $headers['content-length'] ) && $file_size != $headers['content-length'] ) {
2009
+ wp_delete_file( $upload['file'] );
2010
+ return new WP_Error( 'import_file_error', esc_html__( 'Remote file is incorrect size', 'advanced-import' ) );
2011
+ }
2012
+
2013
+ /*if file size is 0*/
2014
+ if ( 0 == $file_size ) {
2015
+ wp_delete_file( $upload['file'] );
2016
+ return new WP_Error( 'import_file_error', esc_html__( 'Zero size file downloaded', 'advanced-import' ) );
2017
+ }
2018
+
2019
+ /*if file is too large*/
2020
+ if ( ! empty( $max_size ) && $file_size > $max_size ) {
2021
+ wp_delete_file( $upload['file'] );
2022
+ return new WP_Error( 'import_file_error', sprintf( esc_html__( 'Remote file is too large, limit is %s', 'advanced-import' ), size_format( $max_size ) ) );
2023
+ }
2024
+ }
2025
+
2026
+ /*keep track of the old and new urls so we can substitute them later*/
2027
+ $this->imported_post_id( $url, $upload['url'] );
2028
+ $this->imported_post_id( $post['guid'], $upload['url'] );
2029
+
2030
+ /*keep track of the destination if the remote url is redirected somewhere else*/
2031
+ if ( isset( $headers['x-final-location'] ) && $headers['x-final-location'] != $url ) {
2032
+ $this->imported_post_id( $headers['x-final-location'], $upload['url'] );
2033
+ }
2034
+ return $upload;
2035
+ }
2036
+
2037
+ /*
2038
+ Replace necessary ID by Local imported ID
2039
+ */
2040
+ private function replace_old_id_to_new( $option_value, $index_key = false ) {
2041
+
2042
+ /*Post IDS*/
2043
+ $replace_post_ids = apply_filters(
2044
+ 'advanced_import_replace_post_ids',
2045
+ array(
2046
+ 'page_id',
2047
+ 'post_id',
2048
+ 'image_id',
2049
+ 'selectpage',
2050
+ 'page_on_front',
2051
+ 'page_for_posts',
2052
+ 'first_page_id',
2053
+ 'second_page_id',
2054
+ /*woocommerce pages*/
2055
+ 'woocommerce_shop_page_id',
2056
+ 'woocommerce_cart_page_id',
2057
+ 'woocommerce_checkout_page_id',
2058
+ 'woocommerce_pay_page_id',
2059
+ 'woocommerce_thanks_page_id',
2060
+ 'woocommerce_myaccount_page_id',
2061
+ 'woocommerce_edit_address_page_id',
2062
+ 'woocommerce_view_order_page_id',
2063
+ 'woocommerce_terms_page_id',
2064
+ /*gutentor*/
2065
+ 'wp_block_id',
2066
+ )
2067
+ );
2068
+
2069
+ /*Terms IDS*/
2070
+ $replace_term_ids = apply_filters(
2071
+ 'advanced_import_replace_term_ids',
2072
+ array(
2073
+ 'cat_id',
2074
+ 'nav_menu',
2075
+ 'online-shop-feature-product-cat',
2076
+ 'online_shop_featured_cats',
2077
+ 'online_shop_wc_product_cat',
2078
+ 'online_shop_wc_product_tag',
2079
+ )
2080
+ );
2081
+
2082
+ /*replace terms in keys*/
2083
+
2084
+ if ( is_array( $option_value ) ) {
2085
+ foreach ( $option_value as $key => $replace_old_value ) {
2086
+
2087
+ if ( is_array( $replace_old_value ) && ! is_null( $replace_old_value ) ) {
2088
+ $option_value[ $key ] = $this->replace_old_id_to_new( $replace_old_value );
2089
+ } elseif ( $this->isJson( $replace_old_value ) && is_string( $replace_old_value ) && ! is_null( $replace_old_value ) ) {
2090
+ $value_array = json_decode( $replace_old_value, true );
2091
+ if ( is_array( $value_array ) ) {
2092
+ $option_value[ $key ] = wp_json_encode( $this->replace_old_id_to_new( $value_array ) );
2093
+ } else {
2094
+ if ( in_array( $key, $replace_post_ids ) && $key !== 0 ) {
2095
+ $new_id = $this->imported_post_id( $replace_old_value );
2096
+ if ( $new_id ) {
2097
+ $option_value[ $key ] = $new_id;
2098
+ }
2099
+ } elseif ( in_array( $key, $replace_term_ids ) && $key !== 0 ) {
2100
+ $new_id = $this->imported_term_id( $replace_old_value );
2101
+ if ( $new_id ) {
2102
+ $option_value[ $key ] = $new_id;
2103
+ }
2104
+ } else {
2105
+ $option_value[ $key ] = $replace_old_value;
2106
+ }
2107
+ }
2108
+ } else {
2109
+
2110
+ if ( in_array( $key, $replace_post_ids ) && $key !== 0 ) {
2111
+
2112
+ $new_id = $this->imported_post_id( $replace_old_value );
2113
+ if ( ! $new_id ) {
2114
+ /**/
2115
+ } else {
2116
+ $option_value[ $key ] = $new_id;
2117
+ }
2118
+ } elseif ( in_array( $key, $replace_term_ids ) && $key !== 0 ) {
2119
+ $new_id = $this->imported_term_id( $replace_old_value );
2120
+ if ( $new_id ) {
2121
+ $option_value[ $key ] = $new_id;
2122
+ }
2123
+ } else {
2124
+ $option_value[ $key ] = $replace_old_value;
2125
+ }
2126
+ }
2127
+ }
2128
+ } elseif ( is_numeric( $option_value ) && $index_key ) {
2129
+
2130
+ if ( in_array( $index_key, $replace_post_ids ) && $index_key !== 0 ) {
2131
+
2132
+ $new_id = $this->imported_post_id( $option_value );
2133
+ if ( ! $new_id ) {
2134
+ /**/
2135
+ } else {
2136
+ $option_value = $new_id;
2137
+ }
2138
+ } elseif ( in_array( $index_key, $replace_term_ids ) && $index_key !== 0 ) {
2139
+ $new_id = $this->imported_term_id( $option_value );
2140
+ if ( $new_id ) {
2141
+ $option_value = $new_id;
2142
+ }
2143
+ }
2144
+ }
2145
+
2146
+ return $option_value;
2147
+ }
2148
+
2149
+ /*
2150
+ * Callback function to importing widgets data
2151
+ * all widgets data is imported from here
2152
+ * return mix
2153
+ * */
2154
+ private function import_content_widgets_data() {
2155
+ $import_widget_data = $this->get_widgets_json();
2156
+ $import_widget_positions = $import_widget_data['widget_positions'];
2157
+ $import_widget_options = $import_widget_data['widget_options'];
2158
+
2159
+ /* get sidebars_widgets */
2160
+ $widget_positions = get_option( 'sidebars_widgets' );
2161
+ if ( ! is_array( $widget_positions ) ) {
2162
+ $widget_positions = array();
2163
+ }
2164
+
2165
+ foreach ( $import_widget_options as $widget_name => $widget_options ) {
2166
+
2167
+ /*replace $widget_options elements with updated imported entries.*/
2168
+ foreach ( $widget_options as $widget_option_id => $widget_option ) {
2169
+ $widget_options[ $widget_option_id ] = $this->replace_old_id_to_new( $widget_option, $widget_option_id );
2170
+ }
2171
+ $existing_options = get_option( 'widget_' . $widget_name, array() );
2172
+ if ( ! is_array( $existing_options ) ) {
2173
+ $existing_options = array();
2174
+ }
2175
+ $new_options = $widget_options + $existing_options;
2176
+
2177
+ $new_options = apply_filters( 'advanced_import_new_options', $new_options );
2178
+
2179
+ update_option( 'widget_' . $widget_name, $new_options );
2180
+ }
2181
+
2182
+ $sidebars_widgets = array_merge( $widget_positions, $import_widget_positions );
2183
+ $sidebars_widgets = apply_filters( 'advanced_import_sidebars_widgets', $sidebars_widgets, $this );
2184
+ update_option( 'sidebars_widgets', $sidebars_widgets );
2185
+
2186
+ return true;
2187
+
2188
+ }
2189
+
2190
+ /*check if string is json*/
2191
+ function isJson( $string ) {
2192
+ $test_json = @json_decode( $string, true );
2193
+ if ( is_array( $test_json ) ) {
2194
+ return true;
2195
+ }
2196
+ return false;
2197
+ }
2198
+
2199
+ /*
2200
+ callback function to importing menus and options data
2201
+ * all menus and import data is imported from here
2202
+ * return mix
2203
+ * */
2204
+ public function import_menu_and_options() {
2205
+
2206
+ /*final wrap up of delayed posts.*/
2207
+ $this->process_delayed_posts( true );
2208
+
2209
+ /*it includes options and menu data*/
2210
+ $theme_options = $this->get_theme_options_json();
2211
+
2212
+ /*options data*/
2213
+ $custom_options = $theme_options['options'];
2214
+
2215
+ /*menu data*/
2216
+ $menu_ids = $theme_options['menu'];
2217
+
2218
+ /*we also want to update the widget area manager options.*/
2219
+ if ( is_array( $custom_options ) ) {
2220
+ foreach ( $custom_options as $option => $value ) {
2221
+ /*replace old entries with updated imported entries.*/
2222
+ $value = $this->replace_old_id_to_new( $value, $option );
2223
+
2224
+ /*we have to update widget page numbers with imported page numbers.*/
2225
+ if (
2226
+ preg_match( '#(wam__position_)(\d+)_#', $option, $matches ) ||
2227
+ preg_match( '#(wam__area_)(\d+)_#', $option, $matches )
2228
+ ) {
2229
+ $new_page_id = $this->imported_post_id( $matches[2] );
2230
+ if ( $new_page_id ) {
2231
+ // we have a new page id for this one. import the new setting value.
2232
+ $option = str_replace( $matches[1] . $matches[2] . '_', $matches[1] . $new_page_id . '_', $option );
2233
+ }
2234
+ }
2235
+ else if ( $value && ! empty( $value['custom_logo'] ) ) {
2236
+ $new_logo_id = $this->imported_post_id( $value['custom_logo'] );
2237
+ if ( $new_logo_id ) {
2238
+ $value['custom_logo'] = $new_logo_id;
2239
+ }
2240
+ }
2241
+ /** For Gutentor */
2242
+ else if ( strpos( $option, 'gutentor-cat' ) !== false ) {
2243
+ $cat_id = substr($option, strrpos($option, '-') + 1);
2244
+ if( 'child' !== $cat_id ){
2245
+ $new_cat_id = $this->imported_term_id( $cat_id );
2246
+ $option = str_replace($cat_id,$new_cat_id,$option);
2247
+ }
2248
+ }
2249
+ update_option( $option, $value );
2250
+ }
2251
+ }
2252
+
2253
+ /*
2254
+ Options completed
2255
+ Menu Start*/
2256
+ $save = array();
2257
+ foreach ( $menu_ids as $menu_id => $term_id ) {
2258
+ $new_term_id = $this->imported_term_id( $term_id );
2259
+ if ( $new_term_id ) {
2260
+ $save[ $menu_id ] = $new_term_id;
2261
+ }
2262
+ }
2263
+
2264
+ if ( $save ) {
2265
+ set_theme_mod( 'nav_menu_locations', array_map( 'absint', $save ) );
2266
+ }
2267
+
2268
+ global $wp_rewrite;
2269
+ $wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
2270
+ update_option( 'rewrite_rules', false );
2271
+ $wp_rewrite->flush_rules( true );
2272
+
2273
+ return true;
2274
+ }
2275
+
2276
+ public function log( $message ) {
2277
+ $this->logs[] = $message;
2278
+ }
2279
+
2280
+
2281
+ public function error( $message ) {
2282
+ $this->logs[] = esc_html__( 'ERROR!!!! ', 'advanced-import' ) . $message;
2283
+ }
2284
+
2285
+ /*
2286
+ Callback function to completed
2287
+ * Show Completed Message
2288
+ * */
2289
+ public function complete_screen() {
2290
+
2291
+ /*check for security*/
2292
+ if ( ! current_user_can( 'upload_files' ) ) {
2293
+ wp_send_json_error(
2294
+ array(
2295
+ 'message' => esc_html__( 'Sorry, you are not allowed to install demo on this site.', 'advanced-import' ),
2296
+ )
2297
+ );
2298
+ }
2299
+
2300
+ require_once ABSPATH . 'wp-admin/includes/file.php';
2301
+ WP_Filesystem();
2302
+ global $wp_filesystem;
2303
+ $wp_filesystem->rmdir( ADVANCED_IMPORT_TEMP, true );
2304
+
2305
+ set_theme_mod( 'advanced_import_setup_complete', time() );
2306
+ /*delete_transient();*/
2307
+ delete_transient( 'content.json' );
2308
+ delete_transient( 'widgets.json' );
2309
+ delete_transient( 'options.json' );
2310
+
2311
+ $message = '<div class="ai-notification-title">';
2312
+ $message .= '<p>' . esc_html__( 'Your Website is Ready!', 'advanced-import' ) . '</p>';
2313
+ $message .= '<p class="ai-actions-buttons">' . sprintf( esc_html__( ' %1$sVisit your Site%2$s ', 'advanced-import' ), '<a target="_blank" href="' . esc_url( home_url( '/' ) ) . '">', '</a>' ) . '</p>';
2314
+ $message .= '<p>' . sprintf( esc_html__( 'Congratulations! All Data is imported successfully. From %1$s WordPress dashboard%2$s you can make changes and modify any of the default content to suit your needs.', 'advanced-import' ), '<a href="' . esc_url( admin_url() ) . '">', '</a>' ) . '</p>';
2315
+ $message .= '</div>';
2316
+
2317
+ apply_filters( 'advanced_import_complete_message', $message );
2318
+
2319
+ do_action( 'advanced_import_before_complete_screen' );
2320
+ echo $message;
2321
+ do_action( 'advanced_import_after_complete_screen' );
2322
+ exit;
2323
+ }
2324
+
2325
+
2326
+ /*
2327
+ callback function for wp_ajax_install_plugin
2328
+ * Install plugin
2329
+ * */
2330
+ function install_plugin() {
2331
+
2332
+ /*check for security*/
2333
+ if ( ! current_user_can( 'install_plugins' ) ) {
2334
+ $status['errorMessage'] = __( 'Sorry, you are not allowed to install plugins on this site.', 'advanced-import' );
2335
+ wp_send_json_error( $status );
2336
+ }
2337
+
2338
+ if ( empty( $_POST['plugin'] ) || empty( $_POST['slug'] ) ) {
2339
+ wp_send_json_error(
2340
+ array(
2341
+ 'slug' => '',
2342
+ 'errorCode' => 'no_plugin_specified',
2343
+ 'errorMessage' => __( 'No plugin specified.', 'advanced-import' ),
2344
+ )
2345
+ );
2346
+ }
2347
+
2348
+ $slug = sanitize_key( wp_unslash( $_POST['slug'] ) );
2349
+ $plugin = plugin_basename( sanitize_text_field( wp_unslash( $_POST['plugin'] ) ) );
2350
+
2351
+ if ( is_plugin_active_for_network( $plugin ) || is_plugin_active( $plugin ) ) {
2352
+ // Plugin is activated
2353
+ wp_send_json_success();
2354
+
2355
+ }
2356
+ $status = array(
2357
+ 'install' => 'plugin',
2358
+ 'slug' => sanitize_key( wp_unslash( $_POST['slug'] ) ),
2359
+ );
2360
+
2361
+ include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
2362
+ include_once ABSPATH . 'wp-admin/includes/plugin-install.php';
2363
+
2364
+ // Looks like a plugin is installed, but not active.
2365
+ if ( file_exists( WP_PLUGIN_DIR . '/' . $slug ) ) {
2366
+ $plugin_data = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin );
2367
+ $status['plugin'] = $plugin;
2368
+ $status['pluginName'] = $plugin_data['Name'];
2369
+
2370
+ if ( current_user_can( 'activate_plugin', $plugin ) && is_plugin_inactive( $plugin ) ) {
2371
+ $result = activate_plugin( $plugin );
2372
+
2373
+ if ( is_wp_error( $result ) ) {
2374
+ $status['errorCode'] = $result->get_error_code();
2375
+ $status['errorMessage'] = $result->get_error_message();
2376
+ wp_send_json_error( $status );
2377
+ }
2378
+
2379
+ wp_send_json_success( $status );
2380
+ }
2381
+ }
2382
+
2383
+ $api = plugins_api(
2384
+ 'plugin_information',
2385
+ array(
2386
+ 'slug' => sanitize_key( wp_unslash( $_POST['slug'] ) ),
2387
+ 'fields' => array(
2388
+ 'sections' => false,
2389
+ ),
2390
+ )
2391
+ );
2392
+
2393
+ if ( is_wp_error( $api ) ) {
2394
+ $status['errorMessage'] = $api->get_error_message();
2395
+ wp_send_json_error( $status );
2396
+ }
2397
+
2398
+ $status['pluginName'] = $api->name;
2399
+
2400
+ $skin = new WP_Ajax_Upgrader_Skin();
2401
+ $upgrader = new Plugin_Upgrader( $skin );
2402
+ $result = $upgrader->install( $api->download_link );
2403
+
2404
+ if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
2405
+ $status['debug'] = $skin->get_upgrade_messages();
2406
+ }
2407
+
2408
+ if ( is_wp_error( $result ) ) {
2409
+ $status['errorCode'] = $result->get_error_code();
2410
+ $status['errorMessage'] = $result->get_error_message();
2411
+ wp_send_json_error( $status );
2412
+ } elseif ( is_wp_error( $skin->result ) ) {
2413
+ $status['errorCode'] = $skin->result->get_error_code();
2414
+ $status['errorMessage'] = $skin->result->get_error_message();
2415
+ wp_send_json_error( $status );
2416
+ } elseif ( $skin->get_errors()->get_error_code() ) {
2417
+ $status['errorMessage'] = $skin->get_error_messages();
2418
+ wp_send_json_error( $status );
2419
+ } elseif ( is_null( $result ) ) {
2420
+ require_once ABSPATH . 'wp-admin/includes/file.php';
2421
+ WP_Filesystem();
2422
+ global $wp_filesystem;
2423
+
2424
+ $status['errorCode'] = 'unable_to_connect_to_filesystem';
2425
+ $status['errorMessage'] = __( 'Unable to connect to the filesystem. Please confirm your credentials.', 'advanced-import' );
2426
+
2427
+ // Pass through the error from WP_Filesystem if one was raised.
2428
+ if ( $wp_filesystem instanceof WP_Filesystem_Base && is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->get_error_code() ) {
2429
+ $status['errorMessage'] = esc_html( $wp_filesystem->errors->get_error_message() );
2430
+ }
2431
+
2432
+ wp_send_json_error( $status );
2433
+ }
2434
+
2435
+ $install_status = install_plugin_install_status( $api );
2436
+
2437
+ if ( current_user_can( 'activate_plugin', $install_status['file'] ) && is_plugin_inactive( $install_status['file'] ) ) {
2438
+ $result = activate_plugin( $install_status['file'] );
2439
+
2440
+ if ( is_wp_error( $result ) ) {
2441
+ $status['errorCode'] = $result->get_error_code();
2442
+ $status['errorMessage'] = $result->get_error_message();
2443
+ wp_send_json_error( $status );
2444
+ }
2445
+ }
2446
+
2447
+ wp_send_json_success( $status );
2448
+ }
2449
+
2450
+ /*
2451
+ callback function to current_screen
2452
+ * Add help Text
2453
+ * @param $screen object screen
2454
+ * */
2455
+ public function help_tabs( $screen ) {
2456
+ if ( ! is_array( $this->hook_suffix ) || ! in_array( $screen->base, $this->hook_suffix ) ) {
2457
+ return;
2458
+ }
2459
+ $current_url = advanced_import_current_url();
2460
+
2461
+ $screen->add_help_tab(
2462
+ array(
2463
+ 'id' => 'ai_help_tab_info',
2464
+ 'title' => __( 'Information', 'advanced-import' ),
2465
+ 'content' =>
2466
+ '<h2>' . __( 'Information', 'advanced-import' ) . '</h2>' .
2467
+ '<p>' . sprintf(
2468
+ __( 'Export you content via, <a href="%s" target="_blank">Advanced Export</a>. You can import export content, widget, customizer and media files too.', 'advanced-import' ),
2469
+ 'https://wordpress.org/plugins/advanced-export/'
2470
+ ) . '</p>' .
2471
+ '<p>' . sprintf(
2472
+ __( 'The zip file exported via <a href="%1$s" target="_blank">Advanced Export</a>. can be imported from this plugin <a href="%2$s">Advanced Import</a>.', 'advanced-import' ),
2473
+ 'https://wordpress.org/support/plugin/advanced-export',
2474
+ 'https://wordpress.org/support/plugin/advanced-import'
2475
+ ) . '</p>' .
2476
+ '<p><a href="' . 'https://wordpress.org/support/plugin/advanced-import' . '" class="button button-primary" target="_blank">' . __( 'Community forum', 'advanced-import' ) . '</a> <a href="' . 'https://www.addonspress.com/' . '" class="button" target="_blank">' . __( 'Author', 'advanced-import' ) . '</a></p>',
2477
+ )
2478
+ );
2479
+
2480
+ $reset_url = wp_nonce_url(
2481
+ add_query_arg( 'ai_reset_wordpress', 'true', $current_url ),
2482
+ 'ai_reset_wordpress',
2483
+ 'ai_reset_wordpress_nonce'
2484
+ );
2485
+ $screen->add_help_tab(
2486
+ array(
2487
+ 'id' => 'ai_help_tab_reset',
2488
+ 'title' => __( 'Reset wizard', 'advanced-import' ),
2489
+ 'content' =>
2490
+ '<h2>' . __( '<strong>WordPress Reset</strong>', 'advanced-import' ) . '</h2>' .
2491
+ '<p>' . __( 'If no important data on your site. You can reset the WordPress back to default again!', 'advanced-import' ) . '</p>' .
2492
+ '<p class="submit"><a href="' . esc_url( $reset_url ) . '" class="button button-primary ai-wp-reset">' . __( 'Run the Reset Wizard', 'advanced-import' ) . '</a></p>',
2493
+ )
2494
+ );
2495
+
2496
+ $screen->set_help_sidebar(
2497
+ '<p><strong>' . __( 'More information:', 'advanced-import' ) . '</strong></p>' .
2498
+ '<p><a href="' . 'https://wordpress.org/plugins/advanced-export/' . '" target="_blank">' . __( 'Advanced Export', 'advanced-import' ) . '</a></p>' .
2499
+ '<p><a href="' . 'https://wordpress.org/plugins/advanced-import/' . '" target="_blank">' . __( 'Advanced Import', 'advanced-import' ) . '</a></p>'
2500
+ );
2501
+ }
2502
+ }
2503
+
2504
+ /**
2505
+ * Begins execution of the plugin.
2506
+ *
2507
+ * Since everything within the plugin is registered via hooks,
2508
+ * then kicking off the plugin from this point in the file does
2509
+ * not affect the page life cycle.
2510
+ *
2511
+ * @since 1.0.0
2512
+ */
2513
+ function advanced_import_admin() {
2514
+ return Advanced_Import_Admin::instance();
2515
+ }
admin/class-elementor-import.php CHANGED
@@ -1,109 +1,115 @@
1
- <?php
2
- if ( ! defined( 'ABSPATH' ) ) {
3
- exit;
4
- }
5
-
6
- /**
7
- * The elementor import functionality of the plugin.
8
- *
9
- *
10
- * @package Advanced_Import
11
- * @subpackage Advanced_Import/admin/Advanced_Import_Elementor
12
- * @author Addons Press <addonspress.com>
13
- */
14
- if ( ! class_exists( 'Advanced_Import_Elementor' ) ) {
15
- /**
16
- * Advanced_Import_Elementor
17
- */
18
- class Advanced_Import_Elementor {
19
- /**
20
- * Main Advanced_Import_Elementor Instance
21
- * Initialize the class and set its properties.
22
- *
23
- * @since 1.0.0
24
- * @return object $instance Advanced_Import_Elementor Instance
25
- */
26
- public static function instance() {
27
-
28
- // Store the instance locally to avoid private static replication
29
- static $instance = null;
30
-
31
- // Only run these methods if they haven't been ran previously
32
- if ( null === $instance ) {
33
- $instance = new self();
34
- }
35
-
36
- // Always return the instance
37
- return $instance;
38
- }
39
-
40
- public function elementor_id_import( &$item, $key ) {
41
- if ( $key == 'id' && ! empty( $item ) && is_numeric( $item ) ) {
42
- // check if this has been imported before
43
- $new_meta_val = advanced_import_admin()->imported_post_id( $item );
44
- if ( $new_meta_val ) {
45
- $item = $new_meta_val;
46
- }
47
- }
48
- if ( $key == 'page' && ! empty( $item ) ) {
49
-
50
- if ( false !== strpos( $item, 'p.' ) ) {
51
- $new_id = str_replace('p.', '', $item);
52
- // check if this has been imported before
53
- $new_meta_val = advanced_import_admin()->imported_post_id( $new_id );
54
- if ( $new_meta_val ) {
55
- $item = 'p.' . $new_meta_val;
56
- }
57
- }else if(is_numeric($item)){
58
- // check if this has been imported before
59
- $new_meta_val = advanced_import_admin()->imported_post_id( $item );
60
- if ( $new_meta_val ) {
61
- $item = $new_meta_val;
62
- }
63
- }
64
- }
65
- if ( $key == 'post_id' && ! empty( $item ) && is_numeric( $item ) ) {
66
- // check if this has been imported before
67
- $new_meta_val = advanced_import_admin()->imported_post_id( $item );
68
- if ( $new_meta_val ) {
69
- $item = $new_meta_val;
70
- }
71
- }
72
- if ( $key == 'url' && ! empty( $item ) && strstr( $item, 'ocalhost' ) ) {
73
- // check if this has been imported before
74
- $new_meta_val = advanced_import_admin()->imported_post_id( $item );
75
- if ( $new_meta_val ) {
76
- $item = $new_meta_val;
77
- }
78
- }
79
- if ( ($key == 'shortcode' || $key == 'editor') && ! empty( $item ) ) {
80
- // we have to fix the [contact-form-7 id=133] shortcode issue.
81
- $item = advanced_import_admin()->parse_shortcode_meta_content($item);
82
-
83
- }
84
- }
85
-
86
- public function elementor_post( $post_id = false ) {
87
-
88
- // regenerate the CSS for this Elementor post
89
- if( class_exists( 'Elementor\Core\Files\CSS\Post' ) ) {
90
- $post_css = new Elementor\Core\Files\CSS\Post($post_id);
91
- $post_css->update();
92
- }
93
- }
94
- }
95
- }
96
-
97
-
98
- /**
99
- * Begins execution of the plugin.
100
- *
101
- * Since everything within the plugin is registered via hooks,
102
- * then kicking off the plugin from this point in the file does
103
- * not affect the page life cycle.
104
- *
105
- * @since 1.0.0
106
- */
107
- function advanced_import_elementor( ) {
108
- return Advanced_Import_Elementor::instance();
109
- }
 
 
 
 
 
 
1
+ <?php
2
+ if ( ! defined( 'ABSPATH' ) ) {
3
+ exit;
4
+ }
5
+
6
+ /**
7
+ * The elementor import functionality of the plugin.
8
+ *
9
+ * @package Advanced_Import
10
+ * @subpackage Advanced_Import/admin/Advanced_Import_Elementor
11
+ * @author Addons Press <addonspress.com>
12
+ */
13
+ if ( ! class_exists( 'Advanced_Import_Elementor' ) ) {
14
+ /**
15
+ * Advanced_Import_Elementor
16
+ */
17
+ class Advanced_Import_Elementor {
18
+ /**
19
+ * Main Advanced_Import_Elementor Instance
20
+ * Initialize the class and set its properties.
21
+ *
22
+ * @since 1.0.0
23
+ * @return object $instance Advanced_Import_Elementor Instance
24
+ */
25
+ public static function instance() {
26
+
27
+ // Store the instance locally to avoid private static replication.
28
+ static $instance = null;
29
+
30
+ // Only run these methods if they haven't been ran previously.
31
+ if ( null === $instance ) {
32
+ $instance = new self();
33
+ }
34
+
35
+ // Always return the instance.
36
+ return $instance;
37
+ }
38
+
39
+ /**
40
+ * Change post id related to elementor to new id
41
+ *
42
+ * @param array $item current array of demo list.
43
+ * @param string $key
44
+ * @return void
45
+ */
46
+ public function elementor_id_import( &$item, $key ) {
47
+ if ( $key == 'id' && ! empty( $item ) && is_numeric( $item ) ) {
48
+ // check if this has been imported before
49
+ $new_meta_val = advanced_import_admin()->imported_post_id( $item );
50
+ if ( $new_meta_val ) {
51
+ $item = $new_meta_val;
52
+ }
53
+ }
54
+ if ( $key == 'page' && ! empty( $item ) ) {
55
+
56
+ if ( false !== strpos( $item, 'p.' ) ) {
57
+ $new_id = str_replace( 'p.', '', $item );
58
+ // check if this has been imported before
59
+ $new_meta_val = advanced_import_admin()->imported_post_id( $new_id );
60
+ if ( $new_meta_val ) {
61
+ $item = 'p.' . $new_meta_val;
62
+ }
63
+ } elseif ( is_numeric( $item ) ) {
64
+ // check if this has been imported before
65
+ $new_meta_val = advanced_import_admin()->imported_post_id( $item );
66
+ if ( $new_meta_val ) {
67
+ $item = $new_meta_val;
68
+ }
69
+ }
70
+ }
71
+ if ( $key == 'post_id' && ! empty( $item ) && is_numeric( $item ) ) {
72
+ // check if this has been imported before
73
+ $new_meta_val = advanced_import_admin()->imported_post_id( $item );
74
+ if ( $new_meta_val ) {
75
+ $item = $new_meta_val;
76
+ }
77
+ }
78
+ if ( $key == 'url' && ! empty( $item ) && strstr( $item, 'ocalhost' ) ) {
79
+ // check if this has been imported before
80
+ $new_meta_val = advanced_import_admin()->imported_post_id( $item );
81
+ if ( $new_meta_val ) {
82
+ $item = $new_meta_val;
83
+ }
84
+ }
85
+ if ( ( $key == 'shortcode' || $key == 'editor' ) && ! empty( $item ) ) {
86
+ // we have to fix the [contact-form-7 id=133] shortcode issue.
87
+ $item = advanced_import_admin()->parse_shortcode_meta_content( $item );
88
+
89
+ }
90
+ }
91
+
92
+ public function elementor_post( $post_id = false ) {
93
+
94
+ // regenerate the CSS for this Elementor post
95
+ if ( class_exists( 'Elementor\Core\Files\CSS\Post' ) ) {
96
+ $post_css = new Elementor\Core\Files\CSS\Post( $post_id );
97
+ $post_css->update();
98
+ }
99
+ }
100
+ }
101
+ }
102
+
103
+
104
+ /**
105
+ * Begins execution of the plugin.
106
+ *
107
+ * Since everything within the plugin is registered via hooks,
108
+ * then kicking off the plugin from this point in the file does
109
+ * not affect the page life cycle.
110
+ *
111
+ * @since 1.0.0
112
+ */
113
+ function advanced_import_elementor() {
114
+ return Advanced_Import_Elementor::instance();
115
+ }
admin/class-reset.php CHANGED
@@ -1,205 +1,206 @@
1
- <?php
2
-
3
- /**
4
- * Reset WordPress
5
- *
6
- * @link https://addonspress.com/
7
- * @since 1.0.0
8
- *
9
- * @package Advanced_Import
10
- * @subpackage Advanced_Import/admin
11
- */
12
-
13
- /**
14
- * The admin-specific functionality of the plugin.
15
- * Reset WordPress
16
- * @package Advanced_Import
17
- * @subpackage Advanced_Import/admin
18
- * @author Addons Press <addonspress.com>
19
- */
20
- class Advanced_Import_Reset_WordPress {
21
-
22
- /**
23
- * Initialize the class and set its properties.
24
- *
25
- * @since 1.0.0
26
- */
27
- public function __construct( ) {}
28
-
29
- /**
30
- * Main Advanced_Import_Reset_WordPress Instance
31
- * Initialize the class and set its properties.
32
- *
33
- * @since 1.0.0
34
- * @return object $instance Advanced_Import_Reset_WordPress Instance
35
- */
36
- public static function instance() {
37
-
38
- // Store the instance locally to avoid private static replication
39
- static $instance = null;
40
-
41
- // Only run these methods if they haven't been ran previously
42
- if ( null === $instance ) {
43
- $instance = new Advanced_Import_Reset_WordPress;
44
-
45
- }
46
-
47
- // Always return the instance
48
- return $instance;
49
- }
50
-
51
- /**
52
- * Hide a notice if the GET variable is set.
53
- */
54
- public function hide_reset_notice() {
55
- if ( isset( $_GET['advanced-import-hide-notice'] ) && isset( $_GET['_advanced_import_notice_nonce'] ) ) {
56
- /*Security*/
57
- if ( ! wp_verify_nonce( $_GET['_advanced_import_notice_nonce'], 'advanced_import_hide_notice_nonce' ) ) {
58
- wp_die( __( 'Action failed. Please refresh the page and retry.', 'advanced-import' ) );
59
- }
60
-
61
- if ( ! current_user_can( 'manage_options' ) ) {
62
- wp_die( __( 'Cheatin&#8217; huh?', 'advanced-import' ) );
63
- }
64
-
65
- $hide_notice = sanitize_text_field( $_GET['advanced-import-hide-notice'] );
66
-
67
- if ( ! empty( $hide_notice ) && 'reset_notice' == $hide_notice ) {
68
- update_option( 'advanced_import_reset_notice', 1 );
69
- }
70
- }
71
- }
72
-
73
- /**
74
- * Reset actions when a reset button is clicked.
75
- */
76
- public function reset_wizard_actions() {
77
- global $wpdb, $current_user;
78
-
79
- if ( ! empty( $_GET['ai_reset_wordpress'] ) && !empty($_GET['ai_reset_wordpress_nonce'] )) {
80
- /*Security*/
81
- if ( ! wp_verify_nonce( wp_unslash( $_GET['ai_reset_wordpress_nonce'] ), 'ai_reset_wordpress' ) ) { // WPCS: input var ok, sanitization ok.
82
- wp_die( esc_html__( 'Action failed. Please refresh the page and retry.', 'advanced-import' ) );
83
- }
84
- if ( ! current_user_can( 'manage_options' ) ) {
85
- wp_die( esc_html__( 'No permission to reset WordPress', 'advanced-import' ) );
86
- }
87
-
88
- require_once ABSPATH . '/wp-admin/includes/upgrade.php';
89
-
90
- $template = get_option( 'template' );
91
- $blogname = get_option( 'blogname' );
92
- $admin_email = get_option( 'admin_email' );
93
- $blog_public = get_option( 'blog_public' );
94
-
95
- $current_url = advanced_import_current_url();
96
-
97
- if ( 'admin' != $current_user->user_login ) {
98
- $user = get_user_by( 'login', 'admin' );
99
- }
100
-
101
- if ( empty( $user->user_level ) || $user->user_level < 10 ) {
102
- $user = $current_user;
103
- }
104
-
105
- // Drop tables.
106
- $drop_tables = $wpdb->get_col( sprintf( "SHOW TABLES LIKE '%s%%'", str_replace( '_', '\_', $wpdb->prefix ) ) );
107
- foreach ( $drop_tables as $table ) {
108
- $wpdb->query( "DROP TABLE IF EXISTS $table" );
109
- }
110
-
111
- // Installs the site.
112
- $result = wp_install( $blogname, $user->user_login, $user->user_email, $blog_public );
113
-
114
- // Updates the user password with a old one.
115
- $wpdb->update(
116
- $wpdb->users,
117
- array(
118
- 'user_pass' => $user->user_pass,
119
- 'user_activation_key' => '',
120
- ),
121
- array( 'ID' => $result['user_id'] )
122
- );
123
-
124
- // Set up the Password change nag.
125
- $default_password_nag = get_user_option( 'default_password_nag', $result['user_id'] );
126
- if ( $default_password_nag ) {
127
- update_user_option( $result['user_id'], 'default_password_nag', false, true );
128
- }
129
-
130
- // Switch current theme.
131
- $current_theme = wp_get_theme( $template );
132
- if ( $current_theme->exists() ) {
133
- switch_theme( $template );
134
- }
135
-
136
- // Activate required plugins.
137
- $required_plugins = (array) apply_filters( 'advanced_import_' . $template . '_required_plugins', array() );
138
- if ( is_array( $required_plugins ) ) {
139
- if ( ! in_array( plugin_basename( ADVANCED_IMPORT_PATH.'/advanced-import.php'), $required_plugins ) ) {
140
- $required_plugins = array_merge( $required_plugins, array( ADVANCED_IMPORT_PATH.'/advanced-import.php') );
141
- }
142
- activate_plugins( $required_plugins, '', is_network_admin(), true );
143
- }
144
-
145
- // Update the cookies.
146
- wp_clear_auth_cookie();
147
- wp_set_auth_cookie( $result['user_id'] );
148
-
149
- // Redirect to demo importer page to display reset success notice.
150
- wp_safe_redirect($current_url.'&reset=true&from=ai-reset-wp');
151
- exit();
152
- }
153
- }
154
-
155
- /**
156
- * Reset wizard notice.
157
- */
158
- public function reset_wizard_notice() {
159
-
160
- $screen = get_current_screen();
161
- if (!in_array( $screen->base, advanced_import_admin()->hook_suffix )){
162
- return;
163
- }
164
- $current_url = advanced_import_current_url();
165
- $reset_url = wp_nonce_url(
166
- add_query_arg( 'ai_reset_wordpress', 'true', $current_url ),
167
- 'ai_reset_wordpress',
168
- 'ai_reset_wordpress_nonce'
169
- );
170
-
171
- $demo_notice_dismiss = get_option( 'advanced_import_reset_notice' );
172
-
173
- // Output reset wizard notice.
174
- if ( ! $demo_notice_dismiss ) {
175
- ?>
176
- <div id="message" class="updated ai-import-message">
177
- <p><?php _e( '<strong>WordPress Reset</strong> &#8211; If no important data on your site. You can reset the WordPress back to default again!', 'advanced-import' ); ?></p>
178
- <p class="submit"><a href="<?php echo esc_url( $reset_url ); ?>" class="button button-primary ai-wp-reset"><?php esc_html_e( 'Run the Reset Wizard', 'advanced-import' ); ?></a> <a class="button-secondary skip" href="<?php echo esc_url( wp_nonce_url( add_query_arg( 'advanced-import-hide-notice', 'reset_notice', $current_url ), 'advanced_import_hide_notice_nonce', '_advanced_import_notice_nonce' ) ); ?>"><?php esc_attr_e( 'Hide this notice', 'advanced-import' ); ?></a></p>
179
- </div>
180
- <?php
181
- } elseif ( isset( $_GET['reset'] ) && 'true' === $_GET['reset'] ) {
182
- $user = get_user_by( 'id', 1 );
183
- ?>
184
- <div id="message" class="notice notice-info is-dismissible">
185
- <p><?php printf( __( 'WordPress has been reset back to defaults. The user <strong>"%1$s"</strong> was recreated with its previous password.', 'advanced-import' ), $user->user_login ); ?></p>
186
- </div>
187
- <?php
188
- }
189
- }
190
-
191
-
192
- }
193
-
194
- /**
195
- * Begins execution of the plugin.
196
- *
197
- * Since everything within the plugin is registered via hooks,
198
- * then kicking off the plugin from this point in the file does
199
- * not affect the page life cycle.
200
- *
201
- * @since 1.0.0
202
- */
203
- function advanced_import_reset_wordpress() {
204
- return Advanced_Import_Reset_WordPress::instance();
205
- }
 
1
+ <?php
2
+
3
+ /**
4
+ * Reset WordPress
5
+ *
6
+ * @link https://addonspress.com/
7
+ * @since 1.0.0
8
+ *
9
+ * @package Advanced_Import
10
+ * @subpackage Advanced_Import/admin
11
+ */
12
+
13
+ /**
14
+ * The admin-specific functionality of the plugin.
15
+ * Reset WordPress
16
+ *
17
+ * @package Advanced_Import
18
+ * @subpackage Advanced_Import/admin
19
+ * @author Addons Press <addonspress.com>
20
+ */
21
+ class Advanced_Import_Reset_WordPress {
22
+
23
+ /**
24
+ * Initialize the class and set its properties.
25
+ *
26
+ * @since 1.0.0
27
+ */
28
+ public function __construct() {}
29
+
30
+ /**
31
+ * Main Advanced_Import_Reset_WordPress Instance
32
+ * Initialize the class and set its properties.
33
+ *
34
+ * @since 1.0.0
35
+ * @return object $instance Advanced_Import_Reset_WordPress Instance
36
+ */
37
+ public static function instance() {
38
+
39
+ // Store the instance locally to avoid private static replication
40
+ static $instance = null;
41
+
42
+ // Only run these methods if they haven't been ran previously
43
+ if ( null === $instance ) {
44
+ $instance = new Advanced_Import_Reset_WordPress();
45
+
46
+ }
47
+
48
+ // Always return the instance
49
+ return $instance;
50
+ }
51
+
52
+ /**
53
+ * Hide a notice if the GET variable is set.
54
+ */
55
+ public function hide_reset_notice() {
56
+ if ( isset( $_GET['advanced-import-hide-notice'] ) && isset( $_GET['_advanced_import_notice_nonce'] ) ) {
57
+ /*Security*/
58
+ if ( ! wp_verify_nonce( $_GET['_advanced_import_notice_nonce'], 'advanced_import_hide_notice_nonce' ) ) {
59
+ wp_die( __( 'Action failed. Please refresh the page and retry.', 'advanced-import' ) );
60
+ }
61
+
62
+ if ( ! current_user_can( 'manage_options' ) ) {
63
+ wp_die( __( 'Cheatin&#8217; huh?', 'advanced-import' ) );
64
+ }
65
+
66
+ $hide_notice = sanitize_text_field( $_GET['advanced-import-hide-notice'] );
67
+
68
+ if ( ! empty( $hide_notice ) && 'reset_notice' == $hide_notice ) {
69
+ update_option( 'advanced_import_reset_notice', 1 );
70
+ }
71
+ }
72
+ }
73
+
74
+ /**
75
+ * Reset actions when a reset button is clicked.
76
+ */
77
+ public function reset_wizard_actions() {
78
+ global $wpdb, $current_user;
79
+
80
+ if ( ! empty( $_GET['ai_reset_wordpress'] ) && ! empty( $_GET['ai_reset_wordpress_nonce'] ) ) {
81
+ /*Security*/
82
+ if ( ! wp_verify_nonce( wp_unslash( $_GET['ai_reset_wordpress_nonce'] ), 'ai_reset_wordpress' ) ) { // WPCS: input var ok, sanitization ok.
83
+ wp_die( esc_html__( 'Action failed. Please refresh the page and retry.', 'advanced-import' ) );
84
+ }
85
+ if ( ! current_user_can( 'manage_options' ) ) {
86
+ wp_die( esc_html__( 'No permission to reset WordPress', 'advanced-import' ) );
87
+ }
88
+
89
+ require_once ABSPATH . '/wp-admin/includes/upgrade.php';
90
+
91
+ $template = get_option( 'template' );
92
+ $blogname = get_option( 'blogname' );
93
+ $admin_email = get_option( 'admin_email' );
94
+ $blog_public = get_option( 'blog_public' );
95
+
96
+ $current_url = advanced_import_current_url();
97
+
98
+ if ( 'admin' != $current_user->user_login ) {
99
+ $user = get_user_by( 'login', 'admin' );
100
+ }
101
+
102
+ if ( empty( $user->user_level ) || $user->user_level < 10 ) {
103
+ $user = $current_user;
104
+ }
105
+
106
+ // Drop tables.
107
+ $drop_tables = $wpdb->get_col( sprintf( "SHOW TABLES LIKE '%s%%'", str_replace( '_', '\_', $wpdb->prefix ) ) );
108
+ foreach ( $drop_tables as $table ) {
109
+ $wpdb->query( "DROP TABLE IF EXISTS $table" );
110
+ }
111
+
112
+ // Installs the site.
113
+ $result = wp_install( $blogname, $user->user_login, $user->user_email, $blog_public );
114
+
115
+ // Updates the user password with a old one.
116
+ $wpdb->update(
117
+ $wpdb->users,
118
+ array(
119
+ 'user_pass' => $user->user_pass,
120
+ 'user_activation_key' => '',
121
+ ),
122
+ array( 'ID' => $result['user_id'] )
123
+ );
124
+
125
+ // Set up the Password change nag.
126
+ $default_password_nag = get_user_option( 'default_password_nag', $result['user_id'] );
127
+ if ( $default_password_nag ) {
128
+ update_user_option( $result['user_id'], 'default_password_nag', false, true );
129
+ }
130
+
131
+ // Switch current theme.
132
+ $current_theme = wp_get_theme( $template );
133
+ if ( $current_theme->exists() ) {
134
+ switch_theme( $template );
135
+ }
136
+
137
+ // Activate required plugins.
138
+ $required_plugins = (array) apply_filters( 'advanced_import_' . $template . '_required_plugins', array() );
139
+ if ( is_array( $required_plugins ) ) {
140
+ if ( ! in_array( plugin_basename( ADVANCED_IMPORT_PATH . '/advanced-import.php' ), $required_plugins ) ) {
141
+ $required_plugins = array_merge( $required_plugins, array( ADVANCED_IMPORT_PATH . '/advanced-import.php' ) );
142
+ }
143
+ activate_plugins( $required_plugins, '', is_network_admin(), true );
144
+ }
145
+
146
+ // Update the cookies.
147
+ wp_clear_auth_cookie();
148
+ wp_set_auth_cookie( $result['user_id'] );
149
+
150
+ // Redirect to demo importer page to display reset success notice.
151
+ wp_safe_redirect( $current_url . '&reset=true&from=ai-reset-wp' );
152
+ exit();
153
+ }
154
+ }
155
+
156
+ /**
157
+ * Reset wizard notice.
158
+ */
159
+ public function reset_wizard_notice() {
160
+
161
+ $screen = get_current_screen();
162
+ if ( ! in_array( $screen->base, advanced_import_admin()->hook_suffix ) ) {
163
+ return;
164
+ }
165
+ $current_url = advanced_import_current_url();
166
+ $reset_url = wp_nonce_url(
167
+ add_query_arg( 'ai_reset_wordpress', 'true', $current_url ),
168
+ 'ai_reset_wordpress',
169
+ 'ai_reset_wordpress_nonce'
170
+ );
171
+
172
+ $demo_notice_dismiss = get_option( 'advanced_import_reset_notice' );
173
+
174
+ // Output reset wizard notice.
175
+ if ( ! $demo_notice_dismiss ) {
176
+ ?>
177
+ <div id="message" class="updated ai-import-message">
178
+ <p><?php _e( '<strong>WordPress Reset</strong> &#8211; If no important data on your site. You can reset the WordPress back to default again!', 'advanced-import' ); ?></p>
179
+ <p class="submit"><a href="<?php echo esc_url( $reset_url ); ?>" class="button button-primary ai-wp-reset"><?php esc_html_e( 'Run the Reset Wizard', 'advanced-import' ); ?></a> <a class="button-secondary skip" href="<?php echo esc_url( wp_nonce_url( add_query_arg( 'advanced-import-hide-notice', 'reset_notice', $current_url ), 'advanced_import_hide_notice_nonce', '_advanced_import_notice_nonce' ) ); ?>"><?php esc_attr_e( 'Hide this notice', 'advanced-import' ); ?></a></p>
180
+ </div>
181
+ <?php
182
+ } elseif ( isset( $_GET['reset'] ) && 'true' === $_GET['reset'] ) {
183
+ $user = get_user_by( 'id', 1 );
184
+ ?>
185
+ <div id="message" class="notice notice-info is-dismissible">
186
+ <p><?php printf( __( 'WordPress has been reset back to defaults. The user <strong>"%1$s"</strong> was recreated with its previous password.', 'advanced-import' ), $user->user_login ); ?></p>
187
+ </div>
188
+ <?php
189
+ }
190
+ }
191
+
192
+
193
+ }
194
+
195
+ /**
196
+ * Begins execution of the plugin.
197
+ *
198
+ * Since everything within the plugin is registered via hooks,
199
+ * then kicking off the plugin from this point in the file does
200
+ * not affect the page life cycle.
201
+ *
202
+ * @since 1.0.0
203
+ */
204
+ function advanced_import_reset_wordpress() {
205
+ return Advanced_Import_Reset_WordPress::instance();
206
+ }
admin/index.php CHANGED
@@ -1 +1 @@
1
- <?php // Silence is golden
1
+ <?php // Silence is golden
advanced-import.php CHANGED
@@ -1,8 +1,8 @@
1
  <?php
2
  // If this file is called directly, abort.
3
  if ( ! defined( 'WPINC' ) ) {
4
- echo 'Hi there! I\'m just a plugin, not much I can do when called directly.';
5
- exit;
6
  }
7
  /**
8
  *
@@ -14,7 +14,7 @@ if ( ! defined( 'WPINC' ) ) {
14
  * Plugin Name: Advanced Import
15
  * Plugin URI: https://addonspress.com/item/advanced-import
16
  * Description: Easily import demo data starter site packages or Migrate your site data
17
- * Version: 1.2.4
18
  * Author: AddonsPress
19
  * Author URI: https://addonspress.com/
20
  * License: GPL-2.0+
@@ -24,16 +24,16 @@ if ( ! defined( 'WPINC' ) ) {
24
  */
25
 
26
  /*Define Constants for this plugin*/
27
- define( 'ADVANCED_IMPORT_VERSION', '1.2.4' );
28
  define( 'ADVANCED_IMPORT_PLUGIN_NAME', 'advanced-import' );
29
- define( 'ADVANCED_IMPORT_PATH', plugin_dir_path( __FILE__ ) );
30
  define( 'ADVANCED_IMPORT_URL', plugin_dir_url( __FILE__ ) );
31
  define( 'ADVANCED_IMPORT_SCRIPT_PREFIX', ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '.min' : '.min' );
32
 
33
- $upload_dir = wp_upload_dir();
34
- $advanced_import_temp = $upload_dir['basedir'] . '/advanced-import-temp/';
35
- $advanced_import_temp_zip = $upload_dir['basedir'] . '/advanced-import-temp-zip/';
36
- $advanced_import_temp_uploads = $advanced_import_temp . '/uploads/';
37
 
38
  define( 'ADVANCED_IMPORT_TEMP', $advanced_import_temp );
39
  define( 'ADVANCED_IMPORT_TEMP_ZIP', $advanced_import_temp_zip );
@@ -44,8 +44,8 @@ define( 'ADVANCED_IMPORT_TEMP_UPLOADS', $advanced_import_temp_uploads );
44
  * This action is documented in includes/class-advanced-import-activator.php
45
  */
46
  function activate_advanced_import() {
47
- require_once ADVANCED_IMPORT_PATH . 'includes/class-advanced-import-activator.php';
48
- Advanced_Import_Activator::activate();
49
  }
50
 
51
  /**
@@ -53,8 +53,8 @@ function activate_advanced_import() {
53
  * This action is documented in includes/class-advanced-import-deactivator.php
54
  */
55
  function deactivate_advanced_import() {
56
- require_once ADVANCED_IMPORT_PATH . 'includes/class-advanced-import-deactivator.php';
57
- Advanced_Import_Deactivator::deactivate();
58
  }
59
 
60
  register_activation_hook( __FILE__, 'activate_advanced_import' );
@@ -76,6 +76,6 @@ require ADVANCED_IMPORT_PATH . 'includes/class-advanced-import.php';
76
  * @since 1.0.0
77
  */
78
  function advanced_import() {
79
- return Advanced_Import::instance();
80
  }
81
- advanced_import();
1
  <?php
2
  // If this file is called directly, abort.
3
  if ( ! defined( 'WPINC' ) ) {
4
+ echo 'Hi there! I\'m just a plugin, not much I can do when called directly.';
5
+ exit;
6
  }
7
  /**
8
  *
14
  * Plugin Name: Advanced Import
15
  * Plugin URI: https://addonspress.com/item/advanced-import
16
  * Description: Easily import demo data starter site packages or Migrate your site data
17
+ * Version: 1.2.5
18
  * Author: AddonsPress
19
  * Author URI: https://addonspress.com/
20
  * License: GPL-2.0+
24
  */
25
 
26
  /*Define Constants for this plugin*/
27
+ define( 'ADVANCED_IMPORT_VERSION', '1.2.5' );
28
  define( 'ADVANCED_IMPORT_PLUGIN_NAME', 'advanced-import' );
29
+ define( 'ADVANCED_IMPORT_PATH', plugin_dir_path( __FILE__ ) );
30
  define( 'ADVANCED_IMPORT_URL', plugin_dir_url( __FILE__ ) );
31
  define( 'ADVANCED_IMPORT_SCRIPT_PREFIX', ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '.min' : '.min' );
32
 
33
+ $upload_dir = wp_upload_dir();
34
+ $advanced_import_temp = $upload_dir['basedir'] . '/advanced-import-temp/';
35
+ $advanced_import_temp_zip = $upload_dir['basedir'] . '/advanced-import-temp-zip/';
36
+ $advanced_import_temp_uploads = $advanced_import_temp . '/uploads/';
37
 
38
  define( 'ADVANCED_IMPORT_TEMP', $advanced_import_temp );
39
  define( 'ADVANCED_IMPORT_TEMP_ZIP', $advanced_import_temp_zip );
44
  * This action is documented in includes/class-advanced-import-activator.php
45
  */
46
  function activate_advanced_import() {
47
+ require_once ADVANCED_IMPORT_PATH . 'includes/class-advanced-import-activator.php';
48
+ Advanced_Import_Activator::activate();
49
  }
50
 
51
  /**
53
  * This action is documented in includes/class-advanced-import-deactivator.php
54
  */
55
  function deactivate_advanced_import() {
56
+ require_once ADVANCED_IMPORT_PATH . 'includes/class-advanced-import-deactivator.php';
57
+ Advanced_Import_Deactivator::deactivate();
58
  }
59
 
60
  register_activation_hook( __FILE__, 'activate_advanced_import' );
76
  * @since 1.0.0
77
  */
78
  function advanced_import() {
79
+ return Advanced_Import::instance();
80
  }
81
+ advanced_import();
assets/css/advanced-import-admin.min.css CHANGED
@@ -1 +1 @@
1
- .ai-body{margin:40px 15px 0}.ai-body img{max-width:100%;height:auto}.ai-header{margin-bottom:40px}.ai-filter-tabs{display:flex;align-items:center;background:#fff;padding:10px 20px;margin-bottom:20px;box-shadow:0 1px 1px rgba(0,0,0,.04);border:1px solid #e5e5e5}.ai-filter-tabs ul{margin-top:0;margin-bottom:0}.ai-filter-tabs ul li{font-size:14px;cursor:pointer;font-weight:600}.ai-count{background:#ca4a1f;display:inline-block;padding:2px 10px;border-radius:50px;margin-left:5px;color:#fff;font-size:12px}.ai-types{display:flex}.ai-types li{margin:0 5px;padding:5px}.ai-form-file-import{cursor:pointer;background:#efefef;padding:8px 25px;margin:0;border-radius:3px;background:#0085ba;border-color:#0073aa #006799 #006799;box-shadow:0 1px 0 #006799;color:#fff;text-decoration:none;text-shadow:0 -1px 1px #006799,1px 0 1px #006799,0 1px 1px #006799,-1px 0 1px #006799}.ai-form-file-import:focus,.ai-form-file-import:hover{background:#0073aa;border-color:#006799}.ai-filter-content{background:#f8f8f8;display:flex}.ai-filter-content.hidden{display:none}.ai-sidebar{flex-basis:250px;min-width:270px;background:#f9f9f9;color:#999;padding-top:30px;border-right:1px solid #ddd;box-shadow:10px 0 10px -3px rgba(0,0,0,.1)}.ai-import-available-categories{margin-top:20px;overflow-y:auto;overflow-x:hidden;max-height:calc(100% - 23px)}.ai-import-available-categories h3{padding-left:30px;padding-right:30px}.ai-import-available-categories ul{margin-top:20px}.ai-import-available-categories ul li{cursor:pointer;font-weight:600;font-size:14px;padding:15px 30px;position:relative;z-index:1;margin:0;border-bottom:1px solid #f1f1f1}.ai-import-available-categories ul li:after{position:absolute;left:0;top:0;background:#f1f1f1;width:0;content:'';height:100%;z-index:-1;transition:all .5s ease-in-out 0s}.ai-import-available-categories ul li:focus,.ai-import-available-categories ul li:hover{border-color:#f1f1f1;color:#444}.ai-import-available-categories ul li span{float:right}.ai-import-available-categories ul li.ai-filter-btn-active{color:#444;border-color:#f1f1f1}.ai-import-available-categories ul li.ai-filter-btn-active:focus,.ai-import-available-categories ul li.ai-filter-btn-active:hover{border-color:#f1f1f1}.ai-import-available-categories ul li.ai-filter-btn-active:focus:after,.ai-import-available-categories ul li.ai-filter-btn-active:hover:after{width:100%}.ai-import-available-categories ul li.ai-filter-btn-active:after{width:100%;transition:all .5s ease-in-out 0s}.ai-search-control{margin-left:auto;margin-right:20px;width:200px}.ai-search-control .ai-search-filter{padding-left:10px;padding-right:10px}.ai-search-filter{height:36px;width:100%}.ai-filter-content-wrapper{flex-basis:calc(100% - 250px);padding:15px}.ai-item-preview{position:relative;z-index:1;line-height:0;border-top-right-radius:4px;border-top-left-radius:4px;background:#fff}.ai-item-preview:after{content:'';width:100%;height:100%;position:absolute;left:0;top:0;box-shadow:0 -130px 70px -42px rgba(0,0,0,.8) inset;z-index:2;opacity:0;visibility:hidden;transition:all .5s ease-in-out 0s}.ai-item-preview .ai-item-screenshot{border-top-right-radius:4px;border-top-left-radius:4px;overflow:hidden}.ai-item-preview .ai-author-info{position:absolute;left:0;right:0;bottom:-100px;width:100%;z-index:3;margin:0;padding:20px;color:#fff;font-size:16px;opacity:0;visibility:hidden;transition:opacity .5s ease-in-out 0s,visibility .9s ease-in-out 0s}.ai-item-preview .ai-details{position:absolute;left:0;right:0;margin:0 auto;top:50%;width:130px;margin:0 auto;background:rgba(0,0,0,.8);height:40px;line-height:40px;text-align:center;z-index:5;font-size:15px;font-weight:600;color:#fff;opacity:0;visibility:hidden;transition:all .5s ease-in-out 0s;transform:translateY(-50%)}.ai-item-preview .ai-premium-label{position:absolute;right:-10px;top:20px;background:#ca4a1f;display:block;z-index:3;line-height:16px;padding:10px 20px;height:16px;font-weight:600;color:#fff}.ai-item-preview .ai-premium-label:before{position:absolute;left:-18px;top:0;height:0;width:0;content:"";border-top:18px solid #ca4a1f;border-left:18px solid transparent;border-bottom:18px solid #ca4a1f}.ai-item-preview .ai-premium-label:after{position:absolute;right:0;content:"";bottom:-10px;width:0;height:0;border-top:10px solid #ca4a1f;border-right:10px solid transparent}.ai-item{display:inline-block;max-width:calc(100% / 3 - 40px);margin:15px;box-shadow:0 2px 15px -3px rgba(0,0,0,.2)}@media (min-width:1600px){.ai-item{max-width:calc(100% / 4 - 40px)}}.ai-item:hover .ai-item-preview:after{visibility:visible;opacity:1}.ai-item:hover .ai-author-info{bottom:10px;visibility:visible;opacity:1}.ai-item:hover .ai-details,.ai-item:hover .ai-item-footer-actions{visibility:visible;opacity:1}.ai-item-footer{padding:20px;background:#fff;position:relative;border-bottom-right-radius:4px;border-bottom-left-radius:4px}.ai-item-footer .theme-name{margin:0;white-space:nowrap;width:98%;overflow:hidden;text-overflow:ellipsis;line-height:24px}.ai-item-footer-actions{position:absolute;right:0;text-align:center;z-index:4;top:0;height:calc(100% - 22px);background:red;padding:11px;opacity:0;transition:all .1s ease-in-out;visibility:hidden;background:rgba(244,244,244,.7);border-left:1px solid rgba(0,0,0,.05)}.ai-item-footer-actions .button{line-height:32px;height:35px}.ai-item-footer-actions .button .dashicons:not(.dashicons-update){width:10px;height:10px;font-size:14px;vertical-align:middle;margin-right:10px;margin-top:-5px}.ai-item-footer-actions .button .dashicons.ai-update{animation:dashicons-spin 1s linear infinite;margin:17px 0 0 10px;width:auto;height:auto;font-size:16px}.ai-item-footer-actions .button .dashicons.dashicons-visibility{font-size:12px}.ai-form{padding:40px;background:#fff}.ai-form .media-title{margin-top:0}.ai-form .input-file{padding:100px;border:1px dashed #cdcdcd;margin:40px 0;background:#f8f8f8;text-align:center;clear:both}.ai-item.ai-action-importing .ai-item-preview:after{visibility:visible;opacity:1}.ai-item.ai-action-importing .ai-author-info{bottom:10px}.ai-item.ai-action-importing .ai-item-footer-actions{top:50%;transform:translateY(-50%)}.ai-item.ai-action-importing .ai-demo-import{padding-right:0}.ai-item.ai-action-importing .ai-item-footer-actions{opacity:1;visibility:visible}@keyframes dashicons-spin{0%{transform:translate3d(-50%,-50%,0) rotate(0)}100%{transform:translate3d(-50%,-50%,0) rotate(360deg)}}.ai-confirm-import-content #swal2-content{text-align:left!important;margin-top:20px}.swal2-actions{width:auto!important}#swal2-content p{padding-left:20px;padding-right:13px}
1
+ .ai-body{margin:40px 15px 0}.ai-body img{max-width:100%;height:auto}.ai-header{margin-bottom:30px;padding:20px;background:#fff;border-left-color:#46b450;border-width:0 0 0 4px;border-style:solid;box-shadow:0 1px 1px rgba(0,0,0,.04)}.ai-header h1{margin-top:0}.ai-header p{margin-bottom:0}.ai-filter-tabs{display:flex;align-items:center;background:#fff;padding:10px 20px;margin-bottom:20px;margin-top:20px;box-shadow:0 1px 1px rgba(0,0,0,.04);border:1px solid #e5e5e5}.ai-filter-tabs ul{margin-top:0;margin-bottom:0}.ai-filter-tabs ul li{font-size:14px;cursor:pointer;font-weight:600}.ai-count{background:#ca4a1f;display:inline-block;padding:2px 10px;border-radius:50px;margin-left:5px;color:#fff;font-size:12px}.ai-types{display:flex}.ai-types li{margin:0 5px;padding:5px}.ai-form-file-import{cursor:pointer;background:#efefef;padding:8px 25px;margin:0;border-radius:3px;background:#0085ba;border-color:#0073aa #006799 #006799;box-shadow:0 1px 0 #006799;color:#fff;text-decoration:none;text-shadow:0 -1px 1px #006799,1px 0 1px #006799,0 1px 1px #006799,-1px 0 1px #006799}.ai-form-file-import:focus,.ai-form-file-import:hover{background:#0073aa;border-color:#006799}.ai-filter-content{background:#f8f8f8;display:flex}.ai-filter-content.hidden{display:none}.ai-sidebar{flex-basis:250px;min-width:270px;background:#f9f9f9;color:#999;padding-top:30px;border-right:1px solid #ddd;box-shadow:10px 0 10px -3px rgba(0,0,0,.1)}.ai-import-available-categories{margin-top:20px;overflow-y:auto;overflow-x:hidden;max-height:calc(100% - 23px)}.ai-import-available-categories h3{padding-left:30px;padding-right:30px}.ai-import-available-categories ul{margin-top:20px}.ai-import-available-categories ul li{cursor:pointer;font-weight:600;font-size:14px;padding:15px 30px;position:relative;z-index:1;margin:0;border-bottom:1px solid #f1f1f1}.ai-import-available-categories ul li:after{position:absolute;left:0;top:0;background:#f1f1f1;width:0;content:'';height:100%;z-index:-1;transition:all .5s ease-in-out 0s}.ai-import-available-categories ul li:focus,.ai-import-available-categories ul li:hover{border-color:#f1f1f1;color:#444}.ai-import-available-categories ul li span{float:right}.ai-import-available-categories ul li.ai-filter-btn-active{color:#444;border-color:#f1f1f1}.ai-import-available-categories ul li.ai-filter-btn-active:focus,.ai-import-available-categories ul li.ai-filter-btn-active:hover{border-color:#f1f1f1}.ai-import-available-categories ul li.ai-filter-btn-active:focus:after,.ai-import-available-categories ul li.ai-filter-btn-active:hover:after{width:100%}.ai-import-available-categories ul li.ai-filter-btn-active:after{width:100%;transition:all .5s ease-in-out 0s}.ai-search-control{margin-left:auto;margin-right:20px;width:200px}.ai-search-control .ai-search-filter{padding-left:10px;padding-right:10px}.ai-search-filter{height:36px;width:100%}.ai-filter-content-wrapper{flex-basis:calc(100% - 250px);padding:15px}.ai-item-preview{position:relative;z-index:1;line-height:0;border-top-right-radius:4px;border-top-left-radius:4px;background:#fff}.ai-item-preview:after{content:'';width:100%;height:100%;position:absolute;left:0;top:0;box-shadow:0 -130px 70px -42px rgba(0,0,0,.8) inset;z-index:2;opacity:0;visibility:hidden;transition:all .5s ease-in-out 0s}.ai-item-preview .ai-item-screenshot{border-top-right-radius:4px;border-top-left-radius:4px;overflow:hidden}.ai-item-preview .ai-author-info{position:absolute;left:0;right:0;bottom:-100px;width:100%;z-index:3;margin:0;padding:20px;color:#fff;font-size:16px;opacity:0;visibility:hidden;transition:opacity .5s ease-in-out 0s,visibility .9s ease-in-out 0s}.ai-item-preview .ai-details{position:absolute;left:0;right:0;margin:0 auto;top:50%;width:130px;margin:0 auto;background:rgba(0,0,0,.8);height:40px;line-height:40px;text-align:center;z-index:5;font-size:15px;font-weight:600;color:#fff;opacity:0;visibility:hidden;transition:all .5s ease-in-out 0s;transform:translateY(-50%)}.ai-item-preview .ai-premium-label{position:absolute;right:-10px;top:20px;background:#ca4a1f;display:block;z-index:3;line-height:16px;padding:10px 20px;height:16px;font-weight:600;color:#fff}.ai-item-preview .ai-premium-label:before{position:absolute;left:-18px;top:0;height:0;width:0;content:"";border-top:18px solid #ca4a1f;border-left:18px solid transparent;border-bottom:18px solid #ca4a1f}.ai-item-preview .ai-premium-label:after{position:absolute;right:0;content:"";bottom:-10px;width:0;height:0;border-top:10px solid #ca4a1f;border-right:10px solid transparent}.ai-item{display:inline-block;max-width:calc(100% / 3 - 40px);margin:15px;box-shadow:0 2px 15px -3px rgba(0,0,0,.2)}@media (min-width:1600px){.ai-item{max-width:calc(100% / 4 - 40px)}}.ai-item:hover .ai-item-preview:after{visibility:visible;opacity:1}.ai-item:hover .ai-author-info{bottom:10px;visibility:visible;opacity:1}.ai-item:hover .ai-details,.ai-item:hover .ai-item-footer-actions{visibility:visible;opacity:1}.ai-item-footer{padding:20px;background:#fff;position:relative;border-bottom-right-radius:4px;border-bottom-left-radius:4px}.ai-item-footer .theme-name{margin:0;white-space:nowrap;width:98%;overflow:hidden;text-overflow:ellipsis;line-height:24px}.ai-item-footer-actions{position:absolute;right:0;text-align:center;z-index:4;top:0;height:calc(100% - 22px);background:red;padding:11px;opacity:0;transition:all .1s ease-in-out;visibility:hidden;background:rgba(244,244,244,.7);border-left:1px solid rgba(0,0,0,.05)}.ai-item-footer-actions .button{line-height:32px;height:35px}.ai-item-footer-actions .button .dashicons:not(.dashicons-update){width:10px;height:10px;font-size:14px;vertical-align:middle;margin-right:10px;margin-top:-5px}.ai-item-footer-actions .button .dashicons.ai-update{animation:dashicons-spin 1s linear infinite;margin:17px 0 0 10px;width:auto;height:auto;font-size:16px}.ai-item-footer-actions .button .dashicons.dashicons-visibility{font-size:12px}.ai-form{padding:40px;background:#fff}.ai-form .media-title{margin-top:0}.ai-form .input-file{padding:100px;border:1px dashed #cdcdcd;margin:40px 0;background:#f8f8f8;text-align:center;clear:both}.ai-item.ai-action-importing .ai-item-preview:after{visibility:visible;opacity:1}.ai-item.ai-action-importing .ai-author-info{bottom:10px}.ai-item.ai-action-importing .ai-item-footer-actions{top:50%;transform:translateY(-50%)}.ai-item.ai-action-importing .ai-demo-import{padding-right:0}.ai-item.ai-action-importing .ai-item-footer-actions{opacity:1;visibility:visible}@keyframes dashicons-spin{0%{transform:translate3d(-50%,-50%,0) rotate(0)}100%{transform:translate3d(-50%,-50%,0) rotate(360deg)}}.ai-confirm-import-content #swal2-content{text-align:left!important;margin-top:20px}.swal2-actions{width:auto!important}#swal2-content p{padding-left:20px;padding-right:13px}
example.php CHANGED
@@ -1,80 +1,83 @@
1
- <?php
2
- function prefix_demo_import_lists(){
3
- $demo_lists = array(
4
- 'demo1' =>array(
5
- 'title' => __( 'Title 1', 'text-domain' ),/*Title*/
6
- 'is_pro' => false,/*Is Premium*/
7
- 'type' => 'gutentor',/*Optional eg gutentor, elementor or other page builders or type*/
8
- 'author' => __( 'Gutentor', 'text-domain' ),/*Author Name*/
9
- 'keywords' => array( 'medical', 'multipurpose' ),/*Search keyword*/
10
- 'categories' => array( 'medical','multipurpose' ),/*Categories*/
11
- 'template_url' => array(
12
- 'content' => 'full-url-path/content.json',/*Full URL Path to content.json*/
13
- 'options' => 'full-url-path/master/options.json',/*Full URL Path to options.json*/
14
- 'widgets' => 'full-url-path/widgets.json'/*Full URL Path to widgets.json*/
15
- ),
16
- 'screenshot_url' => 'full-url-path/screenshot.png?ver=1.6',/*Full URL Path to demo screenshot image*/
17
- 'demo_url' => 'https://www.demo.cosmoswp.com/',/*Full URL Path to Live Demo*/
18
- /* Recommended plugin for this demo */
19
- 'plugins' => array(
20
- array(
21
- 'name' => __( 'Gutentor', 'text-domain' ),
22
- 'slug' => 'gutentor',
23
- ),
24
- )
25
- ),
26
- 'demo2' =>array(
27
- 'title' => __( 'Title 2', 'text-domain' ),/*Title*/
28
- 'is_pro' => false,/*Is Premium*/
29
- 'type' => 'gutentor',/*Optional eg gutentor, elementor or other page builders or type*/
30
- 'author' => __( 'Gutentor', 'text-domain' ),/*Author Name*/
31
- 'keywords' => array( 'about-block', 'about 3' ),/*Search keyword*/
32
- 'categories' => array( 'contact','multipurpose','woocommerce' ),/*Categories*/
33
- 'template_url' => array(
34
- 'content' => 'full-url-path/content.json',/*Full URL Path to content.json*/
35
- 'options' => 'full-url-path/master/options.json',/*Full URL Path to options.json*/
36
- 'widgets' => 'full-url-path/widgets.json'/*Full URL Path to widgets.json*/
37
- ),
38
- 'screenshot_url' => 'full-url-path/screenshot.png?ver=1.6',/*Full URL Path to demo screenshot image*/
39
- 'demo_url' => 'https://www.demo.cosmoswp.com/',/*Full URL Path to Live Demo*/
40
- /* Recommended plugin for this demo */
41
- 'plugins' => array(
42
- array(
43
- 'name' => __( 'Gutentor', 'text-domain' ),
44
- 'slug' => 'gutentor',
45
- ),
46
- array(
47
- 'name' => __( 'Contact Form 7', 'text-domain' ),
48
- 'slug' => 'contact-form-7',
49
- 'main_file' => 'wp-contact-form-7.php',/*the main plugin file of contact form 7 is different from plugin slug */
50
- ),
51
- )
52
- ),
53
- 'demo3' =>array(
54
- 'title' => __( 'Title 1', 'text-domain' ),/*Title*/
55
- 'is_pro' => true,/*Is Premium : Support Premium Version*/
56
- 'pro_url' => 'https://www.cosmoswp.com/pricing/',/*Premium version/Pricing Url*/
57
- 'type' => 'gutentor',/*Optional eg gutentor, elementor or other page builders or type*/
58
- 'author' => __( 'Gutentor', 'text-domain' ),/*Author Name*/
59
- 'keywords' => array( 'woocommerce', 'shop' ),/*Search keyword*/
60
- 'categories' => array( 'woocommerce','multipurpose' ),/*Categories*/
61
- 'template_url' => array(/* Optional for premium theme, you can add your own logic by hook*/
62
- 'content' => 'full-url-path/content.json',/*Full URL Path to content.json*/
63
- 'options' => 'full-url-path/master/options.json',/*Full URL Path to options.json*/
64
- 'widgets' => 'full-url-path/widgets.json'/*Full URL Path to widgets.json*/
65
- ),
66
- 'screenshot_url' => 'full-url-path/screenshot.png?ver=1.6',/*Full URL Path to demo screenshot image*/
67
- 'demo_url' => 'https://www.demo.cosmoswp.com/',/*Full URL Path to Live Demo*/
68
- /* Recommended plugin for this demo */
69
- 'plugins' => array(
70
- array(
71
- 'name' => __( 'Gutentor', 'text-domain' ),
72
- 'slug' => 'gutentor',
73
- ),
74
- )
75
- ),
76
- /*and so on ............................*/
77
- );
78
- return $demo_lists;
79
- }
80
- add_filter('advanced_import_demo_lists','prefix_demo_import_lists');
 
 
 
1
+ <?php
2
+ function prefix_demo_import_lists() {
3
+ $demo_lists = array(
4
+ 'demo1' => array(
5
+ 'title' => __( 'Title 1', 'text-domain' ), /*Title*/
6
+ 'is_pro' => false, /*Is Premium*/
7
+ 'type' => 'gutentor', /*Optional eg gutentor, elementor or other page builders or type*/
8
+ 'author' => __( 'Gutentor', 'text-domain' ), /*Author Name*/
9
+ 'keywords' => array( 'medical', 'multipurpose' ), /*Search keyword*/
10
+ 'categories' => array( 'medical', 'multipurpose' ), /*Categories*/
11
+ 'template_url' => array(
12
+ 'content' => 'full-url-path/content.json', /*Full URL Path to content.json*/
13
+ 'options' => 'full-url-path/master/options.json', /*Full URL Path to options.json*/
14
+ 'widgets' => 'full-url-path/widgets.json', /*Full URL Path to widgets.json*/
15
+ ),
16
+ 'screenshot_url' => 'full-url-path/screenshot.png?ver=1.6', /*Full URL Path to demo screenshot image*/
17
+ 'demo_url' => 'https://www.demo.cosmoswp.com/', /*
18
+ Full URL Path to Live Demo*/
19
+ /* Recommended plugin for this demo */
20
+ 'plugins' => array(
21
+ array(
22
+ 'name' => __( 'Gutentor', 'text-domain' ),
23
+ 'slug' => 'gutentor',
24
+ ),
25
+ ),
26
+ ),
27
+ 'demo2' => array(
28
+ 'title' => __( 'Title 2', 'text-domain' ), /*Title*/
29
+ 'is_pro' => false, /*Is Premium*/
30
+ 'type' => 'gutentor', /*Optional eg gutentor, elementor or other page builders or type*/
31
+ 'author' => __( 'Gutentor', 'text-domain' ), /*Author Name*/
32
+ 'keywords' => array( 'about-block', 'about 3' ), /*Search keyword*/
33
+ 'categories' => array( 'contact', 'multipurpose', 'woocommerce' ), /*Categories*/
34
+ 'template_url' => array(
35
+ 'content' => 'full-url-path/content.json', /*Full URL Path to content.json*/
36
+ 'options' => 'full-url-path/master/options.json', /*Full URL Path to options.json*/
37
+ 'widgets' => 'full-url-path/widgets.json', /*Full URL Path to widgets.json*/
38
+ ),
39
+ 'screenshot_url' => 'full-url-path/screenshot.png?ver=1.6', /*Full URL Path to demo screenshot image*/
40
+ 'demo_url' => 'https://www.demo.cosmoswp.com/', /*
41
+ Full URL Path to Live Demo*/
42
+ /* Recommended plugin for this demo */
43
+ 'plugins' => array(
44
+ array(
45
+ 'name' => __( 'Gutentor', 'text-domain' ),
46
+ 'slug' => 'gutentor',
47
+ ),
48
+ array(
49
+ 'name' => __( 'Contact Form 7', 'text-domain' ),
50
+ 'slug' => 'contact-form-7',
51
+ 'main_file' => 'wp-contact-form-7.php', /*the main plugin file of contact form 7 is different from plugin slug */
52
+ ),
53
+ ),
54
+ ),
55
+ 'demo3' => array(
56
+ 'title' => __( 'Title 1', 'text-domain' ), /*Title*/
57
+ 'is_pro' => true, /*Is Premium : Support Premium Version*/
58
+ 'pro_url' => 'https://www.cosmoswp.com/pricing/', /*Premium version/Pricing Url*/
59
+ 'type' => 'gutentor', /*Optional eg gutentor, elementor or other page builders or type*/
60
+ 'author' => __( 'Gutentor', 'text-domain' ), /*Author Name*/
61
+ 'keywords' => array( 'woocommerce', 'shop' ), /*Search keyword*/
62
+ 'categories' => array( 'woocommerce', 'multipurpose' ), /*Categories*/
63
+ 'template_url' => array(/* Optional for premium theme, you can add your own logic by hook*/
64
+ 'content' => 'full-url-path/content.json', /*Full URL Path to content.json*/
65
+ 'options' => 'full-url-path/master/options.json', /*Full URL Path to options.json*/
66
+ 'widgets' => 'full-url-path/widgets.json', /*Full URL Path to widgets.json*/
67
+ ),
68
+ 'screenshot_url' => 'full-url-path/screenshot.png?ver=1.6', /*Full URL Path to demo screenshot image*/
69
+ 'demo_url' => 'https://www.demo.cosmoswp.com/', /*
70
+ Full URL Path to Live Demo*/
71
+ /* Recommended plugin for this demo */
72
+ 'plugins' => array(
73
+ array(
74
+ 'name' => __( 'Gutentor', 'text-domain' ),
75
+ 'slug' => 'gutentor',
76
+ ),
77
+ ),
78
+ ),
79
+ /*and so on ............................*/
80
+ );
81
+ return $demo_lists;
82
+ }
83
+ add_filter( 'advanced_import_demo_lists', 'prefix_demo_import_lists' );
includes/class-advanced-import-deactivator.php CHANGED
@@ -33,4 +33,4 @@ class Advanced_Import_Deactivator {
33
 
34
  }
35
 
36
- }
33
 
34
  }
35
 
36
+ }
includes/class-advanced-import-i18n.php CHANGED
@@ -41,4 +41,4 @@ class Advanced_Import_i18n {
41
  );
42
 
43
  }
44
- }
41
  );
42
 
43
  }
44
+ }
includes/class-advanced-import-loader.php CHANGED
@@ -57,11 +57,11 @@ class Advanced_Import_Loader {
57
  * Add a new action to the collection to be registered with WordPress.
58
  *
59
  * @since 1.0.0
60
- * @param string $hook The name of the WordPress action that is being registered.
61
- * @param object $component A reference to the instance of the object on which the action is defined.
62
- * @param string $callback The name of the function definition on the $component.
63
- * @param int $priority Optional. The priority at which the function should be fired. Default is 10.
64
- * @param int $accepted_args Optional. The number of arguments that should be passed to the $callback. Default is 1.
65
  */
66
  public function add_action( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) {
67
  $this->actions = $this->add( $this->actions, $hook, $component, $callback, $priority, $accepted_args );
@@ -71,11 +71,11 @@ class Advanced_Import_Loader {
71
  * Add a new filter to the collection to be registered with WordPress.
72
  *
73
  * @since 1.0.0
74
- * @param string $hook The name of the WordPress filter that is being registered.
75
- * @param object $component A reference to the instance of the object on which the filter is defined.
76
- * @param string $callback The name of the function definition on the $component.
77
- * @param int $priority Optional. The priority at which the function should be fired. Default is 10.
78
- * @param int $accepted_args Optional. The number of arguments that should be passed to the $callback. Default is 1
79
  */
80
  public function add_filter( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) {
81
  $this->filters = $this->add( $this->filters, $hook, $component, $callback, $priority, $accepted_args );
@@ -87,12 +87,12 @@ class Advanced_Import_Loader {
87
  *
88
  * @since 1.0.0
89
  * @access private
90
- * @param array $hooks The collection of hooks that is being registered (that is, actions or filters).
91
- * @param string $hook The name of the WordPress filter that is being registered.
92
- * @param object $component A reference to the instance of the object on which the filter is defined.
93
- * @param string $callback The name of the function definition on the $component.
94
- * @param int $priority The priority at which the function should be fired.
95
- * @param int $accepted_args The number of arguments that should be passed to the $callback.
96
  * @return array The collection of actions and filters registered with WordPress.
97
  */
98
  private function add( $hooks, $hook, $component, $callback, $priority, $accepted_args ) {
@@ -102,7 +102,7 @@ class Advanced_Import_Loader {
102
  'component' => $component,
103
  'callback' => $callback,
104
  'priority' => $priority,
105
- 'accepted_args' => $accepted_args
106
  );
107
 
108
  return $hooks;
@@ -126,4 +126,4 @@ class Advanced_Import_Loader {
126
 
127
  }
128
 
129
- }
57
  * Add a new action to the collection to be registered with WordPress.
58
  *
59
  * @since 1.0.0
60
+ * @param string $hook The name of the WordPress action that is being registered.
61
+ * @param object $component A reference to the instance of the object on which the action is defined.
62
+ * @param string $callback The name of the function definition on the $component.
63
+ * @param int $priority Optional. The priority at which the function should be fired. Default is 10.
64
+ * @param int $accepted_args Optional. The number of arguments that should be passed to the $callback. Default is 1.
65
  */
66
  public function add_action( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) {
67
  $this->actions = $this->add( $this->actions, $hook, $component, $callback, $priority, $accepted_args );
71
  * Add a new filter to the collection to be registered with WordPress.
72
  *
73
  * @since 1.0.0
74
+ * @param string $hook The name of the WordPress filter that is being registered.
75
+ * @param object $component A reference to the instance of the object on which the filter is defined.
76
+ * @param string $callback The name of the function definition on the $component.
77
+ * @param int $priority Optional. The priority at which the function should be fired. Default is 10.
78
+ * @param int $accepted_args Optional. The number of arguments that should be passed to the $callback. Default is 1
79
  */
80
  public function add_filter( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) {
81
  $this->filters = $this->add( $this->filters, $hook, $component, $callback, $priority, $accepted_args );
87
  *
88
  * @since 1.0.0
89
  * @access private
90
+ * @param array $hooks The collection of hooks that is being registered (that is, actions or filters).
91
+ * @param string $hook The name of the WordPress filter that is being registered.
92
+ * @param object $component A reference to the instance of the object on which the filter is defined.
93
+ * @param string $callback The name of the function definition on the $component.
94
+ * @param int $priority The priority at which the function should be fired.
95
+ * @param int $accepted_args The number of arguments that should be passed to the $callback.
96
  * @return array The collection of actions and filters registered with WordPress.
97
  */
98
  private function add( $hooks, $hook, $component, $callback, $priority, $accepted_args ) {
102
  'component' => $component,
103
  'callback' => $callback,
104
  'priority' => $priority,
105
+ 'accepted_args' => $accepted_args,
106
  );
107
 
108
  return $hooks;
126
 
127
  }
128
 
129
+ }
includes/class-advanced-import.php CHANGED
@@ -98,7 +98,7 @@ class Advanced_Import {
98
 
99
  // Only run these methods if they haven't been ran previously
100
  if ( null === $instance ) {
101
- $instance = new Advanced_Import;
102
 
103
  $instance->setup_globals();
104
  $instance->load_dependencies();
@@ -128,18 +128,18 @@ class Advanced_Import {
128
  */
129
  private function setup_globals() {
130
 
131
- $this->version = defined('ADVANCED_IMPORT_VERSION')?ADVANCED_IMPORT_VERSION:'1.0.0';
132
  $this->plugin_name = ADVANCED_IMPORT_PLUGIN_NAME;
133
 
134
- //The array of actions and filters registered with this plugins.
135
  $this->actions = array();
136
  $this->filters = array();
137
 
138
  // Misc
139
- $this->domain = 'advanced-import'; // Unique identifier for retrieving translated strings
140
- $this->errors = new WP_Error(); // errors
141
  }
142
-
143
  /**
144
  * Load the required dependencies for this plugin.
145
  *
@@ -188,13 +188,12 @@ class Advanced_Import {
188
  require_once ADVANCED_IMPORT_PATH . 'admin/class-reset.php';
189
 
190
  /*Theme Specific Setting*/
191
- require_once ADVANCED_IMPORT_PATH . 'includes/class-theme-template-library-base.php';
192
-
193
- require_once ADVANCED_IMPORT_PATH . 'includes/theme-template-library/cosmoswp.php'; /*cosmoswp*/
194
- require_once ADVANCED_IMPORT_PATH . 'includes/theme-template-library/acmethemes.php'; /*acmethemes*/
195
 
 
 
196
 
197
- $this->loader = new Advanced_Import_Loader();
198
 
199
  }
200
 
@@ -246,9 +245,9 @@ class Advanced_Import {
246
  $this->loader->add_action( 'wp_ajax_complete_screen', $this->admin, 'complete_screen' );
247
 
248
  /*Reset Process*/
249
- $this->loader->add_action( 'wp_loaded', advanced_import_reset_wordpress(), 'hide_reset_notice',-1 );
250
  $this->loader->add_action( 'admin_init', advanced_import_reset_wordpress(), 'reset_wizard_actions', -1 );
251
- $this->loader->add_action( 'admin_notices', advanced_import_reset_wordpress(), 'reset_wizard_notice' ,-1);
252
 
253
  }
254
 
@@ -291,4 +290,4 @@ class Advanced_Import {
291
  public function get_version() {
292
  return $this->version;
293
  }
294
- }
98
 
99
  // Only run these methods if they haven't been ran previously
100
  if ( null === $instance ) {
101
+ $instance = new Advanced_Import();
102
 
103
  $instance->setup_globals();
104
  $instance->load_dependencies();
128
  */
129
  private function setup_globals() {
130
 
131
+ $this->version = defined( 'ADVANCED_IMPORT_VERSION' ) ? ADVANCED_IMPORT_VERSION : '1.0.0';
132
  $this->plugin_name = ADVANCED_IMPORT_PLUGIN_NAME;
133
 
134
+ // The array of actions and filters registered with this plugins.
135
  $this->actions = array();
136
  $this->filters = array();
137
 
138
  // Misc
139
+ $this->domain = 'advanced-import'; // Unique identifier for retrieving translated strings
140
+ $this->errors = new WP_Error(); // errors
141
  }
142
+
143
  /**
144
  * Load the required dependencies for this plugin.
145
  *
188
  require_once ADVANCED_IMPORT_PATH . 'admin/class-reset.php';
189
 
190
  /*Theme Specific Setting*/
191
+ require_once ADVANCED_IMPORT_PATH . 'includes/class-theme-template-library-base.php';
 
 
 
192
 
193
+ require_once ADVANCED_IMPORT_PATH . 'includes/theme-template-library/cosmoswp.php'; /*cosmoswp*/
194
+ require_once ADVANCED_IMPORT_PATH . 'includes/theme-template-library/acmethemes.php'; /*acmethemes*/
195
 
196
+ $this->loader = new Advanced_Import_Loader();
197
 
198
  }
199
 
245
  $this->loader->add_action( 'wp_ajax_complete_screen', $this->admin, 'complete_screen' );
246
 
247
  /*Reset Process*/
248
+ $this->loader->add_action( 'wp_loaded', advanced_import_reset_wordpress(), 'hide_reset_notice', -1 );
249
  $this->loader->add_action( 'admin_init', advanced_import_reset_wordpress(), 'reset_wizard_actions', -1 );
250
+ $this->loader->add_action( 'admin_notices', advanced_import_reset_wordpress(), 'reset_wizard_notice', -1 );
251
 
252
  }
253
 
290
  public function get_version() {
291
  return $this->version;
292
  }
293
+ }
includes/class-theme-template-library-base.php CHANGED
@@ -1,32 +1,32 @@
1
- <?php
2
-
3
- if ( ! defined( 'ABSPATH' ) ) {
4
- exit;
5
- }
6
-
7
- if ( ! class_exists( 'Advanced_Import_Theme_Template_Library_Base' ) ) {
8
-
9
- /**
10
- * Base Class For CosmosWP for common functions
11
- * @package CosmosWP
12
- * @subpackage CosmosWP Template Library
13
- * @since 1.0.0
14
- *
15
- */
16
- class Advanced_Import_Theme_Template_Library_Base{
17
-
18
- /**
19
- * Run Block
20
- *
21
- * @access public
22
- * @since 1.0.0
23
- * @return void
24
- */
25
- public function run(){
26
-
27
- if( method_exists( $this, 'add_template_library' ) ){
28
- add_filter( 'advanced_import_demo_lists', array( $this, 'add_template_library' ) );
29
- }
30
- }
31
- }
32
- }
1
+ <?php
2
+
3
+ if ( ! defined( 'ABSPATH' ) ) {
4
+ exit;
5
+ }
6
+
7
+ if ( ! class_exists( 'Advanced_Import_Theme_Template_Library_Base' ) ) {
8
+
9
+ /**
10
+ * Base Class For CosmosWP for common functions
11
+ *
12
+ * @package Advanced Import
13
+ * @subpackage Advanced Import Template Library
14
+ * @since 1.0.0
15
+ */
16
+ class Advanced_Import_Theme_Template_Library_Base {
17
+
18
+ /**
19
+ * Run Block
20
+ *
21
+ * @access public
22
+ * @since 1.0.0
23
+ * @return void
24
+ */
25
+ public function run() {
26
+
27
+ if ( method_exists( $this, 'add_template_library' ) ) {
28
+ add_filter( 'advanced_import_demo_lists', array( $this, 'add_template_library' ) );
29
+ }
30
+ }
31
+ }
32
+ }
includes/functions-advanced-import.php CHANGED
@@ -1,29 +1,29 @@
1
- <?php
2
- function advanced_import_allowed_html ( $input ) {
3
- $allowed_html = wp_kses_allowed_html('post');
4
- $output = wp_kses($input, $allowed_html );
5
- return $output;
6
- }
7
-
8
- function advanced_import_current_url () {
9
- global $pagenow;
10
- $current_url = $pagenow == 'tools.php'?admin_url( 'tools.php?page=advanced-import-tool'):admin_url( 'themes.php?page=advanced-import');
11
- return $current_url;
12
- }
13
-
14
- function advanced_import_get_current_theme_author(){
15
- $current_theme = wp_get_theme();
16
- return $current_theme->get('Author');
17
- }
18
- function advanced_import_get_current_theme_slug(){
19
- $current_theme = wp_get_theme();
20
- return $current_theme->stylesheet;
21
- }
22
- function advanced_import_get_theme_screenshot(){
23
- $current_theme = wp_get_theme();
24
- return $current_theme->get_screenshot();
25
- }
26
- function advanced_import_get_theme_name(){
27
- $current_theme = wp_get_theme();
28
- return $current_theme->get('Name');
29
- }
1
+ <?php
2
+ function advanced_import_allowed_html( $input ) {
3
+ $allowed_html = wp_kses_allowed_html( 'post' );
4
+ $output = wp_kses( $input, $allowed_html );
5
+ return $output;
6
+ }
7
+
8
+ function advanced_import_current_url() {
9
+ global $pagenow;
10
+ $current_url = $pagenow == 'tools.php' ? admin_url( 'tools.php?page=advanced-import-tool' ) : admin_url( 'themes.php?page=advanced-import' );
11
+ return $current_url;
12
+ }
13
+
14
+ function advanced_import_get_current_theme_author() {
15
+ $current_theme = wp_get_theme();
16
+ return $current_theme->get( 'Author' );
17
+ }
18
+ function advanced_import_get_current_theme_slug() {
19
+ $current_theme = wp_get_theme();
20
+ return $current_theme->stylesheet;
21
+ }
22
+ function advanced_import_get_theme_screenshot() {
23
+ $current_theme = wp_get_theme();
24
+ return $current_theme->get_screenshot();
25
+ }
26
+ function advanced_import_get_theme_name() {
27
+ $current_theme = wp_get_theme();
28
+ return $current_theme->get( 'Name' );
29
+ }
includes/index.php CHANGED
@@ -1 +1 @@
1
- <?php // Silence is golden
1
+ <?php // Silence is golden
includes/theme-template-library/acmethemes.php CHANGED
@@ -1,103 +1,108 @@
1
- <?php
2
- if ( ! defined( 'ABSPATH' ) ) {
3
- exit;
4
- }
5
-
6
- if ( ! class_exists( 'Advanced_Import_Theme_Acmethemes' ) ) {
7
-
8
- /**
9
- * Functions related to About Block
10
- * @package Acmethemes
11
- * @since 1.0.5
12
- *
13
- */
14
-
15
- class Advanced_Import_Theme_Acmethemes extends Advanced_Import_Theme_Template_Library_Base{
16
-
17
-
18
- /**
19
- * Theme author
20
- * This class is created for acmethemes theme
21
- * Check for author
22
- *
23
- * @since 1.0.5
24
- * @access private
25
- */
26
- private $theme_author = 'acmethemes';
27
-
28
- /**
29
- * Gets an instance of this object.
30
- * Prevents duplicate instances which avoid artefacts and improves performance.
31
- *
32
- * @static
33
- * @access public
34
- * @since 1.0.5
35
- * @return object
36
- */
37
- public static function get_instance() {
38
-
39
- // Store the instance locally to avoid private static replication
40
- static $instance = null;
41
-
42
- // Only run these methods if they haven't been ran previously
43
- if ( null === $instance ) {
44
- $instance = new self();
45
- }
46
-
47
- // Always return the instance
48
- return $instance;
49
-
50
- }
51
-
52
- /**
53
- * Load block library
54
- * Used for blog template loading
55
- *
56
- * @since 1.0.5
57
- * @package Acmethemes
58
- * @author Acmethemes <info@acmethemes.com>
59
- *
60
- * @param$current_demo_list array
61
- * @return array
62
- */
63
- public function add_template_library( $current_demo_list ){
64
- /*common check*/
65
- if( advanced_import_get_current_theme_author() != $this->theme_author){
66
- return $current_demo_list;
67
- }
68
-
69
- /*for acmethemes only
70
- check if acmethemes template library function exist*/
71
- if( function_exists('run_acme_demo_setup') ){
72
- return $current_demo_list;
73
- }
74
-
75
- /*finally fetch template library data from live*/
76
- $templates_list = array();
77
-
78
- $url = 'https://www.acmeit.org/wp-json/acmethemes-demo-api/v1/fetch_templates/?theme-slug='.esc_attr(advanced_import_get_current_theme_slug());
79
- $body_args = [
80
- /*API version*/
81
- 'api_version' => wp_get_theme()['Version'],
82
- /*lang*/
83
- 'site_lang' => get_bloginfo( 'language' ),
84
- ];
85
- $raw_json = wp_safe_remote_get( $url, [
86
- 'timeout' => 100,
87
- 'body' => $body_args,
88
- ] );
89
-
90
- if ( ! is_wp_error( $raw_json ) ) {
91
- $demo_server = json_decode( wp_remote_retrieve_body( $raw_json ), true );
92
- if (json_last_error() === JSON_ERROR_NONE) {
93
- if( is_array( $demo_server )){
94
- $templates_list = $demo_server;
95
- }
96
- }
97
- }
98
-
99
- return array_merge( $current_demo_list, $templates_list );
100
- }
101
- }
102
- }
103
- Advanced_Import_Theme_Acmethemes::get_instance()->run();
 
 
 
 
 
1
+ <?php
2
+ if ( ! defined( 'ABSPATH' ) ) {
3
+ exit;
4
+ }
5
+
6
+ if ( ! class_exists( 'Advanced_Import_Theme_Acmethemes' ) ) {
7
+
8
+ /**
9
+ * Functions related to About Block
10
+ *
11
+ * @package Advanced Import
12
+ * @subpackage Advanced_Import_Theme_Acmethemes
13
+ * @since 1.0.5
14
+ */
15
+
16
+ class Advanced_Import_Theme_Acmethemes extends Advanced_Import_Theme_Template_Library_Base {
17
+
18
+
19
+ /**
20
+ * Theme author
21
+ * This class is created for acmethemes theme
22
+ * Check for author
23
+ *
24
+ * @since 1.0.5
25
+ * @access private
26
+ */
27
+ private $theme_author = 'acmethemes';
28
+
29
+ /**
30
+ * Gets an instance of this object.
31
+ * Prevents duplicate instances which avoid artefacts and improves performance.
32
+ *
33
+ * @static
34
+ * @access public
35
+ * @since 1.0.5
36
+ * @return object
37
+ */
38
+ public static function get_instance() {
39
+
40
+ // Store the instance locally to avoid private static replication
41
+ static $instance = null;
42
+
43
+ // Only run these methods if they haven't been ran previously
44
+ if ( null === $instance ) {
45
+ $instance = new self();
46
+ }
47
+
48
+ // Always return the instance
49
+ return $instance;
50
+
51
+ }
52
+
53
+ /**
54
+ * Load block library
55
+ * Used for blog template loading
56
+ *
57
+ * @since 1.0.5
58
+ * @package Acmethemes
59
+ * @author Acmethemes <info@acmethemes.com>
60
+ *
61
+ * @param$current_demo_list array
62
+ * @return array
63
+ */
64
+ public function add_template_library( $current_demo_list ) {
65
+ /*common check*/
66
+ if ( advanced_import_get_current_theme_author() != $this->theme_author ) {
67
+ return $current_demo_list;
68
+ }
69
+
70
+ /*
71
+ for acmethemes only
72
+ check if acmethemes template library function exist*/
73
+ if ( function_exists( 'run_acme_demo_setup' ) ) {
74
+ return $current_demo_list;
75
+ }
76
+
77
+ /*finally fetch template library data from live*/
78
+ $templates_list = array();
79
+
80
+ $url = 'https://www.acmeit.org/wp-json/acmethemes-demo-api/v1/fetch_templates/?theme-slug=' . esc_attr( advanced_import_get_current_theme_slug() );
81
+ $body_args = array(
82
+ /*API version*/
83
+ 'api_version' => wp_get_theme()['Version'],
84
+ /*lang*/
85
+ 'site_lang' => get_bloginfo( 'language' ),
86
+ );
87
+ $raw_json = wp_safe_remote_get(
88
+ $url,
89
+ array(
90
+ 'timeout' => 100,
91
+ 'body' => $body_args,
92
+ )
93
+ );
94
+
95
+ if ( ! is_wp_error( $raw_json ) ) {
96
+ $demo_server = json_decode( wp_remote_retrieve_body( $raw_json ), true );
97
+ if ( json_last_error() === JSON_ERROR_NONE ) {
98
+ if ( is_array( $demo_server ) ) {
99
+ $templates_list = $demo_server;
100
+ }
101
+ }
102
+ }
103
+
104
+ return array_merge( $current_demo_list, $templates_list );
105
+ }
106
+ }
107
+ }
108
+ Advanced_Import_Theme_Acmethemes::get_instance()->run();
includes/theme-template-library/cosmoswp.php CHANGED
@@ -1,114 +1,119 @@
1
- <?php
2
- if ( ! defined( 'ABSPATH' ) ) {
3
- exit;
4
- }
5
-
6
- if ( ! class_exists( 'Advanced_Import_Theme_CosmosWP' ) ) {
7
-
8
- /**
9
- * Functions related to About Block
10
- * @package CosmosWP
11
- * @since 1.0.5
12
- *
13
- */
14
-
15
- class Advanced_Import_Theme_CosmosWP extends Advanced_Import_Theme_Template_Library_Base{
16
-
17
- /**
18
- * Theme name
19
- * This class is crated for cosmoswp theme
20
- *
21
- * @since 1.0.5
22
- * @access private
23
- */
24
- private $theme = 'cosmoswp';
25
-
26
- /**
27
- * Theme author
28
- * This class is crated for cosmoswp theme
29
- * Double check for author
30
- *
31
- * @since 1.0.5
32
- * @access private
33
- */
34
- private $theme_author = 'cosmoswp';
35
-
36
- /**
37
- * Gets an instance of this object.
38
- * Prevents duplicate instances which avoid artefacts and improves performance.
39
- *
40
- * @static
41
- * @access public
42
- * @since 1.0.5
43
- * @return object
44
- */
45
- public static function get_instance() {
46
-
47
- // Store the instance locally to avoid private static replication
48
- static $instance = null;
49
-
50
- // Only run these methods if they haven't been ran previously
51
- if ( null === $instance ) {
52
- $instance = new self();
53
- }
54
-
55
- // Always return the instance
56
- return $instance;
57
-
58
- }
59
-
60
- /**
61
- * Load block library
62
- * Used for blog template loading
63
- *
64
- * @since 1.0.5
65
- * @package CosmosWP
66
- * @author CosmosWP <info@cosmoswp.com>
67
- *
68
- * @param$current_demo_list array
69
- * @return array
70
- */
71
- public function add_template_library( $current_demo_list ){
72
- /*common check*/
73
- if( strtolower( advanced_import_get_current_theme_author() ) != $this->theme_author){
74
- return $current_demo_list;
75
- }
76
- if( advanced_import_get_current_theme_slug() != $this->theme){
77
- return $current_demo_list;
78
- }
79
-
80
- /*for cosmoswp only
81
- check if cosmoswp template library function exist*/
82
- if( function_exists('run_cosmoswp_template_library') ){
83
- return $current_demo_list;
84
- }
85
-
86
- /*finally fetch template library data from live*/
87
- $templates_list = array();
88
-
89
- $url = 'https://www.demo.cosmoswp.com/wp-json/cosmoswp-demo-api/v1/fetch_templates/';
90
- $body_args = [
91
- /*API version*/
92
- 'api_version' => wp_get_theme()['Version'],
93
- /*lang*/
94
- 'site_lang' => get_bloginfo( 'language' ),
95
- ];
96
- $raw_json = wp_safe_remote_get( $url, [
97
- 'timeout' => 100,
98
- 'body' => $body_args,
99
- ] );
100
-
101
- if ( ! is_wp_error( $raw_json ) ) {
102
- $demo_server = json_decode( wp_remote_retrieve_body( $raw_json ), true );
103
- if (json_last_error() === JSON_ERROR_NONE) {
104
- if( is_array( $demo_server )){
105
- $templates_list = $demo_server;
106
- }
107
- }
108
- }
109
-
110
- return array_merge( $current_demo_list, $templates_list );
111
- }
112
- }
113
- }
114
- Advanced_Import_Theme_CosmosWP::get_instance()->run();
 
 
 
 
 
1
+ <?php
2
+ if ( ! defined( 'ABSPATH' ) ) {
3
+ exit;
4
+ }
5
+
6
+ if ( ! class_exists( 'Advanced_Import_Theme_CosmosWP' ) ) {
7
+
8
+ /**
9
+ * Functions related to About Block
10
+ *
11
+ * @package Advanced Import
12
+ * @subpackage Advanced_Import_Theme_CosmosWP
13
+ * @since 1.0.5
14
+ */
15
+
16
+ class Advanced_Import_Theme_CosmosWP extends Advanced_Import_Theme_Template_Library_Base {
17
+
18
+ /**
19
+ * Theme name
20
+ * This class is crated for cosmoswp theme
21
+ *
22
+ * @since 1.0.5
23
+ * @access private
24
+ */
25
+ private $theme = 'cosmoswp';
26
+
27
+ /**
28
+ * Theme author
29
+ * This class is crated for cosmoswp theme
30
+ * Double check for author
31
+ *
32
+ * @since 1.0.5
33
+ * @access private
34
+ */
35
+ private $theme_author = 'cosmoswp';
36
+
37
+ /**
38
+ * Gets an instance of this object.
39
+ * Prevents duplicate instances which avoid artefacts and improves performance.
40
+ *
41
+ * @static
42
+ * @access public
43
+ * @since 1.0.5
44
+ * @return object
45
+ */
46
+ public static function get_instance() {
47
+
48
+ // Store the instance locally to avoid private static replication
49
+ static $instance = null;
50
+
51
+ // Only run these methods if they haven't been ran previously
52
+ if ( null === $instance ) {
53
+ $instance = new self();
54
+ }
55
+
56
+ // Always return the instance
57
+ return $instance;
58
+
59
+ }
60
+
61
+ /**
62
+ * Load block library
63
+ * Used for blog template loading
64
+ *
65
+ * @since 1.0.5
66
+ * @package CosmosWP
67
+ * @author CosmosWP <info@cosmoswp.com>
68
+ *
69
+ * @param$current_demo_list array
70
+ * @return array
71
+ */
72
+ public function add_template_library( $current_demo_list ) {
73
+ /*common check*/
74
+ if ( strtolower( advanced_import_get_current_theme_author() ) != $this->theme_author ) {
75
+ return $current_demo_list;
76
+ }
77
+ if ( advanced_import_get_current_theme_slug() != $this->theme ) {
78
+ return $current_demo_list;
79
+ }
80
+
81
+ /*
82
+ For cosmoswp only.
83
+ check if cosmoswp template library function exist*/
84
+ if ( function_exists( 'run_cosmoswp_template_library' ) ) {
85
+ return $current_demo_list;
86
+ }
87
+
88
+ /*finally fetch template library data from live*/
89
+ $templates_list = array();
90
+
91
+ $url = 'https://www.demo.cosmoswp.com/wp-json/cosmoswp-demo-api/v1/fetch_templates/';
92
+ $body_args = array(
93
+ /*API version*/
94
+ 'api_version' => wp_get_theme()['Version'],
95
+ /*lang*/
96
+ 'site_lang' => get_bloginfo( 'language' ),
97
+ );
98
+ $raw_json = wp_safe_remote_get(
99
+ $url,
100
+ array(
101
+ 'timeout' => 100,
102
+ 'body' => $body_args,
103
+ )
104
+ );
105
+
106
+ if ( ! is_wp_error( $raw_json ) ) {
107
+ $demo_server = json_decode( wp_remote_retrieve_body( $raw_json ), true );
108
+ if ( json_last_error() === JSON_ERROR_NONE ) {
109
+ if ( is_array( $demo_server ) ) {
110
+ $templates_list = $demo_server;
111
+ }
112
+ }
113
+ }
114
+
115
+ return array_merge( $current_demo_list, $templates_list );
116
+ }
117
+ }
118
+ }
119
+ Advanced_Import_Theme_CosmosWP::get_instance()->run();
index.php CHANGED
@@ -1 +1 @@
1
- <?php // Silence is golden
1
+ <?php // Silence is golden
readme.txt CHANGED
@@ -4,9 +4,9 @@ Contributors: addonspress, codersantosh, acmeit
4
  Donate link: https://addonspress.com/
5
  Tags: import, advanced import, demo import, theme import, widget import, customizer import
6
  Requires at least: 4.5
7
- Tested up to: 5.4.2
8
  Requires PHP: 5.6.20
9
- Stable tag: 1.2.4
10
  License: GPLv2 or later
11
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
12
 
@@ -22,6 +22,8 @@ It is designed specially for theme developer who wants to provide demo data to t
22
 
23
  While you use Demo Import features of themes, Advanced Import may fetches screenshots, images and templates(demo) JSON files from a respective theme site. This helps you to import your site with a single click. You must accept the terms and privacy of the themes you are using to use Demo Import ( Starter Sites Template Library ) Features.
24
 
 
 
25
  Some listed features of Advanced Import are given below :
26
 
27
  * Import demo starter sites very easily
@@ -223,6 +225,13 @@ Advanced Import is generally one-time use plugin, it is meant to be used for Dem
223
 
224
  == Changelog ==
225
 
 
 
 
 
 
 
 
226
  = 1.2.4 - 2020-06-22 =
227
  * Updated : API Url
228
 
4
  Donate link: https://addonspress.com/
5
  Tags: import, advanced import, demo import, theme import, widget import, customizer import
6
  Requires at least: 4.5
7
+ Tested up to: 5.5.3
8
  Requires PHP: 5.6.20
9
+ Stable tag: 1.2.5
10
  License: GPLv2 or later
11
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
12
 
22
 
23
  While you use Demo Import features of themes, Advanced Import may fetches screenshots, images and templates(demo) JSON files from a respective theme site. This helps you to import your site with a single click. You must accept the terms and privacy of the themes you are using to use Demo Import ( Starter Sites Template Library ) Features.
24
 
25
+ View [Advanced Import](https://www.addonspress.com/wordpress-plugins/advanced-import/) Details and Documentation
26
+
27
  Some listed features of Advanced Import are given below :
28
 
29
  * Import demo starter sites very easily
225
 
226
  == Changelog ==
227
 
228
+ = 1.2.5 - 2020-11-11 =
229
+ * Updated : Hook attributes, control each demo import.
230
+ Now developer can provide user template kit separately. View Example : [CosmosWP Template kits](https://www.cosmoswp.com/template-kits/)
231
+ * Updated : PHPCS
232
+ * Updated : Some minor design
233
+ * Updated : Minor changes
234
+
235
  = 1.2.4 - 2020-06-22 =
236
  * Updated : API Url
237
 
uninstall.php CHANGED
@@ -22,4 +22,4 @@
22
  // If uninstall not called from WordPress, then exit.
23
  if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
24
  exit;
25
- }
22
  // If uninstall not called from WordPress, then exit.
23
  if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
24
  exit;
25
+ }