1 | <?php |
||
10 | class Email_Service extends Service { |
||
11 | |||
12 | /** |
||
13 | * Human readable name for this service |
||
14 | * @var string |
||
15 | */ |
||
16 | public $name = 'Email'; |
||
17 | |||
18 | /** |
||
19 | * Output the email form field |
||
20 | * |
||
21 | * @access public |
||
22 | */ |
||
23 | public function field() { |
||
42 | |||
43 | /** |
||
44 | * Not used as we only need a field |
||
45 | * |
||
46 | * @see field |
||
47 | * @return string Empty string |
||
48 | */ |
||
49 | public function form() { |
||
52 | |||
53 | public static function constant() { |
||
74 | |||
75 | /** |
||
76 | * The sentence fragment that is output as part of the schedule sentence |
||
77 | * |
||
78 | * @return string |
||
79 | */ |
||
80 | public function display() { |
||
93 | |||
94 | /** |
||
95 | * Used to determine if the service is in use or not |
||
96 | */ |
||
97 | public function is_service_active() { |
||
100 | |||
101 | /** |
||
102 | * Validate the email and return an error if validation fails |
||
103 | * |
||
104 | * @param array &$new_data Array of new data, passed by reference |
||
105 | * @param array $old_data The data we are replacing |
||
106 | * @return null|array Null on success, array of errors if validation failed |
||
|
|||
107 | */ |
||
108 | public function update( &$new_data, $old_data ) { |
||
134 | |||
135 | /** |
||
136 | * Get an array or validated email address's |
||
137 | * @return array An array of validated email address's |
||
138 | */ |
||
139 | private function get_email_address_array() { |
||
143 | |||
144 | /** |
||
145 | * Fire the email notification on the hmbkp_backup_complete |
||
146 | * |
||
147 | * @see Backup::do_action |
||
148 | * @param string $action The action received from the backup |
||
149 | * @return void |
||
150 | */ |
||
151 | public function action( $action, Backup $backup ) { |
||
152 | |||
153 | if ( 'hmbkp_backup_complete' === $action && $this->get_email_address_array() ) { |
||
154 | |||
155 | $file = $backup->get_backup_filepath(); |
||
156 | |||
157 | $sent = false; |
||
158 | |||
159 | $download = add_query_arg( 'hmbkp_download', base64_encode( $file ), HMBKP_ADMIN_URL ); |
||
160 | $domain = parse_url( home_url(), PHP_URL_HOST ) . parse_url( home_url(), PHP_URL_PATH ); |
||
161 | |||
162 | $headers = 'From: BackUpWordPress <' . apply_filters( 'hmbkp_from_email', get_bloginfo( 'admin_email' ) ) . '>' . "\r\n"; |
||
163 | |||
164 | // The backup failed, send a message saying as much |
||
165 | if ( ! file_exists( $file ) && ( $errors = array_merge( $backup->get_errors(), $backup->get_warnings() ) ) ) { |
||
166 | |||
167 | $error_message = ''; |
||
168 | |||
169 | foreach ( $errors as $error_set ) { |
||
170 | $error_message .= implode( "\n - ", $error_set ); |
||
171 | } |
||
172 | |||
173 | if ( $error_message ) { |
||
174 | $error_message = ' - ' . $error_message; |
||
175 | } |
||
176 | |||
177 | $subject = sprintf( __( 'Backup of %s Failed', 'backupwordpress' ), $domain ); |
||
178 | |||
179 | $message = sprintf( __( 'BackUpWordPress was unable to backup your site %1$s.', 'backupwordpress' ) . "\n\n" . __( 'Here are the errors that we\'ve encountered:', 'backupwordpress' ) . "\n\n" . '%2$s' . "\n\n" . __( 'If the errors above look like Martian, forward this email to %3$s and we\'ll take a look', 'backupwordpress' ) . "\n\n" . __( "Kind Regards,\nThe Apologetic BackUpWordPress Backup Emailing Robot", 'backupwordpress' ), home_url(), $error_message, '[email protected]' ); |
||
180 | |||
181 | wp_mail( $this->get_email_address_array(), $subject, $message, $headers ); |
||
182 | |||
183 | return; |
||
184 | |||
185 | } |
||
186 | |||
187 | $subject = sprintf( __( 'Backup of %s', 'backupwordpress' ), $domain ); |
||
188 | |||
189 | // If it's larger than the max attachment size limit assume it's not going to be able to send the backup |
||
190 | if ( @filesize( $file ) < get_max_attachment_size() ) { |
||
191 | |||
192 | $message = sprintf( __( 'BackUpWordPress has completed a backup of your site %1$s.', 'backupwordpress' ) . "\n\n" . __( 'The backup file should be attached to this email.', 'backupwordpress' ) . "\n\n" . __( 'You can download the backup file by clicking the link below:', 'backupwordpress' ) . "\n\n" . '%2$s' . "\n\n" . __( "Kind Regards,\nThe Happy BackUpWordPress Backup Emailing Robot", 'backupwordpress' ), home_url(), $download ); |
||
193 | |||
194 | $sent = wp_mail( $this->get_email_address_array(), $subject, $message, $headers, $file ); |
||
195 | |||
196 | } |
||
197 | |||
198 | // If we didn't send the email above then send just the notification |
||
199 | if ( ! $sent ) { |
||
200 | |||
201 | $message = sprintf( __( 'BackUpWordPress has completed a backup of your site %1$s.', 'backupwordpress' ) . "\n\n" . __( 'Unfortunately, the backup file was too large to attach to this email.', 'backupwordpress' ) . "\n\n" . __( 'You can download the backup file by clicking the link below:', 'backupwordpress' ) . "\n\n" . '%2$s' . "\n\n" . __( "Kind Regards,\nThe Happy BackUpWordPress Backup Emailing Robot", 'backupwordpress' ), home_url(), $download ); |
||
202 | wp_mail( $this->get_email_address_array(), $subject, $message, $headers ); |
||
203 | |||
204 | } |
||
205 | } |
||
206 | } |
||
207 | |||
208 | public static function intercom_data() { |
||
211 | |||
212 | public static function intercom_data_html() {} |
||
213 | } |
||
214 | |||
217 |
This check looks for the generic type
array
as a return type and suggests a more specific type. This type is inferred from the actual code.