Skip to content

Commit

Permalink
Prevent datetime overflow and fix notice
Browse files Browse the repository at this point in the history
  • Loading branch information
Georgi Nikolov committed Dec 13, 2018
1 parent 5ee217d commit 1491475
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/widget/WP_Mailjet_Subscribe_Widget.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ private function sendSubscriptionEmail($subscriptionOptionsSettings, $instance)
$mailjetContactProperties = $this->getMailjetContactProperties();
$incorectTypeValue = !empty($instance[$locale]['invalid_data_format_message_input']) ? $instance[$locale]['invalid_data_format_message_input'] : Mailjeti18n::getTranslationsFromFile($locale, 'The value you entered is not in the correct format.');

$dataProperties = array();
if(!empty($properties) && is_array($mailjetContactProperties) && !empty($mailjetContactProperties)) {
foreach($properties as $propertyId => $propertyName) {
if($propertyName == '') {
Expand Down Expand Up @@ -144,9 +143,13 @@ private function sendSubscriptionEmail($subscriptionOptionsSettings, $instance)
case "datetime":
$propertyDate = str_replace('-', '/', $properties[$propertyId]);
$datetime = \DateTime::createFromFormat("d/m/Y", $propertyDate);
$errors = \DateTime::getLastErrors();
if (!$datetime instanceof \DateTime) {
return $incorectTypeValue;
}
if (!empty($errors['warning_count'])) {
return $incorectTypeValue;
}
break;
case "bool":
$booleans = array('true', 'false', '1', '0','yes', 'no', 'ok');
Expand Down Expand Up @@ -236,7 +239,7 @@ private function activateConfirmSubscriptionUrl()
break;
case "bool":
$positiveBooleans = array('true', '1', 'yes', 'ok');
if(in_array($propertyName, $positiveBooleans)) {
if(in_array($properties[$property['ID']], $positiveBooleans)) {
$dataProperties[$property['Name']] = true;
}else{
$dataProperties[$property['Name']] = false;
Expand Down

0 comments on commit 1491475

Please sign in to comment.