From cac995e15b2f57d38d8dc3cd31197346d53a8087 Mon Sep 17 00:00:00 2001 From: Jonathan Labreuille Date: Tue, 9 Feb 2016 16:55:00 +0100 Subject: [PATCH] fixed subscribe in comments --- lib/Config/Hooks.php | 15 +++++++++++---- lib/Config/Initializer.php | 2 +- lib/Config/Localizer.php | 3 +-- lib/Subscription/Comment.php | 13 +++++++++++-- 4 files changed, 24 insertions(+), 9 deletions(-) diff --git a/lib/Config/Hooks.php b/lib/Config/Hooks.php index 53ce538120..6b10e81e16 100644 --- a/lib/Config/Hooks.php +++ b/lib/Config/Hooks.php @@ -9,10 +9,17 @@ class Hooks { function init() { // Subscribe in comments if((bool)Setting::getValue('subscribe.on_comment.enabled')) { - add_action( - 'comment_form_after_fields', - '\MailPoet\Subscription\Comment::extendForm' - ); + if(is_user_logged_in()) { + add_action( + 'comment_form_field_comment', + '\MailPoet\Subscription\Comment::extendLoggedInForm' + ); + } else { + add_action( + 'comment_form_after_fields', + '\MailPoet\Subscription\Comment::extendLoggedOutForm' + ); + } add_action( 'comment_post', diff --git a/lib/Config/Initializer.php b/lib/Config/Initializer.php index 2e6d4bb29b..39428c5d77 100644 --- a/lib/Config/Initializer.php +++ b/lib/Config/Initializer.php @@ -25,7 +25,7 @@ class Initializer { register_activation_hook(Env::$file, array($this, 'runMigrator')); register_activation_hook(Env::$file, array($this, 'runPopulator')); - add_action('init', array($this, 'setup')); + add_action('plugins_loaded', array($this, 'setup')); add_action('widgets_init', array($this, 'setupWidget')); } diff --git a/lib/Config/Localizer.php b/lib/Config/Localizer.php index 2e94353339..281dcb18bf 100644 --- a/lib/Config/Localizer.php +++ b/lib/Config/Localizer.php @@ -11,8 +11,7 @@ class Localizer { function init() { add_action( 'init', - array($this, 'setup'), - 0 + array($this, 'setup') ); } diff --git a/lib/Subscription/Comment.php b/lib/Subscription/Comment.php index 4bb3a5dde6..25edc542b8 100644 --- a/lib/Subscription/Comment.php +++ b/lib/Subscription/Comment.php @@ -8,13 +8,22 @@ class Comment { const APPROVED = 1; const PENDING_APPROVAL = 0; - static function extendForm() { + static function extendLoggedInForm($field) { + $field .= self::getSubscriptionField(); + return $field; + } + + static function extendLoggedOutForm() { + echo self::getSubscriptionField(); + } + + static function getSubscriptionField() { $label = Setting::getValue( 'subscribe.on_comment.label', __('Yes, add me to your mailing list.') ); - print '

+ return '