-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsavedpixel-remote-backup.php
More file actions
192 lines (170 loc) · 6.44 KB
/
Copy pathsavedpixel-remote-backup.php
File metadata and controls
192 lines (170 loc) · 6.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
<?php
/**
* Plugin Name: SavedPixel Remote Backup
* Plugin URI: https://wpremotebackup.com
* Description: Create, schedule, and export WordPress backups.
* Version: 1.3.0
* Requires at least: 6.5
* Requires PHP: 8.1
* Author: Byron Jacobs
* Author URI: https://byronjacobs.com
* License: GPL-2.0-or-later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Text Domain: savedpixel-remote-backup
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
require_once __DIR__ . '/includes/savedpixel-admin-shared.php';
savedpixel_register_admin_preview_asset(
plugin_dir_url( __FILE__ ) . 'assets/css/savedpixel-admin-preview.css',
'1.1',
array( 'savedpixel', 'savedpixel-remote-backup', 'savedpixel-remote-backup-monitor' )
);
if ( version_compare( PHP_VERSION, '8.1', '<' ) ) {
add_action( 'admin_notices', function () {
printf(
'<div class="notice notice-error"><p><strong>SavedPixel Remote Backup</strong> requires PHP 8.1 or later. You are running PHP %s.</p></div>',
esc_html( PHP_VERSION )
);
} );
return;
}
try {
if ( ! defined( 'SPRB_VERSION' ) ) {
define( 'SPRB_VERSION', '1.3.0' );
}
if ( ! defined( 'SPRB_PLUGIN_DIR' ) ) {
define( 'SPRB_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
}
if ( ! defined( 'SPRB_PLUGIN_URL' ) ) {
define( 'SPRB_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
}
if ( ! defined( 'SPRB_BASE_DIR' ) ) {
define( 'SPRB_BASE_DIR', WP_CONTENT_DIR . '/remote-backup/' );
}
if ( ! defined( 'SPRB_STORAGE_DIR' ) ) {
define( 'SPRB_STORAGE_DIR', trailingslashit( ABSPATH ) . 'storage/' );
}
if ( ! defined( 'SPRB_DATA_DIR' ) ) {
define( 'SPRB_DATA_DIR', SPRB_BASE_DIR . 'data/' );
}
require_once SPRB_PLUGIN_DIR . 'includes/class-remote-backup-plugin.php';
register_activation_hook( __FILE__, array( 'Remote_Backup_Plugin', 'activate' ) );
register_deactivation_hook( __FILE__, array( 'Remote_Backup_Plugin', 'deactivate' ) );
/**
* Migrate rb_* options to sprb_* on upgrade from ≤1.2.1.
*/
add_action( 'admin_init', function () {
if ( get_option( 'sprb_schema_version', '' ) === SPRB_VERSION ) {
return;
}
$old_keys = array(
'rb_pull_token',
'rb_remote_protocol',
'rb_manual_remote_mode',
'rb_backup_folders',
'rb_retain_db',
'rb_retain_files',
'rb_schedule_database_frequency',
'rb_schedule_database_time',
'rb_schedule_database_weekday',
'rb_schedule_files_frequency',
'rb_schedule_files_time',
'rb_schedule_files_weekday',
'rb_scheduled_remote_mode_database',
'rb_scheduled_remote_mode_files',
'rb_scheduled_scope',
'rb_schedule_frequency',
'rb_schedule_time',
'rb_scheduled_remote_mode',
'rb_active_backup_job_id',
'rb_sim_state',
'rb_ftp_host',
'rb_ftp_port',
'rb_ftp_username',
'rb_ftp_password',
'rb_ftp_path',
'rb_ftp_passive',
'rb_ssh_host',
'rb_ssh_port',
'rb_ssh_username',
'rb_ssh_auth_method',
'rb_ssh_key',
'rb_ssh_password',
'rb_ssh_path',
'rb_gdrive_client_id',
'rb_gdrive_client_secret',
'rb_gdrive_folder_id',
'rb_google_drive_tokens',
'rb_onedrive_client_id',
'rb_onedrive_client_secret',
'rb_onedrive_folder_id',
'rb_onedrive_tokens',
'rb_dropbox_client_id',
'rb_dropbox_client_secret',
'rb_dropbox_folder_name',
'rb_dropbox_tokens',
'rb_monitor_retry_minutes',
'rb_monitor_watch_minutes',
'rb_monitor_notification_email',
);
foreach ( $old_keys as $old_key ) {
$value = get_option( $old_key, null );
if ( null === $value ) {
continue;
}
$new_key = 'sprb_' . substr( $old_key, 3 );
if ( false === get_option( $new_key ) ) {
update_option( $new_key, $value );
}
delete_option( $old_key );
}
// Migrate cron hooks.
$cron_map = array(
'rb_scheduled_backup' => 'sprb_scheduled_backup',
'rb_scheduled_backup_database' => 'sprb_scheduled_backup_database',
'rb_scheduled_backup_files' => 'sprb_scheduled_backup_files',
'rb_monitor_poll' => 'sprb_monitor_poll',
'rb_async_manual_backup' => 'sprb_async_manual_backup',
);
$crons = _get_cron_array();
if ( is_array( $crons ) ) {
$dirty = false;
foreach ( $crons as $ts => &$hooks ) {
foreach ( $cron_map as $old_hook => $new_hook ) {
if ( isset( $hooks[ $old_hook ] ) ) {
$hooks[ $new_hook ] = $hooks[ $old_hook ];
unset( $hooks[ $old_hook ] );
$dirty = true;
}
}
}
unset( $hooks );
if ( $dirty ) {
_set_cron_array( $crons );
}
}
// Migrate transients.
global $wpdb;
$old_transients = $wpdb->get_results( // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching -- One-time migration.
"SELECT option_name, option_value FROM {$wpdb->options} WHERE option_name LIKE '_transient_rb_%' OR option_name LIKE '_transient_timeout_rb_%'"
);
foreach ( $old_transients as $row ) {
$new_name = str_replace( '_rb_', '_sprb_', $row->option_name );
if ( false === get_option( $new_name ) ) {
update_option( $new_name, maybe_unserialize( $row->option_value ) );
}
delete_option( $row->option_name );
}
update_option( 'sprb_schema_version', SPRB_VERSION );
} );
Remote_Backup_Plugin::instance();
} catch ( \Throwable $e ) {
add_action( 'admin_notices', function () use ( $e ) {
printf(
'<div class="notice notice-error"><p><strong>SavedPixel Remote Backup</strong> failed to load: %s</p></div>',
esc_html( $e->getMessage() )
);
} );
}