Encapsulate is_user_logged_in function
This commit is contained in:
@ -4,6 +4,7 @@ namespace MailPoet\Config;
|
||||
|
||||
use MailPoet\Models\Setting;
|
||||
use MailPoet\Subscription\Form;
|
||||
use MailPoet\WP\Functions as WPFunctions;
|
||||
|
||||
class Hooks {
|
||||
|
||||
@ -24,13 +25,15 @@ class Hooks {
|
||||
|
||||
function setupSubscriptionEvents() {
|
||||
$subscribe = Setting::getValue('subscribe', array());
|
||||
$wp = new WPFunctions;
|
||||
|
||||
// Subscribe in comments
|
||||
if(
|
||||
isset($subscribe['on_comment']['enabled'])
|
||||
&&
|
||||
(bool)$subscribe['on_comment']['enabled']
|
||||
) {
|
||||
if(is_user_logged_in()) {
|
||||
if($wp->isUserLoggedIn()) {
|
||||
add_action(
|
||||
'comment_form_field_comment',
|
||||
'\MailPoet\Subscription\Comment::extendLoggedInForm'
|
||||
|
@ -7,6 +7,7 @@ use MailPoet\Models\Setting;
|
||||
use MailPoet\Models\Subscriber;
|
||||
use MailPoet\Subscription\Url;
|
||||
use MailPoet\Util\Helpers;
|
||||
use MailPoet\WP\Functions as WPFunctions;
|
||||
|
||||
class ConfirmationEmailMailer {
|
||||
|
||||
@ -15,13 +16,19 @@ class ConfirmationEmailMailer {
|
||||
/** @var Mailer */
|
||||
private $mailer;
|
||||
|
||||
/** @var WPFunctions */
|
||||
private $wp;
|
||||
|
||||
/**
|
||||
* @param Mailer|null $mailer
|
||||
*/
|
||||
function __construct($mailer = null) {
|
||||
function __construct($mailer = null, WPFunctions $wp = null) {
|
||||
if($mailer) {
|
||||
$this->mailer = $mailer;
|
||||
}
|
||||
if(!$wp) {
|
||||
$this->wp = new WPFunctions;
|
||||
}
|
||||
}
|
||||
|
||||
function sendConfirmationEmail(Subscriber $subscriber) {
|
||||
@ -33,7 +40,7 @@ class ConfirmationEmailMailer {
|
||||
|
||||
$subscriber->count_confirmations++;
|
||||
$subscriber->save();
|
||||
if(!is_user_logged_in() && $subscriber->count_confirmations > self::MAX_CONFIRMATION_EMAILS) {
|
||||
if(!$this->wp->isUserLoggedIn() && $subscriber->count_confirmations > self::MAX_CONFIRMATION_EMAILS) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,7 @@ namespace MailPoet\Subscription;
|
||||
use MailPoet\Models\SubscriberIP;
|
||||
use MailPoet\Util\Helpers;
|
||||
use MailPoet\WP\Hooks;
|
||||
use MailPoet\WP\Functions as WPFunctions;
|
||||
|
||||
class Throttling {
|
||||
static function throttle() {
|
||||
@ -13,8 +14,9 @@ class Throttling {
|
||||
$subscription_limit_base = Hooks::applyFilters('mailpoet_subscription_limit_base', MINUTE_IN_SECONDS);
|
||||
|
||||
$subscriber_ip = Helpers::getIP();
|
||||
$wp = new WPFunctions;
|
||||
|
||||
if($subscription_limit_enabled && !is_user_logged_in()) {
|
||||
if($subscription_limit_enabled && !$wp->isUserLoggedIn()) {
|
||||
if(!empty($subscriber_ip)) {
|
||||
$subscription_count = SubscriberIP::where('ip', $subscriber_ip)
|
||||
->whereRaw(
|
||||
|
@ -32,6 +32,10 @@ class Functions {
|
||||
return call_user_func_array('home_url', func_get_args());
|
||||
}
|
||||
|
||||
function isUserLoggedIn() {
|
||||
return call_user_func_array('is_user_logged_in', func_get_args());
|
||||
}
|
||||
|
||||
function getImageInfo($id) {
|
||||
/*
|
||||
* In some cases wp_get_attachment_image_src ignore the second parameter
|
||||
|
@ -11,6 +11,7 @@ use MailPoet\Models\Subscriber;
|
||||
use MailPoet\Newsletter\Url;
|
||||
use MailPoet\Router\Router;
|
||||
use MailPoet\Tasks\Sending as SendingTask;
|
||||
use MailPoet\WP\Functions as WPFunctions;
|
||||
|
||||
class ShortcodesTest extends \MailPoetTest {
|
||||
function _before() {
|
||||
@ -56,7 +57,7 @@ class ShortcodesTest extends \MailPoetTest {
|
||||
|
||||
function testItDisplaysManageSubscriptionFormForLoggedinExistingUsers() {
|
||||
$wp_user = wp_set_current_user(1);
|
||||
expect(is_user_logged_in())->true();
|
||||
expect((new WPFunctions)->isUserLoggedIn())->true();
|
||||
$subscriber = Subscriber::create();
|
||||
$subscriber->hydrate(Fixtures::get('subscriber_template'));
|
||||
$subscriber->email = $wp_user->data->user_email;
|
||||
@ -72,7 +73,7 @@ class ShortcodesTest extends \MailPoetTest {
|
||||
|
||||
function testItDoesNotDisplayManageSubscriptionFormForLoggedinNonexistentSubscribers() {
|
||||
$wp_user = wp_set_current_user(1);
|
||||
expect(is_user_logged_in())->true();
|
||||
expect((new WPFunctions)->isUserLoggedIn())->true();
|
||||
expect(Subscriber::findOne($wp_user->data->user_email))->false();
|
||||
|
||||
$shortcodes = new Shortcodes();
|
||||
@ -83,7 +84,7 @@ class ShortcodesTest extends \MailPoetTest {
|
||||
|
||||
function testItDoesNotDisplayManageSubscriptionFormForLoggedOutUsers() {
|
||||
wp_set_current_user(0);
|
||||
expect(is_user_logged_in())->false();
|
||||
expect((new WPFunctions)->isUserLoggedIn())->false();
|
||||
|
||||
$shortcodes = new Shortcodes();
|
||||
$shortcodes->init();
|
||||
@ -93,7 +94,7 @@ class ShortcodesTest extends \MailPoetTest {
|
||||
|
||||
function testItDisplaysLinkToManageSubscriptionPageForLoggedinExistingUsers() {
|
||||
$wp_user = wp_set_current_user(1);
|
||||
expect(is_user_logged_in())->true();
|
||||
expect((new WPFunctions)->isUserLoggedIn())->true();
|
||||
$subscriber = Subscriber::create();
|
||||
$subscriber->hydrate(Fixtures::get('subscriber_template'));
|
||||
$subscriber->email = $wp_user->data->user_email;
|
||||
@ -108,7 +109,7 @@ class ShortcodesTest extends \MailPoetTest {
|
||||
|
||||
function testItDoesNotDisplayLinkToManageSubscriptionPageForLoggedinNonexistentSubscribers() {
|
||||
$wp_user = wp_set_current_user(1);
|
||||
expect(is_user_logged_in())->true();
|
||||
expect((new WPFunctions)->isUserLoggedIn())->true();
|
||||
expect(Subscriber::findOne($wp_user->data->user_email))->false();
|
||||
|
||||
$shortcodes = new Shortcodes();
|
||||
@ -119,7 +120,7 @@ class ShortcodesTest extends \MailPoetTest {
|
||||
|
||||
function testItDoesNotDisplayManageSubscriptionPageForLoggedOutUsers() {
|
||||
wp_set_current_user(0);
|
||||
expect(is_user_logged_in())->false();
|
||||
expect((new WPFunctions)->isUserLoggedIn())->false();
|
||||
|
||||
$shortcodes = new Shortcodes();
|
||||
$shortcodes->init();
|
||||
|
Reference in New Issue
Block a user