Editor
2 months ago
Embed
1 month ago
Links
2 months ago
Listing
9 months ago
Options
2 years ago
Preview
1 month ago
Renderer
4 days ago
RestApi
1 week ago
Scheduler
4 days ago
Segment
1 year ago
Sending
1 week ago
Sharing
1 month ago
Shortcodes
3 days ago
Statistics
1 week ago
ViewInBrowser
1 month ago
ApiDataSanitizer.php
3 years ago
AutomatedLatestContent.php
2 months ago
AutomaticEmailsRepository.php
3 years ago
BlockPostQuery.php
2 months ago
BulkActionController.php
1 month ago
BulkActionException.php
1 month ago
DynamicProducts.php
11 months ago
NewsletterCoupon.php
2 months ago
NewsletterDeleteController.php
2 years ago
NewsletterHtmlSanitizer.php
2 years ago
NewsletterPostsRepository.php
2 years ago
NewsletterResendController.php
4 days ago
NewsletterSaveController.php
1 month ago
NewsletterValidator.php
1 year ago
NewslettersRepository.php
2 weeks ago
StatusController.php
1 month ago
Url.php
2 months ago
index.php
3 years ago
NewsletterCoupon.php
43 lines
| 1 | <?php declare(strict_types = 1); |
| 2 | |
| 3 | namespace MailPoet\Newsletter; |
| 4 | |
| 5 | if (!defined('ABSPATH')) exit; |
| 6 | |
| 7 | |
| 8 | use MailPoet\Newsletter\Renderer\Blocks\Coupon; |
| 9 | |
| 10 | class NewsletterCoupon { |
| 11 | public function cleanupBodySensitiveData(array $newsletterBody): array { |
| 12 | if (empty($newsletterBody['content'])) { |
| 13 | return $newsletterBody; |
| 14 | } |
| 15 | $cleanBlocks = $this->cleanupCouponBlocks($newsletterBody['content']['blocks']); |
| 16 | return array_merge( |
| 17 | $newsletterBody, |
| 18 | [ |
| 19 | 'content' => array_merge( |
| 20 | $newsletterBody['content'], |
| 21 | ['blocks' => $cleanBlocks] |
| 22 | ), |
| 23 | ] |
| 24 | ); |
| 25 | } |
| 26 | |
| 27 | private function cleanupCouponBlocks(array &$blocks): array { |
| 28 | foreach ($blocks as &$block) { |
| 29 | if (isset($block['blocks']) && !empty($block['blocks'])) { |
| 30 | $this->cleanupCouponBlocks($block['blocks']); |
| 31 | } |
| 32 | |
| 33 | if (isset($block['type']) && $block['type'] === Coupon::TYPE) { |
| 34 | $block['code'] = Coupon::CODE_PLACEHOLDER; |
| 35 | |
| 36 | if(isset($block['couponId'])) |
| 37 | unset($block['couponId']); |
| 38 | } |
| 39 | } |
| 40 | return $blocks; |
| 41 | } |
| 42 | } |
| 43 |