- Adds check for premium plugin status
- Bypasses subscriber count enforcement if premium is enabled
This commit is contained in:
@ -27,7 +27,6 @@ class Env {
|
||||
static $db_password;
|
||||
static $db_charset;
|
||||
static $db_timezone_offset;
|
||||
static $subscribers_limit = 2000;
|
||||
|
||||
static function init($file, $version) {
|
||||
global $wpdb;
|
||||
@ -39,11 +38,11 @@ class Env {
|
||||
self::$assets_path = self::$path . '/assets';
|
||||
self::$assets_url = plugins_url('/assets', $file);
|
||||
$wp_upload_dir = wp_upload_dir();
|
||||
self::$temp_path = $wp_upload_dir['basedir'].'/'.self::$plugin_name;
|
||||
self::$temp_path = $wp_upload_dir['basedir'] . '/' . self::$plugin_name;
|
||||
if(!is_dir(self::$temp_path)) {
|
||||
mkdir(self::$temp_path);
|
||||
}
|
||||
self::$temp_url = $wp_upload_dir['baseurl'].'/'.self::$plugin_name;
|
||||
self::$temp_url = $wp_upload_dir['baseurl'] . '/' . self::$plugin_name;
|
||||
self::$languages_path = self::$path . '/lang';
|
||||
self::$lib_path = self::$path . '/lib';
|
||||
self::$plugin_prefix = 'mailpoet_';
|
||||
|
@ -4,6 +4,7 @@ namespace MailPoet\Config;
|
||||
use MailPoet\Cron\CronTrigger;
|
||||
use MailPoet\Router;
|
||||
use MailPoet\API;
|
||||
use MailPoet\Util\License\License as License;
|
||||
use MailPoet\WP\Notice as WPNotice;
|
||||
|
||||
if(!defined('ABSPATH')) exit;
|
||||
@ -106,6 +107,7 @@ class Initializer {
|
||||
$this->setupShortcodes();
|
||||
$this->setupHooks();
|
||||
$this->setupImages();
|
||||
$this->setupLicense();
|
||||
$this->setupCronTrigger();
|
||||
|
||||
$this->plugin_initialized = true;
|
||||
@ -116,6 +118,7 @@ class Initializer {
|
||||
|
||||
function onInit() {
|
||||
if(!$this->plugin_initialized) {
|
||||
define('MAILPOET_INITIALIZED', false);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -126,6 +129,8 @@ class Initializer {
|
||||
} catch(\Exception $e) {
|
||||
$this->handleFailedInitialization($e);
|
||||
}
|
||||
|
||||
define('MAILPOET_INITIALIZED', true);
|
||||
}
|
||||
|
||||
function setupWidget() {
|
||||
@ -206,4 +211,9 @@ class Initializer {
|
||||
function handleFailedInitialization($message) {
|
||||
return WPNotice::displayError($message);
|
||||
}
|
||||
|
||||
function setupLicense() {
|
||||
$license = new License();
|
||||
$license->init();
|
||||
}
|
||||
}
|
@ -14,6 +14,7 @@ use MailPoet\Settings\Hosts;
|
||||
use MailPoet\Settings\Pages;
|
||||
use MailPoet\Subscribers\ImportExport\ImportExportFactory;
|
||||
use MailPoet\Listing;
|
||||
use MailPoet\Util\License\License as License;
|
||||
use MailPoet\WP\DateTime;
|
||||
|
||||
if(!defined('ABSPATH')) exit;
|
||||
@ -34,16 +35,6 @@ class Menu {
|
||||
);
|
||||
}
|
||||
|
||||
function checkSubscribersLimit() {
|
||||
$subscribers_count = Subscriber::getTotalSubscribers();
|
||||
if($subscribers_count > Env::$subscribers_limit) {
|
||||
echo $this->renderer->render('limit.html', array(
|
||||
'limit' => Env::$subscribers_limit
|
||||
));
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
function setup() {
|
||||
$main_page_slug = 'mailpoet-newsletters';
|
||||
|
||||
@ -252,7 +243,7 @@ class Menu {
|
||||
}
|
||||
|
||||
function settings() {
|
||||
$this->checkSubscribersLimit();
|
||||
do_action(License::CHECK_PERMISSION, 'Subscribers');
|
||||
|
||||
$settings = Setting::getAll();
|
||||
$flags = $this->_getFlags();
|
||||
@ -326,7 +317,7 @@ class Menu {
|
||||
}
|
||||
|
||||
function segments() {
|
||||
$this->checkSubscribersLimit();
|
||||
do_action(License::CHECK_PERMISSION, 'Subscribers');
|
||||
|
||||
$data = array();
|
||||
$data['items_per_page'] = $this->getLimitPerPage('segments');
|
||||
@ -334,7 +325,7 @@ class Menu {
|
||||
}
|
||||
|
||||
function forms() {
|
||||
$this->checkSubscribersLimit();
|
||||
do_action(License::CHECK_PERMISSION, 'Subscribers');
|
||||
|
||||
$data = array();
|
||||
|
||||
@ -345,7 +336,7 @@ class Menu {
|
||||
}
|
||||
|
||||
function newsletters() {
|
||||
$this->checkSubscribersLimit();
|
||||
do_action(License::CHECK_PERMISSION, 'Subscribers');
|
||||
|
||||
global $wp_roles;
|
||||
|
||||
|
26
lib/Util/License/Features/Subscribers.php
Normal file
26
lib/Util/License/Features/Subscribers.php
Normal file
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
namespace MailPoet\Util\License\Features;
|
||||
|
||||
use MailPoet\Config\Renderer;
|
||||
use MailPoet\Models\Subscriber as SubscriberModel;
|
||||
use MailPoet\Util\License\License;
|
||||
|
||||
class Subscribers {
|
||||
static $subscribers_limit = 2000;
|
||||
|
||||
function check() {
|
||||
if(!License::getLicense() &&
|
||||
SubscriberModel::getTotalSubscribers() > self::$subscribers_limit
|
||||
) {
|
||||
$renderer = new Renderer();
|
||||
echo $renderer->init()->render('limit.html', array(
|
||||
'limit' => self::$subscribers_limit
|
||||
));
|
||||
return $this->terminateRequest();
|
||||
}
|
||||
}
|
||||
|
||||
function terminateRequest() {
|
||||
exit;
|
||||
}
|
||||
}
|
26
lib/Util/License/License.php
Normal file
26
lib/Util/License/License.php
Normal file
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
namespace MailPoet\Util\License;
|
||||
|
||||
class License {
|
||||
const CHECK_PERMISSION = 'mailpoet_premium_feature_permission';
|
||||
const FEATURE_NAMESPACE = 'MailPoet\Util\License\Features\\';
|
||||
|
||||
function init() {
|
||||
add_action(self::CHECK_PERMISSION, array($this, 'checkFeaturePermission'));
|
||||
}
|
||||
|
||||
static function getLicense() {
|
||||
return (defined('MAILPOET_PREMIUM_LICENSE')) ?
|
||||
MAILPOET_PREMIUM_LICENSE :
|
||||
false;
|
||||
}
|
||||
|
||||
function checkFeaturePermission($feature) {
|
||||
$feature = self::FEATURE_NAMESPACE . $feature;
|
||||
if(class_exists($feature)) {
|
||||
$feature = new $feature();
|
||||
$feature->check();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user