Changeset 2024950
- Timestamp:
- 02/05/2019 01:30:20 AM (7 years ago)
- Location:
- lcmd-tracking-codes/trunk
- Files:
-
- 5 edited
-
CHANGELOG.md (modified) (1 diff)
-
README.md (modified) (1 diff)
-
README.txt (modified) (1 diff)
-
includes/views/admin_options.php (modified) (2 diffs)
-
lcmd-tracking-codes.php (modified) (21 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lcmd-tracking-codes/trunk/CHANGELOG.md
r2008793 r2024950 1 1 # Changelog # 2 * 1.0.0 * 3 - Initial version 4 * 1.0.1 * 5 - Fix UA- validation 6 * 1.0.2 * 7 - Update version 8 * 1.0.3 * 9 - Fix GTM- validation + Brazilian language 2 * 1.1.0 * 3 - Fix General Settings 4 - Add Settings tab 5 - Add Contact Form 7 tab 6 10 7 * 1.0.4 * 11 8 - Fix General settings 12 9 - Allways publish general settings 13 10 - Fix minor bug 11 12 * 1.0.3 * 13 - Fix GTM- validation + Brazilian language 14 15 * 1.0.2 * 16 - Update version 17 18 * 1.0.1 * 19 - Fix UA- validation 20 21 * 1.0.0 * 22 - Initial version -
lcmd-tracking-codes/trunk/README.md
r1993730 r2024950 5 5 * Tested up to: 4.9 6 6 * Requires PHP: 7.0 7 * Stable tag: 1. 0.37 * Stable tag: 1.1.0 8 8 * License: AGPL-3.0 9 9 * License URI: https://www.gnu.org/licenses/agpl-3.0.en.html -
lcmd-tracking-codes/trunk/README.txt
r2008795 r2024950 5 5 Tested up to: 4.9 6 6 Requires PHP: 7.0 7 Stable tag: 1. 0.47 Stable tag: 1.1.0 8 8 License: AGPL-3.0 9 9 License URI: https://www.gnu.org/licenses/agpl-3.0.en.html -
lcmd-tracking-codes/trunk/includes/views/admin_options.php
r1993153 r2024950 3 3 <h1>LC Tracking Codes</h1> 4 4 <h2 class="nav-tab-wrapper"> 5 <a href="admin.php?page=lcmd-tracking-codes&tab=settings" class="nav-tab<?php if ( $tab == 'settings' ) echo ' nav-tab-active'; ?>">Settings</a> 5 6 <a href="admin.php?page=lcmd-tracking-codes&tab=google" class="nav-tab<?php if ( $tab == 'google' ) echo ' nav-tab-active'; ?>">Google</a> 6 7 <a href="admin.php?page=lcmd-tracking-codes&tab=bing" class="nav-tab<?php if ( $tab == 'bing' ) echo ' nav-tab-active'; ?>">Bing</a> 8 <a href="admin.php?page=lcmd-tracking-codes&tab=wpcf7" class="nav-tab<?php if ( $tab == 'wpcf7' ) echo ' nav-tab-active'; ?>">Contact Form 7</a> 7 9 <a href="admin.php?page=lcmd-tracking-codes&tab=general" class="nav-tab<?php if ( $tab == 'general' ) echo ' nav-tab-active'; ?>">General</a> 8 10 </h2> 9 11 <?php settings_errors( 'lcmd_tracking_codes_messages' ); ?> 10 12 <div class="wrap"> 13 14 <?php if ( $tab == 'settings' ) : ?> 15 <h2><?php echo __('Settings', self::get_text_domain()); ?></h2> 16 <form method="POST"> 17 <?php settings_fields( 'lcmd_tracking_codes_settings_group_' . $tab ); ?> 18 <input type="hidden" name="tab" value="settings"> 19 <?php foreach($settings_fields as $field) : ?> 20 <div class="form-check"> 21 <input type="checkbox" class="form-check-input" name="<?php echo $field['name']; ?>" id="<?php echo $field['id']; ?>" value="1" <?php if ($field['value'] == 1) { echo "checked"; } ?>> 22 <label for="<?php echo $field['name']; ?>"><?php echo $field['label']; ?></label> 23 <p class="help"><?php echo $field['help']; ?></p> 24 </div> 25 <?php endforeach; ?> 26 <?php submit_button( __('Save Settings', self::get_text_domain()) ); ?> 27 </form> 28 <?php endif; ?> 29 11 30 <?php if ( $tab == 'google' ) : ?> 12 31 <h2>Google Tracking Codes</h2> … … 63 82 <?php endif; ?> 64 83 84 <?php if ( $tab == 'wpcf7' ) : ?> 85 <h2>Contact Form 7</h2> 86 <form method="POST"> 87 <?php settings_fields( 'lcmd_tracking_codes_settings_group_' . $tab ); ?> 88 <input type="hidden" name="tab" value="wpcf7"> 89 <?php foreach($wpcf7_fields as $field) : ?> 90 <div class="form-check"> 91 <input type="checkbox" class="form-check-input" name="<?php echo $field['name']; ?>" id="<?php echo $field['id']; ?>" value="1" <?php if ($field['value'] == 1) { echo "checked"; } ?>> 92 <label for="<?php echo $field['name']; ?>"><?php echo $field['label']; ?></label> 93 <p class="help"><?php echo $field['help']; ?></p> 94 </div> 95 <?php endforeach; ?> 96 <?php submit_button( __('Save Settings', self::get_text_domain()) ); ?> 97 </form> 98 <?php endif; ?> 99 65 100 <?php if ( $tab == 'general' ) : ?> 66 101 <h2>General Tracking Codes</h2> -
lcmd-tracking-codes/trunk/lcmd-tracking-codes.php
r2008793 r2024950 101 101 // Add Meta Bing Webmaster 102 102 add_action( 'wp_head', array( $this, 'add_bing_webmaster' ) , 2 ); 103 104 // Add Contact Form 7 Google Analytics 105 add_action( 'wp_footer', array( $this, 'add_contact_form_7_google_analytics' ) , 2 ); 103 106 104 107 // Add General Tracking Code … … 215 218 { 216 219 $settings_group = 'lcmd_tracking_codes_settings'; 217 register_setting( $settings_group . '_google', 'lcmd_gscvc' ); 218 register_setting( $settings_group . '_google', 'lcmd_gscvf' ); 219 register_setting( $settings_group . '_google', 'lcmd_gau' ); 220 register_setting( $settings_group . '_google', 'lcmd_gtm' ); 221 register_setting( $settings_group . '_google', 'lcmd_gad' ); 222 register_setting( $settings_group . '_bing', 'lcmd_bc' ); 223 register_setting( $settings_group . '_bing', 'lcmd_bcf' ); 224 register_setting( $settings_group . '_general', 'lcmd_general' ); 220 register_setting( $settings_group . '_settings', 'lcmd_hide_when_auth' ); // Settings: Hide when user is authenticated 221 register_setting( $settings_group . '_google', 'lcmd_gscvc' ); // Google Search Console Verification Code 222 register_setting( $settings_group . '_google', 'lcmd_gscvf' ); // Google Search Console Verification File 223 register_setting( $settings_group . '_google', 'lcmd_gau' ); // Google Analitics Userid 224 register_setting( $settings_group . '_google', 'lcmd_gtm' ); // Google Tag Manager 225 register_setting( $settings_group . '_google', 'lcmd_gad' ); // Google Ads 226 // register_setting( $settings_group . '_google', 'lcmd_grc' ); // Google Remarketing Code 227 register_setting( $settings_group . '_bing', 'lcmd_bc' ); // Bing Code 228 register_setting( $settings_group . '_bing', 'lcmd_bcf' ); // Bing Verification File 229 register_setting( $settings_group . '_wpcf7', 'lcmd_cf7ga' ); // Contact Form 7 - Google Analytics 230 register_setting( $settings_group . '_general', 'lcmd_general' ); // General Code 225 231 } 226 232 … … 244 250 } 245 251 252 $settings_fields = array( 253 /* Hide on Admin */ 254 array( 255 'name' => 'lcmd_hide_when_auth', 256 'id' => 'lcmd_hide_when_auth', 257 'label' => __('Hide when a logged user is navigating', self::get_text_domain() ), 258 'help' => __('Set to true to hide all codes when a logged user is navigating through the site.', self::get_text_domain() ), 259 ), 260 ); 261 246 262 $google_fields = array( 263 /* Google Search Console Verification Code */ 247 264 array( 248 265 'name' => 'lcmd_gsvc', … … 254 271 'error_msg' => __( 'Invalid format for Google Verification Code. Please, enter only letters, numbers and/or underscore.', self::get_text_domain() ) 255 272 ), 273 /* Google Search Console Verification File */ 256 274 array( 257 275 'name' => 'lcmd_gsvf', … … 263 281 'error_msg' => __( 'This is not seem to be a valid Google Search Console file. Please, verify the file and resubmit.', self::get_text_domain() ), 264 282 ), 283 /* Google Analytics Userid */ 265 284 array( 266 285 'name' => 'lcmd_gau', … … 272 291 'error_msg' => __( 'Invalid format for Google Analytics. Please, enter a UA-XXXX code.', self::get_text_domain() ) 273 292 ), 293 /* Google Tag Manager */ 274 294 array( 275 295 'name' => 'lcmd_gtm', … … 281 301 'error_msg' => __( 'Invalid format for Google Tag Manager Id. Please, enter a GTM-XXXX code.', self::get_text_domain() ) 282 302 ), 303 /* Google Ads */ 283 304 array( 284 305 'name' => 'lcmd_gad', … … 288 309 'help' => __('Enter your ID Google Ads. Please, refer to <a href="https://ads.google.com" target="_blank">Google Ads</a> for more information.', self::get_text_domain() ) 289 310 ), 311 /* Google Remarketing Code */ 312 /* 313 array( 314 'name' => 'lcmd_grc', 315 'id' => 'lcmd_grc', 316 'label' => __('Google Remarketing', self::get_text_domain() ), 317 'placeholder' => __( 'XXXXXXXX', self::get_text_domain() ), 318 'help' => __('Enter your ID Google Remarketing Code. Please, refer to <a href="https://support.google.com/google-ads/answer/2476688?co=ADWORDS.IsAWNCustomer%3Dtrue&hl=pt-BR&oco=0" target="_blank">Google Remarketing</a> for more information.', self::get_text_domain() ) 319 ), 320 */ 290 321 ); 291 322 $bing_fields = array( 323 /* Bing Code */ 292 324 array( 293 325 'name' => 'lcmd_bc', … … 298 330 'error_msg' => __( 'Invalid format for your Bing Code. Please, enter only numbers and letters.', self::get_text_domain() ) 299 331 ), 332 /* Bing Code File */ 300 333 array( 301 334 'name' => 'lcmd_bcf', … … 307 340 ) 308 341 ); 342 343 $wpcf7_fields = array( 344 /* Contact Form 7 - Google Analytics */ 345 array( 346 'name' => 'lcmd_cf7ga', 347 'id' => 'lcmd_cf7ga', 348 'label' => __('Do you want track Contact Form 7 submission no Google Analytics?', self::get_text_domain()), 349 'help' => __('Set this to true to start tag forms submission.', self::get_text_domain()), 350 ) 351 ); 352 309 353 $general_fields = array( 354 /* General fields */ 310 355 array( 311 356 'name' => 'lcmd_general', … … 319 364 * Get field values 320 365 */ 366 /* Settings Fields */ 367 foreach( $settings_fields as $i => $field ) { 368 $settings_fields[$i]['value'] = get_option($field['name']); 369 } 370 371 /* Google Fields */ 321 372 foreach( $google_fields as $i => $field ) { 322 373 if ( 'lcmd_gsvf' != $field['name'] ) { … … 331 382 } 332 383 } 384 /* Bing Fields */ 333 385 foreach( $bing_fields as $i => $field ) { 334 386 if ( 'lcmd_bcf' != $field['name'] ) { … … 343 395 } 344 396 } 397 /* Contact Form 7 Fields */ 398 foreach( $wpcf7_fields as $i => $field ) { 399 $wpcf7_fields[$i]['value'] = get_option($field['name']); 400 } 401 /* General field */ 345 402 foreach( $general_fields as $i => $field ) { 346 403 $general_fields[$i]['value'] = get_option($field['name']); … … 354 411 if ( isset($_POST['tab']) ) { 355 412 switch( $_POST['tab'] ) { 413 414 /* Settings Fields Validation */ 415 case 'settings': 416 foreach( $settings_fields as $i => $field ) { 417 $has_error = false; 418 $p_field = sanitize_text_field( $_POST[$field['name']] ); 419 420 if ( isset($field['validate']) ) { 421 $e = call_user_func( __NAMESPACE__ . '\\' . $field['validate'], $p_field); 422 if ( ! $e ) { 423 $errors[] = array( 424 'id' => $field['id'], 425 'msg' => $field['error_msg'] 426 ); 427 $has_error = true; 428 } 429 } 430 431 if ( ! $has_error ) { 432 update_option($field['name'], $p_field); 433 $settings_fields[$i]['value'] = $p_field; 434 } 435 } 436 break; 437 438 /* Google Fields Validation*/ 356 439 case 'google': 357 440 foreach( $google_fields as $i => $field ) { … … 405 488 break; 406 489 490 /* Bing Fields Validation */ 407 491 case 'bing': 408 492 foreach( $bing_fields as $i => $field ) { … … 453 537 break; 454 538 539 /* Contact Form 7 Fields Validation */ 540 case 'wpcf7': 541 foreach( $wpcf7_fields as $i => $field ) { 542 $has_error = false; 543 $p_field = sanitize_text_field( $_POST[$field['name']] ); 544 545 if ( isset($field['validate']) ) { 546 $e = call_user_func( __NAMESPACE__ . '\\' . $field['validate'], $p_field); 547 if ( ! $e ) { 548 $errors[] = array( 549 'id' => $field['id'], 550 'msg' => $field['error_msg'] 551 ); 552 $has_error = true; 553 } 554 } 555 556 if ( ! $has_error ) { 557 update_option($field['name'], $p_field); 558 $wpcf7_fields[$i]['value'] = $p_field; 559 } 560 } 561 break; 562 563 /* General Fields Validation */ 455 564 case 'general': 456 565 foreach( $general_fields as $i => $field ) { … … 491 600 } 492 601 602 public function is_hidden() 603 { 604 605 $hide_when = ( get_option('lcmd_hide_when_auth', "0") ); 606 607 if ( empty( $hide_when ) ) { 608 $hide = false; 609 } else { 610 $hide_when = intval($hide_when); 611 612 if ( $hide_when && is_user_logged_in() ) { 613 $hide = true; 614 } else { 615 $hide = false; 616 } 617 } 618 619 return $hide; 620 } 621 493 622 /** 494 623 * Add Google Search Console Meta Tag … … 496 625 public function add_google_search_console() { 497 626 $gsc_code = get_option('lcmd_gsvc'); 498 if ( ! empty($gsc_code) && ! is_user_logged_in() ) {627 if ( ! empty($gsc_code) && ! $this->is_hidden() ) { 499 628 echo '<meta name="google-site-verification" content="' . $gsc_code . '">'; 500 629 } … … 506 635 public function add_google_analytics() { 507 636 $ga_uid = get_option('lcmd_gau'); 508 if ( ! empty($ga_uid) && ! is_user_logged_in() ) {637 if ( ! empty($ga_uid) && ! $this->is_hidden() ) { 509 638 echo ' 510 639 <!-- Global site tag (gtag.js) - Google Analytics --> … … 526 655 public function add_bing_webmaster() { 527 656 $bw_code = get_option('lcmd_bc'); 528 if ( ! empty($bw_code) && ! is_user_logged_in() ) {657 if ( ! empty($bw_code) && ! $this->is_hidden() ) { 529 658 echo '<meta name="msvalidate.01" content="' . $bw_code . '">'; 659 } 660 } 661 662 /** 663 * Add Contact Form 7 Google Analytics 664 */ 665 public function add_contact_form_7_google_analytics() { 666 $cf7_ga = get_option('lcmd_cf7ga'); 667 if ( ! empty($cf7_ga) && ! $this->is_hidden() ) { 668 echo ' 669 <script> 670 document.addEventListener( \'wpcf7mailsent\', function( event ) { 671 ga(\'send\', \'event\', \'Contact Form\', \'submit\'); 672 }, false ); 673 </script> 674 '; 530 675 } 531 676 } … … 538 683 $general = get_option('lcmd_general'); 539 684 // Allway publish general code. 540 echo esc_js( $general );685 echo '<script>' . esc_js( $general ) . '</script>'; 541 686 } 542 687 }
Note: See TracChangeset
for help on using the changeset viewer.