PluginProbe
UpdraftPlus: WP Backup & Migration Plugin / 1.22.14
UpdraftPlus: WP Backup & Migration Plugin v1.22.14
1.26.7 1.26.6 1.26.5 1.26.4 1.26.3 1.9.19 1.9.25 1.9.26 1.9.30 1.9.31 1.9.32 1.9.4 1.9.40 1.9.41 1.9.42 1.9.43 1.9.44 1.9.45 1.9.46 1.9.5 1.9.50 1.9.51 1.9.60 1.9.62 1.9.63 All 371 releases
updraftplus / methods / email.php

email.php in UpdraftPlus: WP Backup & Migration Plugin 1.22.14, at methods/email.php

123 lines 5.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if (!defined('UPDRAFTPLUS_DIR')) die('No direct access allowed.');
4
5 // Files can easily get too big for this method
6
7 if (!class_exists('UpdraftPlus_BackupModule')) require_once(UPDRAFTPLUS_DIR.'/methods/backup-module.php');
8
9 class UpdraftPlus_BackupModule_email extends UpdraftPlus_BackupModule {
10
11 public function backup($backup_array) {
12
13 global $updraftplus;
14
15 $updraft_dir = trailingslashit($updraftplus->backups_dir_location());
16
17 $email = $updraftplus->just_one_email(UpdraftPlus_Options::get_updraft_option('updraft_email'), true);
18
19 if (!is_array($email)) $email = array_filter(array($email));
20
21 foreach ($backup_array as $type => $file) {
22
23 $descrip_type = preg_match('/^(.*)\d+$/', $type, $matches) ? $matches[1] : $type;
24
25 $fullpath = $updraft_dir.$file;
26
27 if (file_exists($fullpath) && filesize($fullpath) > UPDRAFTPLUS_WARN_EMAIL_SIZE) {
28 $size_in_mb_of_big_file = round(filesize($fullpath)/1048576, 1);
29 $toobig_hash = md5($file);
30 $this->log($file.': '.sprintf(__('This backup archive is %s MB in size - the attempt to send this via email is likely to fail (few email servers allow attachments of this size). If so, you should switch to using a different remote storage method.', 'updraftplus'), $size_in_mb_of_big_file), 'warning', 'toobigforemail_'.$toobig_hash);
31 }
32
33 $any_attempted = false;
34 $any_sent = false;
35 $any_skip = false;
36 foreach ($email as $ind => $addr) {
37
38 if (apply_filters('updraftplus_email_backup', true, $addr, $ind, $type)) {
39 foreach (explode(',', $addr) as $sendmail_addr) {
40 if (!preg_match('/^https?:\/\//i', $sendmail_addr)) {
41 $send_short = (strlen($sendmail_addr)>5) ? substr($sendmail_addr, 0, 5).'...' : $sendmail_addr;
42 $this->log("$file: email to: $send_short");
43 $any_attempted = true;
44 $headers = array();
45
46 $subject = __("WordPress Backup", 'updraftplus').': '.get_bloginfo('name').' (UpdraftPlus '.$updraftplus->version.') '.get_date_from_gmt(gmdate('Y-m-d H:i:s', $updraftplus->backup_time), 'Y-m-d H:i');
47 $from_email = apply_filters('updraftplus_email_from_header', $updraftplus->get_email_from_header());
48 $from_name = apply_filters('updraftplus_email_from_name_header', $updraftplus->get_email_from_name_header());
49 // Notice that we don't use the 'wp_mail_from' filter, but only the 'From:' header to set sender name and sender email address, the reason behind it is that some SMTP plugins override the "wp_mail()" function and they do anything they want inside their own "wp_mail()" function, including not to call the php_mailer filter nor the wp_mail_from and wp_mail_from_name filters, but since the function signature remain the same as the WP one, so they may evaluate and do something with the header parameter
50 if ('' !== $from_email) {
51 $headers[] = sprintf('From: %s <%s>', $from_name, $from_email);
52 } else {
53 add_filter('wp_mail_from_name', array($updraftplus, 'get_email_from_name_header'), 9);
54 }
55 add_action('wp_mail_failed', array($updraftplus, 'log_email_delivery_failure'));
56 $sent = wp_mail(trim($sendmail_addr), $subject, sprintf(__("Backup is of: %s.", 'updraftplus'), site_url().' ('.$descrip_type.')'), $headers, array($fullpath));
57 remove_action('wp_mail_failed', array($updraftplus, 'log_email_delivery_failure'));
58 if ($sent) $any_sent = true;
59 }
60 }
61 } else {
62 $log_message = apply_filters('updraftplus_email_backup_skip_log_message', '', $addr, $ind, $descrip_type);
63 if (!empty($log_message)) {
64 $this->log($log_message);
65 }
66 $any_skip = true;
67 }
68 }
69 if ($any_sent) {
70 if (isset($toobig_hash)) {
71 $updraftplus->log_remove_warning('toobigforemail_'.$toobig_hash);
72 // Don't leave it still set for the next archive
73 unset($toobig_hash);
74 }
75 $updraftplus->uploaded_file($file);
76 } elseif ($any_attempted) {
77 $this->log('Mails were not sent successfully');
78 $this->log(__('The attempt to send the backup via email failed (probably the backup was too large for this method)', 'updraftplus'), 'error');
79 } elseif ($any_skip) {
80 $this->log('No email addresses were configured to send email to '.$descrip_type);
81 } else {
82 $this->log('No email addresses were configured to send to');
83 }
84 }
85 return null;
86 }
87
88 /**
89 * Acts as a WordPress options filter
90 *
91 * @param Array $options - An array of options
92 *
93 * @return Array - the returned array can either be the set of updated settings or a WordPress error array
94 */
95 public function options_filter($options) {
96 global $updraftplus;
97 return $updraftplus->just_one_email($options);
98 }
99
100 public function config_print() {
101 global $updraftplus;
102 ?>
103 <tr class="updraftplusmethod email">
104 <th><?php _e('Note:', 'updraftplus');?></th>
105 <td><?php
106
107 $used = apply_filters('updraftplus_email_whichaddresses',
108 sprintf(__("Your site's admin email address (%s) will be used.", 'updraftplus'), get_bloginfo('admin_email').' - <a href="'.esc_attr(admin_url('options-general.php')).'">'.__("configure it here", 'updraftplus').'</a>').
109 ' <a href="'.$updraftplus->get_url('premium').'" target="_blank">'.__('For more options, use Premium', 'updraftplus').'</a>'
110 );
111
112 echo $used.' '.sprintf(__('Be aware that mail servers tend to have size limits; typically around %s MB; backups larger than any limits will likely not arrive.', 'updraftplus'), '10-20');
113 ?>
114 </td>
115 </tr>
116 <?php
117 }
118
119 public function delete($files, $data = null, $sizeinfo = array()) {// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
120 return true;
121 }
122 }
123