Skip to content

Commit f28e18b

Browse files
committed
refactor: sanitize conditional logics
1 parent 0124492 commit f28e18b

File tree

5 files changed

+25
-29
lines changed

5 files changed

+25
-29
lines changed

frontend-dev/src/components/AllIntegrations/MailerPress/MailerPressIntegLayout.jsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export default function MailerPressIntegLayout({
8686
options={
8787
mailerPressConf?.allLists &&
8888
Array.isArray(mailerPressConf.allLists) &&
89-
mailerPressConf.allLists?.map(list => ({
89+
mailerPressConf.allLists.map(list => ({
9090
label: list?.listName,
9191
value: list?.listId?.toString()
9292
}))
@@ -117,7 +117,7 @@ export default function MailerPressIntegLayout({
117117
options={
118118
mailerPressConf?.allTags &&
119119
Array.isArray(mailerPressConf.allTags) &&
120-
mailerPressConf.allTags?.map(tag => ({
120+
mailerPressConf.allTags.map(tag => ({
121121
label: tag?.tagName,
122122
value: tag?.tagId?.toString()
123123
}))
@@ -148,7 +148,7 @@ export default function MailerPressIntegLayout({
148148
/>
149149
)}
150150

151-
{mailerPressConf.mainAction && mailerPressConf?.mailerPressFields && (
151+
{mailerPressConf?.mainAction && mailerPressConf?.mailerPressFields && (
152152
<>
153153
<div className="mt-4">
154154
<b className="wdt-100">{__('Map Fields', 'bit-integrations')}</b>
@@ -163,7 +163,7 @@ export default function MailerPressIntegLayout({
163163
</div>
164164
</div>
165165

166-
{mailerPressConf.field_map.map((itm, i) => (
166+
{mailerPressConf?.field_map.map((itm, i) => (
167167
<MailerPressFieldMap
168168
key={`mailerpress-m-${i + 9}`}
169169
i={i}

frontend-dev/src/pages/ChangelogToggle.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ const changeLog = [
8585
},
8686
{
8787
label: 'Divi Form (Divi Engine)',
88-
desc: 'Fixed a bug where the Create Kids form type returned a null value',
88+
desc: 'Fixed a bug where the Create Kids form type returned a null value.',
8989
isPro: true
9090
}
9191
]

includes/Actions/MailerPress/RecordApiHelper.php

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@ class RecordApiHelper
1818

1919
public function __construct($integId)
2020
{
21-
if (!class_exists('\MailerPress\Core\Kernel')) {
22-
return;
23-
}
24-
2521
$this->_integrationID = $integId;
2622
}
2723

@@ -49,7 +45,7 @@ public function execute($fieldValues, $fieldMap, $lists, $tags, $mainAction)
4945

5046
$defaultResponse = [
5147
'success' => false,
52-
'message' => wp_sprintf(__('%s plugin is not installed or activate', 'bit-integrations'), 'Bit Integration Pro')
48+
'message' => wp_sprintf(__('%s plugin is not installed or activate', 'bit-integrations'), 'Bit Integrations')
5349
];
5450

5551
// Route to appropriate action method
@@ -120,17 +116,17 @@ public function execute($fieldValues, $fieldMap, $lists, $tags, $mainAction)
120116
*/
121117
private function insertRecord($contactData, $lists, $tags)
122118
{
123-
$email = isset($contactData['email']) ? sanitize_email($contactData['email']) : '';
119+
$email = key_exists('email', $contactData) ? sanitize_email($contactData['email']) : null;
124120

125-
if (empty($email)) {
121+
if (\is_null($email)) {
126122
return [
127123
'success' => false,
128124
'message' => __('Email is required', 'bit-integrations')
129125
];
130126
}
131127

132128
$tagIds = [];
133-
if (!empty($tags)) {
129+
if (\is_array($tags)) {
134130
$tagIds = array_map(
135131
function ($id) {
136132
return ['id' => $id];
@@ -140,7 +136,7 @@ function ($id) {
140136
}
141137

142138
$listIds = [];
143-
if (!empty($lists)) {
139+
if (\is_array($lists)) {
144140
$listIds = array_map(
145141
function ($id) {
146142
return ['id' => $id];
@@ -198,11 +194,11 @@ private static function setFieldMap($fieldMap, $fieldValues)
198194
$fieldData = [];
199195

200196
foreach ($fieldMap as $fieldPair) {
201-
if (empty($fieldPair->mailerPressField)) {
197+
if (!isset($fieldPair->mailerPressField) || \is_null($fieldPair->mailerPressField) || $fieldPair->mailerPressField === '') {
202198
continue;
203199
}
204200

205-
$fieldData[$fieldPair->mailerPressField] = ($fieldPair->formField == 'custom' && !empty($fieldPair->customValue))
201+
$fieldData[$fieldPair->mailerPressField] = ($fieldPair->formField == 'custom' && isset($fieldPair->customValue))
206202
? Common::replaceFieldWithValue($fieldPair->customValue, $fieldValues)
207203
: $fieldValues[$fieldPair->formField];
208204
}

includes/Actions/WooCommerce/RecordApiHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function createCustomer($fieldMapCustomer, $required, $module, $fieldValu
4242
}
4343
}
4444

45-
if (empty($fieldDataCustomer)) {
45+
if (!\is_array($fieldDataCustomer) || \count($fieldDataCustomer) === 0) {
4646
return get_current_user_id();
4747
}
4848

includes/Triggers/WC/WCController.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -992,20 +992,20 @@ public static function handle_insert_comment($comment_id, $comment_approved, $co
992992
$comment = get_comment($comment_id, OBJECT);
993993

994994
$finalData = [
995-
'product_id' => $comment->comment_post_ID,
996-
'product_title' => get_the_title($comment->comment_post_ID),
997-
'product_url' => get_permalink($comment->comment_post_ID),
998-
'product_price' => get_post_meta($comment->comment_post_ID, '_price', true),
999-
'product_review' => $comment->comment_content,
1000-
'product_sku' => get_post_meta($comment->comment_post_ID, '_sku', true),
1001-
'product_tags' => get_the_terms($comment->comment_post_ID, 'product_tag'),
1002-
'product_categories' => get_the_terms($comment->comment_post_ID, 'product_cat'),
995+
'product_id' => $comment->comment_post_ID ?? '',
996+
'product_title' => isset($comment->comment_post_ID) ? get_the_title($comment->comment_post_ID) : '',
997+
'product_url' => isset($comment->comment_post_ID) ? get_permalink($comment->comment_post_ID) : '',
998+
'product_price' => isset($comment->comment_post_ID) ? get_post_meta($comment->comment_post_ID, '_price', true) : '',
999+
'product_review' => $comment->comment_content ?? '',
1000+
'product_sku' => isset($comment->comment_post_ID) ? get_post_meta($comment->comment_post_ID, '_sku', true) : '',
1001+
'product_tags' => isset($comment->comment_post_ID) ? get_the_terms($comment->comment_post_ID, 'product_tag') : '',
1002+
'product_categories' => isset($comment->comment_post_ID) ? get_the_terms($comment->comment_post_ID, 'product_cat') : '',
10031003
'product_rating' => get_comment_meta($comment_id, 'rating', true),
1004-
'review_id' => $comment->comment_ID,
1005-
'review_date' => $comment->comment_date,
1004+
'review_id' => $comment->comment_ID ?? '',
1005+
'review_date' => $comment->comment_date ?? '',
10061006
'author_id' => $comment->user_id ?? 0,
1007-
'review_author_name' => $comment->comment_author,
1008-
'author_email' => $comment->comment_author_email,
1007+
'review_author_name' => $comment->comment_author ?? '',
1008+
'author_email' => $comment->comment_author_email ?? '',
10091009
];
10101010

10111011
$flowDetails = json_decode($flows[0]->flow_details);

0 commit comments

Comments
 (0)