PluginProbe
Wp Tracking Codes / 1.9.2
Wp Tracking Codes v1.9.2
trunk 1.0 1.0.1 1.0.2 1.0.3 1.0.4 1.1.0 1.1.0, 1.10.0 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 1.5.0 1.6.0 1.7.0 1.8.0 1.9.0 1.9.1 1.9.2 1.9.3
wp-tracking-codes / includes / class-register-codes.php

class-register-codes.php in Wp Tracking Codes 1.9.2, at includes/class-register-codes.php

424 lines 13.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Wp Tracking Register Codes class
4 *
5 * @package WooCommerc/Classes/API
6 * @version 2.11.0
7 */
8
9 if ( ! defined( 'ABSPATH' ) ) {
10 exit;
11 }
12
13 if ( ! class_exists( 'RegisterCodes' ) ) :
14 class RegisterCodes{
15 /**
16 * Holds the values to be used in the fields callbacks
17 */
18 private $options;
19
20 /**
21 * Instance of this class.
22 *
23 * @var object
24 */
25 protected static $instance = null;
26
27 /**
28 * Start up
29 */
30 private function __construct()
31 {
32 add_action( 'admin_menu', array( $this, 'add_submenu_page' ) );
33 add_action( 'admin_init', array( $this, 'page_init' ) );
34 }
35
36 /**
37 * Return an instance of this class.
38 *
39 * @return object A single instance of this class.
40 */
41 public static function get_instance() {
42 // If the single instance hasn't been set, set it now.
43 if ( null === self::$instance ) {
44 self::$instance = new self();
45 }
46
47 return self::$instance;
48 }
49
50 /**
51 * Add options page
52 */
53 public function add_submenu_page()
54 {
55 add_submenu_page(
56 'options-general.php', // admin page slug
57 __( 'WP Tracking Codes', 'wp-tracking-codes' ), // page title
58 __( 'WP Tracking Codes', 'wp-tracking-codes' ), // menu title
59 'manage_options', // capability required to see the page
60 'wp-tracking-codes', // admin page slug, e.g. options-general.php?page=wporg_options
61 array( $this, 'create_admin_page' ) // callback function to display the options page
62 );
63 }
64
65 /**
66 * Options page callback
67 */
68 public function create_admin_page()
69 {
70 $this->options = get_option( 'tracking_option' );
71 include 'admin/views/html-admin-page.php';
72 }
73
74 /**
75 * Register and add settings
76 */
77 public function page_init()
78 {
79 // Add the section to reading settings so we can add our
80 // fields to it
81 add_settings_section(
82 'tracking_section',
83 '',
84 array( $this, 'tracking_section_callback_function' ),
85 'wp-tracking-codes'
86 );
87 add_settings_section(
88 'google_merchant_section',
89 '',
90 array( $this, 'google_merchant_section_callback_function' ),
91 'wp-tracking-codes'
92 );
93 // Add the field with the names and function to use for our new
94 // settings, put it in our new section
95 add_settings_field(
96 'tracking_google_tag_manager',
97 'Google Tag Manager ID',
98 array( $this, 'tracking_google_tag_manager_callback_function' ),
99 'wp-tracking-codes',
100 'tracking_section'
101 );
102 add_settings_field(
103 'tracking_analytics_4',
104 'Google Analytics 4 (global tag)',
105 array( $this, 'tracking_analytics4_callback_function' ),
106 'wp-tracking-codes',
107 'tracking_section'
108 );
109 add_settings_field(
110 'tracking_analytics_remarketing',
111 'Google ADS (global tag)',
112 array( $this, 'tracking_analytics_remarketing_callback_function' ),
113 'wp-tracking-codes',
114 'tracking_section'
115 );
116 add_settings_field(
117 'tracking_facebook_pixel_code',
118 'Facebook Pixel ID',
119 array( $this, 'tracking_facebook_pixel_code_callback_function' ),
120 'wp-tracking-codes',
121 'tracking_section'
122 );
123 // settings checkbox
124 add_settings_field(
125 'tracking_google_merchant',
126 'Google Merchant ID - Customer Reviews',
127 array( $this, 'tracking_google_merchant_callback_function' ),
128 'wp-tracking-codes',
129 'google_merchant_section'
130 );
131 add_settings_field(
132 'tracking_google_merchant_estimative_delivery_days',
133 'Google Merchant Estimative Delivery Days - Customer Reviews',
134 array( $this, 'tracking_google_merchant_estimative_delivery_days_callback_function' ),
135 'wp-tracking-codes',
136 'google_merchant_section'
137 );
138 add_settings_field(
139 'data_layer_google_tag_manager',
140 'DataLayer Google Tag Manager',
141 array( $this, 'data_layer_google_tag_manager_callback_function' ),
142 'wp-tracking-codes',
143 'google_merchant_section'
144 );
145
146
147 // Register our setting so that $_POST handling is done for us and
148 // our callback function just has to echo the <input>
149 register_setting(
150 'wp-tracking-codes', // Option group
151 'tracking_option', // Option name
152 array( $this, 'sanitize' ) // Sanitize
153 );
154
155 }
156
157 /**
158 * Sanitize each setting field as needed
159 *
160 * @param array $input Contains all settings fields as array keys
161 */
162 public function sanitize( $input )
163 {
164 $new_input = array();
165 if( isset( $input['analytics'] ) )
166 $new_input['analytics'] = sanitize_text_field( $input['analytics'] );
167 if( isset( $input['analytics_4'] ) )
168 $new_input['analytics_4'] = sanitize_text_field( $input['analytics_4'] );
169 if( isset( $input['analytics_remarketing'] ) )
170 $new_input['analytics_remarketing'] = sanitize_text_field( $input['analytics_remarketing'] );
171 if( isset( $input['facebook_pixel_code'] ) )
172 $new_input['facebook_pixel_code'] = sanitize_text_field( $input['facebook_pixel_code'] );
173 if( isset( $input['google_tag_manager'] ) )
174 $new_input['google_tag_manager'] = sanitize_text_field( $input['google_tag_manager'] );
175 if( isset( $input['google_merchant'] ) )
176 $new_input['google_merchant'] = sanitize_text_field( $input['google_merchant'] );
177 if( isset( $input['google_merchant_estimative_delivery_days'] ) )
178 $new_input['google_merchant_estimative_delivery_days'] = sanitize_text_field( $input['google_merchant_estimative_delivery_days'] );
179 if( isset( $input['data_layer_google_tag_manager'] ) )
180 $new_input['data_layer_google_tag_manager'] = sanitize_text_field( $input['data_layer_google_tag_manager'] );
181 return $new_input;
182 }
183
184 /**
185 * Print the Section text
186 */
187 public function tracking_section_callback_function()
188 {
189 // print 'For all:';
190 }
191
192 /**
193 * Print the Section text
194 */
195 public function google_merchant_section_callback_function()
196 {
197 print '<div class="title-section-">'.esc_html_e( 'Only WooCommerce:', 'wp-tracking-codes' ).'</div>';
198
199 }
200
201 public function tracking_analytics4_callback_function()
202 {
203 printf(
204 '<input type="text" id="analytics_4" name="tracking_option[analytics_4]"/ value="%s">',
205 isset( $this->options['analytics_4'] ) ? esc_attr( $this->options['analytics_4']) : ''
206 );
207 printf(
208 '<div class="status" title="Running"><span class="dashicons %s"></span></span></div>',
209 isset( $this->options['analytics_4'] ) && !empty($this->options['analytics_4']) ? 'dashicons-yes' : ''
210 );
211 printf(
212 '<p class="description">'
213 );
214 printf(
215 /* translators: %1$s: search term */
216 esc_html__( 'Example: G-XXXXXXXXXX - %1$s', 'wp-tracking-codes' ),
217 sprintf(
218 '<a href="%s" target="_blank">%s</a>',
219 'https://developers.google.com/tag-platform/devguides/install-gtagjs#google-analytics',
220 esc_html__( 'Help me', 'wp-tracking-codes' )
221 )
222 );
223 printf(
224 '</p>'
225 );
226 }
227
228 public function tracking_analytics_remarketing_callback_function()
229 {
230 printf(
231 '<input type="text" id="analytics_remarketing" name="tracking_option[analytics_remarketing]"/ value="%s">',
232 isset( $this->options['analytics_remarketing'] ) ? esc_attr( $this->options['analytics_remarketing']) : ''
233 );
234 printf(
235 '<div class="status" title="Running"><span class="dashicons %s"></span></span></div>',
236 isset( $this->options['analytics_remarketing'] ) && !empty($this->options['analytics_remarketing']) ? 'dashicons-yes' : ''
237 );
238 printf(
239 '<p class="description">'
240 );
241 printf(
242 /* translators: %1$s: search term */
243 esc_html__( 'Example: AW-YYYYYY - %1$s', 'wp-tracking-codes' ),
244 sprintf(
245 '<a href="%s" target="_blank">%s</a>',
246 'https://developers.google.com/tag-platform/devguides/install-gtagjs#google-ads',
247 esc_html__( 'Help me', 'wp-tracking-codes' )
248 )
249 );
250 printf(
251 '</p>'
252 );
253 }
254
255 public function tracking_facebook_pixel_code_callback_function()
256 {
257 printf(
258 '<input type="text" id="facebook_pixel_code" name="tracking_option[facebook_pixel_code]" value="%s">',
259 isset( $this->options['facebook_pixel_code'] ) ? esc_attr( $this->options['facebook_pixel_code']) : ''
260 );
261 printf(
262 '<div class="status" title="Running"><span class="dashicons %s"></span></span></div>',
263 isset( $this->options['facebook_pixel_code'] ) && !empty($this->options['facebook_pixel_code']) ? 'dashicons-yes' : ''
264 );
265 printf(
266 '<p class="description">'
267 );
268 printf(
269 /* translators: %1$s: search term */
270 esc_html__( 'Example: 1234567890 - %1$s', 'wp-tracking-codes' ),
271 sprintf(
272 '<a href="%s" target="_blank">%s</a>',
273 'https://www.facebook.com/business/help/742478679120153/',
274 esc_html__( 'Help me', 'wp-tracking-codes' )
275 )
276 );
277 printf(
278 '</p>'
279 );
280 }
281
282 public function tracking_google_tag_manager_callback_function()
283 {
284 printf(
285 '<input type="text" id="google_tag_manager" name="tracking_option[google_tag_manager]" value="%s">',
286 isset( $this->options['google_tag_manager'] ) ? esc_attr( $this->options['google_tag_manager']) : ''
287 );
288 printf(
289 '<div class="status" title="Running"><span class="dashicons %s"></span></span></div>',
290 isset( $this->options['google_tag_manager'] ) && !empty($this->options['google_tag_manager']) ? 'dashicons-yes' : ''
291 );
292 printf(
293 '<p class="description">'
294 );
295 printf(
296 /* translators: %1$s: search term */
297 esc_html__( 'Example: GTM-XXXXXX - %1$s', 'wp-tracking-codes' ),
298 sprintf(
299 '<a href="%s" target="_blank">%s</a>',
300 'https://support.google.com/tagmanager/answer/6103696',
301 esc_html__( 'Help me', 'wp-tracking-codes' )
302 )
303 );
304 printf(
305 '</p>'
306 );
307 }
308
309 public function tracking_google_merchant_callback_function()
310 {
311 printf(
312 '<input type="text" id="google_merchant" name="tracking_option[google_merchant]" value="%s">',
313 isset( $this->options['google_merchant'] ) ? esc_attr( $this->options['google_merchant']) : ''
314 );
315 printf(
316 '<div class="status" title="Running"><span class="dashicons %s"></span></span></div>',
317 isset( $this->options['google_merchant'] ) && !empty($this->options['google_merchant']) && isset( $this->options['google_merchant_estimative_delivery_days'] ) && !empty($this->options['google_merchant_estimative_delivery_days']) ? 'dashicons-yes' : ''
318 );
319 printf(
320 '<p class="description">'
321 );
322 printf(
323 /* translators: %1$s: search term */
324 esc_html__( 'Example: 123456789 - %1$s', 'wp-tracking-codes' ),
325 sprintf(
326 '<a href="%s" target="_blank">%s</a><br/>',
327 'https://support.google.com/paymentscenter/answer/7163092?hl=en',
328 esc_html__( 'Help me', 'wp-tracking-codes' )
329 )
330 );
331 printf(
332 /* translators: %1$s: search term */
333 esc_html__( 'This function activates %1$s', 'wp-tracking-codes' ),
334 sprintf(
335 '<a href="%s" target="_blank">%s</a>',
336 'https://support.google.com/merchants/answer/190657?hl=en',
337 esc_html__( 'Seller ratings', 'wp-tracking-codes' )
338 )
339 );
340 printf(
341 /* translators: %1$s: search term */
342 esc_html__( ' on the purchase page - %1$s', 'wp-tracking-codes' ),
343 sprintf(
344 '<a href="%s" target="_blank">%s</a>',
345 'https://support.google.com/merchants/answer/7124018?hl=en&ref_topic=7105048',
346 esc_html__( 'Help me', 'wp-tracking-codes' )
347 )
348 );
349 printf(
350 '</p>'
351 );
352 }
353
354 public function tracking_google_merchant_estimative_delivery_days_callback_function()
355 {
356 printf(
357 '<input type="text" id="google_merchant_estimative_delivery_days" name="tracking_option[google_merchant_estimative_delivery_days]" value="%s">',
358 isset( $this->options['google_merchant_estimative_delivery_days'] ) ? esc_attr( $this->options['google_merchant_estimative_delivery_days']) : ''
359 );
360 printf(
361 esc_html__(' days','wp-tracking-codes')
362 );
363 printf(
364 '<div class="status" title="Running"><span class="dashicons %s"></span></span></div>',
365 isset( $this->options['google_merchant'] ) && !empty($this->options['google_merchant']) && isset( $this->options['google_merchant_estimative_delivery_days'] ) && !empty($this->options['google_merchant_estimative_delivery_days']) ? 'dashicons-yes' : ''
366 );
367 printf(
368 '<p class="description">'.esc_html__( 'Example: 9 - The estimated average number of delivery days for all orders', 'wp-tracking-codes' ).'</p>'
369 );
370 printf(
371 '<p class="description">'
372 );
373 printf(
374 /* translators: %1$s: search term */
375 esc_html__( 'This number added to the order day will be the date that Google will send the survey to the user email, if user allows - %1$s', 'wp-tracking-codes' ),
376 sprintf(
377 '<a href="%s" target="_blank">%s</a>',
378 'https://support.google.com/merchants/answer/7106244?hl=en&ref_topic=7105160&visit_id=637233659345484301-2826177191&rd=1',
379 esc_html__( 'How it works?', 'wp-tracking-codes' )
380 )
381 );
382 printf(
383 '</p>'
384 );
385 }
386
387 public function data_layer_google_tag_manager_callback_function($args)
388 {
389 $options = get_option('tracking_option');
390 $checked = ( isset($options['data_layer_google_tag_manager']) && $options['data_layer_google_tag_manager'] == 1) ? 1 : 0;
391
392 printf(
393 '<input type="checkbox" id="data_layer_google_tag_manager" name="tracking_option[data_layer_google_tag_manager]" value="1"' . checked( 1, $checked, false ) . '/>',
394 isset( $this->options['data_layer_google_tag_manager'] ) ? esc_attr( $this->options['data_layer_google_tag_manager']) : ''
395 );
396 printf(
397 '<p class="description">'
398 );
399 printf(
400 /* translators: %1$s: search term */
401 esc_html__( 'Activate to use datalayer with %1$s', 'wp-tracking-codes' ),
402 sprintf(
403 '<a href="%s" target="_blank">%s</a>',
404 'https://support.google.com/tagmanager/answer/6107169?hl=en#standard-ecommerce',
405 esc_html__( 'Standard Ecommerce (UA)', 'wp-tracking-codes' )
406 )
407 );
408 printf(
409 ' - <a href="%s" target="_blank">%s</a>',
410 'https://support.google.com/tagmanager/answer/6164391?hl=en',
411 esc_html__( 'Help me', 'wp-tracking-codes' )
412 );
413 printf(
414 '</p>'
415 );
416
417 }
418 }
419 endif;
420
421 if( is_admin() ){
422 RegisterCodes::get_instance();
423 }
424