Skip to content

Commit

Permalink
Merge pull request #84 from mailjet/feature/17980_Wordpress_handle_ne…
Browse files Browse the repository at this point in the history
…w_contact_property_data_type_date

Feature/17980 wordpress handle new contact property data type date
  • Loading branch information
Ferhan Ismailov authored Oct 16, 2017
2 parents 617d02f + 374481f commit fb1c88c
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 17 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Contributors: mailjet
Tags: email, marketing, signup, newsletter, widget, smtp, mailjet
Requires at least: 3.3.0
Tested up to: 4.8
Stable tag: 4.2.7
Stable tag: 4.2.8
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

Expand Down Expand Up @@ -90,6 +90,9 @@ Need help? Our multilingual support team is here to answer your questions in any

== Changelog ==

= 4.2.8 =
* Added conversion to timestamp for date time contact properties before send them to the API

= 4.2.7 =
* Subscription widget added validation for contact properties of date type

Expand Down
2 changes: 1 addition & 1 deletion api/mailjet-api-v1.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public function sendRequest($method = false, $params = array(), $request = 'GET'
curl_setopt($curl_handle, CURLOPT_USERPWD, $this->apiKey . ':' . $this->secretKey);
curl_setopt($curl_handle, CURLOPT_VERBOSE, true);
curl_setopt($curl_handle, CURLINFO_HEADER_OUT, true);
curl_setopt($curl_handle, CURLOPT_USERAGENT, 'wordpress-v1.4.2.7');
curl_setopt($curl_handle, CURLOPT_USERAGENT, 'wordpress-v1.4.2.8');

$this->_request_post = false;
if ($request == 'POST')
Expand Down
2 changes: 1 addition & 1 deletion api/mailjet-api-v3.php
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ private function sendRequest($object, $params, $method)
curl_setopt($this->_curl_handle, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($this->_curl_handle, CURLOPT_USERPWD, $this->_apiKey.':'.$this->_secretKey);
curl_setopt($this->_curl_handle, CURLOPT_CUSTOMREQUEST, $method);
curl_setopt($this->_curl_handle, CURLOPT_USERAGENT, 'wordpress-4.2.7');
curl_setopt($this->_curl_handle, CURLOPT_USERAGENT, 'wordpress-4.2.8');

switch ($method) {
case 'GET' :
Expand Down
36 changes: 24 additions & 12 deletions mailjet-widget.php
Original file line number Diff line number Diff line change
Expand Up @@ -408,11 +408,9 @@ function mj_is_float($input) {
}

function mj_is_datetime($input) {
return (((string) (int) $input === $input) && ($input <= PHP_INT_MAX) && ($input >= ~PHP_INT_MAX)) // check for unix timestamp
|| (preg_match("/^[0-9]{1,2}\/[0-9]{1,2}\/[0-9]{4}$/", $input)) // check for "dd/mm/YYYY" format
|| (preg_match("/^[0-9]{4}\/[0-9]{1,2}\/[0-9]{1,2}$/", $input)) // check for "YYYY/mm/dd" format
|| (preg_match("/^[0-9]{4}-(0?[1-9]|1[0-2])-(0?[1-9]|[1-2][0-9]|3[0-1])$/", $input)) // check for "YYYY-mm-dd" | "YYYY-m-d" format
|| (preg_match("/^(0?[1-9]|[1-2][0-9]|3[0-1])-(0?[1-9]|1[0-2])-[0-9]{4}$/", $input)); // check for "dd-mm-YYYY" | "d-m-YYYY" format
return (((string) (int) $input === $input) && ($input <= PHP_INT_MAX) && ($input >= ~PHP_INT_MAX)) // check for unix timestamp
|| (preg_match("/^(0?[1-9]|[1-2][0-9]|3[0-1])-(0?[1-9]|1[0-2])-[0-9]{4}$/", $input)) // check for "dd-mm-YYYY"
|| (preg_match("/^(0?[1-9]|[1-2][0-9]|3[0-1])\/(0?[1-9]|1[0-2])\/[0-9]{4}$/", $input)); // check for "dd/mm/YYYY"
}


Expand Down Expand Up @@ -474,9 +472,19 @@ public function mailjet_subscribe_from_widget()
if ($accountProperty->Datatype === 'str') {
continue;
}

if ($accountProperty->Name === $submittedProperty &&
$this->$dataTypes[$accountProperty->Datatype]($_POST[$submittedProperty]) !== true) {
$error = 'You have entered a contact property with wrong data type, for example a string instead of a number.';
if($accountProperty->Datatype === 'datetime') {
$error = 'You have entered a contact property with wrong data type. Valid format for date time property is "dd-mm-YYYY" or "dd/mm/YYYY".';
}

}

// convert inserted date time property to unix timestamp
if ($accountProperty->Name === $submittedProperty && $accountProperty->Datatype === 'datetime') {
$_POST[$submittedProperty] = strtotime($_POST[$submittedProperty]);
}
}
}
Expand All @@ -503,7 +511,7 @@ public function mailjet_subscribe_from_widget()
$message = str_replace($key, $value, $message);
}
add_filter('wp_mail_content_type', create_function('', 'return "text/html"; '));
wp_mail($_POST['email'], __('Subscription Confirmation', 'wp-mailjet-subscription-widget'), $message,
$result = wp_mail($_POST['email'], __('Subscription Confirmation', 'wp-mailjet-subscription-widget'), $message,
array('From: ' . get_option('blogname') . ' <' . get_option('admin_email') . '>'));
echo '<p class="success">' . __('Subscription confirmation email sent. Please check your inbox and confirm the subscription.',
'wp-mailjet-subscription-widget') . '</p>';
Expand Down Expand Up @@ -553,14 +561,18 @@ function subscribeUser()
}
}

if (!empty($result->Response->Data)) {
$result2 = $this->api->updateContactData(array(
'method' => 'JSON',
'ID' => $email,
'Data' => $properties
));
if (is_object($result)) {
if (!empty($result->Data)) {
$result2 = $this->api->updateContactData(array(
'method' => 'JSON',
'ID' => $email,
'Data' => $properties
));

}
}


echo '<p class="success" listId="' . $_GET['list_id'] . '">';
echo sprintf(__("Thanks for subscribing with %s", 'wp-mailjet-subscription-widget'), $email);
echo '</p>';
Expand Down
5 changes: 4 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Contributors: mailjet
Tags: email, marketing, signup, newsletter, widget, smtp, mailjet
Requires at least: 3.3.0
Tested up to: 4.8
Stable tag: 4.2.7
Stable tag: 4.2.8
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

Expand Down Expand Up @@ -90,6 +90,9 @@ Need help? Our multilingual support team is here to answer your questions in any

== Changelog ==

= 4.2.8 =
* Added conversion to timestamp for date time contact properties before send them to the API

= 4.2.7 =
* Subscription widget added validation for contact properties of date type

Expand Down
2 changes: 1 addition & 1 deletion wp-mailjet.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

/*
Plugin Name: Mailjet for Wordpress
Version: 4.2.7
Version: 4.2.8
Plugin URI: https://www.mailjet.com/plugin/wordpress.htm
Description: Use mailjet SMTP to send email, manage lists and contacts within wordpress
Author: Mailjet SAS
Expand Down

0 comments on commit fb1c88c

Please sign in to comment.