| 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 |
|