<?php // phpcs:ignore SlevomatCodingStandard.TypeHints.DeclareStrictTypes.DeclareStrictTypesMissing namespace MailPoet\API\JSON\v1; if (!defined('ABSPATH')) exit; use MailPoet\API\JSON\Endpoint as APIEndpoint; use MailPoet\API\JSON\Error as APIError; use MailPoet\Config\AccessControl; use MailPoet\Config\ServicesChecker; use MailPoet\WP\Functions as WPFunctions; use MailPoet\WPCOM\DotcomHelperFunctions; use WP_Error; class Premium extends APIEndpoint { const PREMIUM_PLUGIN_SLUG = 'mailpoet-premium'; const PREMIUM_PLUGIN_PATH = 'mailpoet-premium/mailpoet-premium.php'; // This is the path to the managed plugin on Dotcom platform. It is relative to WP_PLUGIN_DIR. const DOTCOM_SYMLINK_PATH = '../../../../wordpress/plugins/mailpoet-premium/latest'; public $permissions = [ 'global' => AccessControl::PERMISSION_MANAGE_SETTINGS, ]; /** @var ServicesChecker */ private $servicesChecker; /** @var WPFunctions */ private $wp; /** @var DotcomHelperFunctions */ private $dotcomHelperFunctions; public function __construct( ServicesChecker $servicesChecker, WPFunctions $wp, DotcomHelperFunctions $dotcomHelperFunctions ) { $this->servicesChecker = $servicesChecker; $this->wp = $wp; $this->dotcomHelperFunctions = $dotcomHelperFunctions; } public function installPlugin() { $premiumKeyValid = $this->servicesChecker->isPremiumKeyValid(false); if (!$premiumKeyValid) { return $this->error(__('Premium key is not valid.', 'mailpoet')); } $pluginInfo = $this->wp->pluginsApi('plugin_information', [ 'slug' => self::PREMIUM_PLUGIN_SLUG, ]); if (!$pluginInfo || $pluginInfo instanceof WP_Error) { return $this->error(__('Error when installing MailPoet Premium plugin.', 'mailpoet')); } $pluginInfo = (array)$pluginInfo; // If we are in Dotcom platform, we try to symlink the plugin instead of downloading it try { if ($this->dotcomHelperFunctions->isDotcom()) { $result = symlink(self::DOTCOM_SYMLINK_PATH, WP_PLUGIN_DIR . '/' . self::PREMIUM_PLUGIN_SLUG); if ($result === true) { return $this->successResponse(); } } } catch (\Exception $e) { // Do nothing and continue with a regular installation } $result = $this->wp->installPlugin($pluginInfo['download_link']); if ($result !== true) { return $this->error(__('Error when installing MailPoet Premium plugin.', 'mailpoet')); } return $this->successResponse(); } public function activatePlugin() { $premiumKeyValid = $this->servicesChecker->isPremiumKeyValid(false); if (!$premiumKeyValid) { return $this->error(__('Premium key is not valid.', 'mailpoet')); } $result = $this->wp->activatePlugin(self::PREMIUM_PLUGIN_PATH); if ($result !== null) { return $this->error(__('Error when activating MailPoet Premium plugin.', 'mailpoet')); } return $this->successResponse(); } private function error($message) { return $this->badRequest([ APIError::BAD_REQUEST => $message, ]); } }
Name | Type | Size | Permission | Actions |
---|---|---|---|---|
Analytics.php | File | 668 B | 0644 |
|
AutomatedLatestContent.php | File | 3.98 KB | 0644 |
|
AutomaticEmails.php | File | 2.83 KB | 0644 |
|
Captcha.php | File | 951 B | 0644 |
|
Coupons.php | File | 1.8 KB | 0644 |
|
CustomFields.php | File | 2.98 KB | 0644 |
|
DynamicSegments.php | File | 11.93 KB | 0644 |
|
FeatureFlags.php | File | 1.42 KB | 0644 |
|
Forms.php | File | 11.3 KB | 0644 |
|
Help.php | File | 2.8 KB | 0644 |
|
ImportExport.php | File | 5.76 KB | 0644 |
|
Mailer.php | File | 3.1 KB | 0644 |
|
NewsletterLinks.php | File | 1.01 KB | 0644 |
|
NewsletterTemplates.php | File | 4.29 KB | 0644 |
|
Newsletters.php | File | 16.01 KB | 0644 |
|
Premium.php | File | 3.03 KB | 0644 |
|
RedirectResponse.php | File | 347 B | 0644 |
|
Segments.php | File | 12.19 KB | 0644 |
|
SendingQueue.php | File | 9.93 KB | 0644 |
|
SendingTaskSubscribers.php | File | 5.42 KB | 0644 |
|
Services.php | File | 12.35 KB | 0644 |
|
Settings.php | File | 16.49 KB | 0644 |
|
Setup.php | File | 1.19 KB | 0644 |
|
SubscriberStats.php | File | 4.08 KB | 0644 |
|
Subscribers.php | File | 12.31 KB | 0644 |
|
Tags.php | File | 1.34 KB | 0644 |
|
UserFlags.php | File | 1.01 KB | 0644 |
|
WoocommerceSettings.php | File | 870 B | 0644 |
|
index.php | File | 6 B | 0644 |
|