Skip to content

Commit

Permalink
Merge pull request #335 from mailjet/DE-840-contact-form-7-integratio…
Browse files Browse the repository at this point in the history
…n-invalid-json-error

De 840 contact form 7 integration invalid json error
  • Loading branch information
oleksandr-mykhailenko authored Aug 13, 2022
2 parents 1093242 + 038b31e commit 570b51e
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 21 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
- Tags: email, marketing, signup, newsletter, widget, smtp, woocommerce, contact form 7
- Requires at least: 4.4
- Tested up to: 6.0.1
- Stable tag: 5.2.24
- Stable tag: 5.2.25
- Requires PHP: 5.6
- License: GPLv2 or later
- License URI: http://www.gnu.org/licenses/gpl-2.0.html
Expand Down Expand Up @@ -205,7 +205,10 @@ find vendor/ -type d -name ".git" -exec rm -rf {} \;
7. Configure abandoned cart notifications for WooCommerce

## Changelog
##### 5.2.24
##### 5.2.25
* Removed var_dump from the code because off error

* ##### 5.2.24
* Fix bug with widget for WP 6+ version

##### 5.2.23
Expand Down
6 changes: 6 additions & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,9 @@ find vendor/ -type d -name ".git" -exec rm -rf {} \;
7. Configure abandoned cart notifications for WooCommerce

== Upgrade notice ==
= 5.2.25 =
* Removed var_dump from the code because off error

= 5.2.24 =
* Fix bug with widget for WP 6+ version

Expand Down Expand Up @@ -235,6 +238,9 @@ find vendor/ -type d -name ".git" -exec rm -rf {} \;
* Removed Bootstrap dependency

== Changelog ==
= 5.2.25 =
* Removed var_dump from the code because off error

= 5.2.24 =
* Fix bug with widget for WP 6+ version

Expand Down
2 changes: 1 addition & 1 deletion src/includes/Mailjet.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function __construct()
if (\defined('MAILJET_VERSION')) {
$this->version = MAILJET_VERSION;
} else {
$this->version = '5.2.24';
$this->version = '5.2.25';
}
$this->plugin_name = 'mailjet';
$this->load_dependencies();
Expand Down
31 changes: 15 additions & 16 deletions src/includes/SettingsPages/ContactForm7Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
*/
class ContactForm7Settings
{
const MAILJET_CHECKBOX = 'mailjet-opt-in';
public const MAILJET_CHECKBOX = 'mailjet-opt-in';

/**
* @param $contactForm
* @return false
*/
public function sendConfirmationEmail($contactForm)
public function sendConfirmationEmail($contactForm): bool
{
$locale = Mailjeti18n::getLocale();
$formdata = \false;
Expand All @@ -31,53 +31,52 @@ public function sendConfirmationEmail($contactForm)
}
}
if (!$formdata) {
return \false;
return false;
}
$invalidFields = $submission->get_invalid_fields();
if (!empty($invalidFields)) {
return \false;
return false;
}
$mailjetCheckbox = $formdata[self::MAILJET_CHECKBOX];
if ($mailjetCheckbox[0] != '') {
$cf7Email = \trim(\stripslashes(get_option('cf7_email')), '[]');
$cf7Email = trim(stripslashes(get_option('cf7_email')), '[]');

if (!isset($formdata[$cf7Email])) {
return false;
}
$email = $formdata[$cf7Email];
$cf7name = \stripslashes(get_option('cf7_fromname', ''));
$cf7name = stripslashes(get_option('cf7_fromname', ''));
$matches = array();
$data = array();
\preg_match_all('/\\[(.*?)\\]/', $cf7name, $matches);
preg_match_all('/\\[(.*?)\\]/', $cf7name, $matches);
if (!empty($matches[1])) {
foreach ($matches[1] as $match) {
if (isset($formdata[$match])) {
$data[] = $formdata[$match];
}
}
}
$newphrase = \str_replace($matches[0], $data, $cf7name);
$newphrase = str_replace($matches[0], $data, $cf7name);
$mailjetCF7List = get_option('mailjet_cf7_list');
$params = \http_build_query(array('cf7list' => $mailjetCF7List, 'email' => $email, 'prop' => $newphrase));
$wpUrl = \sprintf('<a href="%s" target="_blank">%s</a>', get_home_url(), get_home_url());
$subscriptionTemplate = apply_filters('mailjet_confirmation_email_filename', \dirname(\dirname(\dirname(__FILE__))) . '/templates/confirm-subscription-email.php');
$message = \file_get_contents($subscriptionTemplate);
$emailParams = array('__EMAIL_TITLE__' => Mailjeti18n::getTranslationsFromFile($locale, 'Please confirm your subscription'), '__EMAIL_HEADER__' => \sprintf(__(Mailjeti18n::getTranslationsFromFile($locale, 'To receive newsletters from %s please confirm your subscription by clicking the following button:'), 'mailjet-for-wordpress'), $wpUrl), '__WP_URL__' => $wpUrl, '__CONFIRM_URL__' => get_home_url() . '?' . $params . '&token=' . \sha1($params . MailjetSettings::getCryptoHash()), '__CLICK_HERE__' => Mailjeti18n::getTranslationsFromFile($locale, 'Yes, subscribe me to this list'), '__FROM_NAME__' => get_option('blogname'), '__IGNORE__' => Mailjeti18n::getTranslationsFromFile($locale, 'If you received this email by mistake or don\'t wish to subscribe anymore, simply ignore this message.'));
$params = http_build_query(array('cf7list' => $mailjetCF7List, 'email' => $email, 'prop' => $newphrase));
$wpUrl = sprintf('<a href="%s" target="_blank">%s</a>', get_home_url(), get_home_url());
$subscriptionTemplate = apply_filters('mailjet_confirmation_email_filename', dirname(__FILE__, 3) . '/templates/confirm-subscription-email.php');
$message = file_get_contents($subscriptionTemplate);
$emailParams = array('__EMAIL_TITLE__' => Mailjeti18n::getTranslationsFromFile($locale, 'Please confirm your subscription'), '__EMAIL_HEADER__' => sprintf(__(Mailjeti18n::getTranslationsFromFile($locale, 'To receive newsletters from %s please confirm your subscription by clicking the following button:'), 'mailjet-for-wordpress'), $wpUrl), '__WP_URL__' => $wpUrl, '__CONFIRM_URL__' => get_home_url() . '?' . $params . '&token=' . sha1($params . MailjetSettings::getCryptoHash()), '__CLICK_HERE__' => Mailjeti18n::getTranslationsFromFile($locale, 'Yes, subscribe me to this list'), '__FROM_NAME__' => get_option('blogname'), '__IGNORE__' => Mailjeti18n::getTranslationsFromFile($locale, 'If you received this email by mistake or don\'t wish to subscribe anymore, simply ignore this message.'));
foreach ($emailParams as $key => $value) {
$message = \str_replace($key, $value, $message);
$message = str_replace($key, $value, $message);
}
$contact = array();
$contact['Email'] = $email;
if ($cf7name && isset($formdata[$cf7name])) {
$contact['Properties']['name'] = $formdata[$cf7name];
MailjetApi::createMailjetContactProperty('name');
}
var_dump($contact, $mailjetCF7List);
MailjetApi::syncMailjetContact($mailjetCF7List, $contact);
$email_subject = Mailjeti18n::getTranslationsFromFile($locale, 'Subscription Confirmation');
add_filter('wp_mail_content_type', array(SubscriptionOptionsSettings::getInstance(), 'set_html_content_type'));
wp_mail($email, $email_subject, $message, array('From: ' . get_option('blogname') . ' <' . get_option('admin_email') . '>'));
}
return \false;
return false;
}
}
4 changes: 2 additions & 2 deletions wp-mailjet.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* Plugin Name: Mailjet for WordPress
* Plugin URI: https://www.mailjet.com/partners/wordpress/
* Description: The Best WordPress Plugin For Email Newsletters.
* Version: 5.2.24
* Version: 5.2.25
* Tested up to: 6.0.1
* Author: Mailjet SAS
* Author URI: http://mailjet.com
Expand Down Expand Up @@ -55,7 +55,7 @@
/**
* Mailjet plugin version.
*/
define('MAILJET_VERSION', '5.2.24');
define('MAILJET_VERSION', '5.2.25');

/**
* Mailjet Plugid dir.
Expand Down

0 comments on commit 570b51e

Please sign in to comment.