AdvertisingConversionExport.php
4 months ago
Funnels.php
4 months ago
HeatmapSessionRecording.php
4 months ago
SearchEngineKeywordsPerformance.php
4 months ago
UsersFlow.php
4 months ago
WpPremiumBundle.php
4 months ago
WpPremiumBundle.php
106 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Matomo - free/libre analytics platform |
| 4 | * |
| 5 | * @link https://matomo.org |
| 6 | * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later |
| 7 | * @package matomo |
| 8 | */ |
| 9 | |
| 10 | namespace WpMatomo\Admin\PluginSuggestions\Suggestions; |
| 11 | |
| 12 | if ( ! defined( 'ABSPATH' ) ) { |
| 13 | exit; // if accessed directly |
| 14 | } |
| 15 | |
| 16 | use WpMatomo\Admin\PluginSuggestions\Suggestion; |
| 17 | |
| 18 | class WpPremiumBundle extends Suggestion { |
| 19 | |
| 20 | const ALL_PREMIUM_FEATURES = [ |
| 21 | 'AdvertisingConversionExport', |
| 22 | 'Cohorts', |
| 23 | 'CrashAnalytics', |
| 24 | 'CustomReports', |
| 25 | 'FormAnalytics', |
| 26 | 'Funnels', |
| 27 | 'HeatmapSessionRecording', |
| 28 | 'MediaAnalytics', |
| 29 | 'MultiChannelConversionAttribution', |
| 30 | 'SearchEngineKeywordsPerformance', |
| 31 | 'SEOWebVitals', |
| 32 | 'UsersFlow', |
| 33 | 'AbTesting', |
| 34 | 'ActivityLog', |
| 35 | 'LoginSaml', |
| 36 | 'RollUpReporting', |
| 37 | 'WhiteLabel', |
| 38 | ]; |
| 39 | |
| 40 | const INSTALLED_COUNT_THRESHOLD = 3; |
| 41 | |
| 42 | public function should_trigger() { |
| 43 | $installed_count = 0; |
| 44 | foreach ( self::ALL_PREMIUM_FEATURES as $plugin_slug ) { |
| 45 | if ( $this->is_plugin_installed( $plugin_slug ) ) { |
| 46 | ++$installed_count; |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | return $installed_count >= self::INSTALLED_COUNT_THRESHOLD; |
| 51 | } |
| 52 | |
| 53 | public function init() { |
| 54 | $this->plugin_name = __( 'WP Premium Bundle', 'matomo' ); |
| 55 | $this->plugin_desc_long = __( 'Unlock full analytics capacity across your entire site.', 'matomo' ); |
| 56 | $this->plugin_desc_short = __( 'All premium features in one bundle', 'matomo' ); |
| 57 | $this->trigger_desc_short = __( 'Premium Plugins', 'matomo' ); |
| 58 | $this->trigger_desc_long = __( 'Premium features activated', 'matomo' ); |
| 59 | $this->image_file = 'matomo-wordpress-premium-bundle.png'; |
| 60 | } |
| 61 | |
| 62 | public function is_suggestion_applicable() { |
| 63 | // if the marketplace is not installed, we can't check if the user has the |
| 64 | // wp premium bundle or not. but it's possible the user installed the plugins |
| 65 | // manually, so we still check the plugins above. |
| 66 | if ( ! class_exists( \MatomoMarketplaceApi::class ) ) { |
| 67 | return true; |
| 68 | } |
| 69 | |
| 70 | // if the user does not have three premium plugins installed, we don't need |
| 71 | // to check with the marketplace API if the WP premium bundle is available, |
| 72 | // since we won't display the suggestion anyway. |
| 73 | if ( ! $this->should_trigger() ) { |
| 74 | return false; |
| 75 | } |
| 76 | |
| 77 | // if the license is not set in the marketplace, we still do the check for |
| 78 | // the same reason as above |
| 79 | $marketplace_api = new \MatomoMarketplaceApi(); |
| 80 | $license_key = $marketplace_api->get_license_key(); |
| 81 | if ( empty( $license_key ) ) { |
| 82 | return true; |
| 83 | } |
| 84 | |
| 85 | // makes an HTTP request to the marketplace API |
| 86 | $available_licenses = $marketplace_api->get_licenses(); |
| 87 | if ( $this->has_wp_premium_bundle_already( $available_licenses ) ) { |
| 88 | return false; |
| 89 | } |
| 90 | |
| 91 | return true; |
| 92 | } |
| 93 | |
| 94 | private function has_wp_premium_bundle_already( $available_licenses ) { |
| 95 | foreach ( $available_licenses as $license ) { |
| 96 | if ( |
| 97 | ! empty( $license['plugin']['name'] ) |
| 98 | && 'PremiumBundle' === $license['plugin']['name'] |
| 99 | ) { |
| 100 | return true; |
| 101 | } |
| 102 | } |
| 103 | return false; |
| 104 | } |
| 105 | } |
| 106 |