class-comment-form.php
2.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<?php
defined('ABSPATH') or exit;
/**
* Class MC4WP_Comment_Form_Integration
*
* @ignore
*/
class MC4WP_Comment_Form_Integration extends MC4WP_Integration
{
/**
* @var bool
*/
protected $added_through_filter = false;
/**
* @var string
*/
public $name = 'Comment Form';
/**
* @var string
*/
public $description = 'Subscribes people from your WordPress comment form.';
/**
* Add hooks
*/
public function add_hooks()
{
if (! $this->options['implicit']) {
// hooks for outputting the checkbox
add_filter('comment_form_submit_field', array( $this, 'add_checkbox_before_submit_button' ), 90);
add_action('thesis_hook_after_comment_box', array( $this, 'maybe_output_checkbox' ), 90);
add_action('comment_form', array( $this, 'maybe_output_checkbox' ), 90);
}
// hooks for checking if we should subscribe the commenter
add_action('comment_post', array( $this, 'subscribe_from_comment' ), 40, 2);
}
/**
* This adds the checkbox just before the submit button and sets a flag to prevent it from outputting twice
*
* @param $submit_button_html
*
* @return string
*/
public function add_checkbox_before_submit_button($submit_button_html)
{
$this->added_through_filter = true;
return $this->get_checkbox_html() . $submit_button_html;
}
/**
* Output fallback
* Will output the checkbox if comment_form() function does not use `comment_form_submit_field` filter yet.
*/
public function maybe_output_checkbox()
{
if (! $this->added_through_filter) {
$this->output_checkbox();
}
}
/**
* Grabs data from WP Comment Form
*
* @param int $comment_id
* @param string $comment_approved
*
* @return bool|string
*/
public function subscribe_from_comment($comment_id, $comment_approved = '')
{
// was sign-up checkbox checked?
if (! $this->triggered()) {
return false;
}
// is this a spam comment?
if ($comment_approved === 'spam') {
return false;
}
$comment = get_comment($comment_id);
$data = array(
'EMAIL' => $comment->comment_author_email,
'NAME' => $comment->comment_author,
'OPTIN_IP' => $comment->comment_author_IP,
);
return $this->subscribe($data, $comment_id);
}
/**
* @return bool
*/
public function is_installed()
{
return true;
}
/**
* {@inheritdoc }
*/
public function get_object_link($object_id)
{
$comment = get_comment($object_id);
if (! $comment) {
return '';
}
return sprintf('<a href="%s">Comment #%d</a>', get_edit_comment_link($object_id), $object_id);
}
}