add_to_any
3 years ago
addthis
4 years ago
caos_host_analyticsjs_local
3 years ago
custom_facebook_feed
4 years ago
custom_facebook_feed_pro
3 years ago
embed_autocorrect
3 years ago
enfold
4 years ago
enhanced_ecommerce_for_woocommerce_store
4 years ago
facebook_for_woocommerce
3 years ago
ga_google_analytics
3 years ago
gadwp
4 years ago
google_analyticator
4 years ago
google_analytics
4 years ago
google_analytics_plus
4 years ago
google_site_kit
4 years ago
hubspot_leadin
4 years ago
hubspot_tracking_code
4 years ago
instagram_feed
4 years ago
jetpack
3 years ago
litespeed_cache
3 years ago
matomo
4 years ago
ninja_forms
4 years ago
official_facebook_pixel
4 years ago
optinmonster
4 years ago
pixel_caffeine
4 years ago
simple_share_buttons_adder
4 years ago
wd_google_analytics
4 years ago
woocommerce_google_analytics_pro
4 years ago
wp_analytify
4 years ago
wp_google_analytics_events
3 years ago
wp_mautic
3 years ago
wp_piwik
4 years ago
wp_rocket
3 years ago
wp_seopress
4 years ago
wpforms
3 years ago
Base_Cookiebot_Addon.php
3 years ago
Base_Cookiebot_Other_Addon.php
4 years ago
Base_Cookiebot_Plugin_Addon.php
4 years ago
Base_Cookiebot_Theme_Addon.php
4 years ago
Base_Cookiebot_Plugin_Addon.php
74 lines
| 1 | <?php |
| 2 | |
| 3 | namespace cybot\cookiebot\addons\controller\addons; |
| 4 | |
| 5 | use cybot\cookiebot\lib\buffer\Buffer_Output_Interface; |
| 6 | use cybot\cookiebot\lib\Cookie_Consent_Interface; |
| 7 | use cybot\cookiebot\lib\script_loader_tag\Script_Loader_Tag_Interface; |
| 8 | use cybot\cookiebot\lib\Settings_Service_Interface; |
| 9 | use Exception; |
| 10 | |
| 11 | abstract class Base_Cookiebot_Plugin_Addon extends Base_Cookiebot_Addon { |
| 12 | |
| 13 | const PLUGIN_FILE_PATH = ''; |
| 14 | |
| 15 | /** |
| 16 | * @param $settings Settings_Service_Interface |
| 17 | * @param $script_loader_tag Script_Loader_Tag_Interface |
| 18 | * @param $cookie_consent Cookie_Consent_Interface |
| 19 | * @param $buffer_output Buffer_Output_Interface |
| 20 | * |
| 21 | * @throws Exception |
| 22 | * @since 1.3.0 |
| 23 | */ |
| 24 | protected function __construct( |
| 25 | Settings_Service_Interface $settings, |
| 26 | Script_Loader_Tag_Interface $script_loader_tag, |
| 27 | Cookie_Consent_Interface $cookie_consent, |
| 28 | Buffer_Output_Interface $buffer_output |
| 29 | ) { |
| 30 | parent::__construct( $settings, $script_loader_tag, $cookie_consent, $buffer_output ); |
| 31 | $this->validate_required_string_class_constant( 'PLUGIN_FILE_PATH' ); |
| 32 | } |
| 33 | |
| 34 | /** |
| 35 | * @return bool |
| 36 | */ |
| 37 | final public function is_addon_installed() { |
| 38 | $path = WP_PLUGIN_DIR . DIRECTORY_SEPARATOR . static::PLUGIN_FILE_PATH; |
| 39 | return ( file_exists( $path ) && ! is_wp_error( validate_plugin( static::PLUGIN_FILE_PATH ) ) ); |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * Checks if addon plugin is activated |
| 44 | * |
| 45 | * @since 1.3.0 |
| 46 | */ |
| 47 | final public function is_addon_activated() { |
| 48 | return $this->is_addon_installed() && is_plugin_active( static::PLUGIN_FILE_PATH ); |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * @return string |
| 53 | * @throws Exception |
| 54 | */ |
| 55 | final public function get_version() { |
| 56 | $plugin_data = $this->get_plugin_data(); |
| 57 | if ( ! isset( $plugin_data['Version'] ) ) { |
| 58 | throw new Exception( 'Check if plugin is installed before calling get_version()' ); |
| 59 | } |
| 60 | return $plugin_data['Version']; |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * @return string[] |
| 65 | */ |
| 66 | private function get_plugin_data() { |
| 67 | return get_file_data( |
| 68 | WP_PLUGIN_DIR . DIRECTORY_SEPARATOR . static::PLUGIN_FILE_PATH, |
| 69 | array( 'Version' => 'version' ), |
| 70 | false |
| 71 | ); |
| 72 | } |
| 73 | } |
| 74 |