-
Notifications
You must be signed in to change notification settings - Fork 138
/
class-merlin.php
executable file
·2407 lines (1946 loc) · 73.1 KB
/
class-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 Rich Tabor, from ThemeBeans.com & the team at ProteusThemes.com
* @copyright Copyright (c) 2018, 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 base path where Merlin is located.
*
* @var array $strings
*/
protected $base_path = null;
/**
* The base url where Merlin is located.
*
* @var array $strings
*/
protected $base_url = null;
/**
* The location where Merlin is located within the theme or plugin.
*
* @var string $directory
*/
protected $directory = null;
/**
* Top level admin page.
*
* @var string $merlin_url
*/
protected $merlin_url = null;
/**
* The wp-admin parent page slug for the admin menu item.
*
* @var string $parent_slug
*/
protected $parent_slug = null;
/**
* The capability required for this menu to be displayed to the user.
*
* @var string $capability
*/
protected $capability = null;
/**
* The URL for the "Learn more about child themes" link.
*
* @var string $child_action_btn_url
*/
protected $child_action_btn_url = null;
/**
* The flag, to mark, if the theme license step should be enabled.
*
* @var boolean $license_step_enabled
*/
protected $license_step_enabled = false;
/**
* The URL for the "Where can I find the license key?" link.
*
* @var string $theme_license_help_url
*/
protected $theme_license_help_url = null;
/**
* Remove the "Skip" button, if required.
*
* @var string $license_required
*/
protected $license_required = null;
/**
* The item name of the EDD product (this theme).
*
* @var string $edd_item_name
*/
protected $edd_item_name = null;
/**
* The theme slug of the EDD product (this theme).
*
* @var string $edd_theme_slug
*/
protected $edd_theme_slug = null;
/**
* The remote_api_url of the EDD shop.
*
* @var string $edd_remote_api_url
*/
protected $edd_remote_api_url = null;
/**
* Turn on dev mode if you're developing.
*
* @var string $dev_mode
*/
protected $dev_mode = false;
/**
* Ignore.
*
* @var string $ignore
*/
public $ignore = null;
/**
* The object with logging functionality.
*
* @var Logger $logger
*/
public $logger;
/**
* Setup plugin version.
*
* @access private
* @since 1.0
* @return void
*/
private function version() {
if ( ! defined( 'MERLIN_VERSION' ) ) {
define( 'MERLIN_VERSION', '@@pkg.version' );
}
}
/**
* 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(
'base_path' => get_parent_theme_file_path(),
'base_url' => get_parent_theme_file_uri(),
'directory' => 'merlin',
'merlin_url' => 'merlin',
'parent_slug' => 'themes.php',
'capability' => 'manage_options',
'child_action_btn_url' => '',
'dev_mode' => '',
'ready_big_button_url' => home_url( '/' ),
)
);
// Set config arguments.
$this->base_path = $config['base_path'];
$this->base_url = $config['base_url'];
$this->directory = $config['directory'];
$this->merlin_url = $config['merlin_url'];
$this->parent_slug = $config['parent_slug'];
$this->capability = $config['capability'];
$this->child_action_btn_url = $config['child_action_btn_url'];
$this->license_step_enabled = $config['license_step'];
$this->theme_license_help_url = $config['license_help_url'];
$this->license_required = $config['license_required'];
$this->edd_item_name = $config['edd_item_name'];
$this->edd_theme_slug = $config['edd_theme_slug'];
$this->edd_remote_api_url = $config['edd_remote_api_url'];
$this->dev_mode = $config['dev_mode'];
$this->ready_big_button_url = $config['ready_big_button_url'];
// 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->template ) );
// Set the ignore option.
$this->ignore = $this->slug . '_ignore';
// 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 the logger object, so it can be used in the whole class.
require_once trailingslashit( $this->base_path ) . $this->directory . '/includes/class-merlin-logger.php';
$this->logger = Merlin_Logger::get_instance();
// 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_init', array( $this, 'ignore' ), 5 );
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_get_total_content_import_items', array( $this, '_ajax_get_total_content_import_items' ), 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, '_ajax_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_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 trailingslashit( $this->base_path ) . $this->directory . '/includes/class-merlin-downloader.php';
$this->importer = new ProteusThemes\WPContentImporter2\Importer( array( 'fetch_attachments' => true ), $this->logger );
require_once trailingslashit( $this->base_path ) . $this->directory . '/includes/class-merlin-widget-importer.php';
if ( ! class_exists( 'WP_Customize_Setting' ) ) {
require_once ABSPATH . 'wp-includes/class-wp-customize-setting.php';
}
require_once trailingslashit( $this->base_path ) . $this->directory . '/includes/class-merlin-customizer-option.php';
require_once trailingslashit( $this->base_path ) . $this->directory . '/includes/class-merlin-customizer-importer.php';
require_once trailingslashit( $this->base_path ) . $this->directory . '/includes/class-merlin-redux-importer.php';
require_once trailingslashit( $this->base_path ) . $this->directory . '/includes/class-merlin-hooks.php';
$this->hooks = new Merlin_Hooks();
if ( class_exists( 'EDD_Theme_Updater_Admin' ) ) {
$this->updater = new EDD_Theme_Updater_Admin();
}
}
/**
* Set redirection transient on theme switch.
*/
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( menu_page_url( $this->merlin_url ) );
exit;
}
/**
* Give the user the ability to ignore Merlin WP.
*/
public function ignore() {
// Bail out if not on correct page.
if ( ! isset( $_GET['_wpnonce'] ) || ( ! wp_verify_nonce( $_GET['_wpnonce'], 'merlinwp-ignore-nounce' ) || ! is_admin() || ! isset( $_GET[ $this->ignore ] ) || ! current_user_can( 'manage_options' ) ) ) {
return;
}
update_option( 'merlin_' . $this->slug . '_completed', 'ignored' );
}
/**
* 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;
}
/**
* 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_submenu_page(
esc_html( $this->parent_slug ), esc_html( $strings['admin-menu'] ), esc_html( $strings['admin-menu'] ), sanitize_key( $this->capability ), sanitize_key( $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', trailingslashit( $this->base_url ) . $this->directory . '/assets/css/merlin' . $suffix . '.css', array( 'wp-admin' ), MERLIN_VERSION );
// Enqueue javascript.
wp_enqueue_script( 'merlin', trailingslashit( $this->base_url ) . $this->directory . '/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'] ) ); ?>
<?php $ignore_url = wp_nonce_url( admin_url( '?' . $this->ignore . '=true' ), 'merlinwp-ignore-nounce' ); ?>
<?php echo sprintf( '<a class="return-to-dashboard ignore" href="%s">%s</a>', esc_url( $ignore_url ), esc_html( $strings['ignore'] ) ); ?>
</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() {
?>
</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 = trailingslashit( $this->base_path ) . $this->directory . '/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;
}
/**
* Allowed HTML for sprites.
*/
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 . '/assets/images/spinner';
// Retrieve the spinner.
get_template_part( apply_filters( 'merlin_loading_spinner', $spinner ) );
}
/**
* Allowed HTML for the loading spinner.
*/
public function loading_spinner_allowed_html() {
$array = array(
'span' => array(
'class' => array(),
),
'cite' => array(
'class' => array(),
),
);
return apply_filters( 'merlin_loading_spinner_allowed_html', $array );
}
/**
* Setup steps.
*/
public 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' ),
);
if ( $this->license_step_enabled ) {
$this->steps['license'] = array(
'name' => esc_html__( 'License', '@@textdomain' ),
'view' => array( $this, 'license' ),
);
}
// 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
$this->logger->debug( __( 'The welcome step has been displayed', '@@textdomain' ) );
}
/**
* 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;
}
/**
* Theme EDD license step.
*/
protected function license() {
$is_theme_registered = $this->is_theme_registered();
$action_url = $this->theme_license_help_url;
$required = $this->license_required;
$is_theme_registered_class = ( $is_theme_registered ) ? ' is-registered' : null;
// 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 = ! $is_theme_registered ? $strings['license-header%s'] : $strings['license-header-success%s'];
$action = $strings['license-tooltip'];
$label = $strings['license-label'];
$skip = $strings['btn-license-skip'];
$next = $strings['btn-next'];
$paragraph = ! $is_theme_registered ? $strings['license%s'] : $strings['license-success%s'];
$install = $strings['btn-license-activate'];
?>
<div class="merlin__content--transition">
<?php echo wp_kses( $this->svg( array( 'icon' => 'license' ) ), $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( sprintf( $header, $theme ) ); ?></h1>
<p id="license-text"><?php echo esc_html( sprintf( $paragraph, $theme ) ); ?></p>
<?php if ( ! $is_theme_registered ) : ?>
<div class="merlin__content--license-key">
<label for="license-key"><?php echo esc_html( $label ); ?></label>
<div class="merlin__content--license-key-wrapper">
<input type="text" id="license-key" class="js-license-key" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false">
<?php if ( ! empty( $action_url ) ) : ?>
<a href="<?php echo esc_url( $action_url ); ?>" alt="<?php echo esc_attr( $action ); ?>" target="_blank">
<span class="hint--top" aria-label="<?php echo esc_attr( $action ); ?>">
<?php echo wp_kses( $this->svg( array( 'icon' => 'help' ) ), $this->svg_allowed_html() ); ?>
</span>
</a>
<?php endif ?>
</div>
</div>
<?php endif; ?>
</div>
<footer class="merlin__content__footer <?php echo esc_attr( $is_theme_registered_class ); ?>">
<?php if ( ! $is_theme_registered ) : ?>
<?php if ( ! $required ) : ?>
<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>
<?php endif ?>
<a href="<?php echo esc_url( $this->step_next_link() ); ?>" class="merlin__button merlin__button--next button-next js-merlin-license-activate-button" data-callback="activate_license">
<span class="merlin__button--loading__text"><?php echo esc_html( $install ); ?></span>
<?php echo wp_kses( $this->loading_spinner(), $this->loading_spinner_allowed_html() ); ?>
</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
$this->logger->debug( __( 'The license activation step has been displayed', '@@textdomain' ) );
}
/**
* Check, if the theme is currently registered.
*
* @return boolean
*/
private function is_theme_registered() {
$is_registered = get_option( $this->edd_theme_slug . '_license_key_status', false ) === 'valid';
return apply_filters( 'merlin_is_theme_registered', $is_registered );
}
/**
* 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 merlin__button--external" href="<?php echo esc_url( $action_url ); ?>" target="_blank"><?php echo esc_html( $action ); ?></a>
</div>
<footer class="merlin__content__footer">