Plugin Directory

Changeset 2024950


Ignore:
Timestamp:
02/05/2019 01:30:20 AM (7 years ago)
Author:
lcloss
Message:

General code, Settings and Contact Form 7

Location:
lcmd-tracking-codes/trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • lcmd-tracking-codes/trunk/CHANGELOG.md

    r2008793 r2024950  
    11# 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
    107* 1.0.4 *
    118- Fix General settings
    129- Allways publish general settings
    1310- 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  
    55* Tested up to: 4.9
    66* Requires PHP: 7.0
    7 * Stable tag: 1.0.3
     7* Stable tag: 1.1.0
    88* License: AGPL-3.0
    99* License URI: https://www.gnu.org/licenses/agpl-3.0.en.html
  • lcmd-tracking-codes/trunk/README.txt

    r2008795 r2024950  
    55Tested up to: 4.9
    66Requires PHP: 7.0
    7 Stable tag: 1.0.4
     7Stable tag: 1.1.0
    88License: AGPL-3.0
    99License URI: https://www.gnu.org/licenses/agpl-3.0.en.html
  • lcmd-tracking-codes/trunk/includes/views/admin_options.php

    r1993153 r2024950  
    33        <h1>LC Tracking Codes</h1>
    44        <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>
    56            <a href="admin.php?page=lcmd-tracking-codes&tab=google" class="nav-tab<?php if ( $tab == 'google' ) echo ' nav-tab-active';  ?>">Google</a>
    67            <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>
    79            <a href="admin.php?page=lcmd-tracking-codes&tab=general" class="nav-tab<?php if ( $tab == 'general' ) echo ' nav-tab-active';  ?>">General</a>
    810        </h2>
    911        <?php settings_errors( 'lcmd_tracking_codes_messages' ); ?>
    1012        <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
    1130            <?php if ( $tab == 'google' ) : ?>
    1231            <h2>Google Tracking Codes</h2>
     
    6382            <?php endif; ?>
    6483
     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
    65100            <?php if ( $tab == 'general' ) : ?>
    66101            <h2>General Tracking Codes</h2>
  • lcmd-tracking-codes/trunk/lcmd-tracking-codes.php

    r2008793 r2024950  
    101101      // Add Meta Bing Webmaster
    102102      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 );
    103106     
    104107      // Add General Tracking Code
     
    215218   {
    216219      $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
    225231   }
    226232
     
    244250      }
    245251
     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
    246262      $google_fields = array(
     263         /* Google Search Console Verification Code */
    247264         array(
    248265            'name'   => 'lcmd_gsvc',
     
    254271            'error_msg' => __( 'Invalid format for Google Verification Code. Please, enter only letters, numbers and/or underscore.', self::get_text_domain() )
    255272         ),
     273         /* Google Search Console Verification File */
    256274         array(
    257275            'name'   => 'lcmd_gsvf',
     
    263281            'error_msg' => __( 'This is not seem to be a valid Google Search Console file. Please, verify the file and resubmit.', self::get_text_domain() ),
    264282         ),
     283         /* Google Analytics Userid */
    265284         array(
    266285            'name'   => 'lcmd_gau',
     
    272291            'error_msg' => __( 'Invalid format for Google Analytics. Please, enter a UA-XXXX code.', self::get_text_domain() )
    273292         ),
     293         /* Google Tag Manager */
    274294         array(
    275295            'name'   => 'lcmd_gtm',
     
    281301            'error_msg' => __( 'Invalid format for Google Tag Manager Id. Please, enter a GTM-XXXX code.', self::get_text_domain() )
    282302         ),
     303         /* Google Ads */
    283304         array(
    284305            'name'   => 'lcmd_gad',
     
    288309            '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() )
    289310         ),
     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         */
    290321      );
    291322      $bing_fields = array(
     323         /* Bing Code */
    292324         array(
    293325            'name'   => 'lcmd_bc',
     
    298330            'error_msg' => __( 'Invalid format for your Bing Code. Please, enter only numbers and letters.', self::get_text_domain() )
    299331         ),
     332         /* Bing Code File */
    300333         array(
    301334            'name'   => 'lcmd_bcf',
     
    307340         )
    308341      );
     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
    309353      $general_fields = array(
     354         /* General fields */
    310355         array(
    311356            'name'   => 'lcmd_general',
     
    319364       * Get field values
    320365       */
     366      /* Settings Fields */
     367      foreach( $settings_fields as $i => $field ) {
     368         $settings_fields[$i]['value'] = get_option($field['name']);
     369      }
     370
     371      /* Google Fields */
    321372      foreach( $google_fields as $i => $field ) {
    322373         if ( 'lcmd_gsvf' != $field['name'] ) {
     
    331382         }
    332383      }
     384      /* Bing Fields */
    333385      foreach( $bing_fields as $i => $field ) {
    334386         if ( 'lcmd_bcf' != $field['name'] ) {
     
    343395         }
    344396      }
     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 */
    345402      foreach( $general_fields as $i => $field ) {
    346403         $general_fields[$i]['value'] = get_option($field['name']);
     
    354411      if ( isset($_POST['tab']) ) {
    355412         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*/
    356439            case 'google':
    357440               foreach( $google_fields as $i => $field ) {
     
    405488               break;
    406489
     490            /* Bing Fields Validation */
    407491            case 'bing':
    408492               foreach( $bing_fields as $i => $field ) {
     
    453537               break;
    454538
     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 */
    455564            case 'general':
    456565               foreach( $general_fields as $i => $field ) {
     
    491600   }
    492601
     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
    493622   /**
    494623    * Add Google Search Console Meta Tag
     
    496625   public function add_google_search_console() {
    497626      $gsc_code = get_option('lcmd_gsvc');
    498       if ( ! empty($gsc_code) && ! is_user_logged_in() ) {
     627      if ( ! empty($gsc_code) && ! $this->is_hidden() ) {
    499628         echo '<meta name="google-site-verification" content="' . $gsc_code . '">';
    500629      }
     
    506635   public function add_google_analytics() {
    507636      $ga_uid = get_option('lcmd_gau');
    508       if ( ! empty($ga_uid) && ! is_user_logged_in() ) {
     637      if ( ! empty($ga_uid) && ! $this->is_hidden() ) {
    509638        echo '
    510639        <!-- Global site tag (gtag.js) - Google Analytics -->
     
    526655    public function add_bing_webmaster() {
    527656      $bw_code = get_option('lcmd_bc');
    528       if ( ! empty($bw_code) && ! is_user_logged_in() ) {
     657      if ( ! empty($bw_code) && ! $this->is_hidden() ) {
    529658         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        ';
    530675      }
    531676   }
     
    538683      $general = get_option('lcmd_general');
    539684      // Allway publish general code.
    540       echo esc_js( $general );
     685      echo '<script>' . esc_js( $general ) . '</script>';
    541686   }
    542687}
Note: See TracChangeset for help on using the changeset viewer.