Skip to content
This repository has been archived by the owner on May 3, 2022. It is now read-only.

Commit

Permalink
Bump to version 1.2
Browse files Browse the repository at this point in the history
1. Use FrontDesk Campaign ID instead of WordPress page URL for
communication via the API
  • Loading branch information
Aaron Huisinga committed Dec 31, 2015
1 parent 5a8af14 commit 0a4e2bd
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 26 deletions.
27 changes: 25 additions & 2 deletions classes/class-frontdesk.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function createCampaign($title, $permalink)
{
try {
if ($this->api_key != null || $this->api_key != '') {
$this->guzzle->post($this->api_base . 'campaigns/', [
$response = $this->guzzle->post($this->api_base . 'campaigns/', [
'body' => [
'key' => $this->api_key,
'title' => $title,
Expand All @@ -60,12 +60,35 @@ public function createCampaign($title, $permalink)
]);

add_filter('redirect_post_location', [$this, 'add_success_var'], 99);

return $response->json()['data']['id'];
}
} catch (RequestException $e) {
add_filter('redirect_post_location', [$this, 'add_error_var'], 99);
}
}

/**
* Update an existing FrontDesk campaign
* with a new title or permalink.
*
* @param $id
* @param $title
* @param $permalink
*/
public function updateCampaign($id, $title, $permalink)
{
if ($this->api_key != null || $this->api_key != '') {
$this->guzzle->post($this->api_base . 'campaigns/' . $id, [
'body' => [
'key' => $this->api_key,
'title' => $title,
'source' => $permalink
]
]);
}
}

/**
* Create a prospect on tryfrontdesk.com
* using the given data.
Expand All @@ -81,7 +104,7 @@ public function createProspect($data)
$response = $this->guzzle->post($this->api_base . 'subscribers/', [
'body' => [
'key' => $this->api_key,
'source' => $data['source'],
'campaign_id' => $data['campaign_id'],
'email' => $data['email'],
'first_name' => $data['first_name']
]
Expand Down
24 changes: 17 additions & 7 deletions classes/class-homes-report.php
Original file line number Diff line number Diff line change
Expand Up @@ -612,11 +612,7 @@ public function create_frontdesk_campaign($post_ID)
if (get_post_type($post_ID) != $this->token)
return false;

if (($_POST['post_status'] != 'publish') || ($_POST['original_post_status'] == 'publish'))
return false;

global $wpdb;
$title = get_the_title($post_ID);
$permalink = get_permalink($post_ID);

// See if we're using domain mapping
Expand All @@ -632,7 +628,21 @@ public function create_frontdesk_campaign($post_ID)
$permalink = str_replace($domain, 'http://' . $mapped, $permalink);
}

$this->frontdesk->createCampaign($title, $permalink);
if (($_POST['post_status'] != 'publish') || ($_POST['original_post_status'] == 'publish')) {
$campaign_id = get_post_meta($post_ID, 'frontdesk_campaign', true);

if ($campaign_id != '' && is_int($campaign_id)) {
$this->frontdesk->updateCampaign($campaign_id, get_the_title($post_ID), $permalink);
}

return true;
}

$campaign_id = $this->frontdesk->createCampaign(get_the_title($post_ID), $permalink);

if (is_int($campaign_id)) {
update_post_meta($post_ID, 'frontdesk_campaign', $campaign_id);
}
}

/**
Expand Down Expand Up @@ -681,7 +691,7 @@ public function process_submission()
$page_id = sanitize_text_field($_POST['page_id']);
$first_name = sanitize_text_field($_POST['first_name']);
$email = sanitize_text_field($_POST['email']);
$source = sanitize_text_field($_POST['permalink']);
$frontdesk_campaign = sanitize_text_field($_POST['frontdesk_campaign']);
$location = sanitize_text_field($_POST['location']);
$price_range = sanitize_text_field($_POST['price']);

Expand All @@ -702,7 +712,7 @@ public function process_submission()

// Create the prospect on FrontDesk
$frontdesk_id = $this->frontdesk->createProspect([
'source' => $source,
'campaign_id' => $frontdesk_campaign,
'first_name' => $first_name,
'email' => $email
]);
Expand Down
4 changes: 2 additions & 2 deletions homes-report.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php namespace ColdTurkey\HomesReport;
/*
* Plugin Name: Homes Report
* Version: 1.1.3
* Version: 1.2
* Plugin URI: http://www.coldturkeygroup.com/
* Description: WordPress funnel that collects visitor contact information in exchange for a customized report from a Real Estate agent.
* Author: Cold Turkey Group
Expand All @@ -20,7 +20,7 @@
define('HOMES_REPORT_PLUGIN_PATH', trailingslashit(plugin_dir_path(__FILE__)));

if (!defined('HOMES_REPORT_PLUGIN_VERSION'))
define('HOMES_REPORT_PLUGIN_VERSION', '1.1.3');
define('HOMES_REPORT_PLUGIN_VERSION', '1.2');

require_once('classes/class-homes-report.php');

Expand Down
2 changes: 1 addition & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Contributors: Aaron Huisinga
Tags: real estate, platform, homes report
Requires at least: 3.5
Tested up to: 4.3
Stable tag: 1.1.3
Stable tag: 1.2

WordPress funnel that collects visitor contact information in exchange for a customized report from a Real Estate agent.

Expand Down
41 changes: 27 additions & 14 deletions templates/single-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

$id = get_the_ID();
$title = get_the_title();
$permalink = get_permalink();
$frontdesk_campaign = get_post_meta($id, 'frontdesk_campaign', true);
$broker = get_post_meta($id, 'legal_broker', true);
$page_title = get_post_meta($id, 'page_title', true);
$page_subtitle = get_post_meta($id, 'page_subtitle', true);
Expand Down Expand Up @@ -159,7 +159,7 @@
<input type="text" name="email" id="email" class="form-control" required="required" placeholder="Your Email Address">
</div>

<input name="permalink" type="hidden" value="<?= $permalink; ?>">
<input name="frontdesk_campaign" type="hidden" value="<?= $frontdesk_campaign ?>">
<input name="action" type="hidden" id="pf_homes_report_submit_form" value="pf_homes_report_submit_form">
<?php wp_nonce_field('pf_homes_report_submit_form', 'pf_homes_report_nonce'); ?>
<input name="page_id" type="hidden" value="<?= $id ?>">
Expand All @@ -182,26 +182,39 @@
</div>

<?php
if ( $retargeting != null ) {
if ($retargeting != null) {
?>
<!-- Facebook Pixel Code -->
<script>
!function(f,b,e,v,n,t,s){if(f.fbq)return;n=f.fbq=function(){n.callMethod?
n.callMethod.apply(n,arguments):n.queue.push(arguments)};if(!f._fbq)f._fbq=n;
n.push=n;n.loaded=!0;n.version='2.0';n.queue=[];t=b.createElement(e);t.async=!0;
t.src=v;s=b.getElementsByTagName(e)[0];s.parentNode.insertBefore(t,s)}(window,
document,'script','//connect.facebook.net/en_US/fbevents.js');

fbq('init', '<?= $retargeting ?>');
fbq('track', "PageView");</script>
!function (f, b, e, v, n, t, s) {
if (f.fbq)return;
n = f.fbq = function () {
n.callMethod ?
n.callMethod.apply(n, arguments) : n.queue.push(arguments)
};
if (!f._fbq)f._fbq = n;
n.push = n;
n.loaded = !0;
n.version = '2.0';
n.queue = [];
t = b.createElement(e);
t.async = !0;
t.src = v;
s = b.getElementsByTagName(e)[0];
s.parentNode.insertBefore(t, s)
}(window,
document, 'script', '//connect.facebook.net/en_US/fbevents.js');

fbq('init', '<?= $retargeting ?>');
fbq('track', "PageView");</script>
<noscript><img height="1" width="1" style="display:none"
src="https://www.facebook.com/tr?id=<?= $retargeting ?>&ev=PageView&noscript=1"
/></noscript>
src="https://www.facebook.com/tr?id=<?= $retargeting ?>&ev=PageView&noscript=1"
/></noscript>
<?php
echo '<input type="hidden" id="retargeting" value="' . $retargeting . '">';
}

if ( $conversion != null ) {
if ($conversion != null) {
echo '<input type="hidden" id="conversion" value="' . $conversion . '">';
}
?>
Expand Down

0 comments on commit 0a4e2bd

Please sign in to comment.