PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / 5.8.2
Matomo Analytics – Powerful, Privacy-First Insights for WordPress v5.8.2
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 / MarketplaceSetupWizard.php
matomo / classes / WpMatomo / Admin Last commit date
PluginSuggestions 2 months ago TrackingSettings 2 months ago views 2 months ago AccessSettings.php 4 years ago AdBlockDetector.php 7 months ago Admin.php 2 months ago AdminSettings.php 2 months ago AdminSettingsInterface.php 6 years ago AdvancedSettings.php 10 months ago Chart.php 2 months ago CookieConsent.php 4 years ago Dashboard.php 2 months ago ExclusionSettings.php 7 months ago GeolocationSettings.php 2 years ago GetStarted.php 2 months ago ImportWpStatistics.php 2 months ago Info.php 2 months ago InvalidIpException.php 4 years ago Marketplace.php 2 months ago MarketplaceSetupWizard.php 2 months ago MarketplaceSetupWizardBody.php 3 months ago MatomoPage.php 2 months ago MatomoPageContent.php 2 months ago Menu.php 2 months ago PluginMeasurableSettings.php 2 years ago PrivacySettings.php 1 year ago SafeModeMenu.php 2 months ago Summary.php 2 months ago SystemReport.php 2 months ago TrackingSettings.php 4 months ago WhatsNewNotifications.php 2 months ago
MarketplaceSetupWizard.php
108 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;
11
12 use WpMatomo\Feature;
13 use WpMatomo\Settings;
14
15 class MarketplaceSetupWizard extends Feature {
16 const MARKETPLACE_PLUGIN_FILE = 'matomo-marketplace-for-wordpress/matomo-marketplace-for-wordpress.php';
17 const AJAX_IS_ACTIVE_NONCE_NAME = 'matomo-marketplace-setup-wizard-is-active';
18 const AJAX_ACTIVATE_NONCE_NAME = 'matomo-marketplace-setup-wizard-activate';
19
20 public function is_active() {
21 if ( ! is_admin() ) {
22 return false;
23 }
24
25 if ( empty( $_REQUEST['page'] ) ) {
26 return false;
27 }
28
29 if ( Menu::SLUG_GET_STARTED === $_REQUEST['page'] ) {
30 return true;
31 }
32
33 if ( Menu::SLUG_MARKETPLACE !== $_REQUEST['page'] ) {
34 return false;
35 }
36
37 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
38 $tab = isset( $_REQUEST['tab'] ) ? wp_unslash( $_REQUEST['tab'] ) : '';
39 return 'install' === $tab || 'subscriptions' === $tab;
40 }
41
42 public function get_body( $show_titles = true ) {
43 return new MarketplaceSetupWizardBody( $show_titles );
44 }
45
46 public function show() {
47 $matomo_logo_big = plugins_url( 'assets/img/logo-big.png', MATOMO_ANALYTICS_FILE );
48 $marketplace_setup_wizard_body = $this->get_body();
49
50 include dirname( __FILE__ ) . '/views/marketplace_setup_wizard.php';
51 }
52
53 public function register_hooks() {
54 add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_scripts' ] );
55 }
56
57 public function enqueue_scripts() {
58 wp_enqueue_script(
59 'matomo-marketplace-setup-wizard',
60 plugins_url( '/assets/js/marketplace_setup_wizard.js', MATOMO_ANALYTICS_FILE ),
61 [ 'jquery' ],
62 \WpMatomo::VERSION,
63 true
64 );
65
66 wp_localize_script(
67 'matomo-marketplace-setup-wizard',
68 'mtmMarketplaceWizardAjax',
69 [
70 'ajax_url' => admin_url( 'admin-ajax.php' ),
71 'is_active_nonce' => wp_create_nonce( self::AJAX_IS_ACTIVE_NONCE_NAME ),
72 'activate_nonce' => wp_create_nonce( self::AJAX_ACTIVATE_NONCE_NAME ),
73 ]
74 );
75 }
76
77 public function register_ajax() {
78 add_action( 'wp_ajax_matomo_is_marketplace_active', [ self::class, 'is_marketplace_active' ] );
79 add_action( 'wp_ajax_matomo_activate_marketplace', [ self::class, 'activate_marketplace_plugin' ] );
80 }
81
82 public static function is_marketplace_active() {
83 check_ajax_referer( self::AJAX_IS_ACTIVE_NONCE_NAME );
84
85 if ( ! current_user_can( 'activate_plugins' ) ) {
86 wp_send_json_error( [ 'message' => 'forbidden' ], 403 );
87 }
88
89 wp_send_json( [ 'active' => is_plugin_active( self::MARKETPLACE_PLUGIN_FILE ) ] );
90 }
91
92 public static function activate_marketplace_plugin() {
93 check_ajax_referer( self::AJAX_ACTIVATE_NONCE_NAME );
94
95 if ( ! current_user_can( 'activate_plugins' ) ) {
96 wp_send_json_error( [ 'message' => 'forbidden' ], 403 );
97 }
98
99 activate_plugin( self::MARKETPLACE_PLUGIN_FILE );
100 wp_send_json( [] );
101 }
102
103 public static function is_marketplace_installed() {
104 return is_file( WP_PLUGIN_DIR . '/' . self::MARKETPLACE_PLUGIN_FILE )
105 || is_file( WP_CONTENT_DIR . '/mu-plugins/' . self::MARKETPLACE_PLUGIN_FILE );
106 }
107 }
108