PluginProbe
WP Database Backup – Unlimited Database & Files Backup by Backup for WP / 7.1
WP Database Backup – Unlimited Database & Files Backup by Backup for WP v7.1
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 / class-wpdbfullbackuplog.php

class-wpdbfullbackuplog.php in WP Database Backup – Unlimited Database & Files Backup by Backup for WP 7.1, at includes/class-wpdbfullbackuplog.php

64 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 add_action( 'wpdbbkp_backup_completed', array( 'WPDBFullBackupLog', 'wpdbbkp_backup_completed' ), 11 );
3
4 /**
5 * Class WPDBFullBackupLog
6 *
7 * Handles logging and updating backup completion details.
8 */
9 class WPDBFullBackupLog {
10
11 /**
12 * Processes backup completion details and updates options.
13 *
14 * @param array $args Backup completion arguments.
15 */
16 public static function wpdbbkp_backup_completed( &$args ) {
17 global $wp_filesystem;
18
19 // Ensure WP Filesystem is loaded
20 if ( ! function_exists( 'WP_Filesystem' ) ) {
21 require_once ABSPATH . 'wp-admin/includes/file.php';
22 }
23 WP_Filesystem();
24
25 // Retrieve existing options
26 $options = get_option( 'wp_db_backup_backups' );
27 $new_options = array();
28
29 if ( ! empty( $options ) && is_array( $options ) ) {
30 foreach ( $options as $option ) {
31 if ( ! is_array( $option ) ) {
32 continue;
33 }
34 if ( $option['filename'] === $args[0] ) {
35 $option['destination'] = wp_kses( $args[4], wp_kses_allowed_html( 'post' ) );
36 }
37 $new_options[] = $option;
38 }
39 }
40
41 $new_options = wpdbbkp_filter_unique_filenames( $new_options );
42
43 // Update the options
44 update_option( 'wp_db_backup_backups', $new_options, false );
45
46 // Log to file if logging is enabled
47 if ( get_option( 'wp_db_log' ) == 1 ) {
48 if ( isset( $args[5] ) && ! empty( $args[5] ) ) {
49 if ( $wp_filesystem->is_writable( $args[5] ) || ! $wp_filesystem->exists( $args[5] ) ) {
50 $log_content = str_replace( '<br>', "\n", $args[2] );
51
52 // Append to the log file
53 if ( false === $wp_filesystem->put_contents( $args[5], $log_content, FS_APPEND ) ) {
54 // Handle the error if needed
55 return false;
56 }
57
58 return true;
59 }
60 }
61 }
62 }
63 }
64