Files
piratepoet/lib/Referrals/ReferralDetector.php
Jan Jakeš 01a0fe96c4 Remove no longer necessary checks
[MAILPOET-1948]
2019-09-12 13:59:32 +02:00

38 lines
995 B
PHP

<?php
namespace MailPoet\Referrals;
use MailPoet\Settings\SettingsController;
use MailPoet\WP\Functions as WPFunctions;
class ReferralDetector {
const REFERRAL_CONSTANT_NAME = 'MAILPOET_REFERRAL_ID';
const REFERRAL_SETTING_NAME = 'referral_id';
/** @var WPFunctions */
private $wp;
/** @var SettingsController */
private $settings;
function __construct(WPFunctions $wp, SettingsController $settings) {
$this->wp = $wp;
$this->settings = $settings;
}
function detect() {
$referral_id = $this->settings->get(self::REFERRAL_SETTING_NAME, null);
if ($referral_id) {
return $referral_id;
}
$referral_id = $this->wp->getOption(self::REFERRAL_CONSTANT_NAME, null);
if ($referral_id === null && defined(self::REFERRAL_CONSTANT_NAME)) {
$referral_id = constant(self::REFERRAL_CONSTANT_NAME);
}
if ($referral_id !== null) {
$this->settings->set(self::REFERRAL_SETTING_NAME, $referral_id);
}
return $referral_id;
}
}