PluginProbe
WP Coder – Insert & Manage Code Snippets / 4.3
WP Coder – Insert & Manage Code Snippets v4.3
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 4.3, at includes/snippets/class-tools.php

182 lines 5.9 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 $enabled = (bool) get_option( '_wpcoder_enable_debug_log' );
29 if ( $enabled ) {
30 add_action( 'plugins_loaded', [ $this, 'debug_log' ] );
31 add_action( 'admin_bar_menu', [ $this, 'admin_menu_debug' ], 90 );
32 }
33
34 if ( array_key_exists( 'show_page_debug_info', $options ) ) {
35 new WPCoder_Page_Info;
36 }
37
38 if ( array_key_exists( 'theme_switcher', $options ) ) {
39 new WPCoder_Theme_Switcher;
40 }
41
42 if ( array_key_exists( 'markdown_editor', $options ) ) {
43 new WPCoder_Markdown_Editor($options);
44 }
45
46 }
47
48 public function debug_log(): void {
49 error_reporting( E_ALL );
50 ini_set( 'log_errors', 1 );
51 ini_set( 'error_log', WP_CONTENT_DIR . '/debug.log' ); // Log file path
52 }
53
54 public function admin_menu_debug( $wp_admin_bar ): void {
55 if ( ! current_user_can( 'unfiltered_html' ) ) {
56 return;
57 }
58
59 $log_file = WP_CONTENT_DIR . '/debug.log';
60 if ( ! file_exists( $log_file ) || filesize( $log_file ) === 0 ) {
61 return;
62 }
63
64 $wp_admin_bar->add_node( [
65 'id' => 'wpcoder-debug-log-link',
66 'title' => '<span class="ab-icon dashicons-admin-tools" aria-hidden="true"></span><span class="ab-label">Debug Log</span>',
67 'href' => admin_url( 'admin.php?page=' . WPCoder::SLUG . '-debug' ),
68 'meta' => [
69 'title' => 'View Debug Log', // tooltip
70 ],
71 ] );
72 }
73
74 public function add_tracking(): void {
75
76 $user = wp_get_current_user();
77
78 if ( ! empty( $user->roles ) ) {
79 foreach ( $user->roles as $role ) {
80 if ( array_key_exists( 'disable_tracking_tool_user_' . $role, $this->options ) ) {
81 return;
82 }
83 }
84 }
85
86 // Google Analytics code
87 if ( ! empty( $this->options['tracking_tool_google'] ) ) { ?>
88 <script async
89 src="https://www.googletagmanager.com/gtag/js?id=<?php echo esc_attr( $this->options['tracking_tool_google'] ); ?>"></script>
90 <script>
91 window.dataLayer = window.dataLayer || [];
92
93 function gtag() {
94 dataLayer.push(arguments);
95 }
96
97 gtag("js", new Date());
98 gtag("config", "<?php echo esc_attr( $this->options['tracking_tool_google'] ); ?>");
99 </script>
100 <?php }
101
102 // Facebook Pixel code
103 if ( ! empty( $this->options['tracking_tool_facebook'] ) ) { ?>
104 <script>
105 !function (f, b, e, v, n, t, s) {
106 if (f.fbq) return;
107 n = f.fbq = function () {
108 n.callMethod ?
109 n.callMethod.apply(n, arguments) : n.queue.push(arguments)
110 };
111 if (!f._fbq) f._fbq = n;
112 n.push = n;
113 n.loaded = !0;
114 n.version = '2.0';
115 n.queue = [];
116 t = b.createElement(e);
117 t.async = !0;
118 t.src = v;
119 s = b.getElementsByTagName(e)[0];
120 s.parentNode.insertBefore(t, s)
121 }(window, document, 'script',
122 'https://connect.facebook.net/en_US/fbevents.js');
123 fbq('init', '<?php echo esc_attr( $this->options['tracking_tool_facebook'] ); ?>');
124 fbq('track', 'PageView');
125 </script>
126 <noscript>
127 <img height="1" width="1" style="display:none"
128 src="https://www.facebook.com/tr?id=<?php echo esc_attr( $this->options['tracking_tool_facebook'] ); ?>&ev=PageView&noscript=1"/>
129 </noscript>
130 <?php }
131
132 // Pintrest Pixel code
133 if ( ! empty( $this->options['tracking_tool_pintrest'] ) ) { ?>
134 <script type="text/javascript">
135 !function (e) {
136 if (!window.pintrk) {
137 window.pintrk = function () {
138 window.pintrk.queue.push(Array.prototype.slice.call(arguments))
139 };
140 var n = window.pintrk;
141 n.queue = [], n.version = "3.0";
142 var t = document.createElement("script");
143 t.async = !0, t.src = e;
144 var r = document.getElementsByTagName("script")[0];
145 r.parentNode.insertBefore(t, r)
146 }
147 }("https://s.pinimg.com/ct/core.js");
148 pintrk('load', '<?php echo esc_attr( $this->options['tracking_tool_pintrest'] ); ?>');
149 pintrk('page');
150 </script>
151 <noscript>
152 <img height="1" width="1" style="display:none;" alt=""
153 src="https://ct.pinterest.com/v3/?tid=<?php echo esc_attr( $this->options['tracking_tool_pintrest'] ); ?>&noscript=1"/>
154 </noscript>
155 <?php }
156 }
157
158 public function add_adsense_code(): void {
159
160 if ( empty( $this->options['google_adsense_publisher'] ) ) {
161 return;
162 }
163
164 $user = wp_get_current_user();
165
166 if ( ! empty( $user->roles ) ) {
167 foreach ( $user->roles as $role ) {
168 if ( array_key_exists( 'disable_google_adsense_user_' . $role, $this->options ) ) {
169 return;
170 }
171 }
172 }
173
174 // phpcs:disable WordPress.WP.EnqueuedResources.NonEnqueuedScript
175 echo '<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-' . esc_attr( $this->options['google_adsense_publisher'] ) . '" crossorigin="anonymous"></script>';
176 // phpcs:enable
177 }
178
179
180 }
181
182 new WPCoder_Lite_Tools;