Skip to content

Commit

Permalink
Merge pull request #5 from katzwebservices/add-logging
Browse files Browse the repository at this point in the history
Logging
  • Loading branch information
zackkatz committed Apr 1, 2014
2 parents 8ae85da + 1476573 commit 0c87d92
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 5 deletions.
52 changes: 48 additions & 4 deletions infusionsoft.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Plugin Name: Gravity Forms Infusionsoft Add-On
Plugin URI: http://katz.co
Description: Integrates Gravity Forms with Infusionsoft allowing form submissions to be automatically sent to your Infusionsoft account
Version: 1.5.7.1
Version: 1.5.7.2
Author: Katz Web Services, Inc.
Author URI: http://www.katzwebservices.com
Expand Down Expand Up @@ -34,7 +34,7 @@ class GFInfusionsoft {
private static $path = "gravity-forms-infusionsoft/infusionsoft.php";
private static $url = "http://www.gravityforms.com";
private static $slug = "gravity-forms-infusionsoft";
private static $version = "1.5.7.1";
private static $version = "1.5.7.2";
private static $min_gravityforms_version = "1.3.9";
private static $is_debug = NULL;
private static $debug_js = false;
Expand All @@ -48,6 +48,8 @@ class GFInfusionsoft {
public static function init(){
global $pagenow;

self::log_debug('init version: ' . self::$version );

load_plugin_textdomain('gravity-forms-infusionsoft', FALSE, '/gravity-forms-infusionsoft/languages' );

if($pagenow === 'plugins.php') {
Expand All @@ -73,6 +75,9 @@ public static function init(){
if(self::has_access("gravityforms_infusionsoft")){
RGForms::add_settings_page("Infusionsoft", array("GFInfusionsoft", "settings_page"), self::get_base_url() . "/images/infusionsoft_wordpress_icon_32.png");
}

// Enable debug with Gravity Forms Logging Add-on
add_filter( 'gform_logging_supported', array( 'GFInfusionsoft', 'add_debug_settings' ) );
}

//integrating with Members plugin
Expand Down Expand Up @@ -1521,10 +1526,15 @@ public static function get_mapped_field_checkbox($variable_name, $selected_field
}

public static function export($entry, $form){

self::log_debug( 'init export. Entry ID: ' . $entry['id'] );

//Login to Infusionsoft
$api = self::get_api();
if(!empty($api->lastError))
if(!empty($api->lastError)) {
self::log_debug( 'Infusionsoft API Error: ' . print_r( $api->lastError, true ) );
return;
}

//loading data class
require_once(self::get_base_path() . "/data.php");
Expand All @@ -1539,9 +1549,13 @@ public static function export($entry, $form){

public static function export_feed($entry, $form, $feed, $api){

self::log_debug( '[Entry ID: '. $entry['id'] . '] Init Export Feed: ' . print_r( $feed, true ) );

$email_field_id = $feed["meta"]["field_map"]["Email"];
$email = $entry[$email_field_id];

self::log_debug( '[Entry ID: '. $entry['id'] . '] Email: ' . print_r( $email, true ) );

$merge_vars = array();

foreach($feed["meta"]["field_map"] as $var_tag => $field_id){
Expand Down Expand Up @@ -1571,18 +1585,24 @@ public static function export_feed($entry, $form, $feed, $api){
}
}

self::log_debug( '[Entry ID: '. $entry['id'] . '] Infusionsoft Merge Data: ' . print_r( $merge_vars, true ) );

$valid = self::test_api();

if($valid) {
$contact_id = self::add_contact($email, $merge_vars);

self::log_debug( '[Entry ID: '. $entry['id'] . '] Contact ID: ' . print_r( $contact_id, true ) );

if($contact_id) {
$tags_added = self::add_tags_to_contact($contact_id, $merge_vars, $feed, $entry, $form);
self::log_debug( '[Entry ID: '. $entry['id'] . '] Adding Tags: ' . print_r( $tags_added, true ) );
}
// Only set them as marketable if they opt-in
// http://help.infusionsoft.com/developers/services-methods/email/optIn
if(self::is_optin($form, $feed)) {
$opt_in = self::opt_in($email, $entry);
self::log_debug( '[Entry ID: '. $entry['id'] . '] Opt In: ' . print_r( $opt_in, true ) );
}

if(self::is_debug()) {
Expand All @@ -1597,11 +1617,14 @@ public static function export_feed($entry, $form, $feed, $api){
'Adding Tags' => $tags_added,
));
}

self::log_debug( '[Entry ID: '. $entry['id'] . '] Form Entry Data: ' . print_r( $entry, true ) );
self::log_debug( '[Entry ID: '. $entry['id'] . '] Posted Data ($_POST): ' . print_r( $_POST, true ) );
self::add_note($entry, $contact_id);

} elseif(current_user_can('administrator')) {
echo '<div class="error" id="message">'.wpautop(sprintf(__("The form didn't create a contact because the Infusionsoft Gravity Forms Add-on plugin isn't properly configured. %sCheck the configuration%s and try again.", 'gravity-forms-infusionsoft'), '<a href="'.admin_url('admin.php?page=gf_settings&amp;addon=Infusionsoft').'">', '</a>')).'</div>';

self::log_debug( '[Entry ID: '. $entry['id'] . '] '. "API Error: The form didn't create a contact because the Infusionsoft Gravity Forms Add-on plugin isn't properly configured. " );
}
}

Expand Down Expand Up @@ -1887,5 +1910,26 @@ static protected function get_base_path(){
return WP_PLUGIN_DIR . "/" . $folder;
}

/**
* Enables debug with Gravity Forms logging add-on
* @param array $supported_plugins List of plugins
*/
public static function add_debug_settings( $supported_plugins ) {
$supported_plugins['infusionsoft'] = 'Gravity Forms Infusionsoft Add-on';
return $supported_plugins;
}

/**
* Logs messages using Gravity Forms logging add-on
* @param string $message log message
* @return void
*/
public static function log_debug( $message ){
if ( class_exists("GFLogging") ) {
GFLogging::include_logger();
GFLogging::log_message('infusionsoft', $message, KLogger::DEBUG);
}
}


}
7 changes: 6 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Tags: gravity forms, forms, gravity, form, crm, gravity form, infusionsoft, Infusion Soft, small business, business, marketing, e-commerce
Requires at least: 3.3
Tested up to: 3.8
Stable tag: 1.5.7.1
Stable tag: 1.5.7.2
Contributors: katzwebdesign, katzwebservices
Donate link:https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=zackkatz%40gmail%2ecom&item_name=Gravity%20Forms%20Infusionsoft&no_shipping=0&no_note=1&tax=0&currency_code=USD&lc=US&bn=PP%2dDonationsBF&charset=UTF%2d8

Expand Down Expand Up @@ -60,6 +60,9 @@ This plugin is released under a GPL license.

== Changelog ==

= 1.5.7.2 =
* Added: Enable debug logging using Gravity Forms Logging Add-on

= 1.5.7.1 =
* Fixes PHP warning related with unkonw form_id index on line 772
* Fixes "Refresh Fields & Tags" link after saving feed - avoid feed duplication
Expand Down Expand Up @@ -153,6 +156,8 @@ This plugin is released under a GPL license.
* Liftoff!

== Upgrade Notice ==
= 1.5.7.2 =
* Added: Enable debug logging using Gravity Forms Logging Add-on

= 1.5.7.1 =
* Fixes PHP warning related with unkonw form_id index on line 772
Expand Down

0 comments on commit 0c87d92

Please sign in to comment.