Plugin Directory

Changeset 891328


Ignore:
Timestamp:
04/11/2014 12:58:23 PM (12 years ago)
Author:
roblesterjr
Message:

Fixed bug where no field definitions caused error.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • marketo-lead-tracking/trunk/marketotracking.php

    r882948 r891328  
    44 * Plugin URI: http://www.rmlsoftwaresolutions.com/wordpress-plugins
    55 * Description: Attaches Marketo tracking code to website. Lets you map any form field to a specific field in marketo, including custom fields. NOTE: This is not a forms plugin. You use it in conjunction with your existing forms solution, or you can also use it with custom forms.
    6  * Version: 0.4
     6 * Version: 0.5
    77 * Author: Robert Lester
    88 * Author URI: http://www.rmlsoftwaresolutions.com
     
    6565function wmi_call_code() {
    6666    $j = get_option('wmi-mkto-field-map');
    67     $fields = json_decode($j);
    68     $output = '';
    69     foreach ($fields as $map) {
    70         foreach ($map as $k=>$v) {
    71             if (strpos($k, '*') !== false) {
    72                 $emailfield = $v;
    73                 $k = str_replace('*', '', $k);
     67    if ($j) {
     68        $fields = json_decode($j);
     69        $output = '';
     70        foreach ($fields as $map) {
     71            foreach ($map as $k=>$v) {
     72                if (strpos($k, '*') !== false) {
     73                    $emailfield = $v;
     74                    $k = str_replace('*', '', $k);
     75                }
     76                $sendval = $_POST[$v];
     77                if ($sendval) $output .= $k . ': decodeURIComponent("' . rawurlencode($sendval) . '"),';
     78                //if ($sendval) $output .= $k . ': "' . $sendval . '",';
    7479            }
    75             $sendval = $_POST[$v];
    76             if ($sendval) $output .= $k . ': decodeURIComponent("' . rawurlencode($sendval) . '"),';
    77             //if ($sendval) $output .= $k . ': "' . $sendval . '",';
    7880        }
    79     }
    80     $em = $_POST[$emailfield];
    81     $h = hash('sha1', get_option('wmi-mkto-api-key') . $em);
    82     $track = get_option('wmi-mkto-tracking');
    83     if ($em != '' || $track) {
    84     ?>
    85         <script type="text/javascript">
    86             document.write(unescape("%3Cscript src='//munchkin.marketo.net/munchkin.js' type='text/javascript'%3E%3C/script%3E"));
    87         </script>
    88         <script type="text/javascript">
    89             Munchkin.init("<?php echo get_option('wmi-mkto-account-id'); ?>");
    90         </script>
    91     <?php }
    92     if ($em != '') {
     81        $em = $_POST[$emailfield];
     82        $h = hash('sha1', get_option('wmi-mkto-api-key') . $em);
     83        $track = get_option('wmi-mkto-tracking');
     84        if ($em != '' || $track) {
    9385        ?>
    9486            <script type="text/javascript">
    95                 mktoMunchkinFunction("associateLead",{<?php echo rtrim($output, ','); ?>},"<?php echo $h; ?>");
     87                document.write(unescape("%3Cscript src='//munchkin.marketo.net/munchkin.js' type='text/javascript'%3E%3C/script%3E"));
    9688            </script>
    97         <?php
     89            <script type="text/javascript">
     90                Munchkin.init("<?php echo get_option('wmi-mkto-account-id'); ?>");
     91            </script>
     92        <?php }
     93        if ($em != '') {
     94            ?>
     95                <script type="text/javascript">
     96                    mktoMunchkinFunction("associateLead",{<?php echo rtrim($output, ','); ?>},"<?php echo $h; ?>");
     97                </script>
     98            <?php
     99        }
    98100    }
    99101}
Note: See TracChangeset for help on using the changeset viewer.