forked from richtabor/MerlinWP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
merlin.php
executable file
·1838 lines (1479 loc) · 54.1 KB
/
merlin.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* Merlin WP
* Better WordPress Theme Onboarding
*
* The following code is a derivative work from the
* Envato WordPress Theme Setup Wizard by David Baker.
*
* @package Merlin WP
* @version @@pkg.version
* @link https://merlinwp.com/
* @author Richard Tabor, from ThemeBeans.com
* @copyright Copyright (c) 2017, Merlin WP of Inventionn LLC
* @license Licensed GPLv3 for open source use
*/
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Merlin.
*/
class Merlin {
/**
* Current theme.
*
* @var object WP_Theme
*/
protected $theme;
/**
* Current step.
*
* @var string
*/
protected $step = '';
/**
* Steps.
*
* @var array
*/
protected $steps = array();
/**
* TGMPA instance.
*
* @var object
*/
protected $tgmpa;
/**
* Importer.
*
* @var array
*/
protected $importer;
/**
* WP Hook class.
*
* @var Merlin_Hooks
*/
protected $hooks;
/**
* Holds the verified import files.
*
* @var array
*/
public $import_files;
/**
* The base import file name.
*
* @var string
*/
public $import_file_base_name;
/**
* Helper.
*
* @var array
*/
protected $helper;
/**
* Updater.
*
* @var array
*/
protected $updater;
/**
* The text string array.
*
* @var array $strings
*/
protected $strings = null;
/**
* The location where Merlin is located within the theme.
*
* @var string $directory
*/
protected $directory = null;
/**
* Top level admin page.
*
* @var string $merlin_url
*/
protected $merlin_url = null;
/**
* The URL for the "Learn more about child themes" link.
*
* @var string $child_action_btn_url
*/
protected $child_action_btn_url = null;
/**
* Turn on help mode to get some help.
*
* @var string $help_mode
*/
protected $help_mode = false;
/**
* Turn on dev mode if you're developing.
*
* @var string $dev_mode
*/
protected $dev_mode = false;
/**
* The URL for the "Learn more about child themes" link.
*
* @var string $branding
*/
protected $branding = false;
/**
* Setup plugin version.
*
* @access private
* @since 1.0
* @return void
*/
private function version() {
if ( ! defined( 'MERLIN_VERSION' ) ) {
define( 'MERLIN_VERSION', '0.1.3' );
}
}
/**
* Class Constructor.
*
* @param array $config Package-specific configuration args.
* @param array $strings Text for the different elements.
*/
function __construct( $config = array(), $strings = array() ) {
$this->version();
$config = wp_parse_args( $config, array(
'directory' => '',
'merlin_url' => 'merlin',
'child_action_btn_url' => '',
'help_mode' => '',
'dev_mode' => '',
'branding' => '',
) );
// Set config arguments.
$this->directory = $config['directory'];
$this->merlin_url = $config['merlin_url'];
$this->child_action_btn_url = $config['child_action_btn_url'];
$this->help_mode = $config['help_mode'];
$this->dev_mode = $config['dev_mode'];
$this->branding = $config['branding'];
// Strings passed in from the config file.
$this->strings = $strings;
// Retrieve a WP_Theme object.
$this->theme = wp_get_theme();
$this->slug = strtolower( preg_replace( '#[^a-zA-Z]#', '', $this->theme->get( 'Name' ) ) );
// Is Dev Mode turned on?
if ( true !== $this->dev_mode ) {
// Has this theme been setup yet?
$already_setup = get_option( 'merlin_' . $this->slug . '_completed' );
// Return if Merlin has already completed it's setup.
if ( $already_setup ) {
return;
}
}
// Get TGMPA.
if ( class_exists( 'TGM_Plugin_Activation' ) ) {
$this->tgmpa = isset( $GLOBALS['tgmpa'] ) ? $GLOBALS['tgmpa'] : TGM_Plugin_Activation::get_instance();
}
add_action( 'admin_init', array( $this, 'required_classes' ) );
add_action( 'admin_init', array( $this, 'redirect' ), 30 );
add_action( 'after_switch_theme', array( $this, 'switch_theme' ) );
add_action( 'admin_init', array( $this, 'steps' ), 30, 0 );
add_action( 'admin_menu', array( $this, 'add_admin_menu' ) );
add_action( 'admin_init', array( $this, 'admin_page' ), 30, 0 );
add_action( 'admin_footer', array( $this, 'svg_sprite' ) );
add_filter( 'tgmpa_load', array( $this, 'load_tgmpa' ), 10, 1 );
add_action( 'wp_ajax_merlin_content', array( $this, '_ajax_content' ), 10, 0 );
add_action( 'wp_ajax_merlin_plugins', array( $this, '_ajax_plugins' ), 10, 0 );
add_action( 'wp_ajax_merlin_child_theme', array( $this, 'generate_child' ), 10, 0 );
add_action( 'wp_ajax_merlin_activate_license', array( $this, 'activate_license' ), 10, 0 );
add_action( 'wp_ajax_merlin_update_selected_import_data_info', array( $this, 'update_selected_import_data_info' ), 10, 0 );
add_action( 'wp_ajax_merlin_import_finished', array( $this, 'import_finished' ), 10, 0 );
add_action( 'upgrader_post_install', array( $this, 'post_install_check' ), 10, 2 );
add_filter( 'pt-importer/new_ajax_request_response_data', array( $this, 'pt_importer_new_ajax_request_response_data' ) );
add_action( 'import_end', array( $this, 'after_content_import_setup' ) );
add_action( 'import_start', array( $this, 'before_content_import_setup' ) );
add_action( 'admin_init', array( $this, 'register_import_files' ) );
}
/**
* Require necessary classes.
*/
function required_classes() {
if ( ! class_exists( '\WP_Importer' ) ) {
require ABSPATH . '/wp-admin/includes/class-wp-importer.php';
}
require_once get_parent_theme_file_path( $this->directory . '/merlin/includes/class-merlin-downloader.php' );
$logger = new ProteusThemes\WPContentImporter2\WPImporterLogger();
$this->importer = new ProteusThemes\WPContentImporter2\Importer( array( 'fetch_attachments' => true ), $logger );
require_once get_parent_theme_file_path( $this->directory . '/merlin/includes/class-merlin-widget-importer.php' );
if ( ! class_exists( 'WP_Customize_Setting' ) ) {
require_once ABSPATH . 'wp-includes/class-wp-customize-setting.php';
}
require_once get_parent_theme_file_path( $this->directory . '/merlin/includes/class-merlin-customizer-option.php' );
require_once get_parent_theme_file_path( $this->directory . '/merlin/includes/class-merlin-customizer-importer.php' );
require_once get_parent_theme_file_path( $this->directory . '/merlin/includes/class-merlin-hooks.php' );
$this->hooks = new Merlin_Hooks();
if ( class_exists( 'EDD_Theme_Updater_Admin' ) ) {
$this->updater = new EDD_Theme_Updater_Admin();
}
if ( true === $this->help_mode ) {
require get_parent_theme_file_path( $this->directory . '/merlin/includes/class-merlin-helper.php' );
$this->helper = new Merlin_Helper();
}
}
/**
* Set redirection transient.
*/
public function switch_theme() {
if ( ! is_child_theme() ) {
set_transient( $this->theme->template . '_merlin_redirect', 1 );
}
}
/**
* Redirection transient.
*/
public function redirect() {
if ( ! get_transient( $this->theme->template . '_merlin_redirect' ) ) {
return;
}
delete_transient( $this->theme->template . '_merlin_redirect' );
wp_safe_redirect( admin_url( 'themes.php?page= ' . $this->merlin_url ) );
exit;
}
/**
* Conditionally load TGMPA
*
* @param string $status User's manage capabilities.
*/
public function load_tgmpa( $status ) {
return is_admin() || current_user_can( 'install_themes' );
}
/**
* Determine if the user already has theme content installed.
* This can happen if swapping from a previous theme or updated the current theme.
* We change the UI a bit when updating / swapping to a new theme.
*
* @access public
*/
protected function is_possible_upgrade() {
return false;
}
/**
* After a theme update, we clear the slug_merlin_completed option.
* This prompts the user to visit the update page again.
*
* @param string $return To end or not.
* @param string $theme The current theme.
*/
protected function post_install_check( $return, $theme ) {
if ( is_wp_error( $return ) ) {
return $return;
}
if ( $theme !== $this->theme->stylesheet ) {
return $return;
}
update_option( 'merlin_' . $this->slug . '_completed', false );
return $return;
}
/**
* Add the admin menu item, under Appearance.
*/
public function add_admin_menu() {
// Strings passed in from the config file.
$strings = $this->strings;
$this->hook_suffix = add_theme_page(
esc_html( $strings['admin-menu'] ), esc_html( $strings['admin-menu'] ), 'manage_options', $this->merlin_url, array( $this, 'admin_page' )
);
}
/**
* Add the admin page.
*/
public function admin_page() {
// Strings passed in from the config file.
$strings = $this->strings;
// Do not proceed, if we're not on the right page.
if ( empty( $_GET['page'] ) || $this->merlin_url !== $_GET['page'] ) {
return;
}
if ( ob_get_length() ) {
ob_end_clean();
}
$this->step = isset( $_GET['step'] ) ? sanitize_key( $_GET['step'] ) : current( array_keys( $this->steps ) );
// Use minified libraries if dev mode is turned on.
$suffix = ( ( true == $this->dev_mode ) ) ? '' : '.min';
// Enqueue styles.
wp_enqueue_style( 'merlin', get_parent_theme_file_uri( $this->directory . '/merlin/assets/css/merlin' . $suffix . '.css' ), array( 'wp-admin' ), MERLIN_VERSION );
// Enqueue javascript.
wp_enqueue_script( 'merlin', get_parent_theme_file_uri( $this->directory . '/merlin/assets/js/merlin' . $suffix . '.js' ), array( 'jquery-core' ), MERLIN_VERSION );
$texts = array(
'something_went_wrong' => esc_html__( 'Something went wrong. Please refresh the page and try again!', '@@textdomain' ),
);
// Localize the javascript.
if ( class_exists( 'TGM_Plugin_Activation' ) ) {
// Check first if TMGPA is included.
wp_localize_script( 'merlin', 'merlin_params', array(
'tgm_plugin_nonce' => array(
'update' => wp_create_nonce( 'tgmpa-update' ),
'install' => wp_create_nonce( 'tgmpa-install' ),
),
'tgm_bulk_url' => $this->tgmpa->get_tgmpa_url(),
'ajaxurl' => admin_url( 'admin-ajax.php' ),
'wpnonce' => wp_create_nonce( 'merlin_nonce' ),
'texts' => $texts,
) );
} else {
// If TMGPA is not included.
wp_localize_script( 'merlin', 'merlin_params', array(
'ajaxurl' => admin_url( 'admin-ajax.php' ),
'wpnonce' => wp_create_nonce( 'merlin_nonce' ),
'texts' => $texts,
) );
}
ob_start();
/**
* Start the actual page content.
*/
$this->header(); ?>
<div class="merlin__wrapper">
<div class="merlin__content merlin__content--<?php echo esc_attr( strtolower( $this->steps[ $this->step ]['name'] ) ); ?>">
<?php
// Content Handlers.
$show_content = true;
if ( ! empty( $_REQUEST['save_step'] ) && isset( $this->steps[ $this->step ]['handler'] ) ) {
$show_content = call_user_func( $this->steps[ $this->step ]['handler'] );
}
if ( $show_content ) {
$this->body();
}
?>
<?php $this->step_output(); ?>
</div>
<?php echo sprintf( '<a class="return-to-dashboard" href="%s">%s</a>', esc_url( admin_url( '/' ) ), esc_html( $strings['return-to-dashboard'] ) ); ?>
</div>
<?php $this->footer(); ?>
<?php
exit;
}
/**
* Output the header.
*/
protected function header() {
// Strings passed in from the config file.
$strings = $this->strings;
// Get the current step.
$current_step = strtolower( $this->steps[ $this->step ]['name'] );
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes(); ?>>
<head>
<meta name="viewport" content="width=device-width"/>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<?php printf( esc_html( $strings['title%s%s%s%s'] ), '<ti', 'tle>', esc_html( $this->theme->name ), '</title>' ); ?>
<?php do_action( 'admin_print_styles' ); ?>
<?php do_action( 'admin_print_scripts' ); ?>
<?php do_action( 'admin_head' ); ?>
</head>
<body class="merlin__body merlin__body--<?php echo esc_attr( $current_step ); ?>">
<?php
}
/**
* Output the content for the current step.
*/
protected function body() {
isset( $this->steps[ $this->step ] ) ? call_user_func( $this->steps[ $this->step ]['view'] ) : false;
}
/**
* Output the footer.
*/
protected function footer() {
// Is help_mode set in the merlin-config.php file?
if ( true === $this->help_mode ) :
$current_step = strtolower( $this->steps[ $this->step ]['name'] );
$this->helper->helper_wizard( $current_step );
endif;
if ( true === $this->help_mode || true === $this->branding ) :
?>
<a class="merlin--icon" target="_blank" href="https://merlinwp.com">
<?php echo wp_kses( $this->svg( array( 'icon' => 'merlin' ) ), $this->svg_allowed_html() ); ?>
</a>
<?php endif; ?>
</body>
<?php do_action( 'admin_footer' ); ?>
<?php do_action( 'admin_print_footer_scripts' ); ?>
</html>
<?php
}
/**
* SVG
*/
public function svg_sprite() {
// Define SVG sprite file.
$svg = get_parent_theme_file_path( $this->directory . '/merlin/assets/images/sprite.svg' );
// If it exists, include it.
if ( file_exists( $svg ) ) {
require_once apply_filters( 'merlin_svg_sprite', $svg );
}
}
/**
* Return SVG markup.
*
* @param array $args {
* Parameters needed to display an SVG.
*
* @type string $icon Required SVG icon filename.
* @type string $title Optional SVG title.
* @type string $desc Optional SVG description.
* }
* @return string SVG markup.
*/
public function svg( $args = array() ) {
// Make sure $args are an array.
if ( empty( $args ) ) {
return __( 'Please define default parameters in the form of an array.', '@@textdomain' );
}
// Define an icon.
if ( false === array_key_exists( 'icon', $args ) ) {
return __( 'Please define an SVG icon filename.', '@@textdomain' );
}
// Set defaults.
$defaults = array(
'icon' => '',
'title' => '',
'desc' => '',
'aria_hidden' => true, // Hide from screen readers.
'fallback' => false,
);
// Parse args.
$args = wp_parse_args( $args, $defaults );
// Set aria hidden.
$aria_hidden = '';
if ( true === $args['aria_hidden'] ) {
$aria_hidden = ' aria-hidden="true"';
}
// Set ARIA.
$aria_labelledby = '';
if ( $args['title'] && $args['desc'] ) {
$aria_labelledby = ' aria-labelledby="title desc"';
}
// Begin SVG markup.
$svg = '<svg class="icon icon--' . esc_attr( $args['icon'] ) . '"' . $aria_hidden . $aria_labelledby . ' role="img">';
// If there is a title, display it.
if ( $args['title'] ) {
$svg .= '<title>' . esc_html( $args['title'] ) . '</title>';
}
// If there is a description, display it.
if ( $args['desc'] ) {
$svg .= '<desc>' . esc_html( $args['desc'] ) . '</desc>';
}
$svg .= '<use xlink:href="#icon-' . esc_html( $args['icon'] ) . '"></use>';
// Add some markup to use as a fallback for browsers that do not support SVGs.
if ( $args['fallback'] ) {
$svg .= '<span class="svg-fallback icon--' . esc_attr( $args['icon'] ) . '"></span>';
}
$svg .= '</svg>';
return $svg;
}
/**
* Adds data attributes to the body, based on Customizer entries.
*/
public function svg_allowed_html() {
$array = array(
'svg' => array(
'class' => array(),
'aria-hidden' => array(),
'role' => array(),
),
'use' => array(
'xlink:href' => array(),
),
);
return apply_filters( 'merlin_svg_allowed_html', $array );
}
/**
* Loading merlin-spinner.
*/
public function loading_spinner() {
// Define the spinner file.
$spinner = $this->directory . '/merlin/assets/images/spinner';
// Retrieve the spinner.
get_template_part( apply_filters( 'merlin_loading_spinner', $spinner ) );
}
/**
* Setup steps.
*/
function steps() {
$this->steps = array(
'welcome' => array(
'name' => esc_html__( 'Welcome', '@@textdomain' ),
'view' => array( $this, 'welcome' ),
'handler' => array( $this, 'welcome_handler' ),
),
);
$this->steps['child'] = array(
'name' => esc_html__( 'Child', '@@textdomain' ),
'view' => array( $this, 'child' ),
);
// Show the plugin importer, only if TGMPA is included.
if ( class_exists( 'TGM_Plugin_Activation' ) ) {
$this->steps['plugins'] = array(
'name' => esc_html__( 'Plugins', '@@textdomain' ),
'view' => array( $this, 'plugins' ),
);
}
// Show the content importer, only if there's demo content added.
if ( ! empty( $this->import_files ) ) {
$this->steps['content'] = array(
'name' => esc_html__( 'Content', '@@textdomain' ),
'view' => array( $this, 'content' ),
);
}
$this->steps['ready'] = array(
'name' => esc_html__( 'Ready', '@@textdomain' ),
'view' => array( $this, 'ready' ),
);
$this->steps = apply_filters( $this->theme->template . '_merlin_steps', $this->steps );
}
/**
* Output the steps
*/
protected function step_output() {
$ouput_steps = $this->steps;
$array_keys = array_keys( $this->steps );
$current_step = array_search( $this->step, $array_keys, true );
array_shift( $ouput_steps );
?>
<ol class="dots">
<?php
foreach ( $ouput_steps as $step_key => $step ) :
$class_attr = '';
$show_link = false;
if ( $step_key === $this->step ) {
$class_attr = 'active';
} elseif ( $current_step > array_search( $step_key, $array_keys, true ) ) {
$class_attr = 'done';
$show_link = true;
}
?>
<li class="<?php echo esc_attr( $class_attr ); ?>">
<a href="<?php echo esc_url( $this->step_link( $step_key ) ); ?>" title="<?php echo esc_attr( $step['name'] ); ?>"></a>
</li>
<?php endforeach; ?>
</ol>
<?php
}
/**
* Get the step URL.
*
* @param string $step Name of the step, appended to the URL.
*/
protected function step_link( $step ) {
return add_query_arg( 'step', $step );
}
/**
* Get the next step link.
*/
protected function step_next_link() {
$keys = array_keys( $this->steps );
$step = array_search( $this->step, $keys, true ) + 1;
return add_query_arg( 'step', $keys[ $step ] );
}
/**
* Introduction step
*/
protected function welcome() {
// Has this theme been setup yet? Compare this to the option set when you get to the last panel.
$already_setup = get_option( 'merlin_' . $this->slug . '_completed' );
// Theme Name.
$theme = ucfirst( $this->theme );
// Remove "Child" from the current theme name, if it's installed.
$theme = str_replace( ' Child','', $theme );
// Strings passed in from the config file.
$strings = $this->strings;
// Text strings.
$header = ! $already_setup ? $strings['welcome-header%s'] : $strings['welcome-header-success%s'];
$paragraph = ! $already_setup ? $strings['welcome%s'] : $strings['welcome-success%s'];
$start = $strings['btn-start'];
$no = $strings['btn-no'];
?>
<div class="merlin__content--transition">
<?php echo wp_kses( $this->svg( array( 'icon' => 'welcome' ) ), $this->svg_allowed_html() ); ?>
<h1><?php echo esc_html( sprintf( $header, $theme ) ); ?></h1>
<p><?php echo esc_html( sprintf( $paragraph, $theme ) ); ?></p>
</div>
<footer class="merlin__content__footer">
<a href="<?php echo esc_url( wp_get_referer() && ! strpos( wp_get_referer(), 'update.php' ) ? wp_get_referer() : admin_url( '/' ) ); ?>" class="merlin__button merlin__button--skip"><?php echo esc_html( $no ); ?></a>
<a href="<?php echo esc_url( $this->step_next_link() ); ?>" class="merlin__button merlin__button--next merlin__button--proceed merlin__button--colorchange"><?php echo esc_html( $start ); ?></a>
<?php wp_nonce_field( 'merlin' ); ?>
</footer>
<?php
}
/**
* Handles save button from welcome page.
* This is to perform tasks when the setup wizard has already been run.
*/
protected function welcome_handler() {
check_admin_referer( 'merlin' );
return false;
}
/**
* Child theme generator.
*/
protected function child() {
// Variables.
$is_child_theme = is_child_theme();
$child_theme_option = get_option( 'merlin_' . $this->slug . '_child' );
$theme = $child_theme_option ? wp_get_theme( $child_theme_option )->name : $this->theme . ' Child';
$action_url = $this->child_action_btn_url;
// Strings passed in from the config file.
$strings = $this->strings;
// Text strings.
$header = ! $is_child_theme ? $strings['child-header'] : $strings['child-header-success'];
$action = $strings['child-action-link'];
$skip = $strings['btn-skip'];
$next = $strings['btn-next'];
$paragraph = ! $is_child_theme ? $strings['child'] : $strings['child-success%s'];
$install = $strings['btn-child-install'];
?>
<div class="merlin__content--transition">
<?php echo wp_kses( $this->svg( array( 'icon' => 'child' ) ), $this->svg_allowed_html() ); ?>
<svg class="icon icon--checkmark" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 52 52">
<circle class="icon--checkmark__circle" cx="26" cy="26" r="25" fill="none"/><path class="icon--checkmark__check" fill="none" d="M14.1 27.2l7.1 7.2 16.7-16.8"/>
</svg>
<h1><?php echo esc_html( $header ); ?></h1>
<p id="child-theme-text"><?php echo esc_html( sprintf( $paragraph, $theme ) ); ?></p>
<a class="merlin__button merlin__button--knockout merlin__button--no-chevron" href="<?php echo esc_url( $action_url ); ?>" target="_blank"><?php echo esc_html( $action ); ?></a>
</div>
<footer class="merlin__content__footer">
<?php if ( ! $is_child_theme ) : ?>
<a href="<?php echo esc_url( $this->step_next_link() ); ?>" class="merlin__button merlin__button--skip merlin__button--proceed"><?php echo esc_html( $skip ); ?></a>
<a href="<?php echo esc_url( $this->step_next_link() ); ?>" class="merlin__button merlin__button--next button-next" data-callback="install_child">
<span class="merlin__button--loading__text"><?php echo esc_html( $install ); ?></span><?php echo $this->loading_spinner(); ?>
</a>
<?php else : ?>
<a href="<?php echo esc_url( $this->step_next_link() ); ?>" class="merlin__button merlin__button--next merlin__button--proceed merlin__button--colorchange"><?php echo esc_html( $next ); ?></a>
<?php endif; ?>
<?php wp_nonce_field( 'merlin' ); ?>
</footer>
<?php
}
/**
* Theme plugins
*/
protected function plugins() {
// Variables.
$url = wp_nonce_url( add_query_arg( array( 'plugins' => 'go' ) ), 'merlin' );
$method = '';
$fields = array_keys( $_POST );
$creds = request_filesystem_credentials( esc_url_raw( $url ), $method, false, false, $fields );
tgmpa_load_bulk_installer();
if ( false === $creds ) {
return true;
}
if ( ! WP_Filesystem( $creds ) ) {
request_filesystem_credentials( esc_url_raw( $url ), $method, true, false, $fields );
return true;
}
// Are there plugins that need installing/activating?
$plugins = $this->get_tgmpa_plugins();
$count = count( $plugins['all'] );
$class = $count ? null : 'no-plugins';
// Strings passed in from the config file.
$strings = $this->strings;
// Text strings.
$header = $count ? $strings['plugins-header'] : $strings['plugins-header-success'];
$paragraph = $count ? $strings['plugins'] : $strings['plugins-success%s'];
$action = $strings['plugins-action-link'];
$skip = $strings['btn-skip'];
$next = $strings['btn-next'];
$install = $strings['btn-plugins-install'];
?>
<div class="merlin__content--transition">
<?php echo wp_kses( $this->svg( array( 'icon' => 'plugins' ) ), $this->svg_allowed_html() ); ?>
<svg class="icon icon--checkmark" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 52 52">
<circle class="icon--checkmark__circle" cx="26" cy="26" r="25" fill="none"/><path class="icon--checkmark__check" fill="none" d="M14.1 27.2l7.1 7.2 16.7-16.8"/>
</svg>
<h1><?php echo esc_html( $header ); ?></h1>
<p><?php echo esc_html( $paragraph ); ?></p>
<?php if ( $count ) { ?>
<a id="merlin__drawer-trigger" class="merlin__button merlin__button--knockout"><span><?php echo esc_html( $action ); ?></span><span class="chevron"></span></a>
<?php } ?>
</div>
<form action="" method="post">
<?php if ( $count ) : ?>
<ul class="merlin__drawer merlin__drawer--install-plugins">
<?php foreach ( $plugins['all'] as $slug => $plugin ) : ?>
<li data-slug="<?php echo esc_attr( $slug ); ?>">
<?php echo esc_html( $plugin['name'] ); ?>
<span>
<?php
$keys = array();
if ( isset( $plugins['install'][ $slug ] ) ) {
$keys[] = esc_html__( 'Install', '@@textdomain' );
}
if ( isset( $plugins['update'][ $slug ] ) ) {
$keys[] = esc_html__( 'Update', '@@textdomain' );
}
if ( isset( $plugins['activate'][ $slug ] ) ) {
$keys[] = esc_html__( 'Activate', '@@textdomain' );
}
echo implode( esc_html__( 'and', '@@textdomain' ) , $keys );
?>
</span>
<div class="spinner"></div>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
<footer class="merlin__content__footer <?php echo esc_attr( $class ); ?>">
<?php if ( $count ) : ?>
<a id="close" href="<?php echo esc_url( $this->step_next_link() ); ?>" class="merlin__button merlin__button--skip merlin__button--closer merlin__button--proceed"><?php echo esc_html( $skip ); ?></a>
<a id="skip" href="<?php echo esc_url( $this->step_next_link() ); ?>" class="merlin__button merlin__button--skip merlin__button--proceed"><?php echo esc_html( $skip ); ?></a>
<a href="<?php echo esc_url( $this->step_next_link() ); ?>" class="merlin__button merlin__button--next button-next" data-callback="install_plugins">
<span class="merlin__button--loading__text"><?php echo esc_html( $install ); ?></span><?php echo $this->loading_spinner(); ?>
</a>
<?php else : ?>
<a href="<?php echo esc_url( $this->step_next_link() ); ?>" class="merlin__button merlin__button--next merlin__button--proceed merlin__button--colorchange"><?php echo esc_html( $next ); ?></a>
<?php endif; ?>
<?php wp_nonce_field( 'merlin' ); ?>
</footer>
</form>
<?php
}
/**
* Page setup
*/
protected function content() {
$import_info = $this->get_import_data_info();
// Strings passed in from the config file.
$strings = $this->strings;
// Text strings.
$header = $strings['import-header'];
$paragraph = $strings['import'];
$action = $strings['import-action-link'];
$skip = $strings['btn-skip'];
$next = $strings['btn-next'];
$import = $strings['btn-import'];
?>
<div class="merlin__content--transition">
<?php echo wp_kses( $this->svg( array( 'icon' => 'content' ) ), $this->svg_allowed_html() ); ?>
<svg class="icon icon--checkmark" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 52 52">
<circle class="icon--checkmark__circle" cx="26" cy="26" r="25" fill="none"/><path class="icon--checkmark__check" fill="none" d="M14.1 27.2l7.1 7.2 16.7-16.8"/>
</svg>
<h1><?php echo esc_html( $header ); ?></h1>
<p><?php echo esc_html( $paragraph ); ?></p>
<?php if ( 1 < count( $this->import_files ) ) : ?>
<p><?php esc_html_e( 'Select which demo data you want to import:', '@@textdomain' ); ?></p>
<select class="js-merlin-demo-import-select">
<?php foreach ( $this->import_files as $index => $import_file ) : ?>
<?php
$img_src = isset( $import_file['import_preview_image_url'] ) ? $import_file['import_preview_image_url'] : '';
$import_notice = isset( $import_file['import_notice'] ) ? $import_file['import_notice'] : '';
$demo_preview_url = isset( $import_file['preview_url'] ) ? $import_file['preview_url'] : '';
?>
<option value="<?php echo esc_attr( $index ); ?>" data-img-src="<?php echo esc_url( $img_src ); ?>" data-notice="<?php echo esc_html( $import_notice ); ?>" data-preview-url="<?php echo esc_url( $demo_preview_url ); ?>"><?php echo esc_html( $import_file['import_file_name'] ); ?></option>
<?php endforeach; ?>
</select>
<?php endif; ?>
<a id="merlin__drawer-trigger" class="merlin__button merlin__button--knockout"><span><?php echo esc_html( $action ); ?></span><span class="chevron"></span></a>
</div>
<form action="" method="post">
<ul class="merlin__drawer merlin__drawer--import-content js-merlin-drawer-import-content">
<?php echo $this->get_import_steps_html( $import_info ); ?>
</ul>
<footer class="merlin__content__footer">