TrackingSettings
1 year ago
views
1 year ago
AccessSettings.php
4 years ago
Admin.php
1 year ago
AdminSettings.php
2 years ago
AdminSettingsInterface.php
6 years ago
AdvancedSettings.php
1 year ago
Chart.php
4 years ago
CookieConsent.php
4 years ago
Dashboard.php
4 years ago
ExclusionSettings.php
4 years ago
GeolocationSettings.php
2 years ago
GetStarted.php
4 years ago
ImportWpStatistics.php
4 years ago
Info.php
4 years ago
InvalidIpException.php
4 years ago
Marketplace.php
2 years ago
MarketplaceSetupWizard.php
1 year ago
Menu.php
1 year ago
PluginMeasurableSettings.php
2 years ago
PrivacySettings.php
1 year ago
SafeModeMenu.php
4 years ago
Summary.php
1 year ago
SystemReport.php
1 year ago
TrackingSettings.php
1 year ago
WhatsNewNotifications.php
1 year ago
MarketplaceSetupWizard.php
87 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 | class MarketplaceSetupWizard { |
| 13 | const MARKETPLACE_PLUGIN_FILE = 'matomo-marketplace-for-wordpress/matomo-marketplace-for-wordpress.php'; |
| 14 | const AJAX_IS_ACTIVE_NONCE_NAME = 'matomo-marketplace-setup-wizard-is-active'; |
| 15 | const AJAX_ACTIVATE_NONCE_NAME = 'matomo-marketplace-setup-wizard-activate'; |
| 16 | |
| 17 | public function __construct() { |
| 18 | $this->add_hooks(); |
| 19 | } |
| 20 | |
| 21 | public function show() { |
| 22 | $matomo_logo_big = plugins_url( 'assets/img/logo-big.png', MATOMO_ANALYTICS_FILE ); |
| 23 | $user_can_upload_plugins = current_user_can( 'upload_plugins' ); |
| 24 | $user_can_activate_plugins = current_user_can( 'activate_plugins' ); |
| 25 | $is_plugin_installed = is_file( WP_PLUGIN_DIR . '/' . self::MARKETPLACE_PLUGIN_FILE ) |
| 26 | || is_file( WP_CONTENT_DIR . '/mu-plugins/' . self::MARKETPLACE_PLUGIN_FILE ); |
| 27 | |
| 28 | include dirname( __FILE__ ) . '/views/marketplace_setup_wizard.php'; |
| 29 | } |
| 30 | |
| 31 | private function add_hooks() { |
| 32 | if ( ! current_user_can( 'upload_plugins' ) |
| 33 | || ! current_user_can( 'activate_plugins' ) |
| 34 | ) { |
| 35 | return; |
| 36 | } |
| 37 | |
| 38 | $this->enqueue_scripts(); |
| 39 | } |
| 40 | |
| 41 | private function enqueue_scripts() { |
| 42 | wp_enqueue_script( |
| 43 | 'matomo-marketplace-setup-wizard', |
| 44 | plugins_url( '/assets/js/marketplace_setup_wizard.js', MATOMO_ANALYTICS_FILE ), |
| 45 | [ 'jquery' ], |
| 46 | '1.0.0', |
| 47 | true |
| 48 | ); |
| 49 | |
| 50 | wp_localize_script( |
| 51 | 'matomo-marketplace-setup-wizard', |
| 52 | 'mtmMarketplaceWizardAjax', |
| 53 | [ |
| 54 | 'ajax_url' => admin_url( 'admin-ajax.php' ), |
| 55 | 'is_active_nonce' => wp_create_nonce( self::AJAX_IS_ACTIVE_NONCE_NAME ), |
| 56 | 'activate_nonce' => wp_create_nonce( self::AJAX_ACTIVATE_NONCE_NAME ), |
| 57 | ] |
| 58 | ); |
| 59 | } |
| 60 | |
| 61 | public static function register_ajax() { |
| 62 | add_action( 'wp_ajax_matomo_is_marketplace_active', [ self::class, 'is_marketplace_active' ] ); |
| 63 | add_action( 'wp_ajax_matomo_activate_marketplace', [ self::class, 'activate_marketplace_plugin' ] ); |
| 64 | } |
| 65 | |
| 66 | public static function is_marketplace_active() { |
| 67 | check_ajax_referer( self::AJAX_IS_ACTIVE_NONCE_NAME ); |
| 68 | |
| 69 | if ( ! current_user_can( 'activate_plugins' ) ) { |
| 70 | wp_send_json_error( [ 'message' => 'forbidden' ], 403 ); |
| 71 | } |
| 72 | |
| 73 | wp_send_json( [ 'active' => is_plugin_active( self::MARKETPLACE_PLUGIN_FILE ) ] ); |
| 74 | } |
| 75 | |
| 76 | public static function activate_marketplace_plugin() { |
| 77 | check_ajax_referer( self::AJAX_ACTIVATE_NONCE_NAME ); |
| 78 | |
| 79 | if ( ! current_user_can( 'activate_plugins' ) ) { |
| 80 | wp_send_json_error( [ 'message' => 'forbidden' ], 403 ); |
| 81 | } |
| 82 | |
| 83 | activate_plugin( self::MARKETPLACE_PLUGIN_FILE ); |
| 84 | wp_send_json( [] ); |
| 85 | } |
| 86 | } |
| 87 |