1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Email Notification |
5
|
|
|
* |
6
|
|
|
* This class handles table html for email notifications listing. |
7
|
|
|
* |
8
|
|
|
* @package Give |
9
|
|
|
* @subpackage Classes/Emails |
10
|
|
|
* @copyright Copyright (c) 2016, WordImpress |
11
|
|
|
* @license https://opensource.org/licenses/gpl-license GNU Public License |
12
|
|
|
* @since 2.0 |
13
|
|
|
*/ |
14
|
|
|
class Give_Email_Notification_Table extends WP_List_Table { |
15
|
|
|
/** |
16
|
|
|
* @var Give_Email_Notifications $email_notifications |
17
|
|
|
* @since 2.0 |
18
|
|
|
* @access private |
19
|
|
|
*/ |
20
|
|
|
private $email_notifications; |
21
|
|
|
|
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Number of email notifications per page |
25
|
|
|
* |
26
|
|
|
* @since 2.0 |
27
|
|
|
* @access private |
28
|
|
|
* @var int |
29
|
|
|
*/ |
30
|
|
|
private $per_page = - 1; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Give_Email_Notification_Table constructor. |
34
|
|
|
* |
35
|
|
|
* @since 2.0 |
36
|
|
|
* @access public |
37
|
|
|
*/ |
38
|
|
|
public function __construct() { |
39
|
|
|
parent::__construct( array( |
40
|
|
|
'singular' => __( 'Give Email Notification', 'give' ), |
41
|
|
|
'plural' => __( 'Give Email Notifications', 'give' ), |
42
|
|
|
) ); |
43
|
|
|
|
44
|
|
|
$this->email_notifications = Give_Email_Notifications::get_instance(); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Get table columns. |
50
|
|
|
* |
51
|
|
|
* @since 2.0 |
52
|
|
|
* @access public |
53
|
|
|
* |
54
|
|
|
* @return array |
55
|
|
|
*/ |
56
|
|
|
public function get_columns() { |
57
|
|
|
/** |
58
|
|
|
* Filter the table columns |
59
|
|
|
* |
60
|
|
|
* @since 2.0 |
61
|
|
|
*/ |
62
|
|
|
return apply_filters( 'give_email_notification_setting_columns', array( |
63
|
|
|
'cb' => __( 'Email Status', 'give' ), |
64
|
|
|
'name' => __( 'Email', 'give' ), |
65
|
|
|
'email_type' => __( 'Content Type', 'give' ), |
66
|
|
|
'recipient' => __( 'Recipient(s)', 'give' ), |
67
|
|
|
'setting' => __( 'Edit Email', 'give' ), |
68
|
|
|
) ); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Get name column. |
73
|
|
|
* |
74
|
|
|
* @since 2.0 |
75
|
|
|
* @access public |
76
|
|
|
* |
77
|
|
|
* @param Give_Email_Notification $email |
78
|
|
|
* |
79
|
|
|
* @return string |
80
|
|
|
*/ |
81
|
|
|
public function column_name( $email ) { |
82
|
|
|
$edit_url = esc_url( admin_url( 'edit.php?post_type=give_forms&page=give-settings&tab=emails§ion=' . $email->config['id'] ) ); |
83
|
|
|
$actions = $this->get_row_actions( $email ); |
84
|
|
|
|
85
|
|
|
ob_start(); |
86
|
|
|
?> |
87
|
|
|
<a class="row-title" href="<?php echo $edit_url; ?>"><?php echo $email->config['label']; ?></a> |
|
|
|
|
88
|
|
|
|
89
|
|
|
<?php if ( $desc = $email->config['description'] ) : ?> |
90
|
|
|
<?php echo Give()->tooltips->render_help( esc_attr( $desc ) ); ?> |
|
|
|
|
91
|
|
|
<?php endif; ?> |
92
|
|
|
|
93
|
|
|
<?php echo $this->row_actions( $actions ); ?> |
|
|
|
|
94
|
|
|
<?php |
95
|
|
|
return ob_get_clean(); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* Get recipient column. |
100
|
|
|
* |
101
|
|
|
* @since 2.0 |
102
|
|
|
* @access public |
103
|
|
|
* |
104
|
|
|
* @param Give_Email_Notification $email |
105
|
|
|
* |
106
|
|
|
* @return string |
107
|
|
|
*/ |
108
|
|
|
public function column_recipient( $email ) { |
109
|
|
|
ob_start(); |
110
|
|
|
|
111
|
|
|
if( Give_Email_Notification_Util::has_recipient_field( $email ) ) { |
|
|
|
|
112
|
|
|
$recipients = $email->get_recipient(); |
113
|
|
|
if ( is_array( $recipients ) ) { |
114
|
|
|
$recipients = implode( '<br>', $recipients ); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
echo $recipients; |
|
|
|
|
118
|
|
|
|
119
|
|
|
} elseif ( ! empty( $email->config['recipient_group_name'] ) ) { |
120
|
|
|
echo $email->config['recipient_group_name']; |
|
|
|
|
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
return ob_get_clean(); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* Get status column. |
128
|
|
|
* |
129
|
|
|
* @since 2.0 |
130
|
|
|
* @access public |
131
|
|
|
* |
132
|
|
|
* @param Give_Email_Notification $email |
133
|
|
|
* |
134
|
|
|
* @return string |
135
|
|
|
*/ |
136
|
|
|
public function column_cb( $email ) { |
137
|
|
|
$notification_status = $email->get_notification_status(); |
138
|
|
|
$user_can_edit_status = (int) Give_Email_Notification_Util::is_notification_status_editable( $email ); |
139
|
|
|
$icon_classes = Give_Email_Notification_Util::is_email_notification_active( $email ) |
140
|
|
|
? 'dashicons dashicons-yes' |
141
|
|
|
: 'dashicons dashicons-no-alt'; |
142
|
|
|
$attributes = array( |
143
|
|
|
'class' => "give-email-notification-status give-email-notification-{$notification_status}", |
144
|
|
|
'data-id' => $email->config['id'], |
145
|
|
|
'data-status' => $email->get_notification_status(), |
146
|
|
|
'data-edit' => $user_can_edit_status, |
147
|
|
|
); |
148
|
|
|
|
149
|
|
|
if ( ! $user_can_edit_status ) { |
150
|
|
|
$icon_classes = 'dashicons dashicons-lock'; |
151
|
|
|
|
152
|
|
|
$attributes['data-notice'] = esc_attr( $email->config['notices']['non-notification-status-editable'] ); |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
$html = sprintf( |
156
|
|
|
'<span %1$s><i class="%2$s"></i></span></span><span class="spinner"></span>', |
157
|
|
|
give_get_attribute_str( $attributes ), |
158
|
|
|
$icon_classes |
159
|
|
|
); |
160
|
|
|
|
161
|
|
|
return $html; |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
|
165
|
|
|
/** |
166
|
|
|
* Get email_type column. |
167
|
|
|
* |
168
|
|
|
* @since 2.0 |
169
|
|
|
* @access public |
170
|
|
|
* |
171
|
|
|
* @param Give_Email_Notification $email |
172
|
|
|
* |
173
|
|
|
* @return string |
174
|
|
|
*/ |
175
|
|
|
public function column_email_type( Give_Email_Notification $email ) { |
176
|
|
|
return Give_Email_Notification_Util::get_formatted_email_type( $email->config['content_type'] ); |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
/** |
180
|
|
|
* Get setting column. |
181
|
|
|
* |
182
|
|
|
* @since 2.0 |
183
|
|
|
* @access public |
184
|
|
|
* |
185
|
|
|
* @param Give_Email_Notification $email |
186
|
|
|
* |
187
|
|
|
* @return string |
188
|
|
|
*/ |
189
|
|
|
public function column_setting( Give_Email_Notification $email ) { |
190
|
|
|
return Give()->tooltips->render_link( array( |
191
|
|
|
'label' => __( 'Edit', 'give' ) . " {$email->config['label']}", |
|
|
|
|
192
|
|
|
'tag_content' => '<span class="dashicons dashicons-admin-generic"></span>', |
193
|
|
|
'link' => esc_url( admin_url( 'edit.php?post_type=give_forms&page=give-settings&tab=emails§ion=' . $email->config['id'] ) ), |
|
|
|
|
194
|
|
|
'attributes' => array( |
195
|
|
|
'class' => 'button button-small', |
196
|
|
|
), |
197
|
|
|
) ); |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
|
201
|
|
|
/** |
202
|
|
|
* Print row actions. |
203
|
|
|
* |
204
|
|
|
* @since 2.0 |
205
|
|
|
* @access private |
206
|
|
|
* |
207
|
|
|
* @param Give_Email_Notification $email |
208
|
|
|
* |
209
|
|
|
* @return array |
210
|
|
|
*/ |
211
|
|
|
private function get_row_actions( $email ) { |
212
|
|
|
$edit_url = esc_url( admin_url( 'edit.php?post_type=give_forms&page=give-settings&tab=emails§ion=' . $email->config['id'] ) ); |
213
|
|
|
|
214
|
|
|
/** |
215
|
|
|
* Filter the row actions |
216
|
|
|
* |
217
|
|
|
* @since 2.0 |
218
|
|
|
* |
219
|
|
|
* @param array $row_actions |
220
|
|
|
*/ |
221
|
|
|
$row_actions = apply_filters( |
222
|
|
|
'give_email_notification_row_actions', |
223
|
|
|
array( |
224
|
|
|
'edit' => "<a href=\"{$edit_url}\">" . __( 'Edit', 'give' ) . '</a>', |
225
|
|
|
), |
226
|
|
|
$email |
227
|
|
|
); |
228
|
|
|
|
229
|
|
|
return $row_actions; |
230
|
|
|
} |
231
|
|
|
|
232
|
|
|
|
233
|
|
|
/** |
234
|
|
|
* Prepare email notifications |
235
|
|
|
* |
236
|
|
|
* @since 2.0 |
237
|
|
|
* @access public |
238
|
|
|
*/ |
239
|
|
|
public function prepare_items() { |
240
|
|
|
// Set columns. |
241
|
|
|
$columns = $this->get_columns(); |
242
|
|
|
$hidden = array(); |
243
|
|
|
$email_notifications = array(); |
244
|
|
|
$sortable = $this->get_sortable_columns(); |
245
|
|
|
$this->_column_headers = array( $columns, $hidden, $sortable, $this->get_primary_column_name() ); |
246
|
|
|
|
247
|
|
|
// Set email notifications. |
248
|
|
|
/* @var Give_Email_Notification $email_notification */ |
249
|
|
|
foreach ( $this->email_notifications->get_email_notifications() as $email_notification ) { |
250
|
|
|
if ( Give_Email_Notification_Util::is_show_on_emails_setting_page( $email_notification ) ) { |
251
|
|
|
$email_notifications[] = $email_notification; |
252
|
|
|
} |
253
|
|
|
} |
254
|
|
|
|
255
|
|
|
$totalItems = count( $email_notifications ); |
256
|
|
|
$this->items = $email_notifications; |
257
|
|
|
$this->set_pagination_args( array( |
258
|
|
|
'total_items' => $totalItems, |
259
|
|
|
'per_page' => $this->per_page, |
260
|
|
|
) ); |
261
|
|
|
} |
262
|
|
|
|
263
|
|
|
/** |
264
|
|
|
* Message to be displayed when there are no items |
265
|
|
|
* |
266
|
|
|
* @since 2.0 |
267
|
|
|
* @access public |
268
|
|
|
*/ |
269
|
|
|
public function no_items() { |
270
|
|
|
_e( 'No give email notification found.' ); |
271
|
|
|
} |
272
|
|
|
|
273
|
|
|
/** |
274
|
|
|
* Get primary column. |
275
|
|
|
* |
276
|
|
|
* @since 2,0 |
277
|
|
|
* @access public |
278
|
|
|
* |
279
|
|
|
* @return string Name of the default primary column. |
280
|
|
|
*/ |
281
|
|
|
public function get_primary_column_name() { |
282
|
|
|
return 'name'; |
283
|
|
|
} |
284
|
|
|
} |
285
|
|
|
|