TrackingSettings
4 years ago
views
2 years ago
AccessSettings.php
4 years ago
Admin.php
2 years ago
AdminSettings.php
2 years ago
AdminSettingsInterface.php
6 years ago
AdvancedSettings.php
2 years 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
2 years ago
Menu.php
2 years ago
PluginMeasurableSettings.php
2 years ago
PrivacySettings.php
4 years ago
SafeModeMenu.php
4 years ago
Summary.php
4 years ago
SystemReport.php
2 years ago
TrackingSettings.php
4 years ago
MarketplaceSetupWizard.php
72 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 | |
| 15 | public function __construct() { |
| 16 | $this->add_hooks(); |
| 17 | } |
| 18 | |
| 19 | public function show() { |
| 20 | $matomo_logo_big = plugins_url( 'assets/img/logo-big.png', MATOMO_ANALYTICS_FILE ); |
| 21 | $user_can_upload_plugins = current_user_can( 'upload_plugins' ); |
| 22 | $user_can_activate_plugins = current_user_can( 'activate_plugins' ); |
| 23 | $is_plugin_installed = is_file( WP_PLUGIN_DIR . '/' . self::MARKETPLACE_PLUGIN_FILE ) |
| 24 | || is_file( WP_CONTENT_DIR . '/mu-plugins/' . self::MARKETPLACE_PLUGIN_FILE ); |
| 25 | |
| 26 | include dirname( __FILE__ ) . '/views/marketplace_setup_wizard.php'; |
| 27 | } |
| 28 | |
| 29 | private function add_hooks() { |
| 30 | if ( ! current_user_can( 'upload_plugins' ) |
| 31 | || ! current_user_can( 'activate_plugins' ) |
| 32 | ) { |
| 33 | return; |
| 34 | } |
| 35 | |
| 36 | $this->enqueue_scripts(); |
| 37 | } |
| 38 | |
| 39 | private function enqueue_scripts() { |
| 40 | wp_enqueue_script( |
| 41 | 'matomo-marketplace-setup-wizard', |
| 42 | plugins_url( '/assets/js/marketplace_setup_wizard.js', MATOMO_ANALYTICS_FILE ), |
| 43 | [ 'jquery' ], |
| 44 | '1.0.0', |
| 45 | true |
| 46 | ); |
| 47 | |
| 48 | wp_localize_script( |
| 49 | 'matomo-marketplace-setup-wizard', |
| 50 | 'mtmMarketplaceWizardAjax', |
| 51 | [ |
| 52 | 'ajax_url' => admin_url( 'admin-ajax.php' ), |
| 53 | 'nonce' => wp_create_nonce( 'matomo-marketplace-setup-wizard' ), |
| 54 | ] |
| 55 | ); |
| 56 | } |
| 57 | |
| 58 | public static function register_ajax() { |
| 59 | add_action( 'wp_ajax_mtm_is_marketplace_active', [ self::class, 'is_marketplace_active' ] ); |
| 60 | add_action( 'wp_ajax_mtm_activate_marketplace', [ self::class, 'activate_marketplace_plugin' ] ); |
| 61 | } |
| 62 | |
| 63 | public static function is_marketplace_active() { |
| 64 | wp_send_json( [ 'active' => is_plugin_active( self::MARKETPLACE_PLUGIN_FILE ) ] ); |
| 65 | } |
| 66 | |
| 67 | public static function activate_marketplace_plugin() { |
| 68 | activate_plugin( self::MARKETPLACE_PLUGIN_FILE ); |
| 69 | wp_send_json( [] ); |
| 70 | } |
| 71 | } |
| 72 |