Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature 2021 11 05 version fixes #6

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,13 @@ Initial release

#### v1.0.1 - 2021.08.13
Added Lead Source
Added option to submit as webform
Added option to submit as webform

### v1.0.2 - 2021.08.30
Removed logging

### v1.0.3 - 2021.10.22
Do not submit if recaptcha returns spam

### v1.0.4 - 2021.11.05
Version fixes
53 changes: 38 additions & 15 deletions inc/cf7.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,11 @@
defined('ABSPATH') || die('Wordpress is not installed properly.');

/**
* Catch contact form 7 submission
* @param array
* @param array
* @return array
* Submit to zoho
* @return void
*/
function klypZhCf7CatchSubmission($result, $tags)
function klypZhCf7SendToZoho()
{
if (! $result->is_valid()) {
return $result;
}

if (get_option('klyp_cf7tozoho_client_id') == '' && get_option('klyp_cf7tozoho_client_secret') == '') {
return;
}

// form options
$cf7FormId = intval(sanitize_key($_POST['_wpcf7']));
$cf7FormFields = get_post_meta($cf7FormId, '_klyp-cf7-to-zoho-cf-map-fields', true);
Expand All @@ -39,12 +29,45 @@ function klypZhCf7CatchSubmission($result, $tags)
if ($zhFormMethod == 'API') {
$zoho->zhObject = get_post_meta($cf7FormId, '_klyp-cf7-to-zoho-object', true);
$zoho->zhPrimaryKey = get_post_meta($cf7FormId, '_klyp-cf7-to-zoho-primary-key', true);
$zohoReturn = $zoho->upsert();
$zohoReturn = $zoho->upsert();
} elseif ($zhFormMethod == 'Webform') {
$zoho->actionType = get_post_meta($cf7FormId, '_klyp-cf7-to-zoho-method-actionType', true);
$zoho->xnQsjsdp = get_post_meta($cf7FormId, '_klyp-cf7-to-zoho-method-xnQsjsdp', true);
$zoho->xmIwtLD = get_post_meta($cf7FormId, '_klyp-cf7-to-zoho-method-xmIwtLD', true);
$zohoReturn = $zoho->webform();
$zohoReturn = $zoho->webform();
}
}

/**
* If submission is spam
* @param array
* @param array
* @return void
*/
function klypZhCf7CatchSpam($spam, $instance)
{
if ($spam) {
return $spam;
}

return klypZhCf7SendToZoho();
}
add_filter('wpcf7_spam', 'klypZhCf7CatchSpam', 10, 2);

/**
* Catch contact form 7 submission
* @param array
* @param array
* @return array
*/
function klypZhCf7CatchSubmission($result, $tags)
{
if (! $result->is_valid()) {
return $result;
}

if (get_option('klyp_cf7tozoho_client_id') == '' && get_option('klyp_cf7tozoho_client_secret') == '') {
return $result;
}

return $result;
Expand Down
8 changes: 0 additions & 8 deletions inc/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,6 @@ function klypCF7ToZohoGetTokenAccess()

$body = wp_remote_retrieve_body($response);

if (defined('WP_DEBUG') && true === WP_DEBUG) {
error_log('Start of getting token: ' . date('l jS \of F Y h:i:s A'));
error_log('URL: ' . $url);
error_log('Response: ' . print_r($response, true));
error_log('Body: ' . print_r($body, true));
error_log('End of getting token: ' . date('l jS \of F Y h:i:s A'));
}

echo $body;
die();
}
Expand Down
38 changes: 0 additions & 38 deletions inc/zoho-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,6 @@ public function refreshAccessToken()
$params
);

if (defined('WP_DEBUG') && true === WP_DEBUG) {
// log
error_log('Start of refreshing token: ' . date('l jS \of F Y h:i:s A'));
error_log('URL: ' . $url);
error_log('Response: ' . print_r($response, true));
error_log('End of refreshing token: ' . date('l jS \of F Y h:i:s A'));
}

$body = wp_remote_retrieve_body($response);

if ($body) {
Expand All @@ -147,14 +139,6 @@ public function getFormFields()
$response = $this->remoteGet($url, array('Authorization' => 'Zoho-oauthtoken ' . $this->token));
$status = $this->remoteStatus($response);

if (defined('WP_DEBUG') && true === WP_DEBUG) {
// log
error_log('Start of getting fields: ' . date('l jS \of F Y h:i:s A'));
error_log('URL: ' . $url);
error_log('Response: ' . print_r($response, true));
error_log('End of getting fields: ' . date('l jS \of F Y h:i:s A'));
}

if ($status == 200) {
$body = wp_remote_retrieve_body($response);

Expand All @@ -167,10 +151,6 @@ public function getFormFields()
$newRefreshToken = $this->refreshAccessToken();
$this->token = $newRefreshToken;

if (defined('WP_DEBUG') && true === WP_DEBUG) {
error_log('New token generated: ' . $newRefreshToken . ' - ' . date('l jS \of F Y h:i:s A'));
}

return $this->getFormFields();
}
}
Expand All @@ -196,14 +176,6 @@ public function upsert()
$response = $this->remotePost($url, 'POST', $data, array('Authorization' => 'Zoho-oauthtoken ' . $this->token));
$status = $this->remoteStatus($response);

if (defined('WP_DEBUG') && true === WP_DEBUG) {
// start of log
error_log('Start of upsert: ' . date('l jS \of F Y h:i:s A'));
error_log('URL: ' . $url);
error_log('Data: ' . print_r($data, true));
error_log('Response: ' . print_r($response, true));
}

if ($status == 200) {
$body = wp_remote_retrieve_body($response);

Expand All @@ -225,19 +197,9 @@ public function upsert()
} else { // refresh token
$newRefreshToken = $this->refreshAccessToken();
$this->token = $newRefreshToken;

if (defined('WP_DEBUG') && true === WP_DEBUG) {
error_log('New token generated: ' . date('l jS \of F Y h:i:s A'));
}

$this->upsert();
}

if (defined('WP_DEBUG') && true === WP_DEBUG) {
error_log('Return: ' . print_r($return, true));
error_log('End of upsert: ' . date('l jS \of F Y h:i:s A'));
}

return $return;
}
}
2 changes: 1 addition & 1 deletion klyp-cf7-to-zoho.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: Klyp Contact Form 7 to ZOHO
* Plugin URI: https://github.com/klyp/klyp-cf7-to-zoho
* Description: This plugin allows you to map CF7 fields to ZOHO form fields.
* Version: 1.0.0
* Version: 1.0.4
* Author: Klyp
* Author URI: https://klyp.co
* License: GPL2
Expand Down
13 changes: 11 additions & 2 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Tags: contact, form, cf7, zoho
Requires at least: 5.2
Tested up to: 5.6.1
Requires PHP: 7.0
Stable tag: 1.0.1
Stable tag: 1.0.4
License: GPL2+
License URI: https://www.gnu.org/licenses/gpl-2.0.txt

Expand All @@ -20,4 +20,13 @@ Initial release

v1.0.1 - 2021.08.13
Added Lead Source
Added option to submit as webform
Added option to submit as webform

v1.0.2 - 2021.08.30
Removed logging

v1.0.3 - 2021.10.22
Do not submit if recaptcha returns spam

v1.0.4 - 2021.11.05
Version fixes