PluginProbe
UpdraftPlus: WP Backup & Migration Plugin / 1.22.24
UpdraftPlus: WP Backup & Migration Plugin v1.22.24
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.24, at methods/email.php

125 lines 5.7 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')) updraft_try_include_file('methods/backup-module.php', 'require_once');
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 $use_wp_from_name_filter = '' === $from_email;
50 // 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
51 if (!$use_wp_from_name_filter) {
52 $headers[] = sprintf('From: %s <%s>', $from_name, $from_email);
53 } else {
54 add_filter('wp_mail_from_name', array($updraftplus, 'get_email_from_name_header'), 9);
55 }
56 add_action('wp_mail_failed', array($updraftplus, 'log_email_delivery_failure'));
57 $sent = wp_mail(trim($sendmail_addr), $subject, sprintf(__("Backup is of: %s.", 'updraftplus'), site_url().' ('.$descrip_type.')'), $headers, array($fullpath));
58 remove_action('wp_mail_failed', array($updraftplus, 'log_email_delivery_failure'));
59 if ($use_wp_from_name_filter) remove_filter('wp_mail_from_name', array($this, 'get_email_from_name_header'), 9);
60 if ($sent) $any_sent = true;
61 }
62 }
63 } else {
64 $log_message = apply_filters('updraftplus_email_backup_skip_log_message', '', $addr, $ind, $descrip_type);
65 if (!empty($log_message)) {
66 $this->log($log_message);
67 }
68 $any_skip = true;
69 }
70 }
71 if ($any_sent) {
72 if (isset($toobig_hash)) {
73 $updraftplus->log_remove_warning('toobigforemail_'.$toobig_hash);
74 // Don't leave it still set for the next archive
75 unset($toobig_hash);
76 }
77 $updraftplus->uploaded_file($file);
78 } elseif ($any_attempted) {
79 $this->log('Mails were not sent successfully');
80 $this->log(__('The attempt to send the backup via email failed (probably the backup was too large for this method)', 'updraftplus'), 'error');
81 } elseif ($any_skip) {
82 $this->log('No email addresses were configured to send email to '.$descrip_type);
83 } else {
84 $this->log('No email addresses were configured to send to');
85 }
86 }
87 return null;
88 }
89
90 /**
91 * Acts as a WordPress options filter
92 *
93 * @param Array $options - An array of options
94 *
95 * @return Array - the returned array can either be the set of updated settings or a WordPress error array
96 */
97 public function options_filter($options) {
98 global $updraftplus;
99 return $updraftplus->just_one_email($options);
100 }
101
102 public function config_print() {
103 global $updraftplus;
104 ?>
105 <tr class="updraftplusmethod email">
106 <th><?php _e('Note:', 'updraftplus');?></th>
107 <td><?php
108
109 $used = apply_filters('updraftplus_email_whichaddresses',
110 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>').
111 ' <a href="'.$updraftplus->get_url('premium').'" target="_blank">'.__('For more options, use Premium', 'updraftplus').'</a>'
112 );
113
114 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');
115 ?>
116 </td>
117 </tr>
118 <?php
119 }
120
121 public function delete($files, $data = null, $sizeinfo = array()) {// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
122 return true;
123 }
124 }
125