|
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 1.0 |
|
25
|
|
|
* @access static |
|
26
|
|
|
* @var |
|
27
|
|
|
*/ |
|
28
|
|
|
static private $instance; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Singleton pattern. |
|
32
|
|
|
* |
|
33
|
|
|
* @since 1.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 1.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->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->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
|
|
|
return $email->is_notification_status_editable; |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* Check email preview header active or not. |
|
101
|
|
|
* |
|
102
|
|
|
* @since 2.0 |
|
103
|
|
|
* @access public |
|
104
|
|
|
* |
|
105
|
|
|
* @param Give_Email_Notification $email |
|
106
|
|
|
* |
|
107
|
|
|
* @return bool |
|
108
|
|
|
*/ |
|
109
|
|
|
public static function is_email_preview_has_header( Give_Email_Notification $email ) { |
|
110
|
|
|
return $email->has_preview_header; |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* Check email preview header active or not. |
|
115
|
|
|
* |
|
116
|
|
|
* @since 2.0 |
|
117
|
|
|
* @access public |
|
118
|
|
|
* |
|
119
|
|
|
* @param Give_Email_Notification $email |
|
120
|
|
|
* |
|
121
|
|
|
* @return bool |
|
122
|
|
|
*/ |
|
123
|
|
|
public static function is_email_preview( Give_Email_Notification $email ) { |
|
124
|
|
|
return $email->has_preview; |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
|
|
128
|
|
|
/** |
|
129
|
|
|
* Check email active or not. |
|
130
|
|
|
* |
|
131
|
|
|
* @since 2.0 |
|
132
|
|
|
* @access public |
|
133
|
|
|
* |
|
134
|
|
|
* @param Give_Email_Notification $email |
|
135
|
|
|
* |
|
136
|
|
|
* @return string |
|
|
|
|
|
|
137
|
|
|
*/ |
|
138
|
|
|
public static function is_email_notification_active( Give_Email_Notification $email ) { |
|
139
|
|
|
return give_is_setting_enabled( $email->get_notification_status() ); |
|
140
|
|
|
} |
|
141
|
|
|
} |
|
142
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.