Skip to content

Commit

Permalink
Merge pull request #1344 from angelleye/PFW-460
Browse files Browse the repository at this point in the history
Marketing Sidebar - Newsletter Signup Adjustment, PFW-460
  • Loading branch information
kcppdevelopers committed Aug 19, 2019
2 parents 11d69d3 + 9b86995 commit 2d87b85
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 24 deletions.
33 changes: 26 additions & 7 deletions template/sidebar-process.php
Original file line number Diff line number Diff line change
@@ -1,24 +1,43 @@
<?php

add_action('wp_ajax_angelleye_marketing_mailchimp_subscription', 'own_angelleye_marketing_mailchimp_subscription');
add_action('wp_ajax_angelleye_marketing_sendy_subscription', 'own_angelleye_marketing_sendy_subscription');

function own_angelleye_marketing_mailchimp_subscription() {
$url = 'https://angelleye.us7.list-manage.com/subscribe/post-json?u=4c6d56be138a966cd573c928f&id=84c27e6cd1';
$url = add_query_arg(array('EMAIL' => $_POST['email']), $url);
function own_angelleye_marketing_sendy_subscription() {
$url = 'https://sendy.angelleye.com/subscribe';
$response = wp_remote_post($url, array(
'method' => 'POST',
'timeout' => 45,
'redirection' => 5,
'httpversion' => '1.0',
'blocking' => true,
'headers' => array(),
'body' => array(),
'body' => array( 'list' => 'pjFolYKqSdLe57i4uuUz0g', 'boolean' => 'true', 'email' => $_POST['email'], 'gdpr' => 'true', 'silent' => 'true'),
'cookies' => array()
)
);
if (is_wp_error($response)) {
wp_send_json(wp_remote_retrieve_body($response));
} else {
wp_send_json(wp_remote_retrieve_body($response));
$body = wp_remote_retrieve_body($response);
$apiResponse = strval($body);
switch ( $apiResponse ) {
case 'true':
case '1':
prepareResponse( "true", 'Thank you for subscribing!' );
case 'Already subscribed.':
prepareResponse( "true", 'Already subscribed!' );
default:
prepareResponse( "false", $apiResponse );
}
}
}


}

function prepareResponse( $status = false, $msg = 'Something went wrong!' ) {
$return = array(
'result' => $status,
'message' => $msg
);
wp_send_json($return);
}
37 changes: 20 additions & 17 deletions template/sidebar.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,36 @@
</h2>
<div class="angelleye-wizard-text-input">
<label for="mce-EMAIL" class="angelleye-wizard-text-input-label">Email</label>
<input type="text" value="" id="angelleye_mailchimp_email" name="angelleye_mailchimp_email" class="email angelleye-wizard-text-input-field" placeholder="email address">
<input type="text" value="" id="angelleye_sendy_email" name="angelleye_sendy_email" class="email angelleye-wizard-text-input-field" placeholder="email address">
<div style="color: rgba(0, 0, 0, 0.87); background-color: rgb(255, 255, 255); transition: all 450ms cubic-bezier(0.23, 1, 0.32, 1) 0ms; box-sizing: border-box; font-family: Roboto, sans-serif; box-shadow: rgba(0, 0, 0, 0.12) 0px 1px 6px, rgba(0, 0, 0, 0.12) 0px 1px 4px; border-radius: 2px; display: inline-block; min-width: 88px;">
<button style="border: 10px none; box-sizing: border-box; display: inline-block; font-family: Roboto, sans-serif; cursor: pointer; text-decoration: none; margin: 0px; padding: 0px; outline: currentcolor none medium; font-size: inherit; font-weight: inherit; position: relative; height: 36px; line-height: 36px; width: 100%; border-radius: 2px; transition: all 450ms cubic-bezier(0.23, 1, 0.32, 1) 0ms; background-color: green; text-align: center;" tabindex="0" type="button" id="angelleye_mailchimp"><div><div style="height: 36px; border-radius: 2px; transition: all 450ms cubic-bezier(0.23, 1, 0.32, 1) 0ms; top: 0px;"><svg style="display: inline-block; color: rgba(0, 0, 0, 0.87); fill: rgb(255, 255, 255); height: 24px; width: 24px; transition: all 450ms cubic-bezier(0.23, 1, 0.32, 1) 0ms; vertical-align: middle; margin-left: 12px; margin-right: 0px;" viewBox="0 0 28 28"><path d="M20 4H4c-1.1 0-1.99.9-1.99 2L2 18c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2zm0 14H4V8l8 5 8-5v10zm-8-7L4 6h16l-8 5z"></path></svg><span style="position: relative; opacity: 1; font-size: 14px; letter-spacing: 0px; text-transform: uppercase; font-weight: 500; margin: 0px; padding-left: 8px; padding-right: 16px; color: rgb(255, 255, 255);">Sign Up!</span></div></div></button>
<button style="border: 10px none; box-sizing: border-box; display: inline-block; font-family: Roboto, sans-serif; cursor: pointer; text-decoration: none; margin: 0px; padding: 0px; outline: currentcolor none medium; font-size: inherit; font-weight: inherit; position: relative; height: 36px; line-height: 36px; width: 100%; border-radius: 2px; transition: all 450ms cubic-bezier(0.23, 1, 0.32, 1) 0ms; background-color: green; text-align: center;" tabindex="0" type="button" id="angelleye_sendy"><div><div style="height: 36px; border-radius: 2px; transition: all 450ms cubic-bezier(0.23, 1, 0.32, 1) 0ms; top: 0px;"><svg style="display: inline-block; color: rgba(0, 0, 0, 0.87); fill: rgb(255, 255, 255); height: 24px; width: 24px; transition: all 450ms cubic-bezier(0.23, 1, 0.32, 1) 0ms; vertical-align: middle; margin-left: 12px; margin-right: 0px;" viewBox="0 0 28 28"><path d="M20 4H4c-1.1 0-1.99.9-1.99 2L2 18c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2zm0 14H4V8l8 5 8-5v10zm-8-7L4 6h16l-8 5z"></path></svg><span style="position: relative; opacity: 1; font-size: 14px; letter-spacing: 0px; text-transform: uppercase; font-weight: 500; margin: 0px; padding-left: 8px; padding-right: 16px; color: rgb(255, 255, 255);">Sign Up!</span></div></div></button>
</div><br>
</div>
<div id="angelleye_mailchimp_msg">
<div id="angelleye_sendy_msg">
</div>
</div>
<script type="text/javascript">
$("#angelleye_mailchimp").click(function () {
$("#angelleye_sendy").click(function () {
var data = {
'action': 'angelleye_marketing_mailchimp_subscription',
'email': $('#angelleye_mailchimp_email').val()
'action': 'angelleye_marketing_sendy_subscription',
'email': $('#angelleye_sendy_email').val()
};
$.post(ajaxurl, data, function () {

})
.done(function (response) {
response_parsed = JSON.parse(response);
if( response_parsed.result === "success" ) {
$('#angelleye_mailchimp_msg').html(response_parsed.msg);
} else {
$('#angelleye_mailchimp_msg').html(response_parsed.msg);
}
})
.fail(function (response) {
alert(response);
});
.done(function (response) {

console.log(response);
if( response.result === "true" ) {
$('#angelleye_sendy_msg').html(response.message);
$('#angelleye_sendy_email').val("");
} else {
$('#angelleye_sendy_msg').html(response.message);
}
})
.fail(function (response) {
alert(response);
});
});
</script>
<div class="angelleye-sidebar__section m10">
Expand Down

0 comments on commit 2d87b85

Please sign in to comment.