Subscribers limit
- added "limit.html" template - subscribers_limit set in Env class
This commit is contained in:
@@ -27,6 +27,7 @@ class Env {
|
||||
static $db_password;
|
||||
static $db_charset;
|
||||
static $db_timezone_offset;
|
||||
static $subscribers_limit = 2000;
|
||||
|
||||
static function init($file, $version) {
|
||||
global $wpdb;
|
||||
|
@@ -34,6 +34,16 @@ 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';
|
||||
|
||||
@@ -242,6 +252,8 @@ class Menu {
|
||||
}
|
||||
|
||||
function settings() {
|
||||
$this->checkSubscribersLimit();
|
||||
|
||||
$settings = Setting::getAll();
|
||||
$flags = $this->_getFlags();
|
||||
|
||||
@@ -314,12 +326,16 @@ class Menu {
|
||||
}
|
||||
|
||||
function segments() {
|
||||
$this->checkSubscribersLimit();
|
||||
|
||||
$data = array();
|
||||
$data['items_per_page'] = $this->getLimitPerPage('segments');
|
||||
echo $this->renderer->render('segments.html', $data);
|
||||
}
|
||||
|
||||
function forms() {
|
||||
$this->checkSubscribersLimit();
|
||||
|
||||
$data = array();
|
||||
|
||||
$data['items_per_page'] = $this->getLimitPerPage('forms');
|
||||
@@ -329,6 +345,8 @@ class Menu {
|
||||
}
|
||||
|
||||
function newsletters() {
|
||||
$this->checkSubscribersLimit();
|
||||
|
||||
global $wp_roles;
|
||||
|
||||
$data = array();
|
||||
|
@@ -624,6 +624,13 @@ class Subscriber extends Model {
|
||||
);
|
||||
}
|
||||
|
||||
static function getTotalSubscribers() {
|
||||
return self::whereIn('status', array(
|
||||
self::STATUS_SUBSCRIBED,
|
||||
self::STATUS_UNCONFIRMED
|
||||
))->count();
|
||||
}
|
||||
|
||||
static function bulkTrash($orm) {
|
||||
$count = parent::bulkAction($orm, function($subscriber_ids) {
|
||||
self::rawExecute(join(' ', array(
|
||||
|
@@ -438,6 +438,36 @@ class SubscriberTest extends MailPoetTest {
|
||||
expect($subscriber)->notEquals(false);
|
||||
}
|
||||
|
||||
function testItCanTheTotalNumberOfSubscribers() {
|
||||
// remove all subscribers
|
||||
Subscriber::deleteMany();
|
||||
|
||||
$subscriber_1 = Subscriber::createOrUpdate(array(
|
||||
'email' => 'subscriber_1@mailpoet.com',
|
||||
'status' => Subscriber::STATUS_SUBSCRIBED
|
||||
));
|
||||
|
||||
$subscriber_2 = Subscriber::createOrUpdate(array(
|
||||
'email' => 'subscriber_2@mailpoet.com',
|
||||
'status' => Subscriber::STATUS_UNCONFIRMED
|
||||
));
|
||||
|
||||
$subscriber_3 = Subscriber::createOrUpdate(array(
|
||||
'email' => 'subscriber_3@mailpoet.com',
|
||||
'status' => Subscriber::STATUS_UNSUBSCRIBED
|
||||
));
|
||||
|
||||
// counts only subscribed & unconfirmed users
|
||||
$total = Subscriber::getTotalSubscribers();
|
||||
expect($total)->equals(2);
|
||||
|
||||
$subscriber_1->status = Subscriber::STATUS_UNSUBSCRIBED;
|
||||
$subscriber_1->save();
|
||||
|
||||
$total = Subscriber::getTotalSubscribers();
|
||||
expect($total)->equals(1);
|
||||
}
|
||||
|
||||
function _after() {
|
||||
ORM::raw_execute('TRUNCATE ' . Subscriber::$_table);
|
||||
ORM::raw_execute('TRUNCATE ' . Segment::$_table);
|
||||
|
28
views/limit.html
Normal file
28
views/limit.html
Normal file
@@ -0,0 +1,28 @@
|
||||
<% extends 'layout.html' %>
|
||||
|
||||
<% block content %>
|
||||
|
||||
<div class="wrap about-wrap">
|
||||
<h1><%= __("You've reached the %d subscribers limit!") | format(limit) %></h1>
|
||||
|
||||
<p class="about-text">
|
||||
<%= __("MailPoet 3 is currently limited to %d subscribers.") | format(limit) %>
|
||||
</p>
|
||||
|
||||
<img
|
||||
src="http://i2.wp.com/www.mailpoet.com/wp-content/uploads/2015/05/sad-cat.gif?resize=500%2C212"
|
||||
alt="sad-cat"
|
||||
width="500"
|
||||
height="212"
|
||||
/>
|
||||
|
||||
<h3><%= __('Immediately, you can:') %></h3>
|
||||
<ul>
|
||||
<li><%= __('Delete unconfirmed subscribers to have less than %d subscribers.') | format(limit) %></li>
|
||||
<li>
|
||||
<a href="https://docs.mailpoet.com/"><%= __('Contact us')%></a>
|
||||
<%= __('to become a Premium beta tester.')%>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<% endblock %>
|
Reference in New Issue
Block a user