throw_exception_if_php_version_is_incompatible(); $this->cookiebot_init(); register_activation_hook( __FILE__, array( new Cookiebot_Activated(), 'run' ) ); register_deactivation_hook( __FILE__, array( new Cookiebot_Deactivated(), 'run' ) ); } /** * @throws RuntimeException */ private function throw_exception_if_php_version_is_incompatible() { if ( version_compare( PHP_VERSION, self::COOKIEBOT_MIN_PHP_VERSION, '<' ) ) { $message = sprintf( // translators: The placeholder is for the COOKIEBOT_MIN_PHP_VERSION constant __( 'The Cookiebot plugin requires PHP version %s or greater.', 'cookiebot' ), self::COOKIEBOT_MIN_PHP_VERSION ); throw new DomainException( $message ); } } public function cookiebot_init() { Cookiebot_Addons::instance(); load_textdomain( 'cookiebot', CYBOT_COOKIEBOT_PLUGIN_DIR . 'langs/cookiebot-' . get_locale() . '.mo' ); load_plugin_textdomain( 'cookiebot', false, dirname( plugin_basename( __FILE__ ) ) . '/langs' ); if ( is_admin() ) { ( new Menu_Settings() )->add_menu(); if ( is_multisite() && is_plugin_active_for_network( 'cookiebot/cookiebot.php' ) ) { ( new Network_Menu_Settings() )->add_menu(); } ( new Dashboard_Widget_Cookiebot_Status() )->register_hooks(); ( new Cookiebot_Recommendation_Notice() )->register_hooks(); ( new Cookiebot_Temp_Notice() )->register_hooks(); ( new Cookiebot_Review() )->register_hooks(); } ( new Consent_API_Helper() )->register_hooks(); ( new Cookiebot_Javascript_Helper() )->register_hooks(); ( new Cookiebot_Automatic_Updates() )->register_hooks(); ( new Widgets() )->register_hooks(); ( new Cookiebot_Gutenberg_Declaration_Block() )->register_hooks(); ( new WP_Rocket_Helper() )->register_hooks(); $this->set_default_options(); $this->delay_notice_recommendation_on_first_activation(); add_filter( 'plugin_action_links_cookiebot/cookiebot.php', array( $this, 'set_settings_action_link' ) ); } /** * Returns true if an user is logged in and has an edit_themes capability * * @return bool * * @since 3.3.1 * @version 3.4.1 */ public static function can_current_user_edit_theme() { if ( is_user_logged_in() && ( current_user_can( 'edit_themes' ) || current_user_can( 'edit_pages' ) || current_user_can( 'edit_posts' ) ) ) { return true; } return false; } /** * @return string */ public static function get_cbid() { $network_setting = (string) get_site_option( 'cookiebot-cbid', '' ); $setting = (string) get_option( 'cookiebot-cbid', $network_setting ); return empty( $setting ) ? $network_setting : $setting; } /** * @return string */ public static function get_cookie_blocking_mode() { $allowed_modes = array( 'auto', 'manual' ); $network_setting = (string) get_site_option( 'cookiebot-cookie-blocking-mode', 'manual' ); $setting = (string) get_option( 'cookiebot-cookie-blocking-mode', $network_setting ); return in_array( $setting, $allowed_modes, true ) ? $setting : 'manual'; } /** * @return bool */ public static function check_network_auto_blocking_mode() { $network_setting = (string) get_site_option( 'cookiebot-cookie-blocking-mode' ); return $network_setting === 'auto' ? true : false; } /** * @return string */ public static function get_cookie_categories_status() { return self::get_cookie_blocking_mode() === 'auto' ? 'disabled' : ''; } /** * @return bool */ public static function is_cookie_category_selected( $option, $category ) { $categories = get_option( $option ); if ( ! $categories || ! is_array( $categories ) ) { return false; } return in_array( $category, $categories, true ); } /** * Cookiebot_WP Check if Cookiebot is active in admin * * @version 4.2.8 * @since 3.1.0 */ public static function cookiebot_disabled_in_admin() { if ( ( is_network_admin() && get_site_option( 'cookiebot-nooutput-admin', false ) ) || ( ! is_network_admin() && get_site_option( 'cookiebot-nooutput-admin', false ) ) || ( ! is_network_admin() && get_option( 'cookiebot-nooutput-admin', false ) ) ) { return true; } return false; } /** * Cookiebot_WP Set default options * * @version 4.2.5 * @since 4.2.5 */ private function set_default_options() { $options = array( 'cookiebot-nooutput-admin' => '1', 'cookiebot-gcm' => '1', ); $temp_notice_option = get_option( Cookiebot_Temp_Notice::COOKIEBOT_TEMP_OPTION_KEY ); foreach ( $options as $option => $default ) { if ( get_option( $option ) === false && ! get_option( $option . self::OPTION_FIRST_RUN_SUFFIX ) ) { update_option( $option, $default ); } if ( ( get_option( $option ) || get_option( $option ) !== false ) && ! get_option( $option . self::OPTION_FIRST_RUN_SUFFIX ) ) { update_option( $option . self::OPTION_FIRST_RUN_SUFFIX, '1' ); } } if ( empty( $temp_notice_option ) ) { if ( version_compare( phpversion(), '7.0.0' ) >= 0 ) { update_option( Cookiebot_Temp_Notice::COOKIEBOT_TEMP_OPTION_KEY, 'hide' ); } else { update_option( Cookiebot_Temp_Notice::COOKIEBOT_TEMP_OPTION_KEY, 'show' ); } } elseif ( $temp_notice_option !== 'hide' && version_compare( phpversion(), '7.0.0' ) >= 0 ) { update_option( Cookiebot_Temp_Notice::COOKIEBOT_TEMP_OPTION_KEY, 'hide' ); } self::set_tcf_version(); } private static function set_tcf_version() { $iab_version = get_option( 'cookiebot-tcf-version' ); if ( ! empty( $iab_version ) && $iab_version === 'IAB' ) { update_option( 'cookiebot-tcf-version', 'TCFv2.2' ); } } /** * Cookiebot_WP Delay recommendation notice 1 day after first activation * * @version 4.2.5 * @since 4.2.5 */ private function delay_notice_recommendation_on_first_activation() { // Check if recommendation notice delay option exists if ( get_option( Cookiebot_Recommendation_Notice::COOKIEBOT_RECOMMENDATION_OPTION_KEY, false ) === false ) { // Delay in 1 day add_option( Cookiebot_Recommendation_Notice::COOKIEBOT_RECOMMENDATION_OPTION_KEY, strtotime( '+1 day' ) ); } } public function set_settings_action_link( $actions ) { $cblinks = array( '' . esc_html__( 'Dashboard', 'cookiebot' ) . '', ); $actions = array_merge( $actions, $cblinks ); return $actions; } /** * @return string */ public static function get_manager_language() { $locale = get_locale(); $supported_langs = array( 'de_DE' => 'de', 'da_DK' => 'da', 'fr_FR' => 'fr', 'it_IT' => 'it', 'es_ES' => 'es', ); return array_key_exists( $locale, $supported_langs ) ? $supported_langs[ $locale ] : esc_html( 'en' ); } const OPTION_FIRST_RUN_SUFFIX = '-first-run'; }