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 |