Нет описания

ReferralDetector.php 1.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. namespace MailPoet\Referrals;
  3. if (!defined('ABSPATH')) exit;
  4. use MailPoet\Settings\SettingsController;
  5. use MailPoet\WP\Functions as WPFunctions;
  6. class ReferralDetector {
  7. const REFERRAL_CONSTANT_NAME = 'MAILPOET_REFERRAL_ID';
  8. const REFERRAL_SETTING_NAME = 'referral_id';
  9. /** @var WPFunctions */
  10. private $wp;
  11. /** @var SettingsController */
  12. private $settings;
  13. public function __construct(
  14. WPFunctions $wp,
  15. SettingsController $settings
  16. ) {
  17. $this->wp = $wp;
  18. $this->settings = $settings;
  19. }
  20. public function detect() {
  21. $referralId = $this->settings->get(self::REFERRAL_SETTING_NAME, null);
  22. if ($referralId) {
  23. return $referralId;
  24. }
  25. $referralId = $this->wp->getOption(self::REFERRAL_CONSTANT_NAME, null);
  26. if ($referralId === null && defined(self::REFERRAL_CONSTANT_NAME)) {
  27. $referralId = constant(self::REFERRAL_CONSTANT_NAME);
  28. }
  29. if ($referralId !== null) {
  30. $this->settings->set(self::REFERRAL_SETTING_NAME, $referralId);
  31. }
  32. return $referralId;
  33. }
  34. }