@@ -19,182 +19,182 @@ discard block |
||
19 | 19 | |
20 | 20 | |
21 | 21 | |
22 | - /** |
|
23 | - * This property holds the default message types associated with this messenger when it is activated. The values of the array must match a valid message type. |
|
24 | - * This property gets set by the _set_default_message_types() method. |
|
25 | - * |
|
26 | - * @var array |
|
27 | - */ |
|
28 | - protected $_default_message_types = array(); |
|
22 | + /** |
|
23 | + * This property holds the default message types associated with this messenger when it is activated. The values of the array must match a valid message type. |
|
24 | + * This property gets set by the _set_default_message_types() method. |
|
25 | + * |
|
26 | + * @var array |
|
27 | + */ |
|
28 | + protected $_default_message_types = array(); |
|
29 | 29 | |
30 | 30 | |
31 | 31 | |
32 | 32 | |
33 | - /** |
|
34 | - * This property holds the message types that are valid for use with this messenger. |
|
35 | - * It gets set by the _set_valid_message_types() method. |
|
36 | - * |
|
37 | - * @var array |
|
38 | - */ |
|
39 | - protected $_valid_message_types = array(); |
|
33 | + /** |
|
34 | + * This property holds the message types that are valid for use with this messenger. |
|
35 | + * It gets set by the _set_valid_message_types() method. |
|
36 | + * |
|
37 | + * @var array |
|
38 | + */ |
|
39 | + protected $_valid_message_types = array(); |
|
40 | 40 | |
41 | 41 | |
42 | 42 | |
43 | - /** |
|
44 | - * Holds the configuration for the EE_Messages_Validator class to know how to validated the different fields. Note that the Validator will match each field here with the allowed shortcodes set in the "valid_shortcodes" array for the matched message type context. So message types don't need to set a $_validator_config property. |
|
45 | - * |
|
46 | - * Remember, ALL fields must be declared in this array. However, an empty value for the field means that the field will accept all valid shortcodes set for the given context in the message type (by default). |
|
47 | - * |
|
48 | - * Array should be in this format: |
|
49 | - * |
|
50 | - * array( |
|
51 | - * 'field_name(i.e.to)' => array( |
|
52 | - * 'shortcodes' => array('email'), //an array of shortcode groups (correspond to EE_Shortcodes library class) that are allowed in the field. Typically you can just include $this->_valid_shortcodes['field_name'] as the value here (because they will match). |
|
53 | - * 'specific_shortcodes' => array( array('[EVENT_AUTHOR_EMAIL]' => esc_html__('Admin Email', 'event_espresso')), //if this index is present you can further restrict the field to ONLY specific shortcodes if an entire group isn't sufficient. Specific shortcodes need to be listed as an array with the index the shortcode and the value = the label. |
|
54 | - * 'type' => 'email' //this is the field type and should match one of the validator types (see EE_Messages_Validator::validator() for all the possible types). If not required you can just leave empty., |
|
55 | - * 'required' => array'[SHORTCODE]') //this is used to indicate the shortcodes that MUST be in the assembled array of shortcodes by the validator in order for this field to be included in validation. Otherwise the validator will always assign shortcodes for this field (regardless of whether the field settings for the given messenger/message_type/context use the field or not.).. please note, this does NOT mean that the shortcodes listed here MUST be in the given field. |
|
56 | - * ) |
|
57 | - * ) |
|
58 | - * |
|
59 | - * @var array |
|
60 | - */ |
|
61 | - protected $_validator_config = array(); |
|
43 | + /** |
|
44 | + * Holds the configuration for the EE_Messages_Validator class to know how to validated the different fields. Note that the Validator will match each field here with the allowed shortcodes set in the "valid_shortcodes" array for the matched message type context. So message types don't need to set a $_validator_config property. |
|
45 | + * |
|
46 | + * Remember, ALL fields must be declared in this array. However, an empty value for the field means that the field will accept all valid shortcodes set for the given context in the message type (by default). |
|
47 | + * |
|
48 | + * Array should be in this format: |
|
49 | + * |
|
50 | + * array( |
|
51 | + * 'field_name(i.e.to)' => array( |
|
52 | + * 'shortcodes' => array('email'), //an array of shortcode groups (correspond to EE_Shortcodes library class) that are allowed in the field. Typically you can just include $this->_valid_shortcodes['field_name'] as the value here (because they will match). |
|
53 | + * 'specific_shortcodes' => array( array('[EVENT_AUTHOR_EMAIL]' => esc_html__('Admin Email', 'event_espresso')), //if this index is present you can further restrict the field to ONLY specific shortcodes if an entire group isn't sufficient. Specific shortcodes need to be listed as an array with the index the shortcode and the value = the label. |
|
54 | + * 'type' => 'email' //this is the field type and should match one of the validator types (see EE_Messages_Validator::validator() for all the possible types). If not required you can just leave empty., |
|
55 | + * 'required' => array'[SHORTCODE]') //this is used to indicate the shortcodes that MUST be in the assembled array of shortcodes by the validator in order for this field to be included in validation. Otherwise the validator will always assign shortcodes for this field (regardless of whether the field settings for the given messenger/message_type/context use the field or not.).. please note, this does NOT mean that the shortcodes listed here MUST be in the given field. |
|
56 | + * ) |
|
57 | + * ) |
|
58 | + * |
|
59 | + * @var array |
|
60 | + */ |
|
61 | + protected $_validator_config = array(); |
|
62 | 62 | |
63 | 63 | |
64 | 64 | |
65 | - /** |
|
66 | - * This will hold the EEM_message_templates model for interacting with the database and retrieving active templates for the messenger |
|
67 | - * @var object |
|
68 | - */ |
|
69 | - protected $_EEM_data; |
|
65 | + /** |
|
66 | + * This will hold the EEM_message_templates model for interacting with the database and retrieving active templates for the messenger |
|
67 | + * @var object |
|
68 | + */ |
|
69 | + protected $_EEM_data; |
|
70 | 70 | |
71 | 71 | |
72 | 72 | |
73 | - /** |
|
74 | - * this property just holds an array of the various template refs. |
|
75 | - * @var array |
|
76 | - */ |
|
77 | - protected $_template_fields = array(); |
|
73 | + /** |
|
74 | + * this property just holds an array of the various template refs. |
|
75 | + * @var array |
|
76 | + */ |
|
77 | + protected $_template_fields = array(); |
|
78 | 78 | |
79 | 79 | |
80 | 80 | |
81 | 81 | |
82 | - /** |
|
83 | - * This holds an array of the arguments used in parsing a template for the sender. |
|
84 | - * @var array |
|
85 | - */ |
|
86 | - protected $_template_args = array(); |
|
82 | + /** |
|
83 | + * This holds an array of the arguments used in parsing a template for the sender. |
|
84 | + * @var array |
|
85 | + */ |
|
86 | + protected $_template_args = array(); |
|
87 | 87 | |
88 | 88 | |
89 | 89 | |
90 | 90 | |
91 | 91 | |
92 | 92 | |
93 | - /** |
|
94 | - * This property will hold the configuration for any test settings fields that are required for the "test" button that is used to trigger an actual test of this messenger |
|
95 | - * |
|
96 | - * @protected |
|
97 | - * @var array |
|
98 | - */ |
|
99 | - protected $_test_settings_fields = array(); |
|
93 | + /** |
|
94 | + * This property will hold the configuration for any test settings fields that are required for the "test" button that is used to trigger an actual test of this messenger |
|
95 | + * |
|
96 | + * @protected |
|
97 | + * @var array |
|
98 | + */ |
|
99 | + protected $_test_settings_fields = array(); |
|
100 | 100 | |
101 | 101 | |
102 | 102 | |
103 | 103 | |
104 | 104 | |
105 | 105 | |
106 | - /** |
|
107 | - * This will hold the EE_Messages_Template_Pack object when set on the messenger. This is set via the validate and setup method which grabs the template pack from the incoming messages object. |
|
108 | - * |
|
109 | - * @since 4.5.0 |
|
110 | - * |
|
111 | - * @var EE_Messages_Template_Pack |
|
112 | - */ |
|
113 | - protected $_tmp_pack; |
|
106 | + /** |
|
107 | + * This will hold the EE_Messages_Template_Pack object when set on the messenger. This is set via the validate and setup method which grabs the template pack from the incoming messages object. |
|
108 | + * |
|
109 | + * @since 4.5.0 |
|
110 | + * |
|
111 | + * @var EE_Messages_Template_Pack |
|
112 | + */ |
|
113 | + protected $_tmp_pack; |
|
114 | 114 | |
115 | 115 | |
116 | 116 | |
117 | 117 | |
118 | - /** |
|
119 | - * This will hold the variation to use when performing a send. It is set via the validate and setup method which grabs the variation from the incoming messages object on the send method. |
|
120 | - * |
|
121 | - * @since 4.5.0 |
|
122 | - * |
|
123 | - * @var string |
|
124 | - */ |
|
125 | - protected $_variation; |
|
118 | + /** |
|
119 | + * This will hold the variation to use when performing a send. It is set via the validate and setup method which grabs the variation from the incoming messages object on the send method. |
|
120 | + * |
|
121 | + * @since 4.5.0 |
|
122 | + * |
|
123 | + * @var string |
|
124 | + */ |
|
125 | + protected $_variation; |
|
126 | 126 | |
127 | 127 | |
128 | 128 | |
129 | 129 | |
130 | 130 | |
131 | - /** |
|
132 | - * This property is a stdClass that holds labels for all the various supporting properties for this messenger. These labels are set via the _set_supports_labels() method in children classes. Initially this will include the label for: |
|
133 | - * |
|
134 | - * - template pack |
|
135 | - * - template variation |
|
136 | - * |
|
137 | - * @since 4.5.0 |
|
138 | - * |
|
139 | - * @var stdClass |
|
140 | - */ |
|
141 | - protected $_supports_labels; |
|
131 | + /** |
|
132 | + * This property is a stdClass that holds labels for all the various supporting properties for this messenger. These labels are set via the _set_supports_labels() method in children classes. Initially this will include the label for: |
|
133 | + * |
|
134 | + * - template pack |
|
135 | + * - template variation |
|
136 | + * |
|
137 | + * @since 4.5.0 |
|
138 | + * |
|
139 | + * @var stdClass |
|
140 | + */ |
|
141 | + protected $_supports_labels; |
|
142 | 142 | |
143 | 143 | |
144 | 144 | |
145 | 145 | |
146 | 146 | |
147 | - /** |
|
148 | - * This property is set when the send_message() method is called and holds the Message Type used to generate templates with this messenger for the messages. |
|
149 | - * |
|
150 | - * @var EE_message_type |
|
151 | - */ |
|
152 | - protected $_incoming_message_type; |
|
147 | + /** |
|
148 | + * This property is set when the send_message() method is called and holds the Message Type used to generate templates with this messenger for the messages. |
|
149 | + * |
|
150 | + * @var EE_message_type |
|
151 | + */ |
|
152 | + protected $_incoming_message_type; |
|
153 | 153 | |
154 | 154 | |
155 | 155 | |
156 | - /** |
|
157 | - * This flag sets whether a messenger is activated by default on installation (or reactivation) of EE core or not. |
|
158 | - * |
|
159 | - * @var bool |
|
160 | - */ |
|
161 | - public $activate_on_install = false; |
|
156 | + /** |
|
157 | + * This flag sets whether a messenger is activated by default on installation (or reactivation) of EE core or not. |
|
158 | + * |
|
159 | + * @var bool |
|
160 | + */ |
|
161 | + public $activate_on_install = false; |
|
162 | 162 | |
163 | 163 | |
164 | 164 | |
165 | 165 | |
166 | 166 | |
167 | - public function __construct() |
|
168 | - { |
|
169 | - $this->_EEM_data = EEM_Message_Template_Group::instance(); |
|
170 | - $this->_messages_item_type = 'messenger'; |
|
167 | + public function __construct() |
|
168 | + { |
|
169 | + $this->_EEM_data = EEM_Message_Template_Group::instance(); |
|
170 | + $this->_messages_item_type = 'messenger'; |
|
171 | 171 | |
172 | - parent::__construct(); |
|
172 | + parent::__construct(); |
|
173 | 173 | |
174 | - $this->_set_test_settings_fields(); |
|
175 | - $this->_set_template_fields(); |
|
176 | - $this->_set_default_message_types(); |
|
177 | - $this->_set_valid_message_types(); |
|
178 | - $this->_set_validator_config(); |
|
174 | + $this->_set_test_settings_fields(); |
|
175 | + $this->_set_template_fields(); |
|
176 | + $this->_set_default_message_types(); |
|
177 | + $this->_set_valid_message_types(); |
|
178 | + $this->_set_validator_config(); |
|
179 | 179 | |
180 | 180 | |
181 | - $this->_supports_labels = new stdClass(); |
|
182 | - $this->_set_supports_labels(); |
|
183 | - } |
|
181 | + $this->_supports_labels = new stdClass(); |
|
182 | + $this->_set_supports_labels(); |
|
183 | + } |
|
184 | 184 | |
185 | 185 | |
186 | 186 | |
187 | 187 | |
188 | 188 | |
189 | - /** |
|
190 | - * _set_template_fields |
|
191 | - * This sets up the fields that a messenger requires for the message to go out. |
|
192 | - * |
|
193 | - * @abstract |
|
194 | - * @access protected |
|
195 | - * @return void |
|
196 | - */ |
|
197 | - abstract protected function _set_template_fields(); |
|
189 | + /** |
|
190 | + * _set_template_fields |
|
191 | + * This sets up the fields that a messenger requires for the message to go out. |
|
192 | + * |
|
193 | + * @abstract |
|
194 | + * @access protected |
|
195 | + * @return void |
|
196 | + */ |
|
197 | + abstract protected function _set_template_fields(); |
|
198 | 198 | |
199 | 199 | |
200 | 200 | |
@@ -204,14 +204,14 @@ discard block |
||
204 | 204 | |
205 | 205 | |
206 | 206 | |
207 | - /** |
|
208 | - * This method sets the _default_message_type property (see definition in docs attached to property) |
|
209 | - * |
|
210 | - * @abstract |
|
211 | - * @access protected |
|
212 | - * @return void |
|
213 | - */ |
|
214 | - abstract protected function _set_default_message_types(); |
|
207 | + /** |
|
208 | + * This method sets the _default_message_type property (see definition in docs attached to property) |
|
209 | + * |
|
210 | + * @abstract |
|
211 | + * @access protected |
|
212 | + * @return void |
|
213 | + */ |
|
214 | + abstract protected function _set_default_message_types(); |
|
215 | 215 | |
216 | 216 | |
217 | 217 | |
@@ -219,15 +219,15 @@ discard block |
||
219 | 219 | |
220 | 220 | |
221 | 221 | |
222 | - /** |
|
223 | - * Sets the _valid_message_types property (see definition in cods attached to property) |
|
224 | - * |
|
225 | - * @since 4.5.0 |
|
226 | - * |
|
227 | - * @abstract |
|
228 | - * @return void |
|
229 | - */ |
|
230 | - abstract protected function _set_valid_message_types(); |
|
222 | + /** |
|
223 | + * Sets the _valid_message_types property (see definition in cods attached to property) |
|
224 | + * |
|
225 | + * @since 4.5.0 |
|
226 | + * |
|
227 | + * @abstract |
|
228 | + * @return void |
|
229 | + */ |
|
230 | + abstract protected function _set_valid_message_types(); |
|
231 | 231 | |
232 | 232 | |
233 | 233 | |
@@ -235,171 +235,171 @@ discard block |
||
235 | 235 | |
236 | 236 | |
237 | 237 | |
238 | - /** |
|
239 | - * Child classes must declare the $_validator_config property using this method. |
|
240 | - * See comments for $_validator_config for details on what it is used for. |
|
241 | - * |
|
242 | - * NOTE: messengers should set an array of valid shortcodes for ALL scenarios. The corresponding validator class (validators/{messenger}) can be used to restrict only certain shortcodes per template so users cannot add certain shortcodes. |
|
243 | - * |
|
244 | - * @access protected |
|
245 | - * @return void |
|
246 | - */ |
|
247 | - abstract protected function _set_validator_config(); |
|
238 | + /** |
|
239 | + * Child classes must declare the $_validator_config property using this method. |
|
240 | + * See comments for $_validator_config for details on what it is used for. |
|
241 | + * |
|
242 | + * NOTE: messengers should set an array of valid shortcodes for ALL scenarios. The corresponding validator class (validators/{messenger}) can be used to restrict only certain shortcodes per template so users cannot add certain shortcodes. |
|
243 | + * |
|
244 | + * @access protected |
|
245 | + * @return void |
|
246 | + */ |
|
247 | + abstract protected function _set_validator_config(); |
|
248 | 248 | |
249 | 249 | |
250 | 250 | |
251 | 251 | |
252 | 252 | |
253 | 253 | |
254 | - /** |
|
255 | - * We just deliver the messages don't kill us!! This method will need to be modified by child classes for whatever action is taken to actually send a message. |
|
256 | - * |
|
257 | - * @return bool|WP_Error |
|
258 | - * @throw \Exception |
|
259 | - */ |
|
260 | - abstract protected function _send_message(); |
|
254 | + /** |
|
255 | + * We just deliver the messages don't kill us!! This method will need to be modified by child classes for whatever action is taken to actually send a message. |
|
256 | + * |
|
257 | + * @return bool|WP_Error |
|
258 | + * @throw \Exception |
|
259 | + */ |
|
260 | + abstract protected function _send_message(); |
|
261 | 261 | |
262 | 262 | |
263 | 263 | |
264 | 264 | |
265 | - /** |
|
266 | - * We give you pretty previews of the messages! |
|
267 | - * @return string html body for message content. |
|
268 | - */ |
|
269 | - abstract protected function _preview(); |
|
265 | + /** |
|
266 | + * We give you pretty previews of the messages! |
|
267 | + * @return string html body for message content. |
|
268 | + */ |
|
269 | + abstract protected function _preview(); |
|
270 | 270 | |
271 | 271 | |
272 | 272 | |
273 | 273 | |
274 | - /** |
|
275 | - * Used by messengers (or preview) for enqueueing any scripts or styles need in message generation. |
|
276 | - * |
|
277 | - * @since 4.5.0 |
|
278 | - * |
|
279 | - * @return void |
|
280 | - */ |
|
281 | - public function enqueue_scripts_styles() |
|
282 | - { |
|
283 | - do_action('AHEE__EE_messenger__enqueue_scripts_styles'); |
|
284 | - } |
|
274 | + /** |
|
275 | + * Used by messengers (or preview) for enqueueing any scripts or styles need in message generation. |
|
276 | + * |
|
277 | + * @since 4.5.0 |
|
278 | + * |
|
279 | + * @return void |
|
280 | + */ |
|
281 | + public function enqueue_scripts_styles() |
|
282 | + { |
|
283 | + do_action('AHEE__EE_messenger__enqueue_scripts_styles'); |
|
284 | + } |
|
285 | 285 | |
286 | 286 | |
287 | 287 | |
288 | 288 | |
289 | 289 | |
290 | - /** |
|
291 | - * This is used to indicate whether a messenger must be sent immediately or not. |
|
292 | - * eg. The HTML messenger will override this to return true because it should be displayed in user's browser right |
|
293 | - * away. The PDF messenger is similar. |
|
294 | - * |
|
295 | - * This flag thus overrides any priorities that may be set on the message type used to generate the message. |
|
296 | - * |
|
297 | - * Default for this is false. So children classes must override this if they want a message to be executed immediately. |
|
298 | - * |
|
299 | - * @since 4.9.0 |
|
300 | - * @return bool |
|
301 | - */ |
|
302 | - public function send_now() |
|
303 | - { |
|
304 | - return false; |
|
305 | - } |
|
290 | + /** |
|
291 | + * This is used to indicate whether a messenger must be sent immediately or not. |
|
292 | + * eg. The HTML messenger will override this to return true because it should be displayed in user's browser right |
|
293 | + * away. The PDF messenger is similar. |
|
294 | + * |
|
295 | + * This flag thus overrides any priorities that may be set on the message type used to generate the message. |
|
296 | + * |
|
297 | + * Default for this is false. So children classes must override this if they want a message to be executed immediately. |
|
298 | + * |
|
299 | + * @since 4.9.0 |
|
300 | + * @return bool |
|
301 | + */ |
|
302 | + public function send_now() |
|
303 | + { |
|
304 | + return false; |
|
305 | + } |
|
306 | 306 | |
307 | 307 | |
308 | 308 | |
309 | 309 | |
310 | 310 | |
311 | - /** |
|
312 | - * This is a way for a messenger to indicate whether it allows an empty to field or not. |
|
313 | - * Note: If the generated message is a for a preview, this value is ignored. |
|
314 | - * @since 4.9.0 |
|
315 | - * @return bool |
|
316 | - */ |
|
317 | - public function allow_empty_to_field() |
|
318 | - { |
|
319 | - return false; |
|
320 | - } |
|
311 | + /** |
|
312 | + * This is a way for a messenger to indicate whether it allows an empty to field or not. |
|
313 | + * Note: If the generated message is a for a preview, this value is ignored. |
|
314 | + * @since 4.9.0 |
|
315 | + * @return bool |
|
316 | + */ |
|
317 | + public function allow_empty_to_field() |
|
318 | + { |
|
319 | + return false; |
|
320 | + } |
|
321 | 321 | |
322 | 322 | |
323 | 323 | |
324 | 324 | |
325 | 325 | |
326 | - /** |
|
327 | - * Sets the defaults for the _supports_labels property. Can be overridden by child classes. |
|
328 | - * @see property definition for info on how its formatted. |
|
329 | - * |
|
330 | - * @since 4.5.0; |
|
331 | - * @return void |
|
332 | - */ |
|
333 | - protected function _set_supports_labels() |
|
334 | - { |
|
335 | - $this->_set_supports_labels_defaults(); |
|
336 | - } |
|
326 | + /** |
|
327 | + * Sets the defaults for the _supports_labels property. Can be overridden by child classes. |
|
328 | + * @see property definition for info on how its formatted. |
|
329 | + * |
|
330 | + * @since 4.5.0; |
|
331 | + * @return void |
|
332 | + */ |
|
333 | + protected function _set_supports_labels() |
|
334 | + { |
|
335 | + $this->_set_supports_labels_defaults(); |
|
336 | + } |
|
337 | 337 | |
338 | 338 | |
339 | 339 | |
340 | 340 | |
341 | 341 | |
342 | - /** |
|
343 | - * Sets the defaults for the _supports_labels property. |
|
344 | - * |
|
345 | - * @since 4.5.0 |
|
346 | - * |
|
347 | - * @return void |
|
348 | - */ |
|
349 | - private function _set_supports_labels_defaults() |
|
350 | - { |
|
351 | - $this->_supports_labels->template_pack = esc_html__('Template Structure', 'event_espresso'); |
|
352 | - $this->_supports_labels->template_variation = esc_html__('Template Style', 'event_espresso'); |
|
353 | - $this->_supports_labels->template_pack_description = esc_html__('Template Structure options are bundled structural changes for templates.', 'event_espresso'); |
|
342 | + /** |
|
343 | + * Sets the defaults for the _supports_labels property. |
|
344 | + * |
|
345 | + * @since 4.5.0 |
|
346 | + * |
|
347 | + * @return void |
|
348 | + */ |
|
349 | + private function _set_supports_labels_defaults() |
|
350 | + { |
|
351 | + $this->_supports_labels->template_pack = esc_html__('Template Structure', 'event_espresso'); |
|
352 | + $this->_supports_labels->template_variation = esc_html__('Template Style', 'event_espresso'); |
|
353 | + $this->_supports_labels->template_pack_description = esc_html__('Template Structure options are bundled structural changes for templates.', 'event_espresso'); |
|
354 | 354 | |
355 | - $this->_supports_labels->template_variation_description = esc_html__('These are different styles to choose from for the selected template structure. Usually these affect things like font style, color, borders etc. In some cases the styles will also make minor layout changes.', 'event_espresso'); |
|
355 | + $this->_supports_labels->template_variation_description = esc_html__('These are different styles to choose from for the selected template structure. Usually these affect things like font style, color, borders etc. In some cases the styles will also make minor layout changes.', 'event_espresso'); |
|
356 | 356 | |
357 | - $this->_supports_labels = apply_filters('FHEE__EE_messenger___set_supports_labels_defaults___supports_labels', $this->_supports_labels, $this); |
|
358 | - } |
|
357 | + $this->_supports_labels = apply_filters('FHEE__EE_messenger___set_supports_labels_defaults___supports_labels', $this->_supports_labels, $this); |
|
358 | + } |
|
359 | 359 | |
360 | 360 | |
361 | 361 | |
362 | 362 | |
363 | 363 | |
364 | - /** |
|
365 | - * This returns the _supports_labels property. |
|
366 | - * |
|
367 | - * @since 4.5.0 |
|
368 | - * |
|
369 | - * @return stdClass |
|
370 | - */ |
|
371 | - public function get_supports_labels() |
|
372 | - { |
|
373 | - if (empty($this->_supports_labels->template_pack) || empty($this->_supports_labels->template_variation)) { |
|
374 | - $this->_set_supports_labels_defaults(); |
|
375 | - } |
|
376 | - return apply_filters('FHEE__EE_messenger__get_supports_labels', $this->_supports_labels, $this); |
|
377 | - } |
|
364 | + /** |
|
365 | + * This returns the _supports_labels property. |
|
366 | + * |
|
367 | + * @since 4.5.0 |
|
368 | + * |
|
369 | + * @return stdClass |
|
370 | + */ |
|
371 | + public function get_supports_labels() |
|
372 | + { |
|
373 | + if (empty($this->_supports_labels->template_pack) || empty($this->_supports_labels->template_variation)) { |
|
374 | + $this->_set_supports_labels_defaults(); |
|
375 | + } |
|
376 | + return apply_filters('FHEE__EE_messenger__get_supports_labels', $this->_supports_labels, $this); |
|
377 | + } |
|
378 | 378 | |
379 | 379 | |
380 | 380 | |
381 | 381 | |
382 | - /** |
|
383 | - * Used to retrieve a variation (typically the path/url to a css file) |
|
384 | - * |
|
385 | - * @since 4.5.0 |
|
386 | - * |
|
387 | - * @param EE_Messages_Template_Pack $pack The template pack used for retrieving the variation. |
|
388 | - * @param string $message_type_name The name property of the message type that we need the variation for. |
|
389 | - * @param bool $url Whether to return url (true) or path (false). Default is false. |
|
390 | - * @param string $type What variation type to return. Default is 'main'. |
|
391 | - * @param string $variation What variation for the template pack |
|
392 | - * @param bool $skip_filters This allows messengers to add a filter for another messengers get_variation but call skip filters on the callback so there is no recursion on apply_filters. |
|
393 | - * |
|
394 | - * @return string path or url for the requested variation. |
|
395 | - */ |
|
396 | - public function get_variation(EE_Messages_Template_Pack $pack, $message_type_name, $url = false, $type = 'main', $variation = 'default', $skip_filters = false) |
|
397 | - { |
|
398 | - $this->_tmp_pack = $pack; |
|
399 | - $variation_path = apply_filters('EE_messenger__get_variation__variation', false, $pack, $this->name, $message_type_name, $url, $type, $variation, $skip_filters); |
|
400 | - $variation_path = empty($variation_path) ? $this->_tmp_pack->get_variation($this->name, $message_type_name, $type, $variation, $url, '.css', $skip_filters) : $variation_path; |
|
401 | - return $variation_path; |
|
402 | - } |
|
382 | + /** |
|
383 | + * Used to retrieve a variation (typically the path/url to a css file) |
|
384 | + * |
|
385 | + * @since 4.5.0 |
|
386 | + * |
|
387 | + * @param EE_Messages_Template_Pack $pack The template pack used for retrieving the variation. |
|
388 | + * @param string $message_type_name The name property of the message type that we need the variation for. |
|
389 | + * @param bool $url Whether to return url (true) or path (false). Default is false. |
|
390 | + * @param string $type What variation type to return. Default is 'main'. |
|
391 | + * @param string $variation What variation for the template pack |
|
392 | + * @param bool $skip_filters This allows messengers to add a filter for another messengers get_variation but call skip filters on the callback so there is no recursion on apply_filters. |
|
393 | + * |
|
394 | + * @return string path or url for the requested variation. |
|
395 | + */ |
|
396 | + public function get_variation(EE_Messages_Template_Pack $pack, $message_type_name, $url = false, $type = 'main', $variation = 'default', $skip_filters = false) |
|
397 | + { |
|
398 | + $this->_tmp_pack = $pack; |
|
399 | + $variation_path = apply_filters('EE_messenger__get_variation__variation', false, $pack, $this->name, $message_type_name, $url, $type, $variation, $skip_filters); |
|
400 | + $variation_path = empty($variation_path) ? $this->_tmp_pack->get_variation($this->name, $message_type_name, $type, $variation, $url, '.css', $skip_filters) : $variation_path; |
|
401 | + return $variation_path; |
|
402 | + } |
|
403 | 403 | |
404 | 404 | |
405 | 405 | |
@@ -407,494 +407,494 @@ discard block |
||
407 | 407 | |
408 | 408 | |
409 | 409 | |
410 | - /** |
|
411 | - * This just returns the default message types associated with this messenger when it is first activated. |
|
412 | - * |
|
413 | - * @access public |
|
414 | - * @return array |
|
415 | - */ |
|
416 | - public function get_default_message_types() |
|
417 | - { |
|
418 | - $class = get_class($this); |
|
410 | + /** |
|
411 | + * This just returns the default message types associated with this messenger when it is first activated. |
|
412 | + * |
|
413 | + * @access public |
|
414 | + * @return array |
|
415 | + */ |
|
416 | + public function get_default_message_types() |
|
417 | + { |
|
418 | + $class = get_class($this); |
|
419 | 419 | |
420 | - // messenger specific filter |
|
421 | - $default_types = apply_filters('FHEE__' . $class . '__get_default_message_types__default_types', $this->_default_message_types, $this); |
|
420 | + // messenger specific filter |
|
421 | + $default_types = apply_filters('FHEE__' . $class . '__get_default_message_types__default_types', $this->_default_message_types, $this); |
|
422 | 422 | |
423 | - // all messengers filter |
|
424 | - $default_types = apply_filters('FHEE__EE_messenger__get_default_message_types__default_types', $default_types, $this); |
|
425 | - return $default_types; |
|
426 | - } |
|
423 | + // all messengers filter |
|
424 | + $default_types = apply_filters('FHEE__EE_messenger__get_default_message_types__default_types', $default_types, $this); |
|
425 | + return $default_types; |
|
426 | + } |
|
427 | 427 | |
428 | 428 | |
429 | 429 | |
430 | 430 | |
431 | - /** |
|
432 | - * Returns the valid message types associated with this messenger. |
|
433 | - * |
|
434 | - * @since 4.5.0 |
|
435 | - * |
|
436 | - * @return array |
|
437 | - */ |
|
438 | - public function get_valid_message_types() |
|
439 | - { |
|
440 | - $class = get_class($this); |
|
441 | - |
|
442 | - // messenger specific filter |
|
443 | - // messenger specific filter |
|
444 | - $valid_types = apply_filters('FHEE__' . $class . '__get_valid_message_types__valid_types', $this->_valid_message_types, $this); |
|
445 | - |
|
446 | - // all messengers filter |
|
447 | - $valid_types = apply_filters('FHEE__EE_messenger__get_valid_message_types__valid_types', $valid_types, $this); |
|
448 | - return $valid_types; |
|
449 | - } |
|
450 | - |
|
451 | - |
|
452 | - |
|
453 | - |
|
454 | - |
|
455 | - /** |
|
456 | - * this is just used by the custom validators (EE_Messages_Validator classes) to modify the _validator_config for certain message_type/messenger combos where a context may only use certain shortcodes etc. |
|
457 | - * |
|
458 | - * @access public |
|
459 | - * @param array $new_config Whatever is put in here will reset the _validator_config property |
|
460 | - */ |
|
461 | - public function set_validator_config($new_config) |
|
462 | - { |
|
463 | - $this->_validator_config = $new_config; |
|
464 | - } |
|
465 | - |
|
466 | - |
|
467 | - |
|
468 | - |
|
469 | - /** |
|
470 | - * This returns the _validator_config property |
|
471 | - * |
|
472 | - * @access public |
|
473 | - * @return array |
|
474 | - */ |
|
475 | - public function get_validator_config() |
|
476 | - { |
|
477 | - $class = get_class($this); |
|
478 | - |
|
479 | - $config = apply_filters('FHEE__' . $class . '__get_validator_config', $this->_validator_config, $this); |
|
480 | - $config = apply_filters('FHEE__EE_messenger__get_validator_config', $config, $this); |
|
481 | - return $config; |
|
482 | - } |
|
483 | - |
|
484 | - |
|
485 | - |
|
486 | - |
|
487 | - /** |
|
488 | - * this public method accepts a page slug (for an EE_admin page) and will return the response from the child class callback function if that page is registered via the `_admin_registered_page` property set by the child class. |
|
489 | - * |
|
490 | - * @param string $page the slug of the EE admin page |
|
491 | - * @param array $message_types an array of active message type objects |
|
492 | - * @param string $action the page action (to allow for more specific handling - i.e. edit vs. add pages) |
|
493 | - * @param array $extra This is just an extra argument that can be used to pass additional data for setting up page content. |
|
494 | - * @access public |
|
495 | - * @return string content for page |
|
496 | - */ |
|
497 | - public function get_messenger_admin_page_content($page, $action = null, $extra = array(), $message_types = array()) |
|
498 | - { |
|
499 | - return $this->_get_admin_page_content($page, $action, $extra, $message_types); |
|
500 | - } |
|
501 | - |
|
502 | - |
|
503 | - |
|
504 | - /** |
|
505 | - * @param $message_types |
|
506 | - * @param array $extra |
|
507 | - * @return mixed|string |
|
508 | - */ |
|
509 | - protected function _get_admin_content_events_edit($message_types, $extra) |
|
510 | - { |
|
511 | - // defaults |
|
512 | - $template_args = array(); |
|
513 | - $selector_rows = ''; |
|
514 | - |
|
515 | - // we don't need message types here so we're just going to ignore. we do, however, expect the event id here. The event id is needed to provide a link to setup a custom template for this event. |
|
516 | - $event_id = isset($extra['event']) ? $extra['event'] : null; |
|
517 | - |
|
518 | - $template_wrapper_path = EE_LIBRARIES . 'messages/messenger/admin_templates/event_switcher_wrapper.template.php'; |
|
519 | - $template_row_path = EE_LIBRARIES . 'messages/messenger/admin_templates/event_switcher_row.template.php'; |
|
520 | - |
|
521 | - // array of template objects for global and custom (non-trashed) (but remember just for this messenger!) |
|
522 | - $global_templates = EEM_Message_Template_Group::instance()->get_all( |
|
523 | - array( array( 'MTP_messenger' => $this->name, 'MTP_is_global' => true, 'MTP_is_active' => true ) ) |
|
524 | - ); |
|
525 | - $templates_for_event = EEM_Message_Template_Group::instance()->get_all_custom_templates_by_event( |
|
526 | - $event_id, |
|
527 | - array( |
|
528 | - 'MTP_messenger' => $this->name, |
|
529 | - 'MTP_is_active' => true |
|
530 | - ) |
|
531 | - ); |
|
532 | - $templates_for_event = !empty($templates_for_event) ? $templates_for_event : array(); |
|
533 | - |
|
534 | - // so we need to setup the rows for the selectors and we use the global mtpgs (cause those will the active message template groups) |
|
535 | - foreach ($global_templates as $mtpgID => $mtpg) { |
|
536 | - if ($mtpg instanceof EE_Message_Template_Group) { |
|
537 | - // verify this message type is supposed to show on this page |
|
538 | - $mtp_obj = $mtpg->message_type_obj(); |
|
539 | - if (! $mtp_obj instanceof EE_message_type) { |
|
540 | - continue; |
|
541 | - } |
|
542 | - $mtp_obj->admin_registered_pages = (array) $mtp_obj->admin_registered_pages; |
|
543 | - if (! in_array('events_edit', $mtp_obj->admin_registered_pages)) { |
|
544 | - continue; |
|
545 | - } |
|
546 | - $select_values = array(); |
|
547 | - $select_values[ $mtpgID ] = esc_html__('Global', 'event_espresso'); |
|
548 | - $default_value = array_key_exists($mtpgID, $templates_for_event) && ! $mtpg->get('MTP_is_override') ? $mtpgID : null; |
|
549 | - // if the override has been set for the global template, then that means even if there are custom templates already created we ignore them because of the set override. |
|
550 | - if (! $mtpg->get('MTP_is_override')) { |
|
551 | - // any custom templates for this message type? |
|
552 | - $custom_templates = EEM_Message_Template_Group::instance()->get_custom_message_template_by_m_and_mt($this->name, $mtpg->message_type()); |
|
553 | - foreach ($custom_templates as $cmtpgID => $cmtpg) { |
|
554 | - $select_values[ $cmtpgID ] = $cmtpg->name(); |
|
555 | - $default_value = array_key_exists($cmtpgID, $templates_for_event) ? $cmtpgID : $default_value; |
|
556 | - } |
|
557 | - } |
|
558 | - // if there is no $default_value then we set it as the global |
|
559 | - $default_value = empty($default_value) ? $mtpgID : $default_value; |
|
560 | - $edit_url_query_args = [ |
|
561 | - 'page' => 'espresso_messages', |
|
562 | - 'action' => 'edit_message_template', |
|
563 | - 'id' => $default_value, |
|
564 | - 'evt_id' => $event_id |
|
565 | - ]; |
|
566 | - $edit_url = EEH_URL::add_query_args_and_nonce($edit_url_query_args, admin_url('admin.php')); |
|
567 | - $create_url_query_args = [ |
|
568 | - 'page' => 'espresso_messages', |
|
569 | - 'action' => 'add_new_message_template', |
|
570 | - 'GRP_ID' => $default_value, |
|
571 | - 'message_type' => $mtpg->message_type(), |
|
572 | - 'messenger' => $this->name |
|
573 | - ]; |
|
574 | - $create_url = EEH_URL::add_query_args_and_nonce($create_url_query_args, admin_url('admin.php')); |
|
575 | - $st_args['mt_name'] = ucwords($mtp_obj->label['singular']); |
|
576 | - $st_args['mt_slug'] = $mtpg->message_type(); |
|
577 | - $st_args['messenger_slug'] = $this->name; |
|
578 | - $st_args['selector'] = EEH_Form_Fields::select_input('event_message_templates_relation[' . $mtpgID . ']', $select_values, $default_value, 'data-messenger="' . $this->name . '" data-messagetype="' . $mtpg->message_type() . '"', 'message-template-selector'); |
|
579 | - // note that message template group that has override_all_custom set will remove the ability to set a custom message template based off of the global (and that also in turn overrides any other custom templates). |
|
580 | - $st_args['create_button'] = $mtpg->get('MTP_is_override') ? '' : '<a data-messenger="' . $this->name . '" data-messagetype="' . $mtpg->message_type() . '" data-grpid="' . $default_value . '" target="_blank" href="' . $create_url . '" class="button button-small create-mtpg-button">' . esc_html__('Create New Custom', 'event_espresso') . '</a>'; |
|
581 | - $st_args['create_button'] = EE_Registry::instance()->CAP->current_user_can('ee_edit_messages', 'espresso_messages_add_new_message_template') ? $st_args['create_button'] : ''; |
|
582 | - $st_args['edit_button'] = EE_Registry::instance()->CAP->current_user_can('ee_edit_message', 'espresso_messages_edit_message_template', $mtpgID) ? '<a data-messagetype="' . $mtpg->message_type() . '" data-grpid="' . $default_value . '" target="_blank" href="' . $edit_url . '" class="button button-small edit-mtpg-button">' . esc_html__('Edit', 'event_espresso') . '</a>' : ''; |
|
583 | - $selector_rows .= EEH_Template::display_template($template_row_path, $st_args, true); |
|
584 | - } |
|
585 | - } |
|
586 | - |
|
587 | - // if no selectors present then get out. |
|
588 | - if (empty($selector_rows)) { |
|
589 | - return ''; |
|
590 | - } |
|
591 | - |
|
592 | - $template_args['selector_rows'] = $selector_rows; |
|
593 | - return EEH_Template::display_template($template_wrapper_path, $template_args, true); |
|
594 | - } |
|
595 | - |
|
596 | - |
|
597 | - |
|
598 | - |
|
599 | - |
|
600 | - |
|
601 | - /** |
|
602 | - * get_template_fields |
|
603 | - * |
|
604 | - * @access public |
|
605 | - * @return array $this->_template_fields |
|
606 | - */ |
|
607 | - public function get_template_fields() |
|
608 | - { |
|
609 | - $template_fields = apply_filters('FHEE__' . get_class($this) . '__get_template_fields', $this->_template_fields, $this); |
|
610 | - $template_fields = apply_filters('FHEE__EE_messenger__get_template_fields', $template_fields, $this); |
|
611 | - return $template_fields; |
|
612 | - } |
|
613 | - |
|
614 | - |
|
615 | - |
|
616 | - |
|
617 | - /** SETUP METHODS **/ |
|
618 | - /** |
|
619 | - * The following method doesn't NEED to be used by child classes but might be modified by the specific messenger |
|
620 | - * @param string $item |
|
621 | - * @param mixed $value |
|
622 | - */ |
|
623 | - protected function _set_template_value($item, $value) |
|
624 | - { |
|
625 | - if (array_key_exists($item, $this->_template_fields)) { |
|
626 | - $prop = '_' . $item; |
|
627 | - $this->{$prop} = $value; |
|
628 | - } |
|
629 | - } |
|
630 | - |
|
631 | - /** |
|
632 | - * Sets up the message for sending. |
|
633 | - * |
|
634 | - * @param EE_message $message the message object that contains details about the message. |
|
635 | - * @param EE_message_type $message_type The message type object used in combination with this messenger to generate the provided message. |
|
636 | - * |
|
637 | - * @return bool Very important that all messengers return bool for successful send or not. Error messages can be |
|
638 | - * added to EE_Error. |
|
639 | - * true = message sent successfully |
|
640 | - * false = message not sent but can be retried (i.e. the failure might be just due to communication issues at the time of send). |
|
641 | - * Throwing a SendMessageException means the message failed sending and cannot be retried. |
|
642 | - * |
|
643 | - * @throws SendMessageException |
|
644 | - */ |
|
645 | - final public function send_message($message, EE_message_type $message_type) |
|
646 | - { |
|
647 | - try { |
|
648 | - $this->_validate_and_setup($message); |
|
649 | - $this->_incoming_message_type = $message_type; |
|
650 | - $response = $this->_send_message(); |
|
651 | - if ($response instanceof WP_Error) { |
|
652 | - EE_Error::add_error($response->get_error_message(), __FILE__, __FUNCTION__, __LINE__); |
|
653 | - $response = false; |
|
654 | - } |
|
655 | - } catch (\Exception $e) { |
|
656 | - // convert to an instance of SendMessageException |
|
657 | - throw new SendMessageException($e->getMessage()); |
|
658 | - } |
|
659 | - return $response; |
|
660 | - } |
|
661 | - |
|
662 | - |
|
663 | - |
|
664 | - /** |
|
665 | - * Sets up and returns message preview |
|
666 | - * @param EE_Message $message incoming message object |
|
667 | - * @param EE_message_type $message_type This is whatever message type was used in combination with this messenger to generate the message. |
|
668 | - * @param bool $send true we will actually use the _send method (for test sends). FALSE we just return preview |
|
669 | - * @return string return the message html content |
|
670 | - */ |
|
671 | - public function get_preview(EE_Message $message, EE_message_type $message_type, $send = false) |
|
672 | - { |
|
673 | - $this->_validate_and_setup($message); |
|
674 | - |
|
675 | - $this->_incoming_message_type = $message_type; |
|
676 | - |
|
677 | - if ($send) { |
|
678 | - // are we overriding any existing template fields? |
|
679 | - $settings = apply_filters( |
|
680 | - 'FHEE__EE_messenger__get_preview__messenger_test_settings', |
|
681 | - $this->get_existing_test_settings(), |
|
682 | - $this, |
|
683 | - $send, |
|
684 | - $message, |
|
685 | - $message_type |
|
686 | - ); |
|
687 | - if (! empty($settings)) { |
|
688 | - foreach ($settings as $field => $value) { |
|
689 | - $this->_set_template_value($field, $value); |
|
690 | - } |
|
691 | - } |
|
692 | - } |
|
693 | - |
|
694 | - // enqueue preview js so that any links/buttons on the page are disabled. |
|
695 | - if (! $send) { |
|
696 | - // the below may seem like duplication. However, typically if a messenger enqueues scripts/styles, |
|
697 | - // it deregisters all existing wp scripts and styles first. So the second hook ensures our previewer still gets setup. |
|
698 | - add_action('admin_enqueue_scripts', array( $this, 'add_preview_script' ), 10); |
|
699 | - add_action('wp_enqueue_scripts', array( $this, 'add_preview_script' ), 10); |
|
700 | - add_action('AHEE__EE_messenger__enqueue_scripts_styles', array( $this, 'add_preview_script' ), 10); |
|
701 | - } |
|
702 | - |
|
703 | - return $send ? $this->_send_message() : $this->_preview(); |
|
704 | - } |
|
705 | - |
|
706 | - |
|
707 | - |
|
708 | - |
|
709 | - /** |
|
710 | - * Callback for enqueue_scripts so that we setup the preview script for all previews. |
|
711 | - * |
|
712 | - * @since 4.5.0 |
|
713 | - * |
|
714 | - * @return void |
|
715 | - */ |
|
716 | - public function add_preview_script() |
|
717 | - { |
|
718 | - // error message |
|
719 | - EE_Registry::$i18n_js_strings['links_disabled'] = wp_strip_all_tags( |
|
720 | - __('All the links on this page have been disabled because this is a generated preview message for the purpose of ensuring layout, style, and content setup. To test generated links, you must trigger an actual message notification.', 'event_espresso') |
|
721 | - ); |
|
722 | - wp_register_script('ee-messages-preview-js', EE_LIBRARIES_URL . 'messages/messenger/assets/js/ee-messages-preview.js', array( 'jquery' ), EVENT_ESPRESSO_VERSION, true); |
|
723 | - wp_localize_script('ee-messages-preview-js', 'eei18n', EE_Registry::$i18n_js_strings); |
|
724 | - wp_enqueue_script('ee-messages-preview-js'); |
|
725 | - } |
|
726 | - |
|
727 | - |
|
728 | - |
|
729 | - |
|
730 | - /** |
|
731 | - * simply validates the incoming message object and then sets up the properties for the messenger |
|
732 | - * @param EE_Message $message |
|
733 | - * @throws EE_Error |
|
734 | - */ |
|
735 | - protected function _validate_and_setup(EE_Message $message) |
|
736 | - { |
|
737 | - $template_pack = $message->get_template_pack(); |
|
738 | - $variation = $message->get_template_pack_variation(); |
|
739 | - |
|
740 | - // verify we have the required template pack value on the $message object. |
|
741 | - if (! $template_pack instanceof EE_Messages_Template_Pack) { |
|
742 | - throw new EE_Error(esc_html__('Incoming $message object must have an EE_Messages_Template_Pack object available.', 'event_espresso')); |
|
743 | - } |
|
744 | - |
|
745 | - $this->_tmp_pack = $template_pack; |
|
746 | - |
|
747 | - $this->_variation = $variation ? $variation : 'default'; |
|
748 | - |
|
749 | - $template_fields = $this->get_template_fields(); |
|
750 | - |
|
751 | - foreach ($template_fields as $template => $value) { |
|
752 | - if ($template !== 'extra') { |
|
753 | - $column_value = $message->get_field_or_extra_meta('MSG_' . $template); |
|
754 | - $message_template_value = $column_value ? $column_value : null; |
|
755 | - $this->_set_template_value($template, $message_template_value); |
|
756 | - } |
|
757 | - } |
|
758 | - } |
|
759 | - |
|
760 | - |
|
761 | - |
|
762 | - /** |
|
763 | - * Utility method for child classes to get the contents of a template file and return |
|
764 | - * |
|
765 | - * We're assuming the child messenger class has already setup template args! |
|
766 | - * @param bool $preview if true we use the preview wrapper otherwise we use main wrapper. |
|
767 | - * @return string |
|
768 | - * @throws \EE_Error |
|
769 | - */ |
|
770 | - protected function _get_main_template($preview = false) |
|
771 | - { |
|
772 | - $type = $preview ? 'preview' : 'main'; |
|
773 | - |
|
774 | - $wrapper_template = $this->_tmp_pack->get_wrapper($this->name, $type); |
|
775 | - |
|
776 | - // check file exists and is readable |
|
777 | - if (!is_readable($wrapper_template)) { |
|
778 | - throw new EE_Error(sprintf(esc_html__('Unable to access the template file for the %s messenger main content wrapper. The location being attempted is %s.', 'event_espresso'), ucwords($this->label['singular']), $wrapper_template)); |
|
779 | - } |
|
780 | - |
|
781 | - // add message type to template args |
|
782 | - $this->_template_args['message_type'] = $this->_incoming_message_type; |
|
783 | - |
|
784 | - return EEH_Template::display_template($wrapper_template, $this->_template_args, true); |
|
785 | - } |
|
786 | - |
|
787 | - |
|
788 | - |
|
789 | - /** |
|
790 | - * set the _test_settings_fields property |
|
791 | - * |
|
792 | - * @access protected |
|
793 | - * @return void |
|
794 | - */ |
|
795 | - protected function _set_test_settings_fields() |
|
796 | - { |
|
797 | - $this->_test_settings_fields = array(); |
|
798 | - } |
|
799 | - |
|
800 | - |
|
801 | - |
|
802 | - /** |
|
803 | - * return the _test_settings_fields property |
|
804 | - * @return array |
|
805 | - */ |
|
806 | - public function get_test_settings_fields() |
|
807 | - { |
|
808 | - return $this->_test_settings_fields; |
|
809 | - } |
|
810 | - |
|
811 | - |
|
812 | - |
|
813 | - |
|
814 | - /** |
|
815 | - * This just returns any existing test settings that might be saved in the database |
|
816 | - * |
|
817 | - * @access public |
|
818 | - * @return array |
|
819 | - */ |
|
820 | - public function get_existing_test_settings() |
|
821 | - { |
|
822 | - /** @var EE_Message_Resource_Manager $Message_Resource_Manager */ |
|
823 | - $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
824 | - $settings = $Message_Resource_Manager->get_active_messengers_option(); |
|
825 | - return isset($settings[ $this->name ]['test_settings']) ? $settings[ $this->name ]['test_settings'] : array(); |
|
826 | - } |
|
827 | - |
|
828 | - |
|
829 | - |
|
830 | - /** |
|
831 | - * All this does is set the existing test settings (in the db) for the messenger |
|
832 | - * |
|
833 | - * @access public |
|
834 | - * @param $settings |
|
835 | - * @return bool success/fail |
|
836 | - */ |
|
837 | - public function set_existing_test_settings($settings) |
|
838 | - { |
|
839 | - /** @var EE_Message_Resource_Manager $Message_Resource_Manager */ |
|
840 | - $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
841 | - $existing = $Message_Resource_Manager->get_active_messengers_option(); |
|
842 | - $existing[ $this->name ]['test_settings'] = $settings; |
|
843 | - return $Message_Resource_Manager->update_active_messengers_option($existing); |
|
844 | - } |
|
845 | - |
|
846 | - |
|
847 | - |
|
848 | - /** |
|
849 | - * This just returns the field label for a given field setup in the _template_fields property. |
|
850 | - * |
|
851 | - * @since 4.3.0 |
|
852 | - * |
|
853 | - * @param string $field The field to retrieve the label for |
|
854 | - * @return string The label |
|
855 | - */ |
|
856 | - public function get_field_label($field) |
|
857 | - { |
|
858 | - // first let's see if the field requests is in the top level array. |
|
859 | - if (isset($this->_template_fields[ $field ]) && !empty($this->_template_fields[ $field ]['label'])) { |
|
860 | - return $this->_template[ $field ]['label']; |
|
861 | - } |
|
862 | - |
|
863 | - // nope so let's look in the extra array to see if it's there HOWEVER if the field exists as a top level index in the extra array then we know the label is in the 'main' index. |
|
864 | - if (isset($this->_template_fields['extra']) && !empty($this->_template_fields['extra'][ $field ]) && !empty($this->_template_fields['extra'][ $field ]['main']['label'])) { |
|
865 | - return $this->_template_fields['extra'][ $field ]['main']['label']; |
|
866 | - } |
|
867 | - |
|
868 | - // now it's possible this field may just be existing in any of the extra array items. |
|
869 | - if (!empty($this->_template_fields['extra']) && is_array($this->_template_fields['extra'])) { |
|
870 | - foreach ($this->_template_fields['extra'] as $main_field => $subfields) { |
|
871 | - if (!is_array($subfields)) { |
|
872 | - continue; |
|
873 | - } |
|
874 | - if (isset($subfields[ $field ]) && !empty($subfields[ $field ]['label'])) { |
|
875 | - return $subfields[ $field ]['label']; |
|
876 | - } |
|
877 | - } |
|
878 | - } |
|
879 | - |
|
880 | - // if we made it here then there's no label set so let's just return the $field. |
|
881 | - return $field; |
|
882 | - } |
|
883 | - |
|
884 | - |
|
885 | - |
|
886 | - |
|
887 | - /** |
|
888 | - * This is a method called from EE_messages when this messenger is a generating messenger and the sending messenger is a different messenger. Child messengers can set hooks for the sending messenger to callback on if necessary (i.e. swap out css files or something else). |
|
889 | - * |
|
890 | - * @since 4.5.0 |
|
891 | - * |
|
892 | - * @param string $sending_messenger_name the name of the sending messenger so we only set the hooks needed. |
|
893 | - * |
|
894 | - * @return void |
|
895 | - */ |
|
896 | - public function do_secondary_messenger_hooks($sending_messenger_name) |
|
897 | - { |
|
898 | - return; |
|
899 | - } |
|
431 | + /** |
|
432 | + * Returns the valid message types associated with this messenger. |
|
433 | + * |
|
434 | + * @since 4.5.0 |
|
435 | + * |
|
436 | + * @return array |
|
437 | + */ |
|
438 | + public function get_valid_message_types() |
|
439 | + { |
|
440 | + $class = get_class($this); |
|
441 | + |
|
442 | + // messenger specific filter |
|
443 | + // messenger specific filter |
|
444 | + $valid_types = apply_filters('FHEE__' . $class . '__get_valid_message_types__valid_types', $this->_valid_message_types, $this); |
|
445 | + |
|
446 | + // all messengers filter |
|
447 | + $valid_types = apply_filters('FHEE__EE_messenger__get_valid_message_types__valid_types', $valid_types, $this); |
|
448 | + return $valid_types; |
|
449 | + } |
|
450 | + |
|
451 | + |
|
452 | + |
|
453 | + |
|
454 | + |
|
455 | + /** |
|
456 | + * this is just used by the custom validators (EE_Messages_Validator classes) to modify the _validator_config for certain message_type/messenger combos where a context may only use certain shortcodes etc. |
|
457 | + * |
|
458 | + * @access public |
|
459 | + * @param array $new_config Whatever is put in here will reset the _validator_config property |
|
460 | + */ |
|
461 | + public function set_validator_config($new_config) |
|
462 | + { |
|
463 | + $this->_validator_config = $new_config; |
|
464 | + } |
|
465 | + |
|
466 | + |
|
467 | + |
|
468 | + |
|
469 | + /** |
|
470 | + * This returns the _validator_config property |
|
471 | + * |
|
472 | + * @access public |
|
473 | + * @return array |
|
474 | + */ |
|
475 | + public function get_validator_config() |
|
476 | + { |
|
477 | + $class = get_class($this); |
|
478 | + |
|
479 | + $config = apply_filters('FHEE__' . $class . '__get_validator_config', $this->_validator_config, $this); |
|
480 | + $config = apply_filters('FHEE__EE_messenger__get_validator_config', $config, $this); |
|
481 | + return $config; |
|
482 | + } |
|
483 | + |
|
484 | + |
|
485 | + |
|
486 | + |
|
487 | + /** |
|
488 | + * this public method accepts a page slug (for an EE_admin page) and will return the response from the child class callback function if that page is registered via the `_admin_registered_page` property set by the child class. |
|
489 | + * |
|
490 | + * @param string $page the slug of the EE admin page |
|
491 | + * @param array $message_types an array of active message type objects |
|
492 | + * @param string $action the page action (to allow for more specific handling - i.e. edit vs. add pages) |
|
493 | + * @param array $extra This is just an extra argument that can be used to pass additional data for setting up page content. |
|
494 | + * @access public |
|
495 | + * @return string content for page |
|
496 | + */ |
|
497 | + public function get_messenger_admin_page_content($page, $action = null, $extra = array(), $message_types = array()) |
|
498 | + { |
|
499 | + return $this->_get_admin_page_content($page, $action, $extra, $message_types); |
|
500 | + } |
|
501 | + |
|
502 | + |
|
503 | + |
|
504 | + /** |
|
505 | + * @param $message_types |
|
506 | + * @param array $extra |
|
507 | + * @return mixed|string |
|
508 | + */ |
|
509 | + protected function _get_admin_content_events_edit($message_types, $extra) |
|
510 | + { |
|
511 | + // defaults |
|
512 | + $template_args = array(); |
|
513 | + $selector_rows = ''; |
|
514 | + |
|
515 | + // we don't need message types here so we're just going to ignore. we do, however, expect the event id here. The event id is needed to provide a link to setup a custom template for this event. |
|
516 | + $event_id = isset($extra['event']) ? $extra['event'] : null; |
|
517 | + |
|
518 | + $template_wrapper_path = EE_LIBRARIES . 'messages/messenger/admin_templates/event_switcher_wrapper.template.php'; |
|
519 | + $template_row_path = EE_LIBRARIES . 'messages/messenger/admin_templates/event_switcher_row.template.php'; |
|
520 | + |
|
521 | + // array of template objects for global and custom (non-trashed) (but remember just for this messenger!) |
|
522 | + $global_templates = EEM_Message_Template_Group::instance()->get_all( |
|
523 | + array( array( 'MTP_messenger' => $this->name, 'MTP_is_global' => true, 'MTP_is_active' => true ) ) |
|
524 | + ); |
|
525 | + $templates_for_event = EEM_Message_Template_Group::instance()->get_all_custom_templates_by_event( |
|
526 | + $event_id, |
|
527 | + array( |
|
528 | + 'MTP_messenger' => $this->name, |
|
529 | + 'MTP_is_active' => true |
|
530 | + ) |
|
531 | + ); |
|
532 | + $templates_for_event = !empty($templates_for_event) ? $templates_for_event : array(); |
|
533 | + |
|
534 | + // so we need to setup the rows for the selectors and we use the global mtpgs (cause those will the active message template groups) |
|
535 | + foreach ($global_templates as $mtpgID => $mtpg) { |
|
536 | + if ($mtpg instanceof EE_Message_Template_Group) { |
|
537 | + // verify this message type is supposed to show on this page |
|
538 | + $mtp_obj = $mtpg->message_type_obj(); |
|
539 | + if (! $mtp_obj instanceof EE_message_type) { |
|
540 | + continue; |
|
541 | + } |
|
542 | + $mtp_obj->admin_registered_pages = (array) $mtp_obj->admin_registered_pages; |
|
543 | + if (! in_array('events_edit', $mtp_obj->admin_registered_pages)) { |
|
544 | + continue; |
|
545 | + } |
|
546 | + $select_values = array(); |
|
547 | + $select_values[ $mtpgID ] = esc_html__('Global', 'event_espresso'); |
|
548 | + $default_value = array_key_exists($mtpgID, $templates_for_event) && ! $mtpg->get('MTP_is_override') ? $mtpgID : null; |
|
549 | + // if the override has been set for the global template, then that means even if there are custom templates already created we ignore them because of the set override. |
|
550 | + if (! $mtpg->get('MTP_is_override')) { |
|
551 | + // any custom templates for this message type? |
|
552 | + $custom_templates = EEM_Message_Template_Group::instance()->get_custom_message_template_by_m_and_mt($this->name, $mtpg->message_type()); |
|
553 | + foreach ($custom_templates as $cmtpgID => $cmtpg) { |
|
554 | + $select_values[ $cmtpgID ] = $cmtpg->name(); |
|
555 | + $default_value = array_key_exists($cmtpgID, $templates_for_event) ? $cmtpgID : $default_value; |
|
556 | + } |
|
557 | + } |
|
558 | + // if there is no $default_value then we set it as the global |
|
559 | + $default_value = empty($default_value) ? $mtpgID : $default_value; |
|
560 | + $edit_url_query_args = [ |
|
561 | + 'page' => 'espresso_messages', |
|
562 | + 'action' => 'edit_message_template', |
|
563 | + 'id' => $default_value, |
|
564 | + 'evt_id' => $event_id |
|
565 | + ]; |
|
566 | + $edit_url = EEH_URL::add_query_args_and_nonce($edit_url_query_args, admin_url('admin.php')); |
|
567 | + $create_url_query_args = [ |
|
568 | + 'page' => 'espresso_messages', |
|
569 | + 'action' => 'add_new_message_template', |
|
570 | + 'GRP_ID' => $default_value, |
|
571 | + 'message_type' => $mtpg->message_type(), |
|
572 | + 'messenger' => $this->name |
|
573 | + ]; |
|
574 | + $create_url = EEH_URL::add_query_args_and_nonce($create_url_query_args, admin_url('admin.php')); |
|
575 | + $st_args['mt_name'] = ucwords($mtp_obj->label['singular']); |
|
576 | + $st_args['mt_slug'] = $mtpg->message_type(); |
|
577 | + $st_args['messenger_slug'] = $this->name; |
|
578 | + $st_args['selector'] = EEH_Form_Fields::select_input('event_message_templates_relation[' . $mtpgID . ']', $select_values, $default_value, 'data-messenger="' . $this->name . '" data-messagetype="' . $mtpg->message_type() . '"', 'message-template-selector'); |
|
579 | + // note that message template group that has override_all_custom set will remove the ability to set a custom message template based off of the global (and that also in turn overrides any other custom templates). |
|
580 | + $st_args['create_button'] = $mtpg->get('MTP_is_override') ? '' : '<a data-messenger="' . $this->name . '" data-messagetype="' . $mtpg->message_type() . '" data-grpid="' . $default_value . '" target="_blank" href="' . $create_url . '" class="button button-small create-mtpg-button">' . esc_html__('Create New Custom', 'event_espresso') . '</a>'; |
|
581 | + $st_args['create_button'] = EE_Registry::instance()->CAP->current_user_can('ee_edit_messages', 'espresso_messages_add_new_message_template') ? $st_args['create_button'] : ''; |
|
582 | + $st_args['edit_button'] = EE_Registry::instance()->CAP->current_user_can('ee_edit_message', 'espresso_messages_edit_message_template', $mtpgID) ? '<a data-messagetype="' . $mtpg->message_type() . '" data-grpid="' . $default_value . '" target="_blank" href="' . $edit_url . '" class="button button-small edit-mtpg-button">' . esc_html__('Edit', 'event_espresso') . '</a>' : ''; |
|
583 | + $selector_rows .= EEH_Template::display_template($template_row_path, $st_args, true); |
|
584 | + } |
|
585 | + } |
|
586 | + |
|
587 | + // if no selectors present then get out. |
|
588 | + if (empty($selector_rows)) { |
|
589 | + return ''; |
|
590 | + } |
|
591 | + |
|
592 | + $template_args['selector_rows'] = $selector_rows; |
|
593 | + return EEH_Template::display_template($template_wrapper_path, $template_args, true); |
|
594 | + } |
|
595 | + |
|
596 | + |
|
597 | + |
|
598 | + |
|
599 | + |
|
600 | + |
|
601 | + /** |
|
602 | + * get_template_fields |
|
603 | + * |
|
604 | + * @access public |
|
605 | + * @return array $this->_template_fields |
|
606 | + */ |
|
607 | + public function get_template_fields() |
|
608 | + { |
|
609 | + $template_fields = apply_filters('FHEE__' . get_class($this) . '__get_template_fields', $this->_template_fields, $this); |
|
610 | + $template_fields = apply_filters('FHEE__EE_messenger__get_template_fields', $template_fields, $this); |
|
611 | + return $template_fields; |
|
612 | + } |
|
613 | + |
|
614 | + |
|
615 | + |
|
616 | + |
|
617 | + /** SETUP METHODS **/ |
|
618 | + /** |
|
619 | + * The following method doesn't NEED to be used by child classes but might be modified by the specific messenger |
|
620 | + * @param string $item |
|
621 | + * @param mixed $value |
|
622 | + */ |
|
623 | + protected function _set_template_value($item, $value) |
|
624 | + { |
|
625 | + if (array_key_exists($item, $this->_template_fields)) { |
|
626 | + $prop = '_' . $item; |
|
627 | + $this->{$prop} = $value; |
|
628 | + } |
|
629 | + } |
|
630 | + |
|
631 | + /** |
|
632 | + * Sets up the message for sending. |
|
633 | + * |
|
634 | + * @param EE_message $message the message object that contains details about the message. |
|
635 | + * @param EE_message_type $message_type The message type object used in combination with this messenger to generate the provided message. |
|
636 | + * |
|
637 | + * @return bool Very important that all messengers return bool for successful send or not. Error messages can be |
|
638 | + * added to EE_Error. |
|
639 | + * true = message sent successfully |
|
640 | + * false = message not sent but can be retried (i.e. the failure might be just due to communication issues at the time of send). |
|
641 | + * Throwing a SendMessageException means the message failed sending and cannot be retried. |
|
642 | + * |
|
643 | + * @throws SendMessageException |
|
644 | + */ |
|
645 | + final public function send_message($message, EE_message_type $message_type) |
|
646 | + { |
|
647 | + try { |
|
648 | + $this->_validate_and_setup($message); |
|
649 | + $this->_incoming_message_type = $message_type; |
|
650 | + $response = $this->_send_message(); |
|
651 | + if ($response instanceof WP_Error) { |
|
652 | + EE_Error::add_error($response->get_error_message(), __FILE__, __FUNCTION__, __LINE__); |
|
653 | + $response = false; |
|
654 | + } |
|
655 | + } catch (\Exception $e) { |
|
656 | + // convert to an instance of SendMessageException |
|
657 | + throw new SendMessageException($e->getMessage()); |
|
658 | + } |
|
659 | + return $response; |
|
660 | + } |
|
661 | + |
|
662 | + |
|
663 | + |
|
664 | + /** |
|
665 | + * Sets up and returns message preview |
|
666 | + * @param EE_Message $message incoming message object |
|
667 | + * @param EE_message_type $message_type This is whatever message type was used in combination with this messenger to generate the message. |
|
668 | + * @param bool $send true we will actually use the _send method (for test sends). FALSE we just return preview |
|
669 | + * @return string return the message html content |
|
670 | + */ |
|
671 | + public function get_preview(EE_Message $message, EE_message_type $message_type, $send = false) |
|
672 | + { |
|
673 | + $this->_validate_and_setup($message); |
|
674 | + |
|
675 | + $this->_incoming_message_type = $message_type; |
|
676 | + |
|
677 | + if ($send) { |
|
678 | + // are we overriding any existing template fields? |
|
679 | + $settings = apply_filters( |
|
680 | + 'FHEE__EE_messenger__get_preview__messenger_test_settings', |
|
681 | + $this->get_existing_test_settings(), |
|
682 | + $this, |
|
683 | + $send, |
|
684 | + $message, |
|
685 | + $message_type |
|
686 | + ); |
|
687 | + if (! empty($settings)) { |
|
688 | + foreach ($settings as $field => $value) { |
|
689 | + $this->_set_template_value($field, $value); |
|
690 | + } |
|
691 | + } |
|
692 | + } |
|
693 | + |
|
694 | + // enqueue preview js so that any links/buttons on the page are disabled. |
|
695 | + if (! $send) { |
|
696 | + // the below may seem like duplication. However, typically if a messenger enqueues scripts/styles, |
|
697 | + // it deregisters all existing wp scripts and styles first. So the second hook ensures our previewer still gets setup. |
|
698 | + add_action('admin_enqueue_scripts', array( $this, 'add_preview_script' ), 10); |
|
699 | + add_action('wp_enqueue_scripts', array( $this, 'add_preview_script' ), 10); |
|
700 | + add_action('AHEE__EE_messenger__enqueue_scripts_styles', array( $this, 'add_preview_script' ), 10); |
|
701 | + } |
|
702 | + |
|
703 | + return $send ? $this->_send_message() : $this->_preview(); |
|
704 | + } |
|
705 | + |
|
706 | + |
|
707 | + |
|
708 | + |
|
709 | + /** |
|
710 | + * Callback for enqueue_scripts so that we setup the preview script for all previews. |
|
711 | + * |
|
712 | + * @since 4.5.0 |
|
713 | + * |
|
714 | + * @return void |
|
715 | + */ |
|
716 | + public function add_preview_script() |
|
717 | + { |
|
718 | + // error message |
|
719 | + EE_Registry::$i18n_js_strings['links_disabled'] = wp_strip_all_tags( |
|
720 | + __('All the links on this page have been disabled because this is a generated preview message for the purpose of ensuring layout, style, and content setup. To test generated links, you must trigger an actual message notification.', 'event_espresso') |
|
721 | + ); |
|
722 | + wp_register_script('ee-messages-preview-js', EE_LIBRARIES_URL . 'messages/messenger/assets/js/ee-messages-preview.js', array( 'jquery' ), EVENT_ESPRESSO_VERSION, true); |
|
723 | + wp_localize_script('ee-messages-preview-js', 'eei18n', EE_Registry::$i18n_js_strings); |
|
724 | + wp_enqueue_script('ee-messages-preview-js'); |
|
725 | + } |
|
726 | + |
|
727 | + |
|
728 | + |
|
729 | + |
|
730 | + /** |
|
731 | + * simply validates the incoming message object and then sets up the properties for the messenger |
|
732 | + * @param EE_Message $message |
|
733 | + * @throws EE_Error |
|
734 | + */ |
|
735 | + protected function _validate_and_setup(EE_Message $message) |
|
736 | + { |
|
737 | + $template_pack = $message->get_template_pack(); |
|
738 | + $variation = $message->get_template_pack_variation(); |
|
739 | + |
|
740 | + // verify we have the required template pack value on the $message object. |
|
741 | + if (! $template_pack instanceof EE_Messages_Template_Pack) { |
|
742 | + throw new EE_Error(esc_html__('Incoming $message object must have an EE_Messages_Template_Pack object available.', 'event_espresso')); |
|
743 | + } |
|
744 | + |
|
745 | + $this->_tmp_pack = $template_pack; |
|
746 | + |
|
747 | + $this->_variation = $variation ? $variation : 'default'; |
|
748 | + |
|
749 | + $template_fields = $this->get_template_fields(); |
|
750 | + |
|
751 | + foreach ($template_fields as $template => $value) { |
|
752 | + if ($template !== 'extra') { |
|
753 | + $column_value = $message->get_field_or_extra_meta('MSG_' . $template); |
|
754 | + $message_template_value = $column_value ? $column_value : null; |
|
755 | + $this->_set_template_value($template, $message_template_value); |
|
756 | + } |
|
757 | + } |
|
758 | + } |
|
759 | + |
|
760 | + |
|
761 | + |
|
762 | + /** |
|
763 | + * Utility method for child classes to get the contents of a template file and return |
|
764 | + * |
|
765 | + * We're assuming the child messenger class has already setup template args! |
|
766 | + * @param bool $preview if true we use the preview wrapper otherwise we use main wrapper. |
|
767 | + * @return string |
|
768 | + * @throws \EE_Error |
|
769 | + */ |
|
770 | + protected function _get_main_template($preview = false) |
|
771 | + { |
|
772 | + $type = $preview ? 'preview' : 'main'; |
|
773 | + |
|
774 | + $wrapper_template = $this->_tmp_pack->get_wrapper($this->name, $type); |
|
775 | + |
|
776 | + // check file exists and is readable |
|
777 | + if (!is_readable($wrapper_template)) { |
|
778 | + throw new EE_Error(sprintf(esc_html__('Unable to access the template file for the %s messenger main content wrapper. The location being attempted is %s.', 'event_espresso'), ucwords($this->label['singular']), $wrapper_template)); |
|
779 | + } |
|
780 | + |
|
781 | + // add message type to template args |
|
782 | + $this->_template_args['message_type'] = $this->_incoming_message_type; |
|
783 | + |
|
784 | + return EEH_Template::display_template($wrapper_template, $this->_template_args, true); |
|
785 | + } |
|
786 | + |
|
787 | + |
|
788 | + |
|
789 | + /** |
|
790 | + * set the _test_settings_fields property |
|
791 | + * |
|
792 | + * @access protected |
|
793 | + * @return void |
|
794 | + */ |
|
795 | + protected function _set_test_settings_fields() |
|
796 | + { |
|
797 | + $this->_test_settings_fields = array(); |
|
798 | + } |
|
799 | + |
|
800 | + |
|
801 | + |
|
802 | + /** |
|
803 | + * return the _test_settings_fields property |
|
804 | + * @return array |
|
805 | + */ |
|
806 | + public function get_test_settings_fields() |
|
807 | + { |
|
808 | + return $this->_test_settings_fields; |
|
809 | + } |
|
810 | + |
|
811 | + |
|
812 | + |
|
813 | + |
|
814 | + /** |
|
815 | + * This just returns any existing test settings that might be saved in the database |
|
816 | + * |
|
817 | + * @access public |
|
818 | + * @return array |
|
819 | + */ |
|
820 | + public function get_existing_test_settings() |
|
821 | + { |
|
822 | + /** @var EE_Message_Resource_Manager $Message_Resource_Manager */ |
|
823 | + $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
824 | + $settings = $Message_Resource_Manager->get_active_messengers_option(); |
|
825 | + return isset($settings[ $this->name ]['test_settings']) ? $settings[ $this->name ]['test_settings'] : array(); |
|
826 | + } |
|
827 | + |
|
828 | + |
|
829 | + |
|
830 | + /** |
|
831 | + * All this does is set the existing test settings (in the db) for the messenger |
|
832 | + * |
|
833 | + * @access public |
|
834 | + * @param $settings |
|
835 | + * @return bool success/fail |
|
836 | + */ |
|
837 | + public function set_existing_test_settings($settings) |
|
838 | + { |
|
839 | + /** @var EE_Message_Resource_Manager $Message_Resource_Manager */ |
|
840 | + $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
841 | + $existing = $Message_Resource_Manager->get_active_messengers_option(); |
|
842 | + $existing[ $this->name ]['test_settings'] = $settings; |
|
843 | + return $Message_Resource_Manager->update_active_messengers_option($existing); |
|
844 | + } |
|
845 | + |
|
846 | + |
|
847 | + |
|
848 | + /** |
|
849 | + * This just returns the field label for a given field setup in the _template_fields property. |
|
850 | + * |
|
851 | + * @since 4.3.0 |
|
852 | + * |
|
853 | + * @param string $field The field to retrieve the label for |
|
854 | + * @return string The label |
|
855 | + */ |
|
856 | + public function get_field_label($field) |
|
857 | + { |
|
858 | + // first let's see if the field requests is in the top level array. |
|
859 | + if (isset($this->_template_fields[ $field ]) && !empty($this->_template_fields[ $field ]['label'])) { |
|
860 | + return $this->_template[ $field ]['label']; |
|
861 | + } |
|
862 | + |
|
863 | + // nope so let's look in the extra array to see if it's there HOWEVER if the field exists as a top level index in the extra array then we know the label is in the 'main' index. |
|
864 | + if (isset($this->_template_fields['extra']) && !empty($this->_template_fields['extra'][ $field ]) && !empty($this->_template_fields['extra'][ $field ]['main']['label'])) { |
|
865 | + return $this->_template_fields['extra'][ $field ]['main']['label']; |
|
866 | + } |
|
867 | + |
|
868 | + // now it's possible this field may just be existing in any of the extra array items. |
|
869 | + if (!empty($this->_template_fields['extra']) && is_array($this->_template_fields['extra'])) { |
|
870 | + foreach ($this->_template_fields['extra'] as $main_field => $subfields) { |
|
871 | + if (!is_array($subfields)) { |
|
872 | + continue; |
|
873 | + } |
|
874 | + if (isset($subfields[ $field ]) && !empty($subfields[ $field ]['label'])) { |
|
875 | + return $subfields[ $field ]['label']; |
|
876 | + } |
|
877 | + } |
|
878 | + } |
|
879 | + |
|
880 | + // if we made it here then there's no label set so let's just return the $field. |
|
881 | + return $field; |
|
882 | + } |
|
883 | + |
|
884 | + |
|
885 | + |
|
886 | + |
|
887 | + /** |
|
888 | + * This is a method called from EE_messages when this messenger is a generating messenger and the sending messenger is a different messenger. Child messengers can set hooks for the sending messenger to callback on if necessary (i.e. swap out css files or something else). |
|
889 | + * |
|
890 | + * @since 4.5.0 |
|
891 | + * |
|
892 | + * @param string $sending_messenger_name the name of the sending messenger so we only set the hooks needed. |
|
893 | + * |
|
894 | + * @return void |
|
895 | + */ |
|
896 | + public function do_secondary_messenger_hooks($sending_messenger_name) |
|
897 | + { |
|
898 | + return; |
|
899 | + } |
|
900 | 900 | } |
@@ -38,103 +38,103 @@ |
||
38 | 38 | * @since 4.0 |
39 | 39 | */ |
40 | 40 | if (function_exists('espresso_version')) { |
41 | - if (! function_exists('espresso_duplicate_plugin_error')) { |
|
42 | - /** |
|
43 | - * espresso_duplicate_plugin_error |
|
44 | - * displays if more than one version of EE is activated at the same time |
|
45 | - */ |
|
46 | - function espresso_duplicate_plugin_error() |
|
47 | - { |
|
48 | - ?> |
|
41 | + if (! function_exists('espresso_duplicate_plugin_error')) { |
|
42 | + /** |
|
43 | + * espresso_duplicate_plugin_error |
|
44 | + * displays if more than one version of EE is activated at the same time |
|
45 | + */ |
|
46 | + function espresso_duplicate_plugin_error() |
|
47 | + { |
|
48 | + ?> |
|
49 | 49 | <div class="error"> |
50 | 50 | <p> |
51 | 51 | <?php |
52 | - echo esc_html__( |
|
53 | - 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
54 | - 'event_espresso' |
|
55 | - ); ?> |
|
52 | + echo esc_html__( |
|
53 | + 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
54 | + 'event_espresso' |
|
55 | + ); ?> |
|
56 | 56 | </p> |
57 | 57 | </div> |
58 | 58 | <?php |
59 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | - } |
|
61 | - } |
|
62 | - add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
59 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | + } |
|
61 | + } |
|
62 | + add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
63 | 63 | } else { |
64 | - define('EE_MIN_PHP_VER_REQUIRED', '5.6.2'); |
|
65 | - if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
66 | - /** |
|
67 | - * espresso_minimum_php_version_error |
|
68 | - * |
|
69 | - * @return void |
|
70 | - */ |
|
71 | - function espresso_minimum_php_version_error() |
|
72 | - { |
|
73 | - ?> |
|
64 | + define('EE_MIN_PHP_VER_REQUIRED', '5.6.2'); |
|
65 | + if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
66 | + /** |
|
67 | + * espresso_minimum_php_version_error |
|
68 | + * |
|
69 | + * @return void |
|
70 | + */ |
|
71 | + function espresso_minimum_php_version_error() |
|
72 | + { |
|
73 | + ?> |
|
74 | 74 | <div class="error"> |
75 | 75 | <p> |
76 | 76 | <?php |
77 | - printf( |
|
78 | - esc_html__( |
|
79 | - 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
80 | - 'event_espresso' |
|
81 | - ), |
|
82 | - EE_MIN_PHP_VER_REQUIRED, |
|
83 | - PHP_VERSION, |
|
84 | - '<br/>', |
|
85 | - '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
86 | - ); |
|
87 | - ?> |
|
77 | + printf( |
|
78 | + esc_html__( |
|
79 | + 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
80 | + 'event_espresso' |
|
81 | + ), |
|
82 | + EE_MIN_PHP_VER_REQUIRED, |
|
83 | + PHP_VERSION, |
|
84 | + '<br/>', |
|
85 | + '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
86 | + ); |
|
87 | + ?> |
|
88 | 88 | </p> |
89 | 89 | </div> |
90 | 90 | <?php |
91 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
92 | - } |
|
91 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
92 | + } |
|
93 | 93 | |
94 | - add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
95 | - } else { |
|
96 | - define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
97 | - /** |
|
98 | - * espresso_version |
|
99 | - * Returns the plugin version |
|
100 | - * |
|
101 | - * @return string |
|
102 | - */ |
|
103 | - function espresso_version() |
|
104 | - { |
|
105 | - return apply_filters('FHEE__espresso__espresso_version', '4.10.33.rc.007'); |
|
106 | - } |
|
94 | + add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
95 | + } else { |
|
96 | + define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
97 | + /** |
|
98 | + * espresso_version |
|
99 | + * Returns the plugin version |
|
100 | + * |
|
101 | + * @return string |
|
102 | + */ |
|
103 | + function espresso_version() |
|
104 | + { |
|
105 | + return apply_filters('FHEE__espresso__espresso_version', '4.10.33.rc.007'); |
|
106 | + } |
|
107 | 107 | |
108 | - /** |
|
109 | - * espresso_plugin_activation |
|
110 | - * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
111 | - */ |
|
112 | - function espresso_plugin_activation() |
|
113 | - { |
|
114 | - update_option('ee_espresso_activation', true); |
|
115 | - } |
|
108 | + /** |
|
109 | + * espresso_plugin_activation |
|
110 | + * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
111 | + */ |
|
112 | + function espresso_plugin_activation() |
|
113 | + { |
|
114 | + update_option('ee_espresso_activation', true); |
|
115 | + } |
|
116 | 116 | |
117 | - register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
117 | + register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
118 | 118 | |
119 | - require_once __DIR__ . '/core/bootstrap_espresso.php'; |
|
120 | - bootstrap_espresso(); |
|
121 | - } |
|
119 | + require_once __DIR__ . '/core/bootstrap_espresso.php'; |
|
120 | + bootstrap_espresso(); |
|
121 | + } |
|
122 | 122 | } |
123 | 123 | if (! function_exists('espresso_deactivate_plugin')) { |
124 | - /** |
|
125 | - * deactivate_plugin |
|
126 | - * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
127 | - * |
|
128 | - * @access public |
|
129 | - * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
130 | - * @return void |
|
131 | - */ |
|
132 | - function espresso_deactivate_plugin($plugin_basename = '') |
|
133 | - { |
|
134 | - if (! function_exists('deactivate_plugins')) { |
|
135 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
136 | - } |
|
137 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
138 | - deactivate_plugins($plugin_basename); |
|
139 | - } |
|
124 | + /** |
|
125 | + * deactivate_plugin |
|
126 | + * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
127 | + * |
|
128 | + * @access public |
|
129 | + * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
130 | + * @return void |
|
131 | + */ |
|
132 | + function espresso_deactivate_plugin($plugin_basename = '') |
|
133 | + { |
|
134 | + if (! function_exists('deactivate_plugins')) { |
|
135 | + require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
136 | + } |
|
137 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
138 | + deactivate_plugins($plugin_basename); |
|
139 | + } |
|
140 | 140 | } |
141 | 141 | \ No newline at end of file |