PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / 5.12.1
Matomo Analytics – Powerful, Privacy-First Insights for WordPress v5.12.1
5.12.1 5.12.0 5.11.1 5.11.0 5.10.2 5.10.1 trunk 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.3.0 1.3.1 1.3.2 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.1.0 4.1.1 4.1.2 4.1.3 4.10.0 4.11.0 4.12.0 4.13.0 4.13.2 4.13.3 4.13.4 4.13.5 4.14.0 4.14.1 4.14.2 4.15.0 4.15.1 4.15.2 4.15.3 4.2.0 4.3.0 4.3.1 4.4.1 4.4.2 4.5.0 4.6.0 5.0.1 5.0.2 5.0.3 5.0.4 5.0.5 5.0.6 5.0.7 5.0.8 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5 5.1.6 5.1.7 5.10.0 5.2.0 5.2.1 5.2.2 5.3.0 5.3.1 5.3.2 5.3.3 5.6.0 5.6.1 5.7.0 5.7.1 5.8.0 5.8.1 5.8.2
matomo / classes / WpMatomo / Admin / PluginSuggestions / Suggestions / WpPremiumBundle.php
matomo / classes / WpMatomo / Admin / PluginSuggestions / Suggestions Last commit date
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