forked from duracelltomi/gtm4wp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadmin.php
More file actions
1387 lines (1205 loc) · 58.5 KB
/
admin.php
File metadata and controls
1387 lines (1205 loc) · 58.5 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
/**
* Handle WordPress admin page related hooks and functions
*
* @package GTM4WP
* @author Thomas Geiger
* @copyright 2013- Geiger Tamás e.v. (Thomas Geiger s.e.)
* @license GNU General Public License, version 3
*/
define( 'GTM4WP_ADMINSLUG', 'gtm4wp-settings' );
define( 'GTM4WP_ADMIN_GROUP', 'gtm4wp-admin-group' );
define( 'GTM4WP_ADMIN_GROUP_GENERAL', 'gtm4wp-admin-group-general' );
define( 'GTM4WP_ADMIN_GROUP_GTMID', 'gtm4wp-admin-group-gtm-id' );
define( 'GTM4WP_ADMIN_GROUP_CONTAINERON', 'gtm4wp-admin-container-on' );
define( 'GTM4WP_ADMIN_GROUP_COMPATMODE', 'gtm4wp-admin-compat-mode' );
define( 'GTM4WP_ADMIN_GROUP_INFO', 'gtm4wp-admin-group-datalayer-info' );
define( 'GTM4WP_ADMIN_GROUP_INCLUDES', 'gtm4wp-admin-group-includes' );
define( 'GTM4WP_ADMIN_GROUP_EVENTS', 'gtm4wp-admin-group-events' );
define( 'GTM4WP_ADMIN_GROUP_SCROLLER', 'gtm4wp-admin-group-scroller' );
define( 'GTM4WP_ADMIN_GROUP_BLACKLIST', 'gtm4wp-admin-group-blacklist-tags' );
define( 'GTM4WP_ADMIN_GROUP_INTEGRATION', 'gtm4wp-admin-group-integration' );
define( 'GTM4WP_ADMIN_GROUP_ADVANCED', 'gtm4wp-admin-group-advanced' );
define( 'GTM4WP_ADMIN_GROUP_CREDITS', 'gtm4wp-admin-group-credits' );
define( 'GTM4WP_USER_NOTICES_KEY', 'gtm4wp_user_notices_dismisses_json' );
define( 'GTM4WP_PHASE_STABLE', 'gtm4wp-phase-stable' );
define( 'GTM4WP_PHASE_BETA', 'gtm4wp-phase-beta' );
define( 'GTM4WP_PHASE_EXPERIMENTAL', 'gtm4wp-phase-experimental' );
define( 'GTM4WP_PHASE_DEPRECATED', 'gtm4wp-phase-deprecated' );
$GLOBALS['gtm4wp_def_user_notices_dismisses'] = array(
'enter-gtm-code' => false,
'wc-ga-plugin-warning' => false,
'wc-gayoast-plugin-warning' => false,
'php72-warning' => false,
'deprecated-warning' => false,
);
/**
* Generic function to safely escape translated text that outputs on the admin page.
* Allows only basic HTML tags for formatting purposes. No anchor element is allowed.
*
* @param string $text The admin text that needs escaping.
* @return string The escaped text.
*/
function gtm4wp_safe_admin_html( $text ) {
return wp_kses(
$text,
array(
'br' => array(),
'strong' => array(
'style' => array(),
'class' => array(),
),
'em' => array(
'style' => array(),
'class' => array(),
),
'p' => array(
'style' => array(),
'class' => array(),
),
'span' => array(
'style' => array(),
'class' => array(),
),
'code' => array(),
'ul' => array(
'style' => array(),
'class' => array(),
),
'li' => array(
'style' => array(),
'class' => array(),
),
)
);
}
/**
* Generic function to safely escape text that outputs on the admin page.
* Works just like gtm4wp_safe_admin_html() but also allows anchor elements.
*
* @param string $text The admin text that needs escaping.
* @return string The escaped text.
*/
function gtm4wp_safe_admin_html_with_links( $text ) {
return wp_kses(
$text,
array(
'br' => array(),
'strong' => array(
'style' => array(),
'class' => array(),
),
'em' => array(
'style' => array(),
'class' => array(),
),
'p' => array(
'style' => array(),
'class' => array(),
),
'span' => array(
'style' => array(),
'class' => array(),
),
'code' => array(),
'ul' => array(
'style' => array(),
'class' => array(),
),
'li' => array(
'style' => array(),
'class' => array(),
),
'a' => array(
'id' => array(),
'name' => array(),
'href' => array(),
'target' => array(),
'rel' => array(),
),
)
);
}
/**
* Callback function for add_settings_section(). Outputs the HTML of an admin tab.
*
* @see https://developer.wordpress.org/reference/functions/add_settings_section/
*
* @param array $args array of tab attributes.
* @return void
*/
function gtm4wp_admin_output_section( $args ) {
echo '<span class="tabinfo">';
switch ( $args['id'] ) {
case GTM4WP_ADMIN_GROUP_GENERAL:
sprintf(
// translators: 1: opening anchor tag linking to GTM's developer doc homepage. 2: Closing anchor tag.
esc_html__(
'This plugin is intended to be used by IT and marketing staff. Please be sure you read the
%1$sGoogle Tag Manager Help Center%2$s before you start using this plugin.<br /><br />',
'duracelltomi-google-tag-manager'
),
'<a href="https://developers.google.com/tag-manager/" target="_blank" rel="noopener">',
'</a>'
);
break;
case GTM4WP_ADMIN_GROUP_INCLUDES:
esc_html_e( 'Here you can check what data is needed to be included in the dataLayer to be able to access them in Google Tag Manager', 'duracelltomi-google-tag-manager' );
echo '<br />';
printf(
/* translators: 1: opening anchor tag that points to WhichBrowser website. 2: closing anchor tag. */
esc_html__(
'* Browser, OS and Device data is provided using %1$sWhichBrowser%2$s library.',
'duracelltomi-google-tag-manager'
),
'<a href="http://whichbrowser.net/" target="_blank" rel="noopener">',
'</a>'
);
break;
case GTM4WP_ADMIN_GROUP_EVENTS:
esc_html_e( 'Fire tags in Google Tag Manager on special events on your website', 'duracelltomi-google-tag-manager' );
break;
case GTM4WP_ADMIN_GROUP_SCROLLER:
esc_html_e( 'Fire tags based on how the visitor scrolls through your page.', 'duracelltomi-google-tag-manager' );
echo '<br />';
printf(
/* translators: 1: opening anchor tag that points to the corresponding Analytics Talks blog post. 2: closing anchor tag. */
esc_html__(
'Based on the script originaly posted to %1$sAnalytics Talk%2$s',
'duracelltomi-google-tag-manager'
),
'<a href="http://cutroni.com/blog/2012/02/21/advanced-content-tracking-with-google-analytics-part-1/" target="_blank" rel="noopener">',
'</a>'
);
break;
case GTM4WP_ADMIN_GROUP_BLACKLIST:
esc_html_e( 'Here you can control which types of tags, triggers and variables can be executed on your site regardless of what tags are included in your container on the Google Tag Manager site. Use this to increase security!', 'duracelltomi-google-tag-manager' );
echo '<br />';
esc_html_e( 'Do not modify if you do not know what to do, since it can cause issues with your tag deployment!', 'duracelltomi-google-tag-manager' );
echo '<br />';
esc_html_e( 'For example blacklisting everything and only whitelisting the Google Analytics tag without whitelisting the URL variable type will cause your Google Analytics tags to be blocked anyway since the attached triggers (Page View) can not fire!', 'duracelltomi-google-tag-manager' );
break;
case GTM4WP_ADMIN_GROUP_INTEGRATION:
esc_html_e( 'Google Tag Manager for WordPress can integrate with several popular plugins. Please check the plugins you would like to integrate with:', 'duracelltomi-google-tag-manager' );
break;
case GTM4WP_ADMIN_GROUP_ADVANCED:
esc_html_e( 'You usually do not need to modify thoose settings. Please be carefull while hacking here.', 'duracelltomi-google-tag-manager' );
break;
case GTM4WP_ADMIN_GROUP_CREDITS:
esc_html_e( 'Some info about the author of this plugin', 'duracelltomi-google-tag-manager' );
break;
} // end switch
echo '</span>';
}
/**
* Callback function for add_settings_field() to output the HTML of a specific plugin option
*
* @see https://developer.wordpress.org/reference/functions/add_settings_field/
*
* @param array $args Field attributes as array key-value pairs. 'label_for' is the unique ID of the option. 'description' is usually outputed below the option field.
* @return void
*/
function gtm4wp_admin_output_field( $args ) {
global $gtm4wp_options, $gtm4wp_business_verticals;
switch ( $args['label_for'] ) {
case GTM4WP_ADMIN_GROUP_GTMID:
echo wp_kses(
sprintf(
'<input type="text" id="%s" name="%s" value="%s"%s />',
esc_attr( GTM4WP_OPTIONS . '[' . GTM4WP_OPTION_GTM_CODE . ']' ),
esc_attr( GTM4WP_OPTIONS . '[' . GTM4WP_OPTION_GTM_CODE . ']' ),
defined( 'GTM4WP_HARDCODED_GTM_ID' ) ? constant( 'GTM4WP_HARDCODED_GTM_ID' ) : $gtm4wp_options[ GTM4WP_OPTION_GTM_CODE ],
defined( 'GTM4WP_HARDCODED_GTM_ID' ) ? ' readonly="readonly"' : ''
),
array(
'input' => array(
'type' => array(),
'id' => array(),
'name' => array(),
'value' => array(),
'readonly' => array(),
),
)
);
echo '<br />';
// gtm4wp_safe_admin_html_with_links() calls wp_kses().
echo gtm4wp_safe_admin_html_with_links( $args['description'] ); // phpcs:ignore
if ( defined( 'GTM4WP_HARDCODED_GTM_ID' ) ) {
echo '<br /><span class="gtm_wpconfig_set">WARNING! Container ID was set and fixed in wp-config.php. If you wish to change this value, please edit your wp-config.php and change the container ID or remove the GTM4WP_HARDCODED_GTM_ID constant!</span>';
}
echo '<br /><span class="gtmid_validation_error">' . esc_html__( 'This does not seems to be a valid Google Tag Manager ID! Valid format: GTM-XXXXX where X can be numbers and capital letters. Use comma without any space (,) to enter multpile container IDs.', 'duracelltomi-google-tag-manager' ) . '</span>';
break;
case GTM4WP_ADMIN_GROUP_CONTAINERON:
// gtm4wp_safe_admin_html_with_links() calls wp_kses().
echo gtm4wp_safe_admin_html_with_links( $args['description'] ); // phpcs:ignore
echo '<br/><br/>';
echo '<input type="radio" id="' . esc_attr( GTM4WP_OPTIONS . '[container-on]_1' ) . '" name="' . esc_attr( GTM4WP_OPTIONS . '[container-on]' ) . '" value="1" ' . ( GTM4WP_PLACEMENT_OFF !== $gtm4wp_options[ GTM4WP_OPTION_GTM_PLACEMENT ] ? 'checked="checked"' : '' ) . '/> ' . esc_html__( 'On', 'duracelltomi-google-tag-manager' ) . '<br />';
echo '<input type="radio" id="' . esc_attr( GTM4WP_OPTIONS . '[container-on]_0' ) . '" name="' . esc_attr( GTM4WP_OPTIONS . '[container-on]' ) . '" value="0" ' . ( GTM4WP_PLACEMENT_OFF === $gtm4wp_options[ GTM4WP_OPTION_GTM_PLACEMENT ] ? 'checked="checked"' : '' ) . '/> ' . esc_html__( 'Off', 'duracelltomi-google-tag-manager' ) . '<br />';
break;
case GTM4WP_ADMIN_GROUP_COMPATMODE:
// gtm4wp_safe_admin_html_with_links() calls wp_kses().
echo gtm4wp_safe_admin_html_with_links( $args['description'] ); // phpcs:ignore
echo '<br/><br/>';
echo '<input type="radio" id="' . esc_attr( GTM4WP_OPTIONS . '[compat-mode]_' . GTM4WP_PLACEMENT_BODYOPEN_AUTO ) . '" name="' . esc_attr( GTM4WP_OPTIONS . '[compat-mode]' ) . '" value="' . esc_attr( GTM4WP_PLACEMENT_BODYOPEN_AUTO ) . '" ' . ( GTM4WP_PLACEMENT_BODYOPEN_AUTO === $gtm4wp_options[ GTM4WP_OPTION_GTM_PLACEMENT ] || GTM4WP_PLACEMENT_OFF === $gtm4wp_options[ GTM4WP_OPTION_GTM_PLACEMENT ] ? 'checked="checked"' : '' ) . '/> ' . esc_html__( 'Off (no tweak, right placement)', 'duracelltomi-google-tag-manager' ) . '<br />';
echo '<input type="radio" id="' . esc_attr( GTM4WP_OPTIONS . '[compat-mode]_' . GTM4WP_PLACEMENT_FOOTER ) . '" name="' . esc_attr( GTM4WP_OPTIONS . '[compat-mode]' ) . '" value="' . esc_attr( GTM4WP_PLACEMENT_FOOTER ) . '" ' . ( GTM4WP_PLACEMENT_FOOTER === $gtm4wp_options[ GTM4WP_OPTION_GTM_PLACEMENT ] ? 'checked="checked"' : '' ) . '/> ' . esc_html__( 'Footer of the page (not recommended by Google, Search Console verification will not work)', 'duracelltomi-google-tag-manager' ) . '<br />';
echo '<input type="radio" id="' . esc_attr( GTM4WP_OPTIONS . '[compat-mode]_' . GTM4WP_PLACEMENT_BODYOPEN ) . '" name="' . esc_attr( GTM4WP_OPTIONS . '[compat-mode]' ) . '" value="' . esc_attr( GTM4WP_PLACEMENT_BODYOPEN ) . '" ' . ( GTM4WP_PLACEMENT_BODYOPEN === $gtm4wp_options[ GTM4WP_OPTION_GTM_PLACEMENT ] ? 'checked="checked"' : '' ) . '/> ' . esc_html__( 'Manually coded (needs tweak in your template)', 'duracelltomi-google-tag-manager' ) . '<br />';
break;
case GTM4WP_OPTIONS . '[' . GTM4WP_OPTION_DATALAYER_NAME . ']':
echo '<input type="text" id="' . esc_attr( GTM4WP_OPTIONS . '[' . GTM4WP_OPTION_DATALAYER_NAME . ']' ) . '" name="' . esc_attr( GTM4WP_OPTIONS . '[' . GTM4WP_OPTION_DATALAYER_NAME . ']' ) . '" value="' . esc_attr( $gtm4wp_options[ GTM4WP_OPTION_DATALAYER_NAME ] ) . '" /><br />';
// gtm4wp_safe_admin_html_with_links() calls wp_kses().
echo gtm4wp_safe_admin_html_with_links( $args['description'] ); // phpcs:ignore
echo '<br /><span class="datalayername_validation_error">' . esc_html__( 'This does not seems to be a valid JavaScript variable name! Please check and try again', 'duracelltomi-google-tag-manager' ) . '</span>';
break;
case GTM4WP_OPTIONS . '[' . GTM4WP_OPTION_ENV_GTM_AUTH . ']':
echo wp_kses(
sprintf(
'<input type="text" id="%s" name="%s" value="%s"%s />',
esc_attr( GTM4WP_OPTIONS . '[' . GTM4WP_OPTION_ENV_GTM_AUTH . ']' ),
esc_attr( GTM4WP_OPTIONS . '[' . GTM4WP_OPTION_ENV_GTM_AUTH . ']' ),
defined( 'GTM4WP_HARDCODED_GTM_ENV_AUTH' ) ? constant( 'GTM4WP_HARDCODED_GTM_ENV_AUTH' ) : $gtm4wp_options[ GTM4WP_OPTION_ENV_GTM_AUTH ],
defined( 'GTM4WP_HARDCODED_GTM_ENV_AUTH' ) ? ' readonly="readonly"' : ''
),
array(
'input' => array(
'type' => array(),
'id' => array(),
'name' => array(),
'value' => array(),
'readonly' => array(),
),
)
);
echo '<br />';
// gtm4wp_safe_admin_html_with_links() calls wp_kses().
echo gtm4wp_safe_admin_html_with_links( $args['description'] ); // phpcs:ignore
if ( defined( 'GTM4WP_HARDCODED_GTM_ENV_AUTH' ) ) {
echo '<br /><span class="gtm_wpconfig_set">WARNING! Environment auth parameter was set and fixed in wp-config.php. If you wish to change this value, please edit your wp-config.php and change the parameter value or remove the GTM4WP_HARDCODED_GTM_ENV_AUTH constant!</span>';
}
echo '<br /><span class="gtmauth_validation_error">' . esc_html__( 'This does not seems to be a valid gtm_auth parameter! It should only contain letters, number and the "-" character. Please check and try again', 'duracelltomi-google-tag-manager' ) . '</span>';
break;
case GTM4WP_OPTIONS . '[' . GTM4WP_OPTION_ENV_GTM_PREVIEW . ']':
echo wp_kses(
sprintf(
'<input type="text" id="%s" name="%s" value="%s"%s />',
esc_attr( GTM4WP_OPTIONS . '[' . GTM4WP_OPTION_ENV_GTM_PREVIEW . ']' ),
esc_attr( GTM4WP_OPTIONS . '[' . GTM4WP_OPTION_ENV_GTM_PREVIEW . ']' ),
defined( 'GTM4WP_HARDCODED_GTM_ENV_PREVIEW' ) ? constant( 'GTM4WP_HARDCODED_GTM_ENV_PREVIEW' ) : $gtm4wp_options[ GTM4WP_OPTION_ENV_GTM_PREVIEW ],
defined( 'GTM4WP_HARDCODED_GTM_ENV_PREVIEW' ) ? ' readonly="readonly"' : ''
),
array(
'input' => array(
'type' => array(),
'id' => array(),
'name' => array(),
'value' => array(),
'readonly' => array(),
),
)
);
echo '<br />';
// gtm4wp_safe_admin_html_with_links() calls wp_kses().
echo gtm4wp_safe_admin_html_with_links( $args['description'] ); // phpcs:ignore
if ( defined( 'GTM4WP_HARDCODED_GTM_ENV_PREVIEW' ) ) {
echo '<br /><span class="gtm_wpconfig_set">WARNING! Environment preview parameter was set and fixed in wp-config.php. If you wish to change this value, please edit your wp-config.php and change the parameter value or remove the GTM4WP_HARDCODED_GTM_ENV_PREVIEW constant!</span>';
}
echo '<br /><span class="gtmpreview_validation_error">' . esc_html__( 'This does not seems to be a valid gtm_preview parameter! It should have the format "env-NN" where NN is an integer number. Please check and try again', 'duracelltomi-google-tag-manager' ) . '</span>';
break;
case GTM4WP_OPTIONS . '[' . GTM4WP_OPTION_BLACKLIST_ENABLE . ']':
echo '<input type="radio" id="' . esc_attr( GTM4WP_OPTIONS . '[' . GTM4WP_OPTION_BLACKLIST_ENABLE . ']_0' ) . '" name="' . esc_attr( GTM4WP_OPTIONS . '[' . GTM4WP_OPTION_BLACKLIST_ENABLE . ']' ) . '" value="0" ' . ( 0 === $gtm4wp_options[ GTM4WP_OPTION_BLACKLIST_ENABLE ] ? 'checked="checked"' : '' ) . '/> ' . esc_html__( 'Disable feature: control everything on Google Tag Manager interface', 'duracelltomi-google-tag-manager' ) . '<br />';
echo '<input type="radio" id="' . esc_attr( GTM4WP_OPTIONS . '[' . GTM4WP_OPTION_BLACKLIST_ENABLE . ']_1' ) . '" name="' . esc_attr( GTM4WP_OPTIONS . '[' . GTM4WP_OPTION_BLACKLIST_ENABLE . ']' ) . '" value="1" ' . ( 1 === $gtm4wp_options[ GTM4WP_OPTION_BLACKLIST_ENABLE ] ? 'checked="checked"' : '' ) . '/> ' . esc_html__( 'Allow all, except the checked items on all blacklist tabs (blacklist)', 'duracelltomi-google-tag-manager' ) . '<br />';
echo '<input type="radio" id="' . esc_attr( GTM4WP_OPTIONS . '[' . GTM4WP_OPTION_BLACKLIST_ENABLE . ']_2' ) . '" name="' . esc_attr( GTM4WP_OPTIONS . '[' . GTM4WP_OPTION_BLACKLIST_ENABLE . ']' ) . '" value="2" ' . ( 2 === $gtm4wp_options[ GTM4WP_OPTION_BLACKLIST_ENABLE ] ? 'checked="checked"' : '' ) . '/> ' . esc_html__( 'Block all, except the checked items on all blacklist tabs (whitelist)', 'duracelltomi-google-tag-manager' ) . '<br />';
// gtm4wp_safe_admin_html_with_links() calls wp_kses().
echo gtm4wp_safe_admin_html_with_links( $args['description'] ); // phpcs:ignore
break;
case GTM4WP_OPTIONS . '[' . GTM4WP_OPTION_INCLUDE_WEATHERUNITS . ']':
echo '<input type="radio" id="' . esc_attr( GTM4WP_OPTIONS . '[' . GTM4WP_OPTION_INCLUDE_WEATHERUNITS . ']_0' ) . '" name="' . esc_attr( GTM4WP_OPTIONS . '[' . GTM4WP_OPTION_INCLUDE_WEATHERUNITS . ']' ) . '" value="0" ' . ( 0 === $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_WEATHERUNITS ] ? 'checked="checked"' : '' ) . '/> ' . esc_html__( 'Celsius', 'duracelltomi-google-tag-manager' ) . '<br />';
echo '<input type="radio" id="' . esc_attr( GTM4WP_OPTIONS . '[' . GTM4WP_OPTION_INCLUDE_WEATHERUNITS . ']_1' ) . '" name="' . esc_attr( GTM4WP_OPTIONS . '[' . GTM4WP_OPTION_INCLUDE_WEATHERUNITS . ']' ) . '" value="1" ' . ( 1 === $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_WEATHERUNITS ] ? 'checked="checked"' : '' ) . '/> ' . esc_html__( 'Fahrenheit', 'duracelltomi-google-tag-manager' ) . '<br />';
// gtm4wp_safe_admin_html_with_links() calls wp_kses().
echo gtm4wp_safe_admin_html_with_links( $args['description'] ); // phpcs:ignore
break;
case GTM4WP_ADMIN_GROUP_INFO:
// gtm4wp_safe_admin_html_with_links() calls wp_kses().
echo gtm4wp_safe_admin_html_with_links( $args['description'] ); // phpcs:ignore
break;
case GTM4WP_OPTIONS . '[' . GTM4WP_OPTION_INTEGRATE_WCEECBRANDTAXONOMY . ']':
echo '<select id="' . esc_attr( GTM4WP_OPTIONS . '[' . GTM4WP_OPTION_INTEGRATE_WCEECBRANDTAXONOMY . ']' ) . '" name="' . esc_attr( GTM4WP_OPTIONS . '[' . GTM4WP_OPTION_INTEGRATE_WCEECBRANDTAXONOMY . ']' ) . '">';
echo '<option value="">(not set)</option>';
$gtm4wp_taxonomies = get_taxonomies(
array(
'show_ui' => true,
'public' => true,
'_builtin' => false,
),
'object',
'and'
);
foreach ( $gtm4wp_taxonomies as $onetaxonomy ) {
echo '<option value="' . esc_attr( $onetaxonomy->name ) . '"' . esc_attr( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCEECBRANDTAXONOMY ] === $onetaxonomy->name ? ' selected="selected"' : '' ) . '>' . esc_html( $onetaxonomy->label ) . '</option>';
}
echo '</select>';
break;
case GTM4WP_OPTIONS . '[' . GTM4WP_OPTION_INTEGRATE_WCBUSINESSVERTICAL . ']':
echo '<select id="' . esc_attr( GTM4WP_OPTIONS . '[' . GTM4WP_OPTION_INTEGRATE_WCBUSINESSVERTICAL . ']' ) . '" name="' . esc_attr( GTM4WP_OPTIONS . '[' . GTM4WP_OPTION_INTEGRATE_WCBUSINESSVERTICAL . ']' ) . '">';
foreach ( $gtm4wp_business_verticals as $vertical_id => $vertical_display_name ) {
echo '<option value="' . esc_attr( $vertical_id ) . '"' . esc_attr( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCBUSINESSVERTICAL ] === $vertical_id ? ' selected="selected"' : '' ) . '>' . esc_html( $vertical_display_name ) . '</option>';
}
echo '</select><br>';
// gtm4wp_safe_admin_html_with_links() calls wp_kses().
echo gtm4wp_safe_admin_html_with_links( $args['description'] ); // phpcs:ignore
break;
case GTM4WP_OPTIONS . '[' . GTM4WP_OPTION_NOGTMFORLOGGEDIN . ']':
$roles = get_editable_roles();
// gtm4wp_safe_admin_html_with_links() calls wp_kses().
echo gtm4wp_safe_admin_html_with_links( $args['description'] ); // phpcs:ignore
echo '<br/><br/>';
$saved_roles = explode( ',', $gtm4wp_options[ GTM4WP_OPTION_NOGTMFORLOGGEDIN ] );
foreach ( $roles as $role_id => $role_info ) {
$role_name = translate_user_role( $role_info['name'] );
echo '<input type="checkbox" id="' . esc_attr( GTM4WP_OPTIONS . '[' . $args['optionfieldid'] . ']_' . $role_id ) . '" name="' . esc_attr( GTM4WP_OPTIONS . '[' . $args['optionfieldid'] . '][]' ) . '" value="' . esc_attr( $role_id ) . '"' . esc_attr( in_array( $role_id, $saved_roles, true ) ? ' checked="checked"' : '' ) . '><label for="' . esc_attr( GTM4WP_OPTIONS . '[' . $args['optionfieldid'] . ']_' . $role_id ) . '">' . esc_html( $role_name ) . '</label><br/>';
}
break;
default:
if ( preg_match( '/' . GTM4WP_OPTIONS . '\\[blacklist\\-[^\\]]+\\]/i', $args['label_for'] ) ) {
if ( 'blacklist-sandboxed' === $args['entityid'] ) {
echo '<input type="checkbox" id="' . esc_attr( $args['label_for'] ) . '" name="' . esc_attr( $args['label_for'] ) . '" value="1" ' . checked( 1, $gtm4wp_options[ GTM4WP_OPTION_BLACKLIST_SANDBOXED ], false ) . ' /><br />';
} else {
echo '<input type="checkbox" id="' . esc_attr( $args['label_for'] ) . '" name="' . esc_attr( $args['label_for'] ) . '" value="1" ' . checked( 1, in_array( $args['entityid'], $gtm4wp_options[ GTM4WP_OPTION_BLACKLIST_STATUS ], true ), false ) . ' /><br />';
}
// gtm4wp_safe_admin_html_with_links() calls wp_kses().
echo gtm4wp_safe_admin_html_with_links( $args['description'] ); // phpcs:ignore
} else {
$optval = $gtm4wp_options[ $args['optionfieldid'] ];
switch ( gettype( $optval ) ) {
case 'boolean':
echo '<input type="checkbox" id="' . esc_attr( GTM4WP_OPTIONS . '[' . $args['optionfieldid'] . ']' ) . '" name="' . esc_attr( GTM4WP_OPTIONS . '[' . $args['optionfieldid'] . ']' ) . '" value="1" ' . checked( 1, $optval, false ) . ' /><br />';
break;
case 'integer':
echo '<input type="number" step="1" min="0" class="small-text" id="' . esc_attr( GTM4WP_OPTIONS . '[' . $args['optionfieldid'] . ']' ) . '" name="' . esc_attr( GTM4WP_OPTIONS . '[' . $args['optionfieldid'] . ']' ) . '" value="' . esc_attr( $optval ) . '" /><br />';
break;
default:
echo '<input type="text" id="' . esc_attr( GTM4WP_OPTIONS . '[' . $args['optionfieldid'] . ']' ) . '" name="' . esc_attr( GTM4WP_OPTIONS . '[' . $args['optionfieldid'] . ']' ) . '" value="' . esc_attr( $optval ) . '" size="80" /><br />';
} // end switch gettype optval
// gtm4wp_safe_admin_html_with_links() calls wp_kses().
echo gtm4wp_safe_admin_html_with_links( $args['description'] ); // phpcs:ignore
if ( isset( $args['plugintocheck'] ) && ( '' !== $args['plugintocheck'] ) ) {
if ( is_plugin_active( $args['plugintocheck'] ) ) {
echo '<br />' . sprintf(
// translators: 1: the name of the conflicting plugin being checked. 2: either 'active' or 'inactive' using bolded formatting.
esc_html__(
'This plugin (%1$s) is %2$s, it is strongly recommended to enable this integration!',
'duracelltomi-google-tag-manager'
),
esc_html( $args['plugintocheck'] ),
'<strong class="gtm4wp-plugin-active">active</strong>'
);
} else {
echo '<br />' . sprintf(
// translators: 1: the name of the conflicting plugin being checked. 2: either 'active' or 'inactive' using bolded formatting.
esc_html__(
'This plugin (%1$s) is %2$s, enabling this integration could cause issues on frontend!',
'duracelltomi-google-tag-manager'
),
esc_html( $args['plugintocheck'] ),
'<strong class="gtm4wp-plugin-not-active">not active</strong>'
);
}
}
}
} // end switch args label_for
}
/**
* Callback function for register_setting(). Sanitizes GTM4WP option values.
*
* @see https://developer.wordpress.org/reference/functions/register_setting/
*
* @param array $options Array of key-value pairs with GTM4WP options and values.
* @return mixed The sanitized option value.
*/
function gtm4wp_sanitize_options( $options ) {
global $wpdb, $gtm4wp_entity_ids;
$output = gtm4wp_reload_options();
foreach ( $output as $optionname => $optionvalue ) {
if ( isset( $options[ $optionname ] ) ) {
$newoptionvalue = $options[ $optionname ];
} else {
$newoptionvalue = '';
}
if ( GTM4WP_OPTION_INCLUDE_VISITOR_IP_HEADER === $optionname ) {
if ( '' !== $newoptionvalue ) {
$custom_header = strtoupper( str_replace( '-', '_', $newoptionvalue ) );
if ( preg_match( '/[A-Z0-9_]+/', $custom_header ) ) {
$output[ $optionname ] = $custom_header;
} else {
$output[ $optionname ] = '';
}
} else {
$output[ $optionname ] = $newoptionvalue;
}
} elseif ( 'include-' === substr( $optionname, 0, 8 ) ) {
// "include" settings.
$output[ $optionname ] = (bool) $newoptionvalue;
} elseif ( 'event-' === substr( $optionname, 0, 6 ) ) {
// dataLayer events.
$output[ $optionname ] = (bool) $newoptionvalue;
// clear oembed transients when feature is enabled because we need to hook into the oembed process to enable some 3rd party APIs.
if ( $output[ $optionname ] && ! $optionvalue ) {
if ( GTM4WP_OPTION_EVENTS_YOUTUBE === $optionname ) {
// TODO: replace with $wpdb->delete() https://developer.wordpress.org/reference/classes/wpdb/delete/.
$wpdb->query( "DELETE FROM $wpdb->postmeta WHERE meta_value LIKE '%youtube.com%' AND meta_key LIKE '_oembed_%'" ); // phpcs:ignore
}
if ( GTM4WP_OPTION_EVENTS_VIMEO === $optionname ) {
// TODO: replace with $wpdb->delete() https://developer.wordpress.org/reference/classes/wpdb/delete/.
$wpdb->query( "DELETE FROM $wpdb->postmeta WHERE meta_value LIKE '%vimeo.com%' AND meta_key LIKE '_oembed_%'" ); // phpcs:ignore
}
}
} elseif ( 'blacklist-' === substr( $optionname, 0, 10 ) ) {
// blacklist / whitelist entities.
if ( GTM4WP_OPTION_BLACKLIST_ENABLE === $optionname ) {
$output[ $optionname ] = (int) $options[ GTM4WP_OPTION_BLACKLIST_ENABLE ];
} elseif ( GTM4WP_OPTION_BLACKLIST_SANDBOXED === $optionname ) {
$output[ $optionname ] = (bool) $newoptionvalue;
} elseif ( GTM4WP_OPTION_BLACKLIST_STATUS === $optionname ) {
$selected_blacklist_entities = array();
foreach ( $gtm4wp_entity_ids as $gtm_entity_group_id => $gtm_entity_group_list ) {
foreach ( $gtm_entity_group_list as $gtm_entity_id => $gtm_entity_label ) {
$entity_option_id = 'blacklist-' . $gtm_entity_group_id . '-' . $gtm_entity_id;
if ( array_key_exists( $entity_option_id, $options ) ) {
$newoptionvalue = (bool) $options[ $entity_option_id ];
if ( $newoptionvalue ) {
$selected_blacklist_entities[] = $gtm_entity_id;
}
}
}
}
$output[ $optionname ] = implode( ',', $selected_blacklist_entities );
}
} elseif ( GTM4WP_OPTION_INTEGRATE_WCPRODPERIMPRESSION === $optionname ) {
$output[ $optionname ] = (int) $newoptionvalue;
} elseif ( GTM4WP_OPTION_INTEGRATE_WCORDERMAXAGE === $optionname ) {
$output[ $optionname ] = (int) $newoptionvalue;
} elseif ( GTM4WP_OPTION_INTEGRATE_WCDLMAXTIMEOUT === $optionname ) {
$output[ $optionname ] = (int) $newoptionvalue;
} elseif ( GTM4WP_OPTION_INTEGRATE_WCREMPRODIDPREFIX === $optionname ) {
$output[ $optionname ] = trim( (string) $newoptionvalue );
} elseif ( GTM4WP_OPTION_INTEGRATE_WCEECBRANDTAXONOMY === $optionname ) {
$output[ $optionname ] = trim( (string) $newoptionvalue );
} elseif ( GTM4WP_OPTION_INTEGRATE_WCBUSINESSVERTICAL === $optionname ) {
$output[ $optionname ] = trim( (string) $newoptionvalue );
} elseif ( GTM4WP_OPTION_GTMDOMAIN === $optionname ) {
// for PHP 7- compatibility.
if ( ! defined( 'FILTER_FLAG_HOSTNAME' ) ) {
define( 'FILTER_FLAG_HOSTNAME', 0 );
}
// remove https:// prefix if used.
$newoptionvalue = str_replace( 'https://', '', $newoptionvalue );
$newoptionvalue = filter_var( $newoptionvalue, FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME );
if ( false === $newoptionvalue ) {
$newoptionvalue = '';
}
$output[ $optionname ] = trim( (string) $newoptionvalue );
} elseif ( GTM4WP_OPTION_GTMCUSTOMPATH === $optionname ) {
// remove https:// prefix if used.
$newoptionvalue = trim( $newoptionvalue, "\n\r\t\v\x00" );
$gtm_custom_path_has_error = (bool) preg_match( '/^[a-zA-Z0-9\.\-\_\/]*$/', $newoptionvalue );
if ( false === $gtm_custom_path_has_error ) {
add_settings_error( GTM4WP_ADMIN_GROUP, GTM4WP_OPTIONS . '[' . GTM4WP_OPTION_GTMCUSTOMPATH . ']', esc_html__( 'Invalid GTM custom domain path. Value can include anything between a-z, A-Z, 0-9 or any of the characters . - _', 'duracelltomi-google-tag-manager' ) );
$newoptionvalue = '';
}
$output[ $optionname ] = $newoptionvalue;
} elseif ( GTM4WP_OPTION_INTEGRATE_AMPID === $optionname ) {
// Accelerated Mobile Pages settings.
$_ampid_val = trim( $newoptionvalue );
if ( '' === $_ampid_val ) {
$_ampid_list = array();
} else {
$_ampid_list = explode( ',', $_ampid_val );
}
$_ampid_haserror = false;
foreach ( $_ampid_list as $one_amp_id ) {
$_ampid_haserror = $_ampid_haserror || ! preg_match( '/^GTM-[A-Z0-9]+$/', $one_amp_id );
}
if ( $_ampid_haserror && ( count( $_ampid_list ) > 0 ) ) {
add_settings_error( GTM4WP_ADMIN_GROUP, GTM4WP_OPTIONS . '[' . GTM4WP_OPTION_INTEGRATE_AMPID . ']', esc_html__( 'Invalid AMP Google Tag Manager Container ID. Valid ID format: GTM-XXXXX. Use comma without additional space (,) to enter more than one ID.', 'duracelltomi-google-tag-manager' ) );
} else {
$output[ $optionname ] = $newoptionvalue;
}
} elseif ( substr( $optionname, 0, 10 ) === 'integrate-' ) {
// integrations.
$output[ $optionname ] = (bool) $newoptionvalue;
} elseif ( ( GTM4WP_OPTION_GTM_CODE === $optionname ) || ( GTM4WP_OPTION_DATALAYER_NAME === $optionname ) || ( GTM4WP_OPTION_ENV_GTM_AUTH === $optionname ) || ( GTM4WP_OPTION_ENV_GTM_PREVIEW === $optionname ) ) {
// GTM code or dataLayer variable name.
$newoptionvalue = trim( $newoptionvalue );
if ( GTM4WP_OPTION_GTM_CODE === $optionname ) {
$_gtmid_list = explode( ',', $newoptionvalue );
$_gtmid_haserror = false;
foreach ( $_gtmid_list as $one_gtm_id ) {
$_gtmid_haserror = $_gtmid_haserror || ! preg_match( '/^GTM-[A-Z0-9]+$/', $one_gtm_id );
}
if ( $_gtmid_haserror ) {
add_settings_error( GTM4WP_ADMIN_GROUP, GTM4WP_OPTIONS . '[' . GTM4WP_OPTION_GTM_CODE . ']', esc_html__( 'Invalid Google Tag Manager ID. Valid ID format: GTM-XXXXX. Use comma without additional space (,) to enter more than one container ID.', 'duracelltomi-google-tag-manager' ) );
} else {
$output[ $optionname ] = $newoptionvalue;
}
} elseif ( ( GTM4WP_OPTION_DATALAYER_NAME === $optionname ) && ( '' !== $newoptionvalue ) && ( ! preg_match( '/^[a-zA-Z][a-zA-Z0-9_-]*$/', $newoptionvalue ) ) ) {
add_settings_error( GTM4WP_ADMIN_GROUP, GTM4WP_OPTIONS . '[' . GTM4WP_OPTION_DATALAYER_NAME . ']', esc_html__( "Invalid dataLayer variable name. Please start with a character from a-z or A-Z followed by characters from a-z, A-Z, 0-9 or '_' or '-'!", 'duracelltomi-google-tag-manager' ) );
} elseif ( ( GTM4WP_OPTION_ENV_GTM_AUTH === $optionname ) && ( '' !== $newoptionvalue ) && ( ! preg_match( '/^[a-zA-Z0-9-_]+$/', $newoptionvalue ) ) ) {
add_settings_error( GTM4WP_ADMIN_GROUP, GTM4WP_OPTIONS . '[' . GTM4WP_OPTION_ENV_GTM_AUTH . ']', esc_html__( "Invalid gtm_auth environment parameter value. It should only contain letters, numbers or the '-' and '_' characters.", 'duracelltomi-google-tag-manager' ) );
} elseif ( ( GTM4WP_OPTION_ENV_GTM_PREVIEW === $optionname ) && ( '' !== $newoptionvalue ) && ( ! preg_match( '/^env-[0-9]+$/', $newoptionvalue ) ) ) {
add_settings_error( GTM4WP_ADMIN_GROUP, GTM4WP_OPTIONS . '[' . GTM4WP_OPTION_ENV_GTM_PREVIEW . ']', esc_html__( "Invalid gtm_preview environment parameter value. It should have the format 'env-NN' where NN is an integer number.", 'duracelltomi-google-tag-manager' ) );
} else {
$output[ $optionname ] = $newoptionvalue;
}
} elseif ( GTM4WP_OPTION_GTM_PLACEMENT === $optionname ) {
// GTM container ON/OFF + compat mode.
$container_on_off = isset( $options['container-on'] ) && $options['container-on'];
$container_compat = (int) ( isset( $options['compat-mode'] ) ? $options['compat-mode'] : 0 );
if ( ! $container_on_off ) {
$output[ $optionname ] = GTM4WP_PLACEMENT_OFF;
} else {
if ( ( $container_compat < 0 ) || ( $container_compat > 2 ) ) {
$container_compat = 2;
}
$output[ $optionname ] = $container_compat;
}
} elseif ( GTM4WP_OPTION_SCROLLER_CONTENTID === $optionname ) {
// scroll tracking content ID.
$output[ $optionname ] = trim( str_replace( '#', '', $newoptionvalue ) );
} elseif ( GTM4WP_OPTION_NOGTMFORLOGGEDIN === $optionname ) {
// do not output GTM container code for specific user roles.
if ( is_array( $newoptionvalue ) ) {
$output[ $optionname ] = implode( ',', $newoptionvalue );
} else {
$output[ $optionname ] = '';
}
} else {
// anything else.
switch ( gettype( $optionvalue ) ) {
case 'boolean':
$output[ $optionname ] = (bool) $newoptionvalue;
break;
case 'integer':
$output[ $optionname ] = (int) $newoptionvalue;
break;
default:
$output[ $optionname ] = $newoptionvalue;
} // end switch.
}
}
return $output;
}
/**
* Function for admin_init hook. Adds option page tabs.
*
* @see https://developer.wordpress.org/reference/hooks/admin_init/
*
* @return void
*/
function gtm4wp_admin_init() {
require_once __DIR__ . '/admin-tab-basicdata.php';
require_once __DIR__ . '/admin-tab-events.php';
require_once __DIR__ . '/admin-tab-scrolltracking.php';
require_once __DIR__ . '/admin-tab-integrate.php';
require_once __DIR__ . '/admin-tab-advanced.php';
global $gtm4wp_includefieldtexts, $gtm4wp_eventfieldtexts, $gtm4wp_integratefieldtexts, $gtm4wp_scrollerfieldtexts,
$gtm4wp_advancedfieldtexts, $gtm4wp_entity_ids;
register_setting(
GTM4WP_ADMIN_GROUP,
GTM4WP_OPTIONS,
array(
'sanitize_callback' => 'gtm4wp_sanitize_options',
)
);
add_settings_section(
GTM4WP_ADMIN_GROUP_GENERAL,
esc_html__( 'General', 'duracelltomi-google-tag-manager' ),
'gtm4wp_admin_output_section',
GTM4WP_ADMINSLUG
);
add_settings_field(
GTM4WP_ADMIN_GROUP_GTMID,
esc_html__( 'Google Tag Manager ID', 'duracelltomi-google-tag-manager' ),
'gtm4wp_admin_output_field',
GTM4WP_ADMINSLUG,
GTM4WP_ADMIN_GROUP_GENERAL,
array(
'label_for' => GTM4WP_ADMIN_GROUP_GTMID,
'description' => esc_html__( 'Enter your Google Tag Manager ID here. Use comma without space (,) to enter multiple IDs.', 'duracelltomi-google-tag-manager' ),
)
);
add_settings_field(
GTM4WP_ADMIN_GROUP_CONTAINERON,
esc_html__( 'Container code ON/OFF', 'duracelltomi-google-tag-manager' ),
'gtm4wp_admin_output_field',
GTM4WP_ADMINSLUG,
GTM4WP_ADMIN_GROUP_GENERAL,
array(
'label_for' => GTM4WP_ADMIN_GROUP_CONTAINERON,
'description' => gtm4wp_safe_admin_html(
__(
'Turning OFF the Google Tag Manager container itself will remove both the head and the body part of the container code but leave data layer codes working.<br/>
This should be only used in specific cases where you need to place the container code manually or using another tool.',
'duracelltomi-google-tag-manager'
)
),
)
);
add_settings_field(
GTM4WP_ADMIN_GROUP_COMPATMODE,
esc_html__( 'Container code compatibility mode', 'duracelltomi-google-tag-manager' ),
'gtm4wp_admin_output_field',
GTM4WP_ADMINSLUG,
GTM4WP_ADMIN_GROUP_GENERAL,
array(
'label_for' => GTM4WP_ADMIN_GROUP_COMPATMODE,
'description' => gtm4wp_safe_admin_html(
__(
'Compatibility mode decides where to put the second, so called <code><noscript></code> or <code><iframe></code> part of the GTM container code.<br />
This code is usually only executed if your visitor has disabled JavaScript for some reason.<br/>
It is also mandatory in order to verify your site in Google Search Console using the GTM method.<br/>
The main GTM container code will be placed into the <code><head></code> section of your webpages anyway (where it belongs to).<br/><br/>
If you select "Manually coded", you need to edit your template files and add the following line just after the opening <code><body></code> tag:<br />
<code><?php if ( function_exists( \'gtm4wp_the_gtm_tag\' ) ) { gtm4wp_the_gtm_tag(); } ?></code>',
'duracelltomi-google-tag-manager'
)
),
)
);
add_settings_section(
GTM4WP_ADMIN_GROUP_INCLUDES,
esc_html__( 'Basic data', 'duracelltomi-google-tag-manager' ),
'gtm4wp_admin_output_section',
GTM4WP_ADMINSLUG
);
foreach ( $gtm4wp_includefieldtexts as $fieldid => $fielddata ) {
$phase = isset( $fielddata['phase'] ) ? $fielddata['phase'] : GTM4WP_PHASE_STABLE;
add_settings_field(
'gtm4wp-admin-' . $fieldid . '-id',
$fielddata['label'] . '<span class="' . $phase . '"></span>',
'gtm4wp_admin_output_field',
GTM4WP_ADMINSLUG,
GTM4WP_ADMIN_GROUP_INCLUDES,
array(
'label_for' => 'gtm4wp-options[' . $fieldid . ']',
'description' => $fielddata['description'],
'optionfieldid' => $fieldid,
)
);
}
add_settings_section(
GTM4WP_ADMIN_GROUP_EVENTS,
esc_html__( 'Events', 'duracelltomi-google-tag-manager' ),
'gtm4wp_admin_output_section',
GTM4WP_ADMINSLUG
);
foreach ( $gtm4wp_eventfieldtexts as $fieldid => $fielddata ) {
$phase = isset( $fielddata['phase'] ) ? $fielddata['phase'] : GTM4WP_PHASE_STABLE;
add_settings_field(
'gtm4wp-admin-' . $fieldid . '-id',
$fielddata['label'] . '<span class="' . $phase . '"></span>',
'gtm4wp_admin_output_field',
GTM4WP_ADMINSLUG,
GTM4WP_ADMIN_GROUP_EVENTS,
array(
'label_for' => 'gtm4wp-options[' . $fieldid . ']',
'description' => $fielddata['description'],
'optionfieldid' => $fieldid,
)
);
}
add_settings_section(
GTM4WP_ADMIN_GROUP_SCROLLER,
esc_html__( 'Scroll tracking', 'duracelltomi-google-tag-manager' ),
'gtm4wp_admin_output_section',
GTM4WP_ADMINSLUG
);
foreach ( $gtm4wp_scrollerfieldtexts as $fieldid => $fielddata ) {
$phase = isset( $fielddata['phase'] ) ? $fielddata['phase'] : GTM4WP_PHASE_STABLE;
add_settings_field(
'gtm4wp-admin-' . $fieldid . '-id',
$fielddata['label'] . '<span class="' . $phase . '"></span>',
'gtm4wp_admin_output_field',
GTM4WP_ADMINSLUG,
GTM4WP_ADMIN_GROUP_SCROLLER,
array(
'label_for' => 'gtm4wp-options[' . $fieldid . ']',
'description' => $fielddata['description'],
'optionfieldid' => $fieldid,
)
);
}
add_settings_section(
GTM4WP_ADMIN_GROUP_BLACKLIST,
esc_html__( 'Security', 'duracelltomi-google-tag-manager' ),
'gtm4wp_admin_output_section',
GTM4WP_ADMINSLUG
);
add_settings_field(
GTM4WP_OPTION_BLACKLIST_ENABLE,
esc_html__( 'Enable blacklist/whitelist', 'duracelltomi-google-tag-manager' ),
'gtm4wp_admin_output_field',
GTM4WP_ADMINSLUG,
GTM4WP_ADMIN_GROUP_BLACKLIST,
array(
'label_for' => GTM4WP_OPTIONS . '[' . GTM4WP_OPTION_BLACKLIST_ENABLE . ']',
'description' => '',
'optionsfieldid' => GTM4WP_OPTION_BLACKLIST_ENABLE,
)
);
add_settings_field(
GTM4WP_OPTION_BLACKLIST_SANDBOXED,
esc_html__( 'Custom tag/variable templates', 'duracelltomi-google-tag-manager' ),
'gtm4wp_admin_output_field',
GTM4WP_ADMINSLUG,
GTM4WP_ADMIN_GROUP_BLACKLIST,
array(
'label_for' => GTM4WP_OPTIONS . '[' . GTM4WP_OPTION_BLACKLIST_SANDBOXED . ']',
'description' => '',
'entityid' => GTM4WP_OPTION_BLACKLIST_SANDBOXED,
)
);
foreach ( $gtm4wp_entity_ids as $gtm_entity_group_id => $gtm_entity_group_list ) {
foreach ( $gtm_entity_group_list as $gtm_entity_id => $gtm_entity_label ) {
add_settings_field(
'gtm4wp-admin-blacklist-' . $gtm_entity_group_id . '-' . $gtm_entity_id . '-id',
$gtm_entity_label,
'gtm4wp_admin_output_field',
GTM4WP_ADMINSLUG,
GTM4WP_ADMIN_GROUP_BLACKLIST,
array(
'label_for' => 'gtm4wp-options[blacklist-' . $gtm_entity_group_id . '-' . $gtm_entity_id . ']',
'description' => '',
'entityid' => $gtm_entity_id,
)
);
}
}
add_settings_section(
GTM4WP_ADMIN_GROUP_INTEGRATION,
esc_html__( 'Integration', 'duracelltomi-google-tag-manager' ),
'gtm4wp_admin_output_section',
GTM4WP_ADMINSLUG
);
foreach ( $gtm4wp_integratefieldtexts as $fieldid => $fielddata ) {
$phase = isset( $fielddata['phase'] ) ? $fielddata['phase'] : GTM4WP_PHASE_STABLE;
add_settings_field(
'gtm4wp-admin-' . $fieldid . '-id',
$fielddata['label'] . '<span class="' . $phase . '"></span>',
'gtm4wp_admin_output_field',
GTM4WP_ADMINSLUG,
GTM4WP_ADMIN_GROUP_INTEGRATION,
array(
'label_for' => 'gtm4wp-options[' . $fieldid . ']',
'description' => $fielddata['description'],
'optionfieldid' => $fieldid,
'plugintocheck' => isset( $fielddata['plugintocheck'] ) ? $fielddata['plugintocheck'] : '',
)
);
}
add_settings_section(
GTM4WP_ADMIN_GROUP_ADVANCED,
esc_html__( 'Advanced', 'duracelltomi-google-tag-manager' ),
'gtm4wp_admin_output_section',
GTM4WP_ADMINSLUG
);
foreach ( $gtm4wp_advancedfieldtexts as $fieldid => $fielddata ) {
$phase = isset( $fielddata['phase'] ) ? $fielddata['phase'] : GTM4WP_PHASE_STABLE;
add_settings_field(
'gtm4wp-admin-' . $fieldid . '-id',
$fielddata['label'] . '<span class="' . $phase . '"></span>',
'gtm4wp_admin_output_field',
GTM4WP_ADMINSLUG,
GTM4WP_ADMIN_GROUP_ADVANCED,
array(
'label_for' => 'gtm4wp-options[' . $fieldid . ']',
'description' => $fielddata['description'],
'optionfieldid' => $fieldid,
'plugintocheck' => isset( $fielddata['plugintocheck'] ) ? $fielddata['plugintocheck'] : '',
)
);
}
add_settings_section(
GTM4WP_ADMIN_GROUP_CREDITS,
esc_html__( 'Credits', 'duracelltomi-google-tag-manager' ),
'gtm4wp_admin_output_section',
GTM4WP_ADMINSLUG
);
add_settings_field(
GTM4WP_ADMIN_GROUP_INFO,
esc_html__( 'Author', 'duracelltomi-google-tag-manager' ),
'gtm4wp_admin_output_field',
GTM4WP_ADMINSLUG,
GTM4WP_ADMIN_GROUP_CREDITS,
array(
'label_for' => GTM4WP_ADMIN_GROUP_INFO,
'description' => '<strong>Thomas Geiger</strong><br />
Website: <a href="https://gtm4wp.com/" target="_blank" rel="noopener">gtm4wp.com</a><br />
<a href="https://www.linkedin.com/in/duracelltomi" target="_blank" rel="noopener">Me on LinkedIn</a><br />
<a href="https://www.linkedin.com/company/jabjab-online-marketing/" target="_blank" rel="noopener">JabJab Online Marketing on LinkedIn</a>',
)
);
// Apply oembed code changes on the admin as well since the oembed call on the admin is cached by WordPress into a transient that is applied on the frontend later.
require_once __DIR__ . '/../integration/youtube.php';
require_once __DIR__ . '/../integration/vimeo.php';
require_once __DIR__ . '/../integration/soundcloud.php';
}
/**
* Callback function for add_options_page(). Generates the GTM4WP plugin options page.
*
* @see https://developer.wordpress.org/reference/functions/add_options_page/
*
* @return void
*/
function gtm4wp_show_admin_page() {
global $gtp4wp_plugin_url;
?>
<div class="wrap">
<h2><?php esc_html_e( 'Google Tag Manager for WordPress options', 'duracelltomi-google-tag-manager' ); ?></h2>
<form action="options.php" method="post">
<?php settings_fields( GTM4WP_ADMIN_GROUP ); ?>
<?php do_settings_sections( GTM4WP_ADMINSLUG ); ?>
<?php submit_button(); ?>
</form>
</div>