$backup ) : ?> get_item_backup( $id, $backup ); ?>
esc_html__( 'Manual backup', 'woodmart' ), 'date' => gmdate( 'Y-m-d H:i:s', $backup_time ), 'auto' => false, 'options' => $options, 'presets' => $presets, ); update_option( 'xts_backups', $backups ); ob_start(); $this->render(); $content = ob_get_clean(); wp_send_json_success( array( 'content' => $content, 'message' => esc_html__( 'Backup successfully created.', 'woodmart' ), ) ); } /** * Delete backup. */ public function delete_backup() { check_ajax_referer( 'xts_backup_nonce', 'security' ); if ( ! isset( $_POST['id'] ) ) { wp_send_json_error( array( 'message' => esc_html__( 'Something went wrong during backup deleted. ID is missing. Please, try again later.', 'woodmart' ), ) ); } $backups = get_option( 'xts_backups' ); $auto_backups = get_option( 'xts_backups_auto' ); $backup_id = sanitize_text_field( wp_unslash( $_POST['id'] ) ); if ( ! isset( $backups[ $backup_id ] ) && ! isset( $auto_backups[ $backup_id ] ) ) { wp_send_json_error( array( 'message' => esc_html__( 'Something went wrong during backup deleted. ID is missing. Please, try again later.', 'woodmart' ), ) ); } if ( isset( $backups[ $backup_id ] ) ) { unset( $backups[ $backup_id ] ); update_option( 'xts_backups', $backups ); } if ( isset( $auto_backups[ $backup_id ] ) ) { unset( $auto_backups[ $backup_id ] ); update_option( 'xts_backups_auto', $auto_backups ); } ob_start(); $this->render(); $content = ob_get_clean(); wp_send_json_success( array( 'content' => $content, 'message' => esc_html__( 'Backup successfully deleted.', 'woodmart' ), ) ); } /** * Download options export. * * @since 1.0.0 */ public function download_backup() { check_ajax_referer( 'xts_backup_nonce', 'security' ); header( 'Content-Description: File Transfer' ); header( 'Content-type: application/txt' ); header( 'Content-Transfer-Encoding: binary' ); header( 'Expires: 0' ); header( 'Cache-Control: must-revalidate' ); header( 'Pragma: public' ); $file_name = ''; $content = ''; if ( ! isset( $_GET['id'] ) ) { $file_name = 'Error'; $content = esc_html__( 'Something went wrong during backup download. ID is missing. Please, try again later.', 'woodmart' ); } $backups = get_option( 'xts_backups' ); $auto_backups = get_option( 'xts_backups_auto' ); $backup_id = sanitize_text_field( wp_unslash( $_GET['id'] ) ); if ( ! isset( $backups[ $backup_id ] ) && ! isset( $auto_backups[ $backup_id ] ) ) { $file_name = 'Error'; $content = esc_html__( 'Something went wrong during backup download. ID is missing. Please, try again later.', 'woodmart' ); } if ( isset( $backups[ $backup_id ] ) ) { $backup = $backups[ $backup_id ]; $file_name = $backup['title'] . '-' . $backup['date']; $content = wp_json_encode( array( 'options' => $backup['options'], 'presets' => $backup['presets'], ) ); } if ( isset( $auto_backups[ $backup_id ] ) ) { $backup = $auto_backups[ $backup_id ]; $file_name = $backup['title'] . '-' . $backup['date']; $content = wp_json_encode( array( 'options' => $backup['options'], 'presets' => $backup['presets'], ) ); } header( 'Content-Disposition: attachment; filename="' . $file_name . '.json"' ); echo $content; //phpcs:ignore wp_die(); } /** * Apply backup. */ public function apply_backup() { check_ajax_referer( 'xts_backup_nonce', 'security' ); if ( ! isset( $_POST['id'] ) ) { wp_send_json_error( array( 'message' => esc_html__( 'Something went wrong during backup installation. ID is missing. Please, try again later.', 'woodmart' ), ) ); } $backups = get_option( 'xts_backups' ); $auto_backups = get_option( 'xts_backups_auto' ); $backup_id = sanitize_text_field( wp_unslash( $_POST['id'] ) ); $backup = array(); if ( ! isset( $backups[ $backup_id ] ) && ! isset( $auto_backups[ $backup_id ] ) ) { wp_send_json_error( array( 'message' => esc_html__( 'Something went wrong during backup installation. ID is missing. Please, try again later.', 'woodmart' ), ) ); } if ( isset( $backups[ $backup_id ] ) ) { $backup = $backups[ $backup_id ]; } if ( isset( $auto_backups[ $backup_id ] ) ) { $backup = $auto_backups[ $backup_id ]; } $backup['options']['last_message'] = 'import'; $options = ThemeSettingsOptions::get_instance(); $pseudo_post_data = array( 'import-btn' => true, 'import_export' => wp_json_encode( $backup['options'] ), ); $sanitized_options = $options->sanitize_before_save( $pseudo_post_data ); $options->update_options( $sanitized_options ); update_option( 'xts-options-presets', $backup['presets'] ); $presets = Presets::get_active_presets(); array_unshift( $presets, 'default' ); foreach ( $presets as $preset ) { $storage = new WOODMART_Stylesstorage( 'theme_settings_' . $preset ); $storage->reset_data(); $storage->delete_file(); } wp_send_json_success( array( 'message' => esc_html__( 'Backup successfully installed.', 'woodmart' ), ) ); } /** * Create auto backup. */ public function auto_backup() { if ( get_transient( 'xts-woodmart-auto-backup-check' ) ) { return; } $auto_backups = get_option( 'xts_backups_auto' ); $backup_time = time(); $options = get_option( 'xts-woodmart-options' ); $presets = get_option( 'xts-options-presets' ); set_transient( 'xts-woodmart-auto-backup-check', true, DAY_IN_SECONDS ); if ( $auto_backups && 5 <= count( $auto_backups ) ) { foreach ( $auto_backups as $id => $backup ) { if ( $id <= strtotime( '-1 day' ) ) { unset( $auto_backups[ $id ] ); } if ( apply_filters( 'woodmart_auto_backups_count', 10 ) > count( $auto_backups ) ) { break; } } } if ( isset( $options['last_message'] ) ) { unset( $options['last_message'] ); } if ( isset( $options['last_tab'] ) ) { unset( $options['last_tab'] ); } $auto_backups[ $backup_time ] = array( 'title' => esc_html__( 'Auto Backup ', 'woodmart' ), 'date' => gmdate( 'Y-m-d H:i:s', $backup_time ), 'auto' => true, 'options' => $options, 'presets' => $presets, ); update_option( 'xts_backups_auto', $auto_backups, false ); } } Main::get_instance();