PluginProbe
WP Database Backup – Unlimited Database & Files Backup by Backup for WP / 6.11
WP Database Backup – Unlimited Database & Files Backup by Backup for WP v6.11
7.13 7.12 trunk 1.1 2.1.1 5.9 6.0 6.1 6.10 6.11 6.12 6.12.1 6.2 6.3 6.4 6.5 6.5.1 6.6 6.7 6.8 6.9 7.0 7.0.1 7.1 7.10 All 34 releases
wp-database-backup / includes / admin / Destination / Email / class-wpdbbackupemail.php

class-wpdbbackupemail.php in WP Database Backup – Unlimited Database & Files Backup by Backup for WP 6.11, at includes/admin/Destination/Email/class-wpdbbackupemail.php

78 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Destination email.
4 *
5 * @package wpdbbkp
6 */
7
8 if ( ! defined( 'ABSPATH' ) ) {
9 exit; // Exit if accessed directly.
10 }
11
12 add_action( 'wp_db_backup_completed', array( 'WPDBBackupEmail', 'wp_db_backup_completed' ), 11 );
13
14 /**
15 * WPDBBackupEmail Class.
16 *
17 * @class WPDBBackupEmail
18 */
19 class WPDBBackupEmail {
20
21 /**
22 * Run after complete backup.
23 *
24 * @param array $args - backup details.
25 */
26 public static function wp_db_backup_completed( &$args ) {
27
28 $destination_email = get_option( 'wp_db_backup_destination_Email' );
29 if ( isset( $destination_email ) && 1 === (int) $destination_email && get_option( 'wp_db_backup_email_id' ) ) {
30 update_option('wpdbbkp_backupcron_current','Processing Email Backup', false);
31 $to = sanitize_email( get_option( 'wp_db_backup_email_id' ) );
32 $subject = 'Database Backup (' . get_bloginfo( 'name' ) . ')';
33 $filename = $args[0];
34 $filesze = $args[3];
35 $site_url = site_url();
36 $log_message_attachment = '';
37 $message = '';
38
39 include 'template-email-notification.php';
40
41 $headers = array( 'Content-Type: text/html; charset=UTF-8' );
42 $wp_db_backup_email_attachment_file = get_option( 'wp_db_backup_email_attachment' );
43 if ( 'yes' === $wp_db_backup_email_attachment_file && $filesze <= 209700000 ) {
44 $attachments = $args[1];
45 $log_message_attachment = ' with attached backup file.';
46 } else {
47 $attachments = '';
48 }
49 if ( wp_mail( $to, $subject, $message, $headers, $attachments ) ) {
50 $args[4] = $args[4] .= 'Email, ';
51 }
52 $log_message = '<b>Send Backup Mail to</b>:' . $to;
53 $log_message .= $log_message_attachment;
54 $wp_db_remove_local_backup = get_option( 'wp_db_remove_local_backup' );
55 if ( 1 === (int) $wp_db_remove_local_backup ) {
56 $log_message .= ' Removed local backup file.';
57 }
58 $args[2] = $args[2] . ' <br>' . $log_message;
59 }
60 }
61
62 /**
63 * Run after complete backup.
64 *
65 * @param bool $bytes - bytes details.
66 * @param int $precision - precision details.
67 */
68 public static function wp_db_backup_format_bytes( $bytes, $precision = 2 ) {
69 $units = array( 'B', 'KB', 'MB', 'GB', 'TB' );
70 $bytes = max( $bytes, 0 );
71 $pow = floor( ( $bytes ? log( $bytes ) : 0 ) / log( 1024 ) );
72 $pow = min( $pow, count( $units ) - 1 );
73 $bytes /= pow( 1024, $pow );
74 return round( $bytes, $precision ) . ' ' . $units[ $pow ];
75 }
76
77 }
78