PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / 2.2.0
GiveWP – Donation Plugin and Fundraising Platform v2.2.0
4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 2.31.0 2.31.1 2.32.0 2.33.0 2.33.1 2.33.2 2.33.3 2.33.4 2.33.5 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7 2.5.0 2.5.1 2.5.10 2.5.11 2.5.12 2.5.13 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.7 2.5.8 2.5.9 2.6.0 2.6.1 2.6.2 2.6.3 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.8.0 2.8.1 2.9.0 2.9.1 2.9.2 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1.0 3.1.1 3.1.2 3.10.0 3.11.0 3.12.0 3.12.1 3.12.2 3.12.3 3.13.0 3.14.0 3.14.1 3.14.2 3.15.0 3.15.1 3.16.0 3.16.1 3.16.2 3.16.3 3.16.4 3.16.5 3.17.0 3.17.1 3.17.2 3.18.0 3.19.0 3.19.1 3.19.2 3.19.3 3.19.4 3.2.0 3.2.1 3.2.2 3.20.0 3.21.0 3.21.1 3.22.0 3.22.1 3.22.2 3.3.0 3.3.1 3.4.0 3.4.1 3.4.2 3.5.0 3.5.1 3.6.0 3.6.1 3.6.2 3.7.0 3.8.0 3.9.0 4.0.0 4.1.0 4.1.1 4.10.0 4.10.1 4.11.0 4.12.0 4.13.0 4.13.1 4.13.2 4.14.0 4.14.1 4.14.2 4.14.3 4.14.4 4.14.5 4.14.6 4.2.0 4.2.1 4.3.0 4.3.1 4.3.2 4.4.0 4.5.0 4.6.1 4.7.0 4.7.1 4.8.0 4.8.1 4.9.0 trunk 1.9.0 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.10.0 2.10.1 2.10.2 2.10.3 2.10.4 2.11.0 2.11.1 2.11.2 2.11.3 2.12.0 2.12.1 2.12.2 2.12.3 2.13.0 2.13.1 2.13.2 2.13.3 2.13.4 2.14.0 2.15.0 2.16.0 2.16.1 2.17.0 2.17.1 2.17.3 2.18.0 2.18.1 2.19.1 2.19.2 2.19.3 2.19.4 2.19.5 2.19.6 2.19.7 2.19.8 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.20.0 2.20.1 2.20.2 2.21.0 2.21.1 2.21.2 2.21.3 2.21.4 2.22.0 2.22.1 2.22.2 2.22.3 2.23.0 2.23.1 2.23.2 2.24.0 2.24.1 2.24.2 2.25.0 2.25.1 2.25.2 2.25.3 2.26.0 2.27.0 2.27.1 2.27.2 2.27.3 2.28.0 2.29.0 2.29.1 2.29.2
give / includes / admin / emails / class-email-notification-util.php
give / includes / admin / emails Last commit date
abstract-email-notification.php 7 years ago ajax-handler.php 8 years ago backward-compatibility.php 8 years ago class-donation-receipt-email.php 8 years ago class-donor-register-email.php 7 years ago class-email-access-email.php 7 years ago class-email-notification-table.php 8 years ago class-email-notification-util.php 8 years ago class-email-notifications.php 8 years ago class-email-setting-field.php 8 years ago class-new-donation-email.php 8 years ago class-new-donor-register-email.php 8 years ago class-new-offline-donation-email.php 7 years ago class-offline-donation-instruction-email.php 7 years ago filters.php 8 years ago
class-email-notification-util.php
341 lines
1 <?php
2 /**
3 * Email Notification Util
4 *
5 * This class contains helper functions for email notification.
6 *
7 * @package Give
8 * @subpackage Classes/Emails
9 * @copyright Copyright (c) 2016, WordImpress
10 * @license https://opensource.org/licenses/gpl-license GNU Public License
11 * @since 2.0
12 */
13
14 // Exit if access directly.
15 if ( ! defined( 'ABSPATH' ) ) {
16 exit;
17 }
18
19
20 class Give_Email_Notification_Util {
21 /**
22 * Instance.
23 *
24 * @since 2.0
25 * @access static
26 * @var
27 */
28 static private $instance;
29
30 /**
31 * Singleton pattern.
32 *
33 * @since 2.0
34 * @access private
35 * Give_Email_Notification_Util constructor.
36 */
37 private function __construct() {
38 }
39
40
41 /**
42 * Get instance.
43 *
44 * @since 2.0
45 * @access static
46 * @return static
47 */
48 static function get_instance() {
49 if ( null === static::$instance ) {
50 self::$instance = new static();
51 }
52
53 return self::$instance;
54 }
55
56
57 /**
58 * Check if notification has preview field or not.
59 *
60 * @since 2.0
61 * @access public
62 *
63 * @param Give_Email_Notification $email
64 *
65 * @return bool
66 */
67 public static function has_preview( Give_Email_Notification $email ) {
68 return $email->config['has_preview'];
69 }
70
71 /**
72 * Check if notification has recipient field or not.
73 *
74 * @since 2.0
75 * @access public
76 *
77 * @param Give_Email_Notification $email
78 *
79 * @return bool
80 */
81 public static function has_recipient_field( Give_Email_Notification $email ) {
82 return $email->config['has_recipient_field'];
83 }
84
85 /**
86 * Check if admin can edit notification status or not.
87 *
88 * @since 2.0
89 * @access public
90 *
91 * @param Give_Email_Notification $email
92 *
93 * @return bool
94 */
95 public static function is_notification_status_editable( Give_Email_Notification $email ) {
96 $user_can_edit = $email->config['notification_status_editable'];
97
98 return (bool) $user_can_edit;
99 }
100
101 /**
102 * Check if admin can edit notification status or not.
103 *
104 * @since 2.0
105 * @access public
106 *
107 * @param Give_Email_Notification $email
108 *
109 * @return bool
110 */
111 public static function is_content_type_editable( Give_Email_Notification $email ) {
112 return $email->config['content_type_editable'];
113 }
114
115 /**
116 * Check email preview header active or not.
117 *
118 * @since 2.0
119 * @access public
120 *
121 * @param Give_Email_Notification $email
122 *
123 * @return bool
124 */
125 public static function is_email_preview_has_header( Give_Email_Notification $email ) {
126 return $email->config['has_preview_header'];
127 }
128
129 /**
130 * Check email preview header active or not.
131 *
132 * @since 2.0
133 * @access public
134 *
135 * @param Give_Email_Notification $email
136 *
137 * @return bool
138 */
139 public static function is_email_preview( Give_Email_Notification $email ) {
140 return $email->config['has_preview'];
141 }
142
143 /**
144 * Check if email notification setting appear on emails setting page or not.
145 *
146 * @since 2.0
147 * @access public
148 *
149 * @param Give_Email_Notification $email
150 *
151 * @return bool
152 */
153 public static function is_show_on_emails_setting_page( Give_Email_Notification $email ){
154 return $email->config['show_on_emails_setting_page'];
155 }
156
157 /**
158 * Check if we can use form email options.
159 *
160 * @since 2.0
161 * @access public
162 *
163 * @param Give_Email_Notification $email
164 * @param int $form_id
165 *
166 * @return bool
167 */
168 public static function can_use_form_email_options( Give_Email_Notification $email, $form_id = null ){
169 return give_is_setting_enabled( give_get_meta( $form_id, '_give_email_options', true ) );
170 }
171
172 /**
173 * Check email active or not.
174 *
175 * @since 2.0
176 * @access public
177 *
178 * @param Give_Email_Notification $email
179 * @param int $form_id
180 *
181 * @return string
182 */
183 public static function is_email_notification_active( Give_Email_Notification $email, $form_id = null ) {
184 $notification_status = $email->get_notification_status( $form_id );
185
186
187 $notification_status = empty( $form_id )
188 ? give_is_setting_enabled( $notification_status )
189 : give_is_setting_enabled( give_get_option( "{$email->config['id']}_notification", $email->config['notification_status'] ) ) && give_is_setting_enabled( $notification_status, array( 'enabled', 'global' ) );
190 // To check if email notification is active or not on a per-form basis, email notification must be globally active—otherwise it will be considered disabled.
191
192 /**
193 * Filter to modify is email active notification
194 *
195 * @since 2.1.3
196 *
197 * @param bool $notification_status True if notification is enable and false when disable
198 * @param Give_Email_Notification $email Class instances Give_Email_Notification.
199 * @param int $form_id Donation Form ID.
200 *
201 * @param bool $notification_status True if notification is enable and false when disable
202 */
203 return apply_filters( "give_{$email->config['id']}_is_email_notification_active", $notification_status, $email, $form_id );
204 }
205
206 /**
207 * Check if admin preview email or not
208 *
209 * @since 2.0
210 * @access public
211 * @return bool $is_preview
212 */
213 public static function can_preview_email() {
214 $is_preview = false;
215
216 if (
217 current_user_can( 'manage_give_settings' )
218 && ! empty( $_GET['give_action'] )
219 && 'preview_email' === $_GET['give_action']
220 ) {
221 $is_preview = true;
222 }
223
224 return $is_preview;
225 }
226
227 /**
228 * Check if admin preview email or not
229 *
230 * @since 2.0
231 * @access public
232 * @return bool $is_preview
233 */
234 public static function can_send_preview_email() {
235 $is_preview = false;
236
237 if (
238 current_user_can( 'manage_give_settings' )
239 && ! empty( $_GET['give_action'] )
240 && 'send_preview_email' === $_GET['give_action']
241 ) {
242 $is_preview = true;
243 }
244
245 return $is_preview;
246 }
247
248
249 /**
250 * Get formatted text for email content type.
251 *
252 * @since 2.0
253 * @access public
254 *
255 * @param string $content_type
256 *
257 * @return string
258 */
259 public static function get_formatted_email_type( $content_type ) {
260 $email_contents = array(
261 'text/html' => __( 'HTML', 'give' ),
262 'text/plain' => __( 'Plain', 'give' ),
263 );
264
265 return $email_contents[ $content_type ];
266 }
267
268
269 /**
270 * Get email notification option value.
271 *
272 * @since 2.0
273 * @access public
274 *
275 * @param Give_Email_Notification $email
276 * @param string $option_name
277 * @param int $form_id
278 * @param mixed $default
279 *
280 * @return mixed
281 */
282 public static function get_value( Give_Email_Notification $email, $option_name, $form_id = null, $default = false ) {
283 // If form id set then option name can be contain _give_ prefix which is only used for meta key,
284 // So make sure you are using correct option name.
285 $global_option_name = ( 0 === strpos( $option_name, '_give_' )
286 ? str_replace( '_give_', '', $option_name )
287 : $option_name );
288 $option_value = give_get_option( $global_option_name, $default );
289
290 if (
291 ! empty( $form_id )
292 && give_is_setting_enabled(
293 give_get_meta(
294 $form_id,
295 Give_Email_Setting_Field::get_prefix( $email, $form_id ) . 'notification',
296 true,
297 'global'
298 )
299 )
300 ) {
301 $option_value = get_post_meta( $form_id, $option_name, true );
302
303 // Get only email field value from recipients setting.
304 if( Give_Email_Setting_Field::get_prefix( $email, $form_id ) . 'recipient' === $option_name ) {
305 $option_value = wp_list_pluck( $option_value, 'email' );
306 }
307 }
308
309 $option_value = empty( $option_value ) ? $default : $option_value;
310
311 /**
312 * Filter the setting value
313 *
314 * @since 2.0
315 */
316 return apply_filters( 'give_email_setting_value', $option_value, $option_name, $email, $form_id, $default );
317 }
318
319
320 /**
321 * Get email logo.
322 *
323 * @since 2.1.5
324 *
325 * @access public
326 *
327 * @param integer $form_id FOrm ID.
328 *
329 * @return string
330 */
331 public static function get_email_logo( $form_id ) {
332
333 // Email logo tag.
334 $header_img = $form_id && give_is_setting_enabled( give_get_meta( $form_id, '_give_email_options', true ) )
335 ? give_get_meta( $form_id, '_give_email_logo', true )
336 : give_get_option( 'email_logo', '' );
337
338 return $header_img;
339 }
340 }
341