ister() { \register_setting(self::OPTION_GROUP, self::SETTING_BANNER_ACTIVE, ['type' => 'boolean', 'show_in_rest' => \true]); \register_setting(self::OPTION_GROUP, self::SETTING_BLOCKER_ACTIVE, ['type' => 'boolean', 'show_in_rest' => \true]); \register_setting(self::OPTION_GROUP, self::SETTING_OPERATOR_COUNTRY, ['type' => 'string', 'show_in_rest' => \true, 'show_in_rest' => ['schema' => ['type' => 'string', 'enum' => \array_merge(\array_keys(Iso3166OneAlpha2::getCodes()), [''])]]]); \register_setting(self::OPTION_GROUP, self::SETTING_OPERATOR_CONTACT_ADDRESS, ['type' => 'string', 'show_in_rest' => \true]); \register_setting(self::OPTION_GROUP, self::SETTING_OPERATOR_CONTACT_PHONE, ['type' => 'string', 'show_in_rest' => \true]); \register_setting(self::OPTION_GROUP, self::SETTING_OPERATOR_CONTACT_EMAIL, ['type' => 'string', 'show_in_rest' => \true]); \register_setting(self::OPTION_GROUP, self::SETTING_OPERATOR_CONTACT_FORM_ID, ['type' => 'number', 'show_in_rest' => \true]); \register_setting(self::OPTION_GROUP, self::SETTING_COOKIE_POLICY_ID, ['type' => 'number', 'show_in_rest' => \true]); // WP < 5.3 does not support array types yet, so we need to store serialized \register_setting(self::OPTION_GROUP, self::SETTING_TERRITORIAL_LEGAL_BASIS, ['type' => 'string', 'show_in_rest' => \true]); $this->overrideRegister(); } // Documented in AbstractGeneral public function isBannerActive() { return \get_option(self::SETTING_BANNER_ACTIVE); } // Documented in AbstractGeneral public function isBlockerActive() { return \get_option(self::SETTING_BLOCKER_ACTIVE); } // Documented in AbstractGeneral public function getTerritorialLegalBasis() { $option = \explode(',', \get_option(self::SETTING_TERRITORIAL_LEGAL_BASIS, '')); $option = \array_intersect($option, self::LEGAL_BASIS_ALLOWED); $option = \array_values($option); return \count($option) > 0 ? $option : [self::TERRITORIAL_LEGAL_BASIS_GDPR]; } // Documented in AbstractGeneral public function getOperatorCountry() { return \get_option(self::SETTING_OPERATOR_COUNTRY, ''); } // Documented in AbstractGeneral public function getOperatorContactAddress() { return \get_option(self::SETTING_OPERATOR_CONTACT_ADDRESS, self::DEFAULT_OPERATOR_CONTACT_ADDRESS); } // Documented in AbstractGeneral public function getOperatorContactPhone() { return \get_option(self::SETTING_OPERATOR_CONTACT_PHONE, self::DEFAULT_OPERATOR_CONTACT_PHONE); } // Documented in AbstractGeneral public function getOperatorContactEmail() { return \get_option(self::SETTING_OPERATOR_CONTACT_EMAIL, self::DEFAULT_OPERATOR_CONTACT_EMAIL); } // Documented in AbstractGeneral public function getServiceGroups() { return \array_map(function ($data) { return ServiceGroup::fromJson($data); }, \DevOwl\RealCookieBanner\settings\CookieGroup::getInstance()->toJson()); } // Documented in AbstractGeneral public function getBlocker() { return \array_map(function ($data) { return ServicesBlocker::fromJson($data); }, \DevOwl\RealCookieBanner\settings\Blocker::getInstance()->toJson()); } // Documented in AbstractGeneral public function getBannerLinks() { return \array_map(function ($data) { return SettingsBannerLink::fromJson($data); }, \DevOwl\RealCookieBanner\settings\BannerLink::getInstance()->toJson()); } // Documented in AbstractGeneral public function getLanguages() { return \array_map(function ($data) { return Language::fromJson($data); }, Core::getInstance()->getCompLanguage()->getLanguageSwitcher()); } // Documented in AbstractGeneral public function getOperatorContactFormId() { return \get_option(self::SETTING_OPERATOR_CONTACT_FORM_ID, 0); } // Documented in AbstractGeneral public function getOperatorContactFormUrl($default = \false) { $compLanguage = Core::getInstance()->getCompLanguage(); $id = $this->getOperatorContactFormId(); if ($id > 0) { $id = $compLanguage->getCurrentPostId($id, 'page'); $permalink = Utils::getPermalink($id); if ($permalink !== \false) { return $permalink; } } return $default; } // Documented in AbstractGeneral public function getCookiePolicyId() { return \get_option(self::SETTING_COOKIE_POLICY_ID, 0); } // Documented in AbstractGeneral public function getCookiePolicyUrl($default = \false) { $compLanguage = Core::getInstance()->getCompLanguage(); $id = $this->getCookiePolicyId(); if ($id > 0) { $id = $compLanguage->getCurrentPostId($id, 'page'); $permalink = Utils::getPermalink($id); if ($permalink !== \false) { return $permalink; } } return $default; } /** * Get default privacy policy post ID. */ public function getDefaultPrivacyPolicy() { $privacyPolicy = \intval(\get_option('wp_page_for_privacy_policy', 0)); return \in_array(\get_post_status($privacyPolicy), ['draft', 'publish'], \true) ? $privacyPolicy : 0; } /** * Get default operator contact email. */ public function getDefaultOperatorContactEmail() { return \get_bloginfo('admin_email'); } /** * Get default operator country. We try to calculate the country from the blog language. */ public function getDefaultOperatorCountry() { $locale = \strtoupper(\get_locale()); $potentialLocales = \array_reverse(\explode('_', $locale)); $isoCodes = \array_keys(Iso3166OneAlpha2::getCodes()); foreach ($potentialLocales as $pl) { if (\in_array($pl, $isoCodes, \true)) { return $pl; } } return ''; } /** * Get default territorial legal basis. */ public function getDefaultTerritorialLegalBasis() { $country = $this->getDefaultOperatorCountry(); $legalBasis = [self::TERRITORIAL_LEGAL_BASIS_GDPR]; switch ($country) { case 'CH': $legalBasis[] = self::TERRITORIAL_LEGAL_BASIS_DSG_SWITZERLAND; break; default: break; } return $legalBasis; } /** * When a page gets deleted, check if the value is our configured contact form page and reset the value accordingly. * * Why using `before_delete_post` instead of `delete_post`? We are deleting also translations in PolyLang/WPML and we need * to do this before the deletion process is done. * * @param number $postId */ public function before_delete_post($postId) { $contactFormId = \get_option(self::SETTING_OPERATOR_CONTACT_FORM_ID); $cookiePolicyId = \get_option(self::SETTING_COOKIE_POLICY_ID); if ($postId === $contactFormId) { \update_option(self::SETTING_OPERATOR_CONTACT_FORM_ID, self::DEFAULT_OPERATOR_CONTACT_FORM_ID); } if ($postId === $cookiePolicyId) { \update_option(self::SETTING_COOKIE_POLICY_ID, self::DEFAULT_COOKIE_POLICY_ID); // When the cookie policy page got deleted, also delete the translations $compLanguage = Core::getInstance()->getCompLanguage(); $postIdTranslations = $compLanguage->getPostTranslationIds($postId, 'page'); foreach ($postIdTranslations as $translationId) { if ($translationId !== $postId) { \wp_delete_post($translationId, \true); } } } } /** * Get singleton instance. * * @return General * @codeCoverageIgnore */ public static function getInstance() { return self::$me === null ? self::$me = new \DevOwl\RealCookieBanner\settings\General() : self::$me; } }