PluginProbe
WP Coder – Insert & Manage Code Snippets / 3.5.1
WP Coder – Insert & Manage Code Snippets v3.5.1
4.5.1 1.1 2.3.1 2.3.2 2.4.1 2.5.1 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 3.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.1 3.1.1 3.2 3.2.1 3.3 3.4 3.5 3.5.1 All 39 releases
wp-coder / includes / snippets / class-tools.php

class-tools.php in WP Coder – Insert & Manage Code Snippets 3.5.1, at includes/snippets/class-tools.php

137 lines 4.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 use WPCoder\Dashboard\DBManager;
4 use WPCoder\Dashboard\FolderManager;
5 use WPCoder\WPCoder;
6
7 defined( 'ABSPATH' ) || exit;
8
9 class WPCoder_Lite_Tools {
10
11 /**
12 * @var false|mixed|null
13 */
14 private $options;
15
16 public function __construct() {
17 $options = get_option( '_wp_coder_tools', [] );
18 $this->options = $options;
19
20 if ( array_key_exists( 'enable_tracking_tool', $options ) ) {
21 add_action( 'wp_head', [ $this, 'add_tracking' ] );
22 }
23
24 if ( array_key_exists( 'enable_google_adsense', $options ) ) {
25 add_action( 'wp_head', array( $this, 'add_adsense_code' ) );
26 }
27
28 }
29
30
31 public function add_tracking(): void {
32
33 $user = wp_get_current_user();
34
35 if ( ! empty( $user->roles ) ) {
36 foreach ( $user->roles as $role ) {
37 if ( array_key_exists( 'disable_tracking_tool_user_' . $role, $this->options ) ) {
38 return;
39 }
40 }
41 }
42
43 // Google Analytics code
44 if ( ! empty( $this->options['tracking_tool_google'] ) ) { ?>
45 <script async
46 src="https://www.googletagmanager.com/gtag/js?id=<?php echo esc_attr( $this->options['tracking_tool_google'] ); ?>"></script>
47 <script>
48 window.dataLayer = window.dataLayer || [];
49
50 function gtag() {
51 dataLayer.push(arguments);
52 }
53
54 gtag("js", new Date());
55 gtag("config", "<?php echo esc_attr( $this->options['tracking_tool_google'] ); ?>");
56 </script>
57 <?php }
58
59 // Facebook Pixel code
60 if ( ! empty( $this->options['tracking_tool_facebook'] ) ) { ?>
61 <script>
62 !function (f, b, e, v, n, t, s) {
63 if (f.fbq) return;
64 n = f.fbq = function () {
65 n.callMethod ?
66 n.callMethod.apply(n, arguments) : n.queue.push(arguments)
67 };
68 if (!f._fbq) f._fbq = n;
69 n.push = n;
70 n.loaded = !0;
71 n.version = '2.0';
72 n.queue = [];
73 t = b.createElement(e);
74 t.async = !0;
75 t.src = v;
76 s = b.getElementsByTagName(e)[0];
77 s.parentNode.insertBefore(t, s)
78 }(window, document, 'script',
79 'https://connect.facebook.net/en_US/fbevents.js');
80 fbq('init', '<?php echo esc_attr( $this->options['tracking_tool_facebook'] ); ?>');
81 fbq('track', 'PageView');
82 </script>
83 <noscript>
84 <img height="1" width="1" style="display:none"
85 src="https://www.facebook.com/tr?id=<?php echo esc_attr( $this->options['tracking_tool_facebook'] ); ?>&ev=PageView&noscript=1"/>
86 </noscript>
87 <?php }
88
89 // Pintrest Pixel code
90 if ( ! empty( $this->options['tracking_tool_pintrest'] ) ) { ?>
91 <script type="text/javascript">
92 !function (e) {
93 if (!window.pintrk) {
94 window.pintrk = function () {
95 window.pintrk.queue.push(Array.prototype.slice.call(arguments))
96 };
97 var n = window.pintrk;
98 n.queue = [], n.version = "3.0";
99 var t = document.createElement("script");
100 t.async = !0, t.src = e;
101 var r = document.getElementsByTagName("script")[0];
102 r.parentNode.insertBefore(t, r)
103 }
104 }("https://s.pinimg.com/ct/core.js");
105 pintrk('load', '<?php echo esc_attr( $this->options['tracking_tool_pintrest'] ); ?>');
106 pintrk('page');
107 </script>
108 <noscript>
109 <img height="1" width="1" style="display:none;" alt=""
110 src="https://ct.pinterest.com/v3/?tid=<?php echo esc_attr( $this->options['tracking_tool_pintrest'] ); ?>&noscript=1"/>
111 </noscript>
112 <?php }
113 }
114
115 public function add_adsense_code() {
116
117 if(empty( $this->options['google_adsense_publisher'] )) {
118 return;
119 }
120
121 $user = wp_get_current_user();
122
123 if ( ! empty( $user->roles ) ) {
124 foreach ( $user->roles as $role ) {
125 if ( array_key_exists( 'disable_google_adsense_user_' . $role, $this->options ) ) {
126 return;
127 }
128 }
129 }
130
131 $output = '<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-'.esc_attr($this->options['google_adsense_publisher']).'" crossorigin="anonymous"></script>';
132 echo $output;
133 }
134
135 }
136
137 new WPCoder_Lite_Tools;