-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathAdmin.php
More file actions
executable file
·1425 lines (1243 loc) · 45.3 KB
/
Admin.php
File metadata and controls
executable file
·1425 lines (1243 loc) · 45.3 KB
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
/**
* Handles admin logic for the onboarding.
*
* @package templates-patterns-collection
*/
namespace TIOB;
use TIOB\Importers\Cleanup\Active_State;
/**
* Class Admin
*
* @package templates-patterns-collection
*/
class Admin {
use White_Label_Config;
// TODO: revert this after implementation
// const API = 'neve.test/wp-json';
const API = 'api.themeisle.com';
const IMPORTED_TEMPLATES_COUNT_OPT = 'tiob_premade_imported';
const FEEDBACK_DISMISSED_OPT = 'tiob_feedback_dismiss';
const TC_REMOVED_KEY = 'tiob_tc_removed';
const TC_NEW_NOTICE_DISMISSED = 'tiob_new_tc_notice_dismissed';
const VISITED_LIBRARY_OPT = 'tiob_library_visited';
/**
* Admin page slug
*
* @var string
*/
private $page_slug = 'tiob-starter-sites';
/**
* Option and transient namespace for email skip.
*
* @var string
*/
private $skip_email_subscribe_namespace = 'tpc_skip_email_subscribe';
/**
* Neve font pairs
*
* @var array
*/
private $font_pairs_neve = array();
/**
* Google fonts
*
* @var array
*/
private $google_fonts = array();
public static function get_templates_cloud_endpoint() {
return 'https://' . self::API . '/templates-cloud/';
}
/**
* Initialize the Admin.
*/
public function init() {
License::get_instance();
$this->maybe_remove_tc();
add_filter( 'query_vars', array( $this, 'add_onboarding_query_var' ) );
add_action( 'after_switch_theme', array( $this, 'get_previous_theme' ) );
add_filter( 'neve_dashboard_page_data', array( $this, 'localize_sites_library' ) );
add_action( 'admin_menu', array( $this, 'register' ) );
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue' ) );
add_filter( 'ti_tpc_editor_data', array( $this, 'add_tpc_editor_data' ), 20 );
add_action( 'admin_init', array( $this, 'activation_redirect' ) );
add_filter( 'themeisle_sdk_blackfriday_data', array( $this, 'add_black_friday_data' ) );
$this->setup_white_label();
add_action( 'wp_ajax_skip_subscribe', array( $this, 'skip_subscribe' ) );
add_action( 'wp_ajax_nopriv_skip_subscribe', array( $this, 'skip_subscribe' ) );
add_action( 'wp_ajax_mark_onboarding_done', array( $this, 'mark_onboarding_done' ) );
add_action( 'wp_ajax_nopriv_mark_onboarding_done', array( $this, 'mark_onboarding_done' ) );
add_action( 'wp_ajax_tpc_get_logs', array( $this, 'external_get_logs' ) );
add_action( 'wp_ajax_dismiss_new_tc_notice', array( $this, 'dismiss_new_tc_notice' ) );
$this->register_feedback_settings();
$this->register_prevent_clone_hooks();
$this->get_font_parings();
}
/**
* Removes template cloud for users that:
* - didn't have a license key yet;
* - have 0 templates saved;
*
* @return void
*/
public function maybe_remove_tc() {
$status = get_option( self::TC_REMOVED_KEY );
if ( $status !== false ) {
return;
}
if ( ! License::has_active_license() ) {
update_option( self::TC_REMOVED_KEY, 'yes' );
return;
}
$license = License::get_instance();
if ( ! $license->has_any_templates() ) {
update_option( self::TC_REMOVED_KEY, 'yes' );
return;
}
update_option( self::TC_REMOVED_KEY, 'no' );
}
/**
* Check if the legacy template cloud is still available.
*
* @return bool
*/
public static function has_legacy_template_cloud() {
return get_option( self::TC_REMOVED_KEY, 'no' ) === 'no';
}
public function dismiss_new_tc_notice() {
$response = array(
'success' => false,
'code' => 'ti__ob_not_allowed',
'message' => 'Not allowed!',
);
if ( ! isset( $_REQUEST['nonce'] ) ) {
$this->ensure_ajax_response( $response );
return;
}
if ( ! wp_verify_nonce( $_REQUEST['nonce'], 'dismiss_new_tc_notice' ) ) {
$this->ensure_ajax_response( $response );
return;
}
unset( $response['code'] );
unset( $response['message'] );
update_option( self::TC_NEW_NOTICE_DISMISSED, 'yes' );
$this->ensure_ajax_response( $response );
}
/**
* Register hooks to prevent meta cloning for the templates.
* This is needed because the template id is unique, and we don't want to clone it.
* @return void
*/
public function register_prevent_clone_hooks() {
$allowed_post_types = Editor::get_allowed_post_types();
if ( empty( $allowed_post_types ) ) {
return;
}
foreach ( $allowed_post_types as $post_type ) {
add_filter(
'update_' . $post_type . '_metadata',
function ( $value, $post_id, $meta_key, $meta_value, $prev_value ) use ( $post_type ) {
if ( $this->check_unique_template_id_on_meta_change( $post_id, $meta_key, $post_type, $meta_value ) ) {
return true;
}
return $value;
},
10,
5
);
add_filter(
'add_' . $post_type . '_metadata',
function ( $value, $post_id, $meta_key, $meta_value, $unique ) use ( $post_type ) {
if ( $this->check_unique_template_id_on_meta_change( $post_id, $meta_key, $post_type, $meta_value ) ) {
return true;
}
return $value;
},
10,
5
);
}
}
/**
* Check that the meta value is unique for the allowed post types that support Templates Cloud.
*
* @param int $post_id The post ID.
* @param string $meta_key The meta key.
* @param string $meta_type The meta type. The post type ( post, page, neve_custom_layouts etc. ).
* @param string $meta_value The meta value.
*
* @return bool
*/
public function check_unique_template_id_on_meta_change( $post_id, $meta_key, $meta_type, $meta_value ) {
// Skip check if the meta key is not one of the allowed ones.
if ( ! in_array(
$meta_key,
array(
'_ti_tpc_template_sync',
'_ti_tpc_template_id',
'_ti_tpc_screenshot_url',
'_ti_tpc_site_slug',
'_ti_tpc_published',
),
true
)
) {
return false;
}
if ( empty( $meta_value ) ) {
return false;
}
$template_id = get_post_meta( $post_id, '_ti_tpc_template_id', true );
if ( empty( $template_id ) && $meta_key === '_ti_tpc_template_id' ) {
$template_id = $meta_value;
}
// Check if the template ID is used on any other posts or pages
// exclude the current post from the query
$args = array(
'post_type' => $meta_type,
'meta_key' => '_ti_tpc_template_id',
'meta_value' => $template_id,
'post__not_in' => array( $post_id ),
'posts_per_page' => 1,
'fields' => 'ids',
);
$query = new \WP_Query( $args );
$duplicate_id = $query->get_posts();
if ( ! empty( $duplicate_id ) ) {
// The template ID is already used on another post
return true;
}
return false;
}
/**
* Register feedback settings.
*
* @return void
*/
private function register_feedback_settings() {
register_setting(
'tiob_feedback',
self::IMPORTED_TEMPLATES_COUNT_OPT,
array(
'type' => 'integer',
'show_in_rest' => true,
'default' => 0,
)
);
register_setting(
'tiob_feedback',
self::FEEDBACK_DISMISSED_OPT,
array(
'type' => 'boolean',
'show_in_rest' => true,
'default' => false,
)
);
}
/**
* Return the skip subscribe status.
* Used to determine if email form should be displayed.
*
* @return bool
*/
private function get_skip_subscribe_status() {
$status = false;
if ( 'yes' === get_option( $this->skip_email_subscribe_namespace, 'no' ) ) {
$status = true;
}
if ( get_transient( $this->skip_email_subscribe_namespace ) ) {
$status = true;
}
return $status;
}
/**
* Utility method to ensure proper response for ajax call.
*
* @param array $response
*/
private function ensure_ajax_response( $response ) {
echo json_encode( $response );
die();
}
/**
* Handles the `skip_subscribe` ajax action.
*/
public function skip_subscribe() {
$response = array(
'success' => false,
'code' => 'ti__ob_not_allowed',
'message' => 'Not allowed!',
);
if ( ! isset( $_REQUEST['nonce'] ) ) {
$this->ensure_ajax_response( $response );
return;
}
if ( ! wp_verify_nonce( $_REQUEST['nonce'], 'skip_subscribe_nonce' ) ) {
$this->ensure_ajax_response( $response );
return;
}
unset( $response['code'] );
unset( $response['message'] );
$response['success'] = true;
if ( isset( $_REQUEST['isTempSkip'] ) ) {
set_transient( $this->skip_email_subscribe_namespace, 'yes', 7 * DAY_IN_SECONDS );
$this->ensure_ajax_response( $response );
return;
}
update_option( $this->skip_email_subscribe_namespace, 'yes' );
$this->ensure_ajax_response( $response );
}
/**
* Handles the `mark_onboarding_done` ajax action.
*/
public function mark_onboarding_done() {
$response = array(
'success' => false,
'code' => 'ti__ob_not_allowed',
'message' => 'Not allowed!',
);
if ( ! isset( $_REQUEST['nonce'] ) ) {
$this->ensure_ajax_response( $response );
return;
}
if ( ! wp_verify_nonce( $_REQUEST['nonce'], 'onboarding_done_nonce' ) ) {
$this->ensure_ajax_response( $response );
return;
}
unset( $response['code'] );
unset( $response['message'] );
update_option( 'tpc_onboarding_done', 'yes' );
$this->ensure_ajax_response( $response );
}
/**
* Hook into editor data to add Neve plan if available
* or return the proper tier if stand-alone license is valid.
*
* @param array $data tiTpc exported data.
*
* @return array
*/
public function add_tpc_editor_data( $data ) {
$plan = $this->neve_license_plan();
$data['tier'] = License::get_license_tier( $plan );
return $data;
}
/**
* Redirect to onboarding if user is new.
*
* @return void
*/
public function activation_redirect() {
$should_run_obd = get_option( 'tpc_maybe_run_onboarding', false );
if ( ! $should_run_obd ) {
return;
}
if ( ! $this->should_load_onboarding() ) {
return;
}
delete_option( 'tpc_maybe_run_onboarding' );
$query_args = array( 'page' => 'neve-onboarding' );
if ( defined( 'TI_ONBOARDING_DEFAULT_SITE' ) && TI_ONBOARDING_DEFAULT_SITE ) {
$query_args['site'] = sanitize_key( TI_ONBOARDING_DEFAULT_SITE );
} else {
$query_args['show'] = 'welcome';
}
wp_safe_redirect( add_query_arg( $query_args, admin_url( 'admin.php' ) ) );
exit();
}
/**
* Use the Neve builtin compatibility to check for specific support.
*
* @return bool
*/
private function neve_theme_has_support( $feature ) {
if ( defined( 'NEVE_COMPATIBILITY_FEATURES' ) ) {
$features = NEVE_COMPATIBILITY_FEATURES;
return isset( $features[ $feature ] );
}
return false;
}
/**
* Use the features defined in the TIOB plugin to check for specific support.
*
* @param string $feature The feature to check for.
*
* @return bool
*/
private function tiob_has_support( $feature ) {
if ( defined( 'TIOB_FEATURES' ) ) {
$features = TIOB_FEATURES;
return isset( $features[ $feature ] );
}
return false;
}
/**
* Utility method to add a theme page from an array.
*
* @param array $page_data Page data.
* @param int $offset Offset for the menu position.
*
* @return void
*/
private function add_theme_page_for_tiob( $page_data, $offset = 2 ) {
if ( $this->neve_theme_has_support( 'theme_dedicated_menu' ) ) {
global $submenu;
$theme_page = 'neve-welcome';
$capability = 'activate_plugins';
add_submenu_page(
$theme_page,
$page_data['page_title'],
$page_data['page_title'],
$capability,
$page_data['menu_slug'],
$page_data['callback']
);
$item = array_pop( $submenu[ $theme_page ] );
array_splice( $submenu[ $theme_page ], $offset, 0, array( $item ) );
return;
}
// When using the new menu location we will not register items on the theme page anymore.
if ( $this->tiob_has_support( 'new_menu' ) ) {
return;
}
add_theme_page(
$page_data['page_title'],
$page_data['menu_title'],
$page_data['capability'],
$page_data['menu_slug'],
$page_data['callback']
);
}
/**
* Utility method to add a plugin sub-page from an array.
*
* @param array $page_data Page data.
*
* @return void
*/
private function add_subpage_for_tiob( $page_data ) {
$capability = 'manage_options';
add_submenu_page(
$page_data['parent_slug'],
$page_data['page_title'],
$page_data['menu_title'],
$capability,
$page_data['menu_slug'],
$page_data['callback']
);
}
/**
* Register theme options page.
*
* @return bool|void
*/
public function register() {
$has_neve = defined( 'NEVE_VERSION' );
// Legacy users that had the plugin and had templates.
if ( self::has_legacy_template_cloud() ) {
$this->register_legacy_template_cloud_pages();
return;
}
if ( ! $has_neve ) {
$this->register_starter_sites_page( true );
return;
}
$this->register_starter_sites_page();
}
private function register_starter_sites_page( $in_appearance = false ) {
// WL disables starter sites.
if ( $this->is_starter_sites_disabled() ) {
return;
}
$starter_site_data = array(
'page_title' => __( 'Starter Sites', 'templates-patterns-collection' ),
'menu_title' => $this->get_prefix_for_menu_item() . __( 'Onboarding', 'templates-patterns-collection' ),
'capability' => 'install_plugins',
'menu_slug' => 'neve-onboarding',
'callback' => array(
$this,
'render_onboarding',
),
);
if ( $in_appearance ) {
$starter_site_data['page_title'] = __( 'Starter Templates', 'templates-patterns-collection' );
$starter_site_data['menu_title'] = __( 'Starter Templates', 'templates-patterns-collection' );
add_theme_page(
$starter_site_data['page_title'],
$starter_site_data['menu_title'],
$starter_site_data['capability'],
$starter_site_data['menu_slug'],
$starter_site_data['callback']
);
}
$this->add_theme_page_for_tiob( $starter_site_data, 2 );
}
/**
* Legacy template cloud pages.
*
* @return false|void
*/
public function register_legacy_template_cloud_pages() {
$icon = 'data:image/svg+xml;base64,PHN2ZwogICAgICAgIHdpZHRoPSIxMDAiCiAgICAgICAgaGVpZ2h0PSIxMDAiCiAgICAgICAgdmlld0JveD0iMCAwIDEwMCAxMDAiCiAgICAgICAgZmlsbD0iI2YwZjBmMSIKICAgICAgICB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciCj4KICAgIDxwYXRoCiAgICAgICAgICAgIGQ9Ik05NS4wMjY0IDEwMEg0Ljk3MzU2QzIuMjI3OTcgMTAwIDAgOTcuNzcyIDAgOTUuMDI2NFY0Ljk3MzU2QzAgMi4yMjc5NyAyLjIyNzk3IDAgNC45NzM1NiAwSDk1LjAyNjRDOTcuNzcyIDAgMTAwIDIuMjI3OTcgMTAwIDQuOTczNTZWOTUuMDI2NEMxMDAgOTcuNzcyIDk3Ljc3MiAxMDAgOTUuMDI2NCAxMDBaIE04Mi42OTQxIDg2Ljc0NDhWMzAuODIwNVYxOC40NjUzSDcwLjM1MDJIMTQuNDE0NkwyNi43NTg0IDMwLjgyMDVINzAuMzUwMlY3NC40MDFMODIuNjk0MSA4Ni43NDQ4WiBNNDIuMjQxNiA1OC45MjkxTDQyLjI1MjggNzEuMTgzTDUzLjIzNTIgODIuMTY1M0w1My4xOTAyIDQ3Ljk4MDZMMTguOTk0MSA0Ny45MzU1TDI5Ljk3NjUgNTguOTA2Nkw0Mi4yNDE2IDU4LjkyOTFaIgogICAgICAgICAgICBmaWxsPSIjZjBmMGYxIgogICAgLz4KPC9zdmc+Cg==';
$priority = 61; // The position of the menu item, 60 is the position of the Appearance menu.
$plugin_page = 'tiob-plugin';
$tpc_menu_page_data = array(
'page_title' => __( 'Templates Cloud', 'templates-patterns-collection' ),
'menu_title' => __( 'Templates Cloud', 'templates-patterns-collection' ),
'capability' => 'manage_options',
'menu_slug' => $plugin_page,
'callback' => array(
$this,
'render_starter_sites',
),
);
add_menu_page(
$tpc_menu_page_data['page_title'],
$tpc_menu_page_data['menu_title'],
$tpc_menu_page_data['capability'],
$tpc_menu_page_data['menu_slug'],
$tpc_menu_page_data['callback'],
$icon,
$priority
);
if ( $this->is_library_disabled() && $this->is_starter_sites_disabled() ) {
return false;
}
$library_data = array(
'parent_slug' => $plugin_page,
'page_title' => __( 'My Library', 'templates-patterns-collection' ),
'menu_title' => __( 'My Library', 'templates-patterns-collection' ),
'capability' => 'activate_plugins',
'menu_slug' => $plugin_page,
'callback' => $tpc_menu_page_data['callback'],
);
$settings_data = array(
'parent_slug' => $plugin_page,
'page_title' => __( 'Settings', 'templates-patterns-collection' ),
'menu_title' => __( 'Settings', 'templates-patterns-collection' ),
'capability' => 'activate_plugins',
'menu_slug' => 'admin.php?page=' . $plugin_page . '#settings',
'callback' => '',
);
if ( $this->is_starter_sites_disabled() && ! $this->is_library_disabled() ) {
$library_data['menu_slug'] = $plugin_page;
$library_data['callback'] = array(
$this,
'render_starter_sites',
);
$this->add_subpage_for_tiob( $library_data );
$this->add_subpage_for_tiob( $settings_data );
return false;
}
$this->register_starter_sites_page();
if ( $this->is_library_disabled() ) {
return false;
}
$this->add_subpage_for_tiob( $library_data );
$this->add_subpage_for_tiob( $settings_data );
}
/**
* Map license plan from Neve if available.
*
* @return int
*/
private function neve_license_plan() {
$category = apply_filters( 'product_neve_license_plan', -1 );
$category_mapping = License::NEVE_CATEGORY_MAPPING;
return $category > -1 && isset( $category_mapping[ $category ] ) ? $category_mapping[ $category ] : -1;
}
/**
* Render method for the starter sites page.
*/
public function render_starter_sites() {
echo '<div id="tpc-app"/>';
}
/**
* Render method for the onboarding page.
*/
public function render_onboarding() {
echo '<div id="ob-app"/>';
}
/**
* Decide if the new onboarding should load
*
* @return bool
*/
private function should_load_onboarding() {
if ( ! current_user_can( 'install_plugins' ) ) {
return false;
}
if ( $this->is_starter_sites_disabled() ) {
return false;
}
$current_theme = wp_get_theme();
$template = $current_theme->template === 'neve' ? $current_theme->template : $current_theme->parent();
if ( $template !== 'neve' ) {
return false;
}
$onboarding_done = get_option( 'tpc_onboarding_done', 'no' );
if ( $onboarding_done === 'yes' ) {
return false;
}
return get_option( 'tpc_obd_new_user', 'no' ) === 'yes';
}
/**
* Enqueue scripts and styles
*
* @return void
*/
public function enqueue() {
$screen = get_current_screen();
if ( ! isset( $screen->id ) ) {
return;
}
if ( strpos( $screen->id, '_page_neve-onboarding' ) ) {
wp_enqueue_media();
$onboarding_dependencies = ( include TIOB_PATH . 'onboarding/build/index.asset.php' );
wp_register_style( 'tiobObd', TIOB_URL . 'onboarding/build/style-index.css', array( 'wp-components' ), $onboarding_dependencies['version'] );
wp_style_add_data( 'tiobObd', 'rtl', 'replace' );
wp_enqueue_style( 'tiobObd' );
wp_register_script( 'tiobObd', TIOB_URL . 'onboarding/build/index.js', array_merge( $onboarding_dependencies['dependencies'], array( 'updates', 'regenerator-runtime' ) ), $onboarding_dependencies['version'], true );
wp_localize_script( 'tiobObd', 'tiobDash', apply_filters( 'neve_dashboard_page_data', $this->get_localization() ) );
wp_enqueue_script( 'tiobObd' );
wp_set_script_translations( 'tiobObd', 'templates-patterns-collection' );
if ( ! empty( $this->google_fonts ) ) {
$font_chunks = array_chunk( $this->google_fonts, absint( count( $this->google_fonts ) / 5 ) );
foreach ( $font_chunks as $index => $fonts_chunk ) {
wp_enqueue_style(
'tiob-google-fonts-' . $index,
'https://fonts.googleapis.com/css?family=' . implode( '|', $fonts_chunk ) . '&display=swap"',
array(),
$onboarding_dependencies['version']
);
}
}
do_action( 'themeisle_internal_page', TIOB_BASENAME, 'onboarding' );
}
$is_tiob_page = strpos( $screen->id, '_page_tiob-plugin' ) !== false;
if ( strpos( $screen->id, '_page_' . $this->page_slug ) === false && ! $is_tiob_page ) {
return;
}
$dismiss_notice = isset( $_GET['dismiss_notice'] ) && $_GET['dismiss_notice'] === 'yes';
if ( $dismiss_notice ) {
update_option( self::VISITED_LIBRARY_OPT, 'yes' );
}
$dependencies = ( include TIOB_PATH . 'assets/build/app.asset.php' );
wp_register_style( 'tiob', TIOB_URL . 'assets/build/style-app.css', array( 'wp-components' ), $dependencies['version'] );
wp_style_add_data( 'tiob', 'rtl', 'replace' );
wp_enqueue_style( 'tiob' );
wp_register_script( 'tiob', TIOB_URL . 'assets/build/app.js', array_merge( $dependencies['dependencies'], array( 'updates', 'regenerator-runtime' ) ), $dependencies['version'], true );
$tiob_dash = apply_filters( 'neve_dashboard_page_data', $this->get_localization() );
if ( $is_tiob_page ) {
$tiob_dash['hideStarterSites'] = true;
}
wp_localize_script( 'tiob', 'tiobDash', apply_filters( 'neve_dashboard_page_data', $tiob_dash ) );
wp_enqueue_script( 'tiob' );
wp_set_script_translations( 'tiob', 'templates-patterns-collection' );
do_action( 'themeisle_internal_page', TIOB_BASENAME, 'onboarding' );
}
/**
* Get localization data for the dashboard script.
*
* @return array
*/
private function get_localization() {
$theme_name = apply_filters( 'ti_wl_theme_name', 'Neve' );
$user = wp_get_current_user();
$neve_upgrade_link = 'https://themeisle.com/themes/neve/upgrade/';
$upgrade_url = apply_filters(
'neve_upgrade_link_from_child_theme_filter',
tsdk_translate_link( tsdk_utmify( $neve_upgrade_link, 'freevspro' ), 'query' )
);
$upgrade_url_tpc = tsdk_translate_link( tsdk_utmify( 'https://themeisle.com/plugins/templates-cloud', 'tcupgrade' ), 'query' );
if ( defined( 'NEVE_VERSION' ) ) {
$upgrade_url_tpc = apply_filters(
'neve_upgrade_link_from_child_theme_filter',
tsdk_translate_link( tsdk_utmify( $neve_upgrade_link, 'templatecloud' ), 'query' )
);
}
return array(
'version' => TIOB_VERSION,
'nonce' => wp_create_nonce( 'wp_rest' ),
'assets' => TIOB_URL . 'assets/',
'upgradeURL' => $upgrade_url,
'upgradeURLTpc' => $upgrade_url_tpc,
'siteUrl' => trailingslashit( get_site_url() ),
'strings' => array(
/* translators: %s - Theme name */
'starterSitesTabDescription' => __( 'Choose from multiple unique demos, specially designed for you, that can be installed with a single click. You just need to choose your favorite, and we will take care of everything else.', 'templates-patterns-collection' ),
),
'cleanupAllowed' => ( ! empty( get_transient( Active_State::STATE_NAME ) ) ) ? 'yes' : 'no',
'onboarding' => array(),
'hasFileSystem' => WP_Filesystem(),
'themesURL' => admin_url( 'themes.php' ),
'themeAction' => $this->get_theme_action(),
'brandedTheme' => $this->get_whitelabel_name(),
'hideStarterSites' => $this->is_starter_sites_disabled(),
'hideMyLibrary' => $this->is_library_disabled(),
'fontParings' => $this->font_pairs_neve,
'endpoint' => ( defined( 'TPC_TEMPLATES_CLOUD_ENDPOINT' ) ) ? TPC_TEMPLATES_CLOUD_ENDPOINT : self::get_templates_cloud_endpoint(),
'params' => array(
'site_url' => get_site_url(),
'license_id' => License::get_license_data()->key,
),
'upsellNotifications' => $this->get_upsell_notifications(),
'isValidLicense' => $this->has_valid_addons(),
'licenseTIOB' => License::get_license_data(),
'emailSubscribe' => array(
'ajaxURL' => esc_url( admin_url( 'admin-ajax.php' ) ),
'nonce' => wp_create_nonce( 'skip_subscribe_nonce' ),
'skipStatus' => $this->get_skip_subscribe_status() ? 'yes' : 'no',
'email' => ( ! empty( $user->user_email ) ) ? $user->user_email : '',
),
'onboardingDone' => array(
'ajaxURL' => esc_url( admin_url( 'admin-ajax.php' ) ),
'nonce' => wp_create_nonce( 'onboarding_done_nonce' ),
),
'feedback' => array(
'count' => get_option( self::IMPORTED_TEMPLATES_COUNT_OPT, 0 ),
'dismissed' => get_option( self::FEEDBACK_DISMISSED_OPT, false ),
),
'onboardingUpsell' => array(
'dashboard' => tsdk_translate_link( tsdk_utmify( 'https://store.themeisle.com/', 'onboarding_upsell' ), 'query' ),
'contact' => tsdk_translate_link( tsdk_utmify( 'https://themeisle.com/contact/', 'onboarding_upsell' ), 'query' ),
'upgrade' => tsdk_translate_link( tsdk_utmify( 'https://themeisle.com/themes/neve/upgrade/', 'onboarding_upsell' ), 'query' ),
'upgradeToast' => tsdk_translate_link( tsdk_utmify( 'https://themeisle.com/themes/neve/upgrade/', 'onboarding_toast' ), 'query' ),
),
'onboardingAllowed' => $this->should_load_onboarding(),
'onboardingRedirect' => admin_url( 'admin.php?page=neve-onboarding' ),
'tiobSettings' => admin_url( 'admin.php?page=tiob-plugin#settings' ),
'links' => array(
array(
'label' => __( 'Support', 'templates-patterns-collection' ),
'is_external' => true,
'url' => tsdk_translate_link( tsdk_utmify( 'https://themeisle.com/contact/', 'settings_page' ), 'query' ),
),
array(
'label' => __( 'Feature request', 'templates-patterns-collection' ),
'target' => '_self',
'url' => admin_url( 'admin.php?page=tiob-plugin&tab=feedback#settings' ),
),
array(
'label' => __( 'Leave a review', 'templates-patterns-collection' ),
'is_external' => true,
'url' => 'https://wordpress.org/support/plugin/templates-patterns-collection/reviews/#new-post',
),
array(
'label' => __( 'Documentation', 'templates-patterns-collection' ),
'url' => tsdk_utmify( 'https://docs.themeisle.com/article/1354-neve-template-cloud-library', 'settings_page' ),
'is_button' => true,
),
),
'isFSETheme' => self::is_fse_theme(),
'newTCNotice' => array(
'show' => get_option( self::TC_NEW_NOTICE_DISMISSED, 'no' ) !== 'yes' && self::has_legacy_template_cloud(),
'ajaxURL' => esc_url( admin_url( 'admin-ajax.php' ) ),
'nonce' => wp_create_nonce( 'dismiss_new_tc_notice' ),
),
'onboardingPluginCompatibility' => array(
'hyve-lite' => is_php_version_compatible( '8.1' ),
),
);
}
/**
* Check if the current theme is a FSE theme,
*
* @return bool
*/
public static function is_fse_theme() {
if ( function_exists( 'wp_is_block_theme' ) ) {
return (bool) wp_is_block_theme();
}
if ( function_exists( 'gutenberg_is_fse_theme' ) ) {
return (bool) gutenberg_is_fse_theme();
}
return false;
}
/**
* Neve Pro upsells.
* @return array
*/
private function get_upsell_notifications() {
$notifications['upsell_1'] = array(
// We use these strings in Neve already so lets reuse the translations here.
'text' => esc_html__( 'Purchase the Business plan or higher to get instant access to all Premium Starter Site Templates — including Expert Sites — and much more.', 'neve' ), //phpcs:ignore WordPress.WP.I18n.TextDomainMismatch
'cta' => __( 'Get Neve Business', 'neve' ), //phpcs:ignore WordPress.WP.I18n.TextDomainMismatch
'url' => tsdk_utmify( 'https://themeisle.com/themes/neve/upgrade/', '<builder_name>notice', 'nevedashboard' ),
);
return $notifications;
}
/**
* Gets theme action.
*/
private function get_theme_action() {
if ( defined( 'NEVE_VERSION' ) ) {
return false;
}
$themes = wp_get_themes();
foreach ( $themes as $theme_slug => $args ) {
$theme = wp_get_theme( $theme_slug );
if ( $theme->get( 'TextDomain' ) === 'neve' ) {
return array(
'action' => 'activate',
'slug' => $theme_slug,
'nonce' => wp_create_nonce( 'switch-theme_' . $theme_slug ),
);
}
}
return array(
'action' => 'install',
'slug' => 'neve',
'nonce' => wp_create_nonce( 'switch-theme_neve' ),
);
}
/**
* Check if we can use the font pair to check for Google fonts.
*
* @param array $font_pair The font pair.
* @param string $key The key to check.
*
* @return bool
*/
private function font_array_key_is_defined( $font_pair, $key = 'bodyFont' ) {
return isset( $font_pair[ $key ] ) && isset( $font_pair[ $key ]['fontSource'] ) && isset( $font_pair[ $key ]['font'] );
}
/**
* Check if the font pair is `Prata` and `Hanken Grotesk`.
*
* @param $font_pair
*
* @return bool
*/
private function is_font_prata_and_hanke( $font_pair ) {
return $this->font_array_key_is_defined( $font_pair, 'bodyFont' ) && $this->font_array_key_is_defined( $font_pair, 'headingFont' ) && 'Prata' === $font_pair['headingFont']['font'] && 'Hanken Grotesk' === $font_pair['bodyFont']['font'];
}
/**
* Get the slug from the font pair.
*
* @param array $font_pair The font pair.
*
* @return string
*/
private function get_slug_from_font_pair( $font_pair ) {
return strtolower( str_replace( ' ', '', $font_pair['headingFont']['font'] ) ) . '-' . strtolower( str_replace( ' ', '', $font_pair['bodyFont']['font'] ) );
}
/**
* Get font parings
*/
private function get_font_parings() {
$font_pair_neve = array(
array(
'headingFont' => array(
'font' => 'Inter',
'fontSource' => 'Google',
'previewSize' => '25px',
),
'bodyFont' => array(
'font' => 'Inter',
'fontSource' => 'Google',
),
),
array(
'headingFont' => array(
'font' => 'Playfair Display',
'fontSource' => 'Google',
'previewSize' => '27px',
),
'bodyFont' => array(
'font' => 'Source Sans Pro',
'fontSource' => 'Google',
'previewSize' => '18px',
),
),
array(
'headingFont' => array(
'font' => 'Montserrat',
'fontSource' => 'Google',
),
'bodyFont' => array(
'font' => 'Open Sans',
'fontSource' => 'Google',
),
),
array(
'headingFont' => array(
'font' => 'Nunito',
'fontSource' => 'Google',
),