PluginProbe
Property Hive / 1.4.6
Property Hive v1.4.6
2.3.1 2.3.0 2.2.6 2.2.5 2.2.4 2.2.3 2.2.2 1.4.46 1.4.47 1.4.48 1.4.49 1.4.5 1.4.50 1.4.51 1.4.52 1.4.53 1.4.54 1.4.55 1.4.56 1.4.57 1.4.58 1.4.59 1.4.6 1.4.60 1.4.61 All 261 releases
propertyhive / includes / admin / settings / class-ph-settings-emails.php

class-ph-settings-emails.php in Property Hive 1.4.6, at includes/admin/settings/class-ph-settings-emails.php

444 lines 16.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * PropertyHive Email Settings
4 *
5 * @author PropertyHive
6 * @category Admin
7 * @package PropertyHive/Admin
8 * @version 1.0.0
9 */
10
11 if ( ! defined( 'ABSPATH' ) ) {
12 exit; // Exit if accessed directly
13 }
14
15 if ( ! class_exists( 'PH_Settings_Emails' ) ) :
16
17 /**
18 * PH_Settings_Emails.
19 */
20 class PH_Settings_Emails extends PH_Settings_Page {
21
22 /**
23 * Constructor.
24 */
25 public function __construct() {
26 $this->id = 'email';
27 $this->label = __( 'Emails', 'propertyhive' );
28
29 add_filter( 'propertyhive_settings_tabs_array', array( $this, 'add_settings_page' ), 20 );
30 add_action( 'propertyhive_sections_' . $this->id, array( $this, 'output_sections' ) );
31 add_action( 'propertyhive_settings_' . $this->id, array( $this, 'output' ) );
32 add_action( 'propertyhive_settings_save_' . $this->id, array( $this, 'save' ) );
33
34 add_action( 'propertyhive_admin_field_email_queue', array( $this, 'email_queue_setting' ) );
35 }
36
37 /**
38 * Get sections.
39 *
40 * @return array
41 */
42 public function get_sections() {
43 $sections = array(
44 '' => __( 'Email Options', 'propertyhive' ),
45 );
46
47 if ( get_option('propertyhive_module_disabled_contacts', '') != 'yes' )
48 {
49 $sections['log'] = __( 'Email Queue', 'propertyhive' );
50 }
51
52 return apply_filters( 'propertyhive_get_sections_' . $this->id, $sections );
53 }
54
55 /**
56 * Get settings array.
57 *
58 * @return array
59 */
60 public function get_settings() {
61 $settings = array(
62
63 array( 'title' => __( 'Email Sender Settings', 'propertyhive' ), 'type' => 'title', 'id' => 'email_sender_options' ),
64
65 array(
66 'title' => __( '"From" Email Address', 'propertyhive' ),
67 'id' => 'propertyhive_email_from_address',
68 'type' => 'text',
69 'css' => 'min-width:300px;',
70 'default' => get_option('admin_email'),
71 'autoload' => false,
72 'desc_tip' => false,
73 ),
74
75 array( 'type' => 'sectionend', 'id' => 'email_sender_options' ),
76
77 array( 'title' => __( 'Email Template Settings', 'propertyhive' ), 'type' => 'title', 'id' => 'email_template_options' ),
78
79 array(
80 'title' => __( 'Header Image URL', 'propertyhive' ),
81 'desc' => __( 'URL to an image you want to show in the email header. Upload images using the media uploader (Admin > Media).', 'propertyhive' ),
82 'id' => 'propertyhive_email_header_image',
83 'type' => 'text',
84 'css' => 'min-width:300px;',
85 'placeholder' => 'http://',
86 'default' => '',
87 'autoload' => false,
88 'desc_tip' => true,
89 ),
90
91 array(
92 'title' => __( 'Email Background Colour', 'propertyhive' ),
93 'desc' => __( 'The background colour for Property Hive email templates.', 'propertyhive' ),
94 'id' => 'propertyhive_email_background_color',
95 'type' => 'color',
96 'css' => 'width:6em;',
97 'default' => '#f7f7f7',
98 'autoload' => false,
99 'desc_tip' => true,
100 ),
101
102 array(
103 'title' => __( 'Body Background Colour', 'propertyhive' ),
104 'desc' => __( 'The main body background colour.', 'propertyhive' ),
105 'id' => 'propertyhive_email_body_background_color',
106 'type' => 'color',
107 'css' => 'width:6em;',
108 'default' => '#ffffff',
109 'autoload' => false,
110 'desc_tip' => true,
111 ),
112
113 array(
114 'title' => __( 'Body Text Colour', 'propertyhive' ),
115 'desc' => __( 'The main body text colour.', 'propertyhive' ),
116 'id' => 'propertyhive_email_text_color',
117 'type' => 'color',
118 'css' => 'width:6em;',
119 'default' => '#333333',
120 'autoload' => false,
121 'desc_tip' => true,
122 ),
123
124 array( 'type' => 'sectionend', 'id' => 'email_template_options' ),
125
126 array( 'title' => __( 'Enquiry Auto Responder Settings', 'propertyhive' ), 'type' => 'title', 'id' => 'enquiry_auto_responder_email_options' ),
127
128 array(
129 'title' => __( 'Auto Responder Enabled', 'propertyhive' ),
130 'id' => 'propertyhive_enquiry_auto_responder',
131 'type' => 'checkbox',
132 'default' => '',
133 ),
134
135 array(
136 'title' => __( 'Auto Responder Email Subject', 'propertyhive' ),
137 'id' => 'propertyhive_enquiry_auto_responder_email_subject',
138 'type' => 'text',
139 'css' => 'min-width:300px;',
140 ),
141
142 array(
143 'title' => __( 'Auto Responder Email Body', 'propertyhive' ),
144 'id' => 'propertyhive_enquiry_auto_responder_email_body',
145 'type' => 'textarea',
146 'css' => 'min-width:300px; height:110px;',
147 ),
148
149 array( 'type' => 'sectionend', 'id' => 'enquiry_auto_responder_email_options' )
150
151 );
152
153 if ( get_option('propertyhive_module_disabled_contacts', '') != 'yes' )
154 {
155 $settings[] = array( 'title' => __( 'Property Match Email Settings', 'propertyhive' ), 'type' => 'title', 'id' => 'applicant_match_email_options' );
156
157 $settings[] = array(
158 'title' => __( 'Default Email Subject', 'propertyhive' ),
159 'id' => 'propertyhive_property_match_default_email_subject',
160 'type' => 'text',
161 'css' => 'min-width:300px;',
162 );
163
164 $settings[] = array(
165 'title' => __( 'Default Email Body', 'propertyhive' ),
166 'id' => 'propertyhive_property_match_default_email_body',
167 'type' => 'textarea',
168 'css' => 'min-width:300px; height:110px;',
169 );
170
171 $settings[] = array(
172 'title' => __( 'Automatically Send Matching Properties To Applicants', 'propertyhive' ),
173 'desc' => __( 'Enabling this setting will mean applicants will automatically get sent emailed properties as they\'re added.<br><br>
174 - This will only apply to properties added from the moment this option is activated.<br>
175 - When enabled, this can disabled on a per-applicant basis by going into their record<br>
176 - When sending out lots of emails we recommend using <a href="https://en-gb.wordpress.org/plugins/tags/smtp" target="_blank">a plugin</a> to send them out using SMTP. Your web developer or hosting company should be able to advise on this.', 'propertyhive' ),
177 'id' => 'propertyhive_auto_property_match',
178 'type' => 'checkbox',
179 'default' => '',
180 );
181
182 $settings[] = array( 'type' => 'sectionend', 'id' => 'applicant_match_email_options' );
183 }
184
185 $settings = apply_filters( 'propertyhive_email_settings', $settings );
186
187 return apply_filters( 'propertyhive_get_settings_' . $this->id, $settings );
188 }
189
190 /**
191 * Get email queue settings array
192 *
193 * @return array
194 */
195 public function get_email_queue_settings() {
196
197 return apply_filters( 'propertyhive_email_queue_settings', array(
198
199 array( 'title' => __( 'Email Queue', 'propertyhive' ), 'type' => 'title', 'desc' => '', 'id' => 'email_queue_options' ),
200
201 array(
202 'type' => 'email_queue'
203 ),
204
205 array( 'type' => 'sectionend', 'id' => 'email_queue_options'),
206
207 ) ); // End general map settings
208 }
209
210 /**
211 * Output email queue
212 *
213 * @access public
214 * @return void
215 */
216 public function email_queue_setting()
217 {
218 global $wpdb, $post;
219
220 $additional_query = '';
221 $additional_query_string = '';
222 if ( isset($_GET['date_from']) && $_GET['date_from'] != '' )
223 {
224 $additional_query_string .= '&date_from=' . $_GET['date_from'];
225 if ( $_GET['date_from'] != 'all' )
226 {
227 $additional_query .= " AND send_at >= '" . $_GET['date_from'] . " 00:00:00' ";
228 }
229 }
230 else
231 {
232 // Default to 7 days
233 $additional_query .= " AND send_at >= '" . date("Y-m-d", strtotime('-7 days')) . " 00:00:00' ";
234 }
235 ?>
236 <tr valign="top">
237 <td style="padding:0">
238
239 <p>Some processes, such as property matching, can result in a lot of emails being sent at once. To cater for this we queue emails and send them out in batches at regular intervals.</p>
240
241 <p>Using this screen you can see which emails have been sent, which have failed, and how many are queued to be sent.</p>
242
243 <br>
244
245 <p><strong><?php
246 $next_due = wp_next_scheduled( 'propertyhive_process_email_log' );
247
248 if ( $next_due == FALSE )
249 {
250 echo 'Whoops. WordPress doesn\'t have the emails automated task scheduled. A quick fix for this is to deactivate, then re-activate the plugin.';
251 }
252 else
253 {
254 echo __( 'Next scheduled to run at', 'propertyhive' ) . ' ' . date("H:i jS F Y", $next_due);
255 }
256 ?></strong> <a href="<?php echo admin_url('admin.php?page=ph-settings&tab=email&section=log&custom_email_log_cron=propertyhive_process_email_log' ); ?>" class="button">Run Now</a></p>
257
258 <br>
259
260 <ul class="subsubsub">
261 <?php
262 $emails = $wpdb->get_var("
263 SELECT COUNT(*)
264 FROM " . $wpdb->prefix . "ph_email_log
265 WHERE
266 method = 'email'
267 ");
268 ?>
269 <li class="all"><a href="<?php echo admin_url('admin.php?page=ph-settings&tab=email&section=log' . $additional_query_string); ?>"<?php if ( !isset($_GET['status']) || (isset($_GET['status']) && $_GET['status'] == '') ) { echo ' class="current"'; } ?>>All <span class="count">(<?php echo number_format($emails); ?>)</span></a> |</li>
270 <?php
271 $emails = $wpdb->get_var("
272 SELECT COUNT(*)
273 FROM " . $wpdb->prefix . "ph_email_log
274 WHERE
275 method = 'email'
276 AND
277 status = ''
278 ");
279 ?>
280 <li class="queued"><a href="<?php echo admin_url('admin.php?page=ph-settings&tab=email&section=log&status=queued' . $additional_query_string); ?>"<?php if ( isset($_GET['status']) && $_GET['status'] == 'queued' ) { echo ' class="current"'; } ?>>Queued <span class="count">(<?php echo number_format($emails); ?>)</span></a> |</li>
281 <?php
282 $emails = $wpdb->get_var("
283 SELECT COUNT(*)
284 FROM " . $wpdb->prefix . "ph_email_log
285 WHERE
286 method = 'email'
287 AND
288 status IN ('fail1', 'fail2')
289 ");
290 ?>
291 <li class="failed"><a href="<?php echo admin_url('admin.php?page=ph-settings&tab=email&section=log&status=failed' . $additional_query_string); ?>"<?php if ( isset($_GET['status']) && $_GET['status'] == 'failed' ) { echo ' class="current"'; } ?>>Failed <span class="count">(<?php echo number_format($emails); ?>)</span></a> |</li>
292 <?php
293 $emails = $wpdb->get_var("
294 SELECT COUNT(*)
295 FROM " . $wpdb->prefix . "ph_email_log
296 WHERE
297 method = 'email'
298 AND
299 status = 'sent'
300 ");
301 ?>
302 <li class="sent"><a href="<?php echo admin_url('admin.php?page=ph-settings&tab=email&section=log&status=sent' . $additional_query_string); ?>"<?php if ( isset($_GET['status']) && $_GET['status'] == 'sent' ) { echo ' class="current"'; } ?>>Sent <span class="count">(<?php echo number_format($emails); ?>)</span></a></li>
303 </ul>
304
305 <div class="tablenav top">
306 <div class="alignleft actions bulkactions">
307 <div class="alignleft actions">
308 <input type="hidden" name="page" value="ph-settings">
309 <input type="hidden" name="tab" value="email">
310 <input type="hidden" name="section" value="log">
311 <input type="hidden" name="status" value="<?php echo ( ( isset($_GET['status']) ) ? $_GET['status'] : '' ); ?>">
312 <select name="date_from" id="dropdown_date_from">
313 <option value="<?php echo date("Y-m-d", strtotime("-7 days")); ?>"<?php if ( isset($_GET['date_from']) && $_GET['date_from'] == date("Y-m-d", strtotime("-7 days")) ) { echo ' selected'; } ?>>Last 7 Days</option>
314 <option value="<?php echo date("Y-m-d", strtotime("-14 days")); ?>"<?php if ( isset($_GET['date_from']) && $_GET['date_from'] == date("Y-m-d", strtotime("-14 days")) ) { echo ' selected'; } ?>>Last 14 Days</option>
315 <option value="<?php echo date("Y-m-d", strtotime("-30 days")); ?>"<?php if ( isset($_GET['date_from']) && $_GET['date_from'] == date("Y-m-d", strtotime("-30 days")) ) { echo ' selected'; } ?>>Last 30 Days</option>
316 <option value="all"<?php if ( isset($_GET['date_from']) && $_GET['date_from'] == 'all' ) { echo ' selected'; } ?>>All Time</option>
317 </select>
318 <input type="submit" name="filter_action" id="post-query-submit" class="button" value="Filter">
319
320 <script>
321 jQuery(document).ready(function()
322 {
323 jQuery('#_wpnonce').remove();
324 jQuery('input[name=\'_wp_http_referer\']').remove();
325 jQuery('#mainform').attr('method', 'get');
326 jQuery('#mainform').attr('action', '<?php echo admin_url('admin.php'); ?>');
327 });
328 </script>
329 </div>
330 </div>
331 </div>
332
333 <table class="ph_email_queue widefat" cellspacing="0">
334 <thead>
335 <tr>
336 <th class="date-time"><?php _e( 'Date/Time', 'propertyhive' ); ?></th>
337 <th class="recipient"><?php _e( 'Recipient', 'propertyhive' ); ?></th>
338 <th class="subject"><?php _e( 'Subject', 'propertyhive' ); ?></th>
339 <th class="status"><?php _e( 'Status', 'propertyhive' ); ?></th>
340 <th class="actions">&nbsp;</th>
341 </tr>
342 </thead>
343 <tbody>
344 <?php
345 $query = "
346 SELECT
347 email_id,
348 contact_id,
349 to_email_address,
350 subject,
351 status,
352 send_at
353 FROM " . $wpdb->prefix . "ph_email_log
354 WHERE
355 method = 'email' ";
356 if ( isset($_GET['status']) )
357 {
358 switch ( $_GET['status'] )
359 {
360 case "queued": { $query .= " AND status = '' "; break; }
361 case "failed": { $query .= " AND status IN ('fail1', 'fail2') "; break; }
362 case "sent": { $query .= " AND status = 'sent' "; break; }
363 }
364 }
365
366 $query .= " ORDER BY send_at DESC
367 LIMIT 250
368 ";
369 $emails = $wpdb->get_results( $query );
370
371 foreach ( $emails as $email )
372 {
373 ?>
374 <tr>
375 <td class="date-time"><?php echo date("jS M Y H:i", strtotime($email->send_at)); ?></td>
376 <td class="recipient"><?php echo '<a href="' . get_edit_post_link($email->contact_id) . '">' . get_the_title($email->contact_id) . '</a><br>' . $email->to_email_address; ?></td>
377 <td class="subject"><?php echo $email->subject; ?></td>
378 <td class="status"><?php
379 switch ($email->status)
380 {
381 case "fail1": { echo 'First attempt failed. Will retry'; break; }
382 case "fail2": { echo 'Failed after 2 attempts'; break; }
383 case "sent": { echo 'Sent'; break; }
384 default: { echo 'Queued'; }
385 }
386 ?></td>
387 <td class="actions">
388 <a href="<?php echo wp_nonce_url( admin_url('?view_propertyhive_email=' . $email->email_id . '&email_id=' . $email->email_id ), 'view-email' ) ?>" target="_blank" class="button">View Email</a>
389 </td>
390 </tr>
391 <?php
392 }
393 ?>
394 </tbody>
395 </table>
396 </td>
397 </tr>
398 <?php
399 }
400
401 /**
402 * Output the settings.
403 */
404 public function output() {
405 global $current_section, $hide_save_button;
406
407 if ( $current_section )
408 {
409 switch ($current_section)
410 {
411 case "log": { $settings = $this->get_email_queue_settings(); $hide_save_button = true; break; }
412 default: { die("Unknown setting section"); }
413 }
414 }
415 else
416 {
417 $settings = $this->get_settings();
418 }
419
420 PH_Admin_Settings::output_fields( $settings );
421 }
422
423 /**
424 * Save settings.
425 */
426 public function save() {
427 PH_Admin_Settings::save_fields( $this->get_settings() );
428
429 if ( isset($_POST['propertyhive_auto_property_match']) && $_POST['propertyhive_auto_property_match'] == '1' )
430 {
431 update_option( 'propertyhive_auto_property_match_enabled_date', date("Y-m-d H:i:s"), FALSE);
432
433 wp_schedule_event( time(), 'hourly', 'propertyhive_auto_email_match' ); // Skew it by 30 minutes to reduce conflict with email log processing
434 }
435 else
436 {
437 wp_clear_scheduled_hook( 'propertyhive_auto_email_match' );
438 }
439 }
440 }
441
442 endif;
443
444 return new PH_Settings_Emails();