| 1 |
<?php |
| 2 |
|
| 3 |
namespace BitCode\BitForm\Core\Util; |
| 4 |
|
| 5 |
trait PostHelpers |
| 6 |
{ |
| 7 |
protected function postFieldMapping($postMap, $fieldValues, $postID, $entryID) |
| 8 |
{ |
| 9 |
$postData = []; |
| 10 |
|
| 11 |
$uploadFeatureImg = new WpFileHandler($this->_formID); |
| 12 |
|
| 13 |
foreach ($postMap as $fieldPair) { |
| 14 |
if (!empty($fieldPair->postField) && !empty($fieldPair->formField)) { |
| 15 |
$formField = $fieldPair->formField; |
| 16 |
|
| 17 |
$postField = $fieldPair->postField; |
| 18 |
|
| 19 |
if ('_thumbnail_id' === $fieldPair->postField && !empty($fieldValues[$formField])) { |
| 20 |
$uploadFeatureImg->uploadFeatureImg($fieldValues[$formField], $entryID, $postID); |
| 21 |
} else { |
| 22 |
if ('custom' === $fieldPair->formField && isset($fieldPair->customValue)) { |
| 23 |
$postData[$postField] = $fieldPair->customValue; |
| 24 |
} else { |
| 25 |
$postData[$postField] = $fieldValues[$formField]; |
| 26 |
} |
| 27 |
} |
| 28 |
} |
| 29 |
} |
| 30 |
return $postData; |
| 31 |
} |
| 32 |
|
| 33 |
protected function setPostData($integrationDetails) |
| 34 |
{ |
| 35 |
$postData = []; |
| 36 |
|
| 37 |
$postData['comment_status'] = isset($integrationDetails->comment_status) ? $integrationDetails->comment_status : ''; |
| 38 |
|
| 39 |
$postData['post_status'] = isset($integrationDetails->post_status) ? $integrationDetails->post_status : ''; |
| 40 |
|
| 41 |
$postData['post_type'] = isset($integrationDetails->post_type) ? $integrationDetails->post_type : ''; |
| 42 |
|
| 43 |
if (isset($integrationDetails->post_author) && 'logged_in_user' !== $integrationDetails->post_author) { |
| 44 |
$postData['post_author'] = $integrationDetails->post_author; |
| 45 |
} else { |
| 46 |
$postData['post_author'] = get_current_user_id(); |
| 47 |
} |
| 48 |
|
| 49 |
return $postData; |
| 50 |
} |
| 51 |
} |
| 52 |
|