-
Notifications
You must be signed in to change notification settings - Fork 66
/
Copy pathenvato_setup.php
3008 lines (2658 loc) · 108 KB
/
envato_setup.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
/**
* Envato Theme Setup Wizard Class
*
* Takes new users through some basic steps to setup their ThemeForest theme.
*
* @author dtbaker
* @author vburlak
* @package envato_wizard
* @version 1.3.0
*
*
* 1.2.0 - added custom_logo
* 1.2.1 - ignore post revisioins
* 1.2.2 - elementor widget data replace on import
* 1.2.3 - auto export of content.
* 1.2.4 - fix category menu links
* 1.2.5 - post meta un json decode
* 1.2.6 - post meta un json decode
* 1.2.7 - elementor generate css on import
* 1.2.8 - backwards compat with old meta format
* 1.2.9 - theme setup auth
* 1.3.0 - ob_start fix
*
* Based off the WooThemes installer.
*
*
*
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! class_exists( 'Envato_Theme_Setup_Wizard' ) ) {
/**
* Envato_Theme_Setup_Wizard class
*/
class Envato_Theme_Setup_Wizard {
/**
* The class version number.
*
* @since 1.1.1
* @access private
*
* @var string
*/
protected $version = '1.3.0';
/** @var string Current theme name, used as namespace in actions. */
protected $theme_name = '';
/** @var string Theme author username, used in check for oauth. */
protected $envato_username = '';
/** @var string Full url to server-script.php (available from https://gist.github.com/dtbaker ) */
protected $oauth_script = '';
/** @var string Current Step */
protected $step = '';
/** @var array Steps for the setup wizard */
protected $steps = array();
/**
* Relative plugin path
*
* @since 1.1.2
*
* @var string
*/
protected $plugin_path = '';
/**
* Relative plugin url for this plugin folder, used when enquing scripts
*
* @since 1.1.2
*
* @var string
*/
protected $plugin_url = '';
/**
* The slug name to refer to this menu
*
* @since 1.1.1
*
* @var string
*/
protected $page_slug;
/**
* TGMPA instance storage
*
* @var object
*/
protected $tgmpa_instance;
/**
* TGMPA Menu slug
*
* @var string
*/
protected $tgmpa_menu_slug = 'tgmpa-install-plugins';
/**
* TGMPA Menu url
*
* @var string
*/
protected $tgmpa_url = 'themes.php?page=tgmpa-install-plugins';
/**
* The slug name for the parent menu
*
* @since 1.1.2
*
* @var string
*/
protected $page_parent;
/**
* Complete URL to Setup Wizard
*
* @since 1.1.2
*
* @var string
*/
protected $page_url;
/**
* @since 1.1.8
*
*/
public $site_styles = array();
/**
* @since 1.3.1
*
*/
public $default_theme_style;
/**
* Holds the current instance of the theme manager
*
* @since 1.1.3
* @var Envato_Theme_Setup_Wizard
*/
private static $instance = null;
/**
* @since 1.1.3
*
* @return Envato_Theme_Setup_Wizard
*/
public static function get_instance() {
if ( ! self::$instance ) {
self::$instance = new self;
}
return self::$instance;
}
/**
* A dummy constructor to prevent this class from being loaded more than once.
*
* @see Envato_Theme_Setup_Wizard::instance()
*
* @since 1.1.1
* @access private
*/
public function __construct() {
$this->init_globals();
$this->init_actions();
}
/**
* Get the default style. Can be overriden by theme init scripts.
*
* @see Envato_Theme_Setup_Wizard::instance()
*
* @since 1.1.7
* @access public
*/
public function get_default_theme_style() {
if( $this->default_theme_style ){
return $this->default_theme_style;
}elseif( $this->site_styles && count($this->site_styles) > 0 ){
foreach ( $this->site_styles as $style_name => $style_data ) {
return $style_name;
}
}else{
return false;
}
}
/**
* Get the default style. Can be overriden by theme init scripts.
*
* @see Envato_Theme_Setup_Wizard::instance()
*
* @since 1.1.9
* @access public
*/
public function get_header_logo_width() {
return '200px';
}
/**
* Get the default style. Can be overriden by theme init scripts.
*
* @see Envato_Theme_Setup_Wizard::instance()
*
* @since 1.1.9
* @access public
*/
public function get_logo_image() {
$logo_image_id = get_theme_mod( 'custom_logo' );
if ( $logo_image_id ) {
$logo_image_object = wp_get_attachment_image_src( $logo_image_id, 'full' );
$image_url = $logo_image_object[0];
} else {
$image_url = get_theme_mod( 'logo_header_image', get_template_directory_uri() . '/images/' . get_theme_mod( 'dtbwp_site_color', $this->get_default_theme_style() ) . '/logo.png' );
}
return apply_filters( 'envato_setup_logo_image', $image_url );
}
/**
* Setup the class globals.
*
* @since 1.1.1
* @access public
*/
public function init_globals() {
$current_theme = wp_get_theme();
$this->theme_name = apply_filters( 'theme_setup_wizard_theme_name', strtolower( preg_replace( '#[^a-zA-Z]#', '', $current_theme->get( 'Name' ) ) ) );
$this->theme_slug = apply_filters( 'theme_setup_wizard_theme_slug', strtolower( preg_replace( '#[^a-zA-Z]#', '-', $current_theme->get( 'Name' ) ) ) );
$this->envato_username = apply_filters( $this->theme_name . '_theme_setup_wizard_username', 'dtbaker' );
$this->oauth_script = apply_filters( $this->theme_name . '_theme_setup_wizard_oauth_script', 'http://dtbaker.net/files/envato/wptoken/server-script.php' );
$this->page_slug = apply_filters( $this->theme_name . '_theme_setup_wizard_page_slug', $this->theme_name . '-setup' );
$this->parent_slug = apply_filters( $this->theme_name . '_theme_setup_wizard_parent_slug', '' );
$this->default_theme_style = apply_filters( $this->theme_name . '_theme_setup_wizard_default_theme_style', '' );
// create an images/styleX/ folder for each style here.
$this->site_styles = apply_filters( $this->theme_name . '_theme_setup_wizard_site_styles', array() );
//If we have parent slug - set correct url
if ( $this->parent_slug !== '' ) {
$this->page_url = 'admin.php?page=' . $this->page_slug;
} else {
$this->page_url = 'themes.php?page=' . $this->page_slug;
}
$this->page_url = apply_filters( $this->theme_name . '_theme_setup_wizard_page_url', $this->page_url );
//set relative plugin path url
$this->plugin_path = trailingslashit( $this->cleanFilePath( dirname( __FILE__ ) ) );
$relative_url = str_replace( $this->cleanFilePath( get_template_directory() ), '', $this->plugin_path );
$this->plugin_url = trailingslashit( get_template_directory_uri() . $relative_url );
}
/**
* Setup the hooks, actions and filters.
*
* @uses add_action() To add actions.
* @uses add_filter() To add filters.
*
* @since 1.1.1
* @access public
*/
public function init_actions() {
if ( apply_filters( $this->theme_name . '_enable_setup_wizard', true ) && current_user_can( 'manage_options' ) ) {
add_action( 'after_switch_theme', array( $this, 'switch_theme' ) );
if ( class_exists( 'TGM_Plugin_Activation' ) && isset( $GLOBALS['tgmpa'] ) ) {
add_action( 'init', array( $this, 'get_tgmpa_instanse' ), 30 );
add_action( 'init', array( $this, 'set_tgmpa_url' ), 40 );
}
add_action( 'admin_menu', array( $this, 'admin_menus' ) );
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
add_action( 'admin_init', array( $this, 'admin_redirects' ), 30 );
add_action( 'admin_init', array( $this, 'init_wizard_steps' ), 30 );
add_action( 'admin_init', array( $this, 'setup_wizard' ), 30 );
add_filter( 'tgmpa_load', array( $this, 'tgmpa_load' ), 10, 1 );
add_action( 'wp_ajax_envato_setup_plugins', array( $this, 'ajax_plugins' ) );
add_action( 'wp_ajax_envato_setup_content', array( $this, 'ajax_content' ) );
}
if ( function_exists( 'envato_market' ) ) {
add_action( 'admin_init', array( $this, 'envato_market_admin_init' ), 20 );
add_filter( 'http_request_args', array( $this, 'envato_market_http_request_args' ), 10, 2 );
add_action( 'wp_ajax_dtbwp_update_notice_handler', array($this,'ajax_notice_handler') );
add_action( 'admin_notices', array($this,'admin_theme_auth_notice') );
}
add_action( 'upgrader_post_install', array( $this, 'upgrader_post_install' ), 10, 2 );
}
/**
* After a theme update we clear the setup_complete option. This prompts the user to visit the update page again.
*
* @since 1.1.8
* @access public
*/
public function upgrader_post_install( $return, $theme ) {
if ( is_wp_error( $return ) ) {
return $return;
}
if ( $theme != get_stylesheet() ) {
return $return;
}
update_option( 'envato_setup_complete', false );
return $return;
}
/**
* We 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.
*
* @since 1.1.8
* @access public
*/
public function is_possible_upgrade() {
return false;
}
public function enqueue_scripts() {
}
public function tgmpa_load( $status ) {
return is_admin() || current_user_can( 'install_themes' );
}
public function switch_theme() {
set_transient( '_' . $this->theme_name . '_activation_redirect', 1 );
}
public function admin_redirects() {
if ( ! get_transient( '_' . $this->theme_name . '_activation_redirect' ) || get_option( 'envato_setup_complete', false ) ) {
return;
}
delete_transient( '_' . $this->theme_name . '_activation_redirect' );
wp_safe_redirect( admin_url( $this->page_url ) );
exit;
}
/**
* Get configured TGMPA instance
*
* @access public
* @since 1.1.2
*/
public function get_tgmpa_instanse() {
$this->tgmpa_instance = call_user_func( array( get_class( $GLOBALS['tgmpa'] ), 'get_instance' ) );
}
/**
* Update $tgmpa_menu_slug and $tgmpa_parent_slug from TGMPA instance
*
* @access public
* @since 1.1.2
*/
public function set_tgmpa_url() {
$this->tgmpa_menu_slug = ( property_exists( $this->tgmpa_instance, 'menu' ) ) ? $this->tgmpa_instance->menu : $this->tgmpa_menu_slug;
$this->tgmpa_menu_slug = apply_filters( $this->theme_name . '_theme_setup_wizard_tgmpa_menu_slug', $this->tgmpa_menu_slug );
$tgmpa_parent_slug = ( property_exists( $this->tgmpa_instance, 'parent_slug' ) && $this->tgmpa_instance->parent_slug !== 'themes.php' ) ? 'admin.php' : 'themes.php';
$this->tgmpa_url = apply_filters( $this->theme_name . '_theme_setup_wizard_tgmpa_url', $tgmpa_parent_slug . '?page=' . $this->tgmpa_menu_slug );
}
/**
* Add admin menus/screens.
*/
public function admin_menus() {
if ( $this->is_submenu_page() ) {
//prevent Theme Check warning about "themes should use add_theme_page for adding admin pages"
$add_subpage_function = 'add_submenu' . '_page';
$add_subpage_function( $this->parent_slug, esc_html__( 'Setup Wizard' ), esc_html__( 'Setup Wizard' ), 'manage_options', $this->page_slug, array(
$this,
'setup_wizard',
) );
} else {
add_theme_page( esc_html__( 'Setup Wizard' ), esc_html__( 'Setup Wizard' ), 'manage_options', $this->page_slug, array(
$this,
'setup_wizard',
) );
}
}
/**
* Setup steps.
*
* @since 1.1.1
* @access public
* @return array
*/
public function init_wizard_steps() {
$this->steps = array(
'introduction' => array(
'name' => esc_html__( 'Introduction' ),
'view' => array( $this, 'envato_setup_introduction' ),
'handler' => array( $this, 'envato_setup_introduction_save' ),
),
);
if ( class_exists( 'TGM_Plugin_Activation' ) && isset( $GLOBALS['tgmpa'] ) ) {
$this->steps['default_plugins'] = array(
'name' => esc_html__( 'Plugins' ),
'view' => array( $this, 'envato_setup_default_plugins' ),
'handler' => '',
);
}
$this->steps['updates'] = array(
'name' => esc_html__( 'Updates' ),
'view' => array( $this, 'envato_setup_updates' ),
'handler' => array( $this, 'envato_setup_updates_save' ),
);
if( count($this->site_styles) > 1 ) {
$this->steps['style'] = array(
'name' => esc_html__( 'Style' ),
'view' => array( $this, 'envato_setup_color_style' ),
'handler' => array( $this, 'envato_setup_color_style_save' ),
);
}
$this->steps['default_content'] = array(
'name' => esc_html__( 'Content' ),
'view' => array( $this, 'envato_setup_default_content' ),
'handler' => '',
);
$this->steps['design'] = array(
'name' => esc_html__( 'Logo' ),
'view' => array( $this, 'envato_setup_logo_design' ),
'handler' => array( $this, 'envato_setup_logo_design_save' ),
);
$this->steps['customize'] = array(
'name' => esc_html__( 'Customize' ),
'view' => array( $this, 'envato_setup_customize' ),
'handler' => '',
);
$this->steps['help_support'] = array(
'name' => esc_html__( 'Support' ),
'view' => array( $this, 'envato_setup_help_support' ),
'handler' => '',
);
$this->steps['next_steps'] = array(
'name' => esc_html__( 'Ready!' ),
'view' => array( $this, 'envato_setup_ready' ),
'handler' => '',
);
$this->steps = apply_filters( $this->theme_name . '_theme_setup_wizard_steps', $this->steps );
}
/**
* Show the setup wizard
*/
public function setup_wizard() {
if ( empty( $_GET['page'] ) || $this->page_slug !== $_GET['page'] ) {
return;
}
ob_end_clean();
$this->step = isset( $_GET['step'] ) ? sanitize_key( $_GET['step'] ) : current( array_keys( $this->steps ) );
wp_register_script( 'jquery-blockui', $this->plugin_url . 'js/jquery.blockUI.js', array( 'jquery' ), '2.70', true );
wp_register_script( 'envato-setup', $this->plugin_url . 'js/envato-setup.js', array(
'jquery',
'jquery-blockui',
), $this->version );
wp_localize_script( 'envato-setup', 'envato_setup_params', array(
'tgm_plugin_nonce' => array(
'update' => wp_create_nonce( 'tgmpa-update' ),
'install' => wp_create_nonce( 'tgmpa-install' ),
),
'tgm_bulk_url' => admin_url( $this->tgmpa_url ),
'ajaxurl' => admin_url( 'admin-ajax.php' ),
'wpnonce' => wp_create_nonce( 'envato_setup_nonce' ),
'verify_text' => esc_html__( '...verifying' ),
) );
//wp_enqueue_style( 'envato_wizard_admin_styles', $this->plugin_url . '/css/admin.css', array(), $this->version );
wp_enqueue_style( 'envato-setup', $this->plugin_url . 'css/envato-setup.css', array(
'wp-admin',
'dashicons',
'install',
), $this->version );
//enqueue style for admin notices
wp_enqueue_style( 'wp-admin' );
wp_enqueue_media();
wp_enqueue_script( 'media' );
ob_start();
$this->setup_wizard_header();
$this->setup_wizard_steps();
$show_content = true;
echo '<div class="envato-setup-content">';
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->setup_wizard_content();
}
echo '</div>';
$this->setup_wizard_footer();
exit;
}
public function get_step_link( $step ) {
return add_query_arg( 'step', $step, admin_url( 'admin.php?page=' . $this->page_slug ) );
}
public function get_next_step_link() {
$keys = array_keys( $this->steps );
return add_query_arg( 'step', $keys[ array_search( $this->step, array_keys( $this->steps ) ) + 1 ], remove_query_arg( 'translation_updated' ) );
}
/**
* Setup Wizard Header
*/
public function setup_wizard_header() {
?>
<!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
// avoid theme check issues.
echo '<t';
echo 'itle>' . esc_html__( 'Theme › Setup Wizard' ) . '</ti' . 'tle>'; ?>
<?php wp_print_scripts( 'envato-setup' ); ?>
<?php do_action( 'admin_print_styles' ); ?>
<?php do_action( 'admin_print_scripts' ); ?>
<?php do_action( 'admin_head' ); ?>
</head>
<body class="envato-setup wp-core-ui">
<h1 id="wc-logo">
<a href="http://themeforest.net/user/dtbaker/portfolio" target="_blank"><?php
$image_url = $this->get_logo_image();
if ( $image_url ) {
$image = '<img class="site-logo" src="%s" alt="%s" style="width:%s; height:auto" />';
printf(
$image,
$image_url,
get_bloginfo( 'name' ),
$this->get_header_logo_width()
);
} else { ?>
<img src="<?php echo esc_url( $this->plugin_url . 'images/logo.png' ); ?>" alt="Envato install wizard" /><?php
} ?></a>
</h1>
<?php
}
/**
* Setup Wizard Footer
*/
public function setup_wizard_footer() {
?>
<?php if ( 'next_steps' === $this->step ) : ?>
<a class="wc-return-to-dashboard"
href="<?php echo esc_url( admin_url() ); ?>"><?php esc_html_e( 'Return to the WordPress Dashboard' ); ?></a>
<?php endif; ?>
</body>
<?php
@do_action( 'admin_footer' ); // this was spitting out some errors in some admin templates. quick @ fix until I have time to find out what's causing errors.
do_action( 'admin_print_footer_scripts' );
?>
</html>
<?php
}
/**
* Output the steps
*/
public function setup_wizard_steps() {
$ouput_steps = $this->steps;
array_shift( $ouput_steps );
?>
<ol class="envato-setup-steps">
<?php foreach ( $ouput_steps as $step_key => $step ) : ?>
<li class="<?php
$show_link = false;
if ( $step_key === $this->step ) {
echo 'active';
} elseif ( array_search( $this->step, array_keys( $this->steps ) ) > array_search( $step_key, array_keys( $this->steps ) ) ) {
echo 'done';
$show_link = true;
}
?>"><?php
if ( $show_link ) {
?>
<a href="<?php echo esc_url( $this->get_step_link( $step_key ) ); ?>"><?php echo esc_html( $step['name'] ); ?></a>
<?php
} else {
echo esc_html( $step['name'] );
}
?></li>
<?php endforeach; ?>
</ol>
<?php
}
/**
* Output the content for the current step
*/
public function setup_wizard_content() {
isset( $this->steps[ $this->step ] ) ? call_user_func( $this->steps[ $this->step ]['view'] ) : false;
}
/**
* Introduction step
*/
public function envato_setup_introduction() {
if ( false && isset( $_REQUEST['debug'] ) ) {
echo '<pre>';
// debug inserting a particular post so we can see what's going on
$post_type = 'nav_menu_item';
$post_id = 239; // debug this particular import post id.
$all_data = $this->_get_json( 'default.json' );
if ( ! $post_type || ! isset( $all_data[ $post_type ] ) ) {
echo "Post type $post_type not found.";
} else {
echo "Looking for post id $post_id \n";
foreach ( $all_data[ $post_type ] as $post_data ) {
if ( $post_data['post_id'] == $post_id ) {
//print_r( $post_data );
$this->_process_post_data( $post_type, $post_data, 0, true );
}
}
}
$this->_handle_delayed_posts();
print_r( $this->logs );
echo '</pre>';
} else if ( isset( $_REQUEST['export'] ) ) {
@include( 'envato-setup-export.php' );
} else if ( $this->is_possible_upgrade() ) {
?>
<h1><?php printf( esc_html__( 'Welcome to the setup wizard for %s.' ), wp_get_theme() ); ?></h1>
<p><?php esc_html_e( 'It looks like you may have recently upgraded to this theme. Great! This setup wizard will help ensure all the default settings are correct. It will also show some information about your new website and support options.' ); ?></p>
<p class="envato-setup-actions step">
<a href="<?php echo esc_url( $this->get_next_step_link() ); ?>"
class="button-primary button button-large button-next"><?php esc_html_e( 'Let\'s Go!' ); ?></a>
<a href="<?php echo esc_url( wp_get_referer() && ! strpos( wp_get_referer(), 'update.php' ) ? wp_get_referer() : admin_url( '' ) ); ?>"
class="button button-large"><?php esc_html_e( 'Not right now' ); ?></a>
</p>
<?php
} else if ( get_option( 'envato_setup_complete', false ) ) {
?>
<h1><?php printf( esc_html__( 'Welcome to the setup wizard for %s.' ), wp_get_theme() ); ?></h1>
<p><?php esc_html_e( 'It looks like you have already run the setup wizard. Below are some options: ' ); ?></p>
<ul>
<li>
<a href="<?php echo esc_url( $this->get_next_step_link() ); ?>"
class="button-primary button button-next button-large"><?php esc_html_e( 'Run Setup Wizard Again' ); ?></a>
</li>
<li>
<form method="post">
<input type="hidden" name="reset-font-defaults" value="yes">
<input type="submit" class="button-primary button button-large button-next"
value="<?php esc_attr_e( 'Reset font style and colors' ); ?>" name="save_step"/>
<?php wp_nonce_field( 'envato-setup' ); ?>
</form>
</li>
</ul>
<p class="envato-setup-actions step">
<a href="<?php echo esc_url( wp_get_referer() && ! strpos( wp_get_referer(), 'update.php' ) ? wp_get_referer() : admin_url( '' ) ); ?>"
class="button button-large"><?php esc_html_e( 'Cancel' ); ?></a>
</p>
<?php
} else {
?>
<h1><?php printf( esc_html__( 'Welcome to the setup wizard for %s.' ), wp_get_theme() ); ?></h1>
<p><?php printf( esc_html__( 'Thank you for choosing the %s theme from ThemeForest. This quick setup wizard will help you configure your new website. This wizard will install the required WordPress plugins, default content, logo and tell you a little about Help & Support options. It should only take 5 minutes.' ), wp_get_theme() ); ?></p>
<p><?php esc_html_e( 'No time right now? If you don\'t want to go through the wizard, you can skip and return to the WordPress dashboard. Come back anytime if you change your mind!' ); ?></p>
<p class="envato-setup-actions step">
<a href="<?php echo esc_url( $this->get_next_step_link() ); ?>"
class="button-primary button button-large button-next"><?php esc_html_e( 'Let\'s Go!' ); ?></a>
<a href="<?php echo esc_url( wp_get_referer() && ! strpos( wp_get_referer(), 'update.php' ) ? wp_get_referer() : admin_url( '' ) ); ?>"
class="button button-large"><?php esc_html_e( 'Not right now' ); ?></a>
</p>
<?php
}
}
public function filter_options( $options ) {
return $options;
}
/**
*
* Handles save button from welcome page. This is to perform tasks when the setup wizard has already been run. E.g. reset defaults
*
* @since 1.2.5
*/
public function envato_setup_introduction_save() {
check_admin_referer( 'envato-setup' );
if ( ! empty( $_POST['reset-font-defaults'] ) && $_POST['reset-font-defaults'] == 'yes' ) {
// clear font options
update_option( 'tt_font_theme_options', array() );
// do other reset options here.
// reset site color
remove_theme_mod( 'dtbwp_site_color' );
if ( class_exists( 'dtbwp_customize_save_hook' ) ) {
$site_color_defaults = new dtbwp_customize_save_hook();
$site_color_defaults->save_color_options();
}
$file_name = get_template_directory() . '/style.custom.css';
if ( file_exists( $file_name ) ) {
require_once( ABSPATH . 'wp-admin/includes/file.php' );
WP_Filesystem();
global $wp_filesystem;
$wp_filesystem->put_contents( $file_name, '' );
}
?>
<p>
<strong><?php esc_html_e( 'Options have been reset. Please go to Appearance > Customize in the WordPress backend.' ); ?></strong>
</p>
<?php
return true;
}
return false;
}
private function _get_plugins() {
$instance = call_user_func( array( get_class( $GLOBALS['tgmpa'] ), 'get_instance' ) );
$plugins = array(
'all' => array(), // Meaning: all plugins which still have open actions.
'install' => array(),
'update' => array(),
'activate' => array(),
);
foreach ( $instance->plugins as $slug => $plugin ) {
if ( $instance->is_plugin_active( $slug ) && false === $instance->does_plugin_have_update( $slug ) ) {
// No need to display plugins if they are installed, up-to-date and active.
continue;
} else {
$plugins['all'][ $slug ] = $plugin;
if ( ! $instance->is_plugin_installed( $slug ) ) {
$plugins['install'][ $slug ] = $plugin;
} else {
if ( false !== $instance->does_plugin_have_update( $slug ) ) {
$plugins['update'][ $slug ] = $plugin;
}
if ( $instance->can_plugin_activate( $slug ) ) {
$plugins['activate'][ $slug ] = $plugin;
}
}
}
}
return $plugins;
}
/**
* Page setup
*/
public function envato_setup_default_plugins() {
tgmpa_load_bulk_installer();
// install plugins with TGM.
if ( ! class_exists( 'TGM_Plugin_Activation' ) || ! isset( $GLOBALS['tgmpa'] ) ) {
die( 'Failed to find TGM' );
}
$url = wp_nonce_url( add_query_arg( array( 'plugins' => 'go' ) ), 'envato-setup' );
$plugins = $this->_get_plugins();
// copied from TGM
$method = ''; // Leave blank so WP_Filesystem can populate it as necessary.
$fields = array_keys( $_POST ); // Extra fields to pass to WP_Filesystem.
if ( false === ( $creds = request_filesystem_credentials( esc_url_raw( $url ), $method, false, false, $fields ) ) ) {
return true; // Stop the normal page form from displaying, credential request form will be shown.
}
// Now we have some credentials, setup WP_Filesystem.
if ( ! WP_Filesystem( $creds ) ) {
// Our credentials were no good, ask the user for them again.
request_filesystem_credentials( esc_url_raw( $url ), $method, true, false, $fields );
return true;
}
/* If we arrive here, we have the filesystem */
?>
<h1><?php esc_html_e( 'Default Plugins' ); ?></h1>
<form method="post">
<?php
$plugins = $this->_get_plugins();
if ( count( $plugins['all'] ) ) {
?>
<p><?php esc_html_e( 'Your website needs a few essential plugins. The following plugins will be installed or updated:' ); ?></p>
<ul class="envato-wizard-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[] = 'Installation';
}
if ( isset( $plugins['update'][ $slug ] ) ) {
$keys[] = 'Update';
}
if ( isset( $plugins['activate'][ $slug ] ) ) {
$keys[] = 'Activation';
}
echo implode( ' and ', $keys ) . ' required';
?>
</span>
<div class="spinner"></div>
</li>
<?php } ?>
</ul>
<?php
} else {
echo '<p><strong>' . esc_html_e( 'Good news! All plugins are already installed and up to date. Please continue.' ) . '</strong></p>';
} ?>
<p><?php esc_html_e( 'You can add and remove plugins later on from within WordPress.' ); ?></p>
<p class="envato-setup-actions step">
<a href="<?php echo esc_url( $this->get_next_step_link() ); ?>"
class="button-primary button button-large button-next"
data-callback="install_plugins"><?php esc_html_e( 'Continue' ); ?></a>
<a href="<?php echo esc_url( $this->get_next_step_link() ); ?>"
class="button button-large button-next"><?php esc_html_e( 'Skip this step' ); ?></a>
<?php wp_nonce_field( 'envato-setup' ); ?>
</p>
</form>
<?php
}
public function ajax_plugins() {
if ( ! check_ajax_referer( 'envato_setup_nonce', 'wpnonce' ) || empty( $_POST['slug'] ) ) {
wp_send_json_error( array( 'error' => 1, 'message' => esc_html__( 'No Slug Found' ) ) );
}
$json = array();
// send back some json we use to hit up TGM
$plugins = $this->_get_plugins();
// what are we doing with this plugin?
foreach ( $plugins['activate'] as $slug => $plugin ) {
if ( $_POST['slug'] == $slug ) {
$json = array(
'url' => admin_url( $this->tgmpa_url ),
'plugin' => array( $slug ),
'tgmpa-page' => $this->tgmpa_menu_slug,
'plugin_status' => 'all',
'_wpnonce' => wp_create_nonce( 'bulk-plugins' ),
'action' => 'tgmpa-bulk-activate',
'action2' => - 1,
'message' => esc_html__( 'Activating Plugin' ),
);
break;
}
}
foreach ( $plugins['update'] as $slug => $plugin ) {
if ( $_POST['slug'] == $slug ) {
$json = array(
'url' => admin_url( $this->tgmpa_url ),
'plugin' => array( $slug ),
'tgmpa-page' => $this->tgmpa_menu_slug,
'plugin_status' => 'all',
'_wpnonce' => wp_create_nonce( 'bulk-plugins' ),
'action' => 'tgmpa-bulk-update',
'action2' => - 1,
'message' => esc_html__( 'Updating Plugin' ),
);
break;
}
}
foreach ( $plugins['install'] as $slug => $plugin ) {
if ( $_POST['slug'] == $slug ) {
$json = array(
'url' => admin_url( $this->tgmpa_url ),
'plugin' => array( $slug ),
'tgmpa-page' => $this->tgmpa_menu_slug,
'plugin_status' => 'all',
'_wpnonce' => wp_create_nonce( 'bulk-plugins' ),
'action' => 'tgmpa-bulk-install',
'action2' => - 1,
'message' => esc_html__( 'Installing Plugin' ),
);
break;
}
}
if ( $json ) {
$json['hash'] = md5( serialize( $json ) ); // used for checking if duplicates happen, move to next plugin
wp_send_json( $json );
} else {
wp_send_json( array( 'done' => 1, 'message' => esc_html__( 'Success' ) ) );
}
exit;
}
private function _content_default_get() {
$content = array();
// find out what content is in our default json file.
$available_content = $this->_get_json( 'default.json' );
foreach ( $available_content as $post_type => $post_data ) {
if ( count( $post_data ) ) {
$first = current( $post_data );
$post_type_title = ! empty( $first['type_title'] ) ? $first['type_title'] : ucwords( $post_type ) . 's';
if ( $post_type_title == 'Navigation Menu Items' ) {
$post_type_title = 'Navigation';
}
$content[ $post_type ] = array(
'title' => $post_type_title,
'description' => sprintf( esc_html__( 'This will create default %s as seen in the demo.' ), $post_type_title ),
'pending' => esc_html__( 'Pending.' ),
'installing' => esc_html__( 'Installing.' ),
'success' => esc_html__( 'Success.' ),
'install_callback' => array( $this, '_content_install_type' ),
'checked' => $this->is_possible_upgrade() ? 0 : 1,
// dont check if already have content installed.
);
}
}
$content['widgets'] = array(
'title' => esc_html__( 'Widgets' ),
'description' => esc_html__( 'Insert default sidebar widgets as seen in the demo.' ),
'pending' => esc_html__( 'Pending.' ),
'installing' => esc_html__( 'Installing Default Widgets.' ),
'success' => esc_html__( 'Success.' ),
'install_callback' => array( $this, '_content_install_widgets' ),
'checked' => $this->is_possible_upgrade() ? 0 : 1,
// dont check if already have content installed.
);
$content['settings'] = array(
'title' => esc_html__( 'Settings' ),
'description' => esc_html__( 'Configure default settings.' ),
'pending' => esc_html__( 'Pending.' ),
'installing' => esc_html__( 'Installing Default Settings.' ),
'success' => esc_html__( 'Success.' ),
'install_callback' => array( $this, '_content_install_settings' ),
'checked' => $this->is_possible_upgrade() ? 0 : 1,
// dont check if already have content installed.
);
$content = apply_filters( $this->theme_name . '_theme_setup_wizard_content', $content );
return $content;
}
/**
* Page setup
*/
public function envato_setup_default_content() {
?>
<h1><?php esc_html_e( 'Default Content' ); ?></h1>
<form method="post">
<?php if ( $this->is_possible_upgrade() ) { ?>
<p><?php esc_html_e( 'It looks like you already have content installed on this website. If you would like to install the default demo content as well you can select it below. Otherwise just choose the upgrade option to ensure everything is up to date.' ); ?></p>
<?php } else { ?>
<p><?php printf( esc_html__( 'It\'s time to insert some default content for your new WordPress website. Choose what you would like inserted below and click Continue. It is recommended to leave everything selected. Once inserted, this content can be managed from the WordPress admin dashboard. ' ), '<a href="' . esc_url( admin_url( 'edit.php?post_type=page' ) ) . '" target="_blank">', '</a>' ); ?></p>
<?php } ?>
<table class="envato-setup-pages" cellspacing="0">
<thead>
<tr>
<td class="check"></td>
<th class="item"><?php esc_html_e( 'Item' ); ?></th>