Files
piratepoet/lib/Referrals/ReferralDetector.php
Jan Jakeš 54549ff037 Convert variable names to camel case
[MAILPOET-1796]
2020-01-14 15:22:42 +01:00

38 lines
1000 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;
public function __construct(WPFunctions $wp, SettingsController $settings) {
$this->wp = $wp;
$this->settings = $settings;
}
public function detect() {
$referralId = $this->settings->get(self::REFERRAL_SETTING_NAME, null);
if ($referralId) {
return $referralId;
}
$referralId = $this->wp->getOption(self::REFERRAL_CONSTANT_NAME, null);
if ($referralId === null && defined(self::REFERRAL_CONSTANT_NAME)) {
$referralId = constant(self::REFERRAL_CONSTANT_NAME);
}
if ($referralId !== null) {
$this->settings->set(self::REFERRAL_SETTING_NAME, $referralId);
}
return $referralId;
}
}