UrlDecorator.php
35 lines
| 1 | <?php // phpcs:ignore SlevomatCodingStandard.TypeHints.DeclareStrictTypes.DeclareStrictTypesMissing |
| 2 | |
| 3 | namespace MailPoet\Referrals; |
| 4 | |
| 5 | if (!defined('ABSPATH')) exit; |
| 6 | |
| 7 | |
| 8 | use MailPoet\Settings\SettingsController; |
| 9 | use MailPoet\WP\Functions as WPFunctions; |
| 10 | |
| 11 | class UrlDecorator { |
| 12 | |
| 13 | /** @var WPFunctions */ |
| 14 | private $wp; |
| 15 | |
| 16 | /** @var SettingsController */ |
| 17 | private $settings; |
| 18 | |
| 19 | public function __construct( |
| 20 | WPFunctions $wp, |
| 21 | SettingsController $settings |
| 22 | ) { |
| 23 | $this->wp = $wp; |
| 24 | $this->settings = $settings; |
| 25 | } |
| 26 | |
| 27 | public function decorate($url) { |
| 28 | $referralId = $this->settings->get(ReferralDetector::REFERRAL_SETTING_NAME, null); |
| 29 | if ($referralId === null) { |
| 30 | return $url; |
| 31 | } |
| 32 | return $this->wp->addQueryArg('ref', $referralId, $url); |
| 33 | } |
| 34 | } |
| 35 |