Plugin Directory

Changeset 1382226


Ignore:
Timestamp:
03/30/2016 07:43:24 PM (10 years ago)
Author:
adamlytics
Message:

Updating code to prevent errors, also adding meta tag for quick and easy validation

Location:
adobe-dtm/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • adobe-dtm/trunk/adobe-dtm.php

    r1381562 r1382226  
    22/*
    33Plugin Name: Adobe DTM for Wordpress
    4 Version: 1.2
     4Version: 1.3
    55Plugin URI: http://www.searchdiscovery.com/adobe-dtm-for-wordpress/
    66Description: The first Adobe Dynamic Tag Management (DTM) plugin for WordPress.
     
    99*/
    1010
    11 define('SDIDTM_VERSION', '1.2');
     11define('SDIDTM_VERSION', '1.3');
    1212define('SDIDTM_PATH', plugin_dir_path(__FILE__));
    1313
     
    2727    if($isAssoc == true){
    2828      foreach($options as $opt){
    29         $value = $dtmSaved[$opt['name']];
     29        $value = isset($dtmSaved[$opt['name']]) ? $dtmSaved[$opt['name']] : '';
    3030        if(!$value){
    3131          $value = $opt['default'];
     
    3535        }
    3636        $newOptions[$opt['name']] = $opt;
    37         $newOptions[$opt['name']]['value'] = $value; 
     37        $newOptions[$opt['name']]['value'] = $value;
    3838      }
    3939    }
     
    4141      if($type == 'config'){
    4242        foreach($options as $opt){
    43           if($dtmSaved && $dtmSaved[$opt['name']]){
     43          if(isset($dtmSaved) && isset($dtmSaved[$opt['name']])){
    4444            $opt['value'] = $dtmSaved[$opt['name']];
    4545          }
     
    5858          $chk = $opt;
    5959          $ipt = $opt;
    60           if($dtmSaved && $dtmSaved['include-'.$opt['name']]){
     60          if(isset($dtmSaved) && isset($dtmSaved['include-'.$opt['name']])){
    6161            $chk['value'] = $dtmSaved['include-'.$opt['name']];
    6262          }
     
    8686      else if($type == 'disable'){
    8787        foreach($options as $opt){
    88           if(isset($dtmSaved) && $dtmSaved['disable-'.$opt['name']]){
     88          if(isset($dtmSaved) && isset($dtmSaved['disable-'.$opt['name']])){
    8989            $opt['value'] = $dtmSaved['disable-'.$opt['name']];
    9090          }
  • adobe-dtm/trunk/dtm.php

    r1067347 r1382226  
    11<?php
    2 global $dtm;
     2global $dtm, $v;
    33
    44function SDIDTM_checked( $args ){
     
    3131    }
    3232    if($d['code'] == 'guest' && count($current_user->roles) == 0){
    33       if(SDIDTM_checked($v)){
    34         $isDisabled = true;
    35       }
     33        if(isset($v)){
     34            if(SDIDTM_checked($v)){
     35                $isDisabled = true;
     36            }
     37        }
    3638    }
    3739  }
     
    98100  $s = $dtmSaved;
    99101
    100   $postType = SDIDTM_include($s['include-posttype']);
    101   $postLbl = SDIDTM_value($data['posttype']);
    102   $subPostType = SDIDTM_include($s['include-postsubtype']);
    103   $subPostLbl = SDIDTM_value($data['postsubtype']);
     102  $postType = isset($s['include-posttype']) ? SDIDTM_include($s['include-posttype']) : '';
     103  $postLbl = isset($data['posttype']) ? SDIDTM_value($data['posttype']) : '';
     104  $subPostType = isset($s['include-postsubtype']) ? SDIDTM_include($s['include-postsubtype']) : '';
     105  $subPostLbl = isset($data['postsubtype']) ? SDIDTM_value($data['postsubtype']) : '';
    104106
    105107  if(SDIDTM_disable()){
     
    108110
    109111  $date = array();
    110  
    111   if (SDIDTM_include($s['include-loggedin'])) {
    112     if (is_user_logged_in()) {
    113       $dataLayer[SDIDTM_value($data['loggedin'])] = "logged-in";
    114     } else {
    115       $dataLayer[SDIDTM_value($data['loggedin'])] = "logged-out";
    116     }
    117   }
    118 
    119   if (SDIDTM_include($s['include-userrole'])) {
    120     get_currentuserinfo();
    121     $dataLayer[SDIDTM_value($data['userrole'])] = ($current_user->roles[0] == NULL ? "guest" : $current_user->roles[0]);
    122   }
    123  
    124   if (SDIDTM_include($s['include-posttitle'])) {
    125     $dataLayer[SDIDTM_value($data['posttitle'])] = strip_tags(wp_title("|", false, "right"));
     112
     113  if(isset($s['include-loggedin'])){
     114      if (SDIDTM_include($s['include-loggedin'])) {
     115        if (is_user_logged_in()) {
     116          $dataLayer[SDIDTM_value($data['loggedin'])] = "logged-in";
     117        } else {
     118          $dataLayer[SDIDTM_value($data['loggedin'])] = "logged-out";
     119        }
     120      }
     121  }
     122
     123  if(isset($s['include-userrole'])){
     124      if (SDIDTM_include($s['include-userrole'])) {
     125        get_currentuserinfo();
     126        $dataLayer[SDIDTM_value($data['userrole'])] = ($current_user->roles[0] == NULL ? "guest" : $current_user->roles[0]);
     127      }
     128  }
     129
     130  if(isset($s['include-posttitle'])){
     131      if (SDIDTM_include($s['include-posttitle'])) {
     132        $dataLayer[SDIDTM_value($data['posttitle'])] = strip_tags(wp_title("|", false, "right"));
     133      }
    126134  }
    127135
     
    131139    }
    132140
    133     if(SDIDTM_include($s['include-custom'])){
    134       $meta = get_post_custom();
    135       $newmeta = array();
    136       foreach($meta as $mn=>$mv){
    137         if(strpos($mn, "_edit_")===false && strpos($mn, "_wp_")===false){
    138           $newmeta[$mn] = $mv;
    139         }
    140       }
    141       $dataLayer[SDIDTM_value($data['custom'])] = $newmeta;
     141    if(isset($s['include-custom'])){
     142        if(SDIDTM_include($s['include-custom'])){
     143          $meta = get_post_custom();
     144          $newmeta = array();
     145          foreach($meta as $mn=>$mv){
     146            if(strpos($mn, "_edit_")===false && strpos($mn, "_wp_")===false){
     147              $newmeta[$mn] = $mv;
     148            }
     149          }
     150          $dataLayer[SDIDTM_value($data['custom'])] = $newmeta;
     151        }
    142152    }
    143153
     
    149159    }
    150160
    151     if(SDIDTM_include($s['include-comments'])){
    152       if(comments_open()){
    153         $dataLayer[SDIDTM_value($data['comments'])] = get_comments_number();
    154       }
    155     }
    156    
    157     if (SDIDTM_include($s['include-categories'])) {
    158       $_post_cats = get_the_category();
    159       if ($_post_cats) {
    160         $dataLayer[SDIDTM_value($data['categories'])] = array();
    161         foreach ($_post_cats as $_one_cat) {
    162           $dataLayer[SDIDTM_value($data['categories'])][] = $_one_cat->slug;
    163         }
    164       }
    165     }
    166    
    167     if (SDIDTM_include($s['include-tags'])) {
    168       $_post_tags = get_the_tags();
    169       if ($_post_tags) {
    170         $dataLayer[SDIDTM_value($data['tags'])] = array();
    171         foreach ($_post_tags as $tag) {
    172           $dataLayer[SDIDTM_value($data['tags'])][] = $tag->slug;
    173         }
    174       }
    175     }
    176    
    177     if (SDIDTM_include($s['include-author'])) {
    178       $postuser = get_userdata($GLOBALS["post"]->post_author);
    179       if (false !== $postuser) {
    180         $dataLayer[SDIDTM_value($data['author'])] = $postuser->display_name;
    181       }
    182     }
    183    
     161    if(isset($s['include-comments'])){
     162        if(SDIDTM_include($s['include-comments'])){
     163          if(comments_open()){
     164            $dataLayer[SDIDTM_value($data['comments'])] = get_comments_number();
     165          }
     166        }
     167    }
     168
     169    if(isset($s['include-categories'])){
     170        if (SDIDTM_include($s['include-categories'])) {
     171          $_post_cats = get_the_category();
     172          if ($_post_cats) {
     173            $dataLayer[SDIDTM_value($data['categories'])] = array();
     174            foreach ($_post_cats as $_one_cat) {
     175              $dataLayer[SDIDTM_value($data['categories'])][] = $_one_cat->slug;
     176            }
     177          }
     178        }
     179    }
     180
     181    if(isset($s['include-tags'])){
     182        if (SDIDTM_include($s['include-tags'])) {
     183          $_post_tags = get_the_tags();
     184          if ($_post_tags) {
     185            $dataLayer[SDIDTM_value($data['tags'])] = array();
     186            foreach ($_post_tags as $tag) {
     187              $dataLayer[SDIDTM_value($data['tags'])][] = $tag->slug;
     188            }
     189          }
     190        }
     191    }
     192
     193    if(isset($s['include-author'])){
     194        if (SDIDTM_include($s['include-author'])) {
     195          $postuser = get_userdata($GLOBALS["post"]->post_author);
     196          if (false !== $postuser) {
     197            $dataLayer[SDIDTM_value($data['author'])] = $postuser->display_name;
     198          }
     199        }
     200    }
     201
    184202    $date["date"] = get_the_date();
    185203    $date["year"] = get_the_date("Y");
     
    187205    $date["day"] = get_the_date("d");
    188206  }
    189  
     207
    190208  if (is_archive() || is_post_type_archive()) {
    191209    if ($postType) {
    192210      $dataLayer[$postLbl] = get_post_type();
    193      
     211
    194212      if (is_category()) {
    195213        $dataLayer[$subPostLbl] = "category-" . get_post_type();
     
    202220      } else if (is_year()) {
    203221        $dataLayer[$subPostLbl] = "year-" . get_post_type();
    204        
     222
    205223        $date["year"] = get_the_date("Y");
    206224      } else if (is_month()) {
     
    210228      } else if (is_day()) {
    211229        $dataLayer[$subPostLbl] = "day-" . get_post_type();
    212        
     230
    213231        $date["date"] = get_the_date();
    214232        $date["year"] = get_the_date("Y");
     
    219237      } else if (is_date()) {
    220238        $dataLayer[$subPostLbl] = "date-" . get_post_type();
    221        
     239
    222240        $date["date"] = get_the_date();
    223241        $date["year"] = get_the_date("Y");
     
    226244      }
    227245    }
    228    
     246
    229247    if ((is_tax() || is_category()) && $SDIDTM_options[SDIDTM_include($s['include-categories'])]) {
    230248      $_post_cats = get_the_category();
     
    234252      }
    235253    }
    236    
     254
    237255    if (SDIDTM_include($s['include-author']) && (is_author())) {
    238256      $dataLayer[SDIDTM_value($data['author'])] = get_the_author();
    239257    }
    240258  }
    241  
     259
    242260  if (is_search()) {
    243261    if(SDIDTM_include($s['include-searchterm'])){
     
    251269    }
    252270  }
    253  
     271
    254272  if (is_front_page() && $postType) {
    255273    $dataLayer[$postLbl] = "homepage";
    256274  }
    257  
     275
    258276  if (!is_front_page() && is_home() && $postType) {
    259277    $dataLayer[$postLbl] = "blog-home";
    260278  }
    261  
    262   if (SDIDTM_include($s['include-postcount'])) {
    263     $dataLayer[SDIDTM_value($data['postcount'])] = (int)$wp_query->post_count;
    264     // $dataLayer["postCountTotal"] = (int)$wp_query->found_posts;
    265   }
    266 
    267   if (SDIDTM_include($s['include-postdate']) && count($date)>0) {
    268     $dataLayer[SDIDTM_value($data['postdate'])] = $date;
    269   }
    270  
     279
     280  if(isset($s['include-postcount'])){
     281      if (SDIDTM_include($s['include-postcount'])) {
     282        $dataLayer[SDIDTM_value($data['postcount'])] = (int)$wp_query->post_count;
     283        // $dataLayer["postCountTotal"] = (int)$wp_query->found_posts;
     284      }
     285  }
     286
     287  if(isset($s['include-postdate'])){
     288      if (SDIDTM_include($s['include-postdate']) && count($date)>0) {
     289        $dataLayer[SDIDTM_value($data['postdate'])] = $date;
     290      }
     291  }
     292
    271293  return $dataLayer;
    272294}
     
    275297  global $dtm;
    276298  $config = SDIDTM_get_options('config', true);
    277  
     299
    278300  $dataLayer = array();
    279301  $dataLayer = (array)apply_filters("sdidtm_build_datalayer", $dataLayer);
    280  
     302
    281303  $_dtm_header_content = '';
    282  
     304
    283305  if ($config['dtm-code']['value'] != "" && !SDIDTM_disable()) {
    284306    $_dtm_header_content.= '
     
    292314    }
    293315  }
    294  
    295   echo $_dtm_header_content;
     316
     317  echo $_dtm_header_content."\n<meta name=\"adobe-dtm-wordpress\" content=\"true\">";
    296318}
    297319
     
    300322  global $dtm;
    301323  $config = SDIDTM_get_options('config', true);
    302  
     324
    303325  $_dtm_tag = '';
    304  
     326
    305327  if ($config['dtm-code']['value'] != "" && !SDIDTM_checked($config['include-dtm-exists']) && !SDIDTM_disable()) {
    306328    $_dtm_tag.= '
     
    311333</script>';
    312334  }
    313  
     335
    314336  echo $_dtm_tag;
    315337}
  • adobe-dtm/trunk/readme.txt

    r1072944 r1382226  
    4949== Changelog ==
    5050
     51= 1.3 =
     52Updated code for servers with very strict PHP settings to prevent errors.  Also added a meta tag with name "adobe-dtm-wordpress" to easily identify if the plugin is installed successfully.
     53
    5154= 1.1 =
    5255Code enhancements.
Note: See TracChangeset for help on using the changeset viewer.