1 <?php |
1 <?php |
2 /* |
2 /* |
3 Plugin Name: Database Backup for WordPress |
3 Plugin Name: Database Backup for WordPress |
4 Plugin URI: https://github.com/matzko/wp-db-backup |
4 Plugin URI: https://github.com/deliciousbrains/wp-db-backup |
5 Description: On-demand backup of your WordPress database. Navigate to <a href="edit.php?page=wp-db-backup">Tools → Backup</a> to get started. |
5 Description: On-demand backup of your WordPress database. Navigate to <a href="edit.php?page=wp-db-backup">Tools → Backup</a> to get started. |
6 Author: Delicious Brains |
6 Author: Delicious Brains |
7 Author URI: https://deliciousbrains.com |
7 Author URI: https://deliciousbrains.com |
8 Version: 2.4 |
8 Version: 2.5.2 |
9 Domain Path: /languages |
9 Domain Path: /languages |
10 |
|
11 Copyright 2018 Austin Matzko (email : austin at pressedcode.com) |
|
12 |
10 |
13 This program is free software; you can redistribute it and/or modify |
11 This program is free software; you can redistribute it and/or modify |
14 it under the terms of the GNU General Public License as published by |
12 it under the terms of the GNU General Public License as published by |
15 the Free Software Foundation; either version 2 of the License, or |
13 the Free Software Foundation; either version 2 of the License, or |
16 (at your option) any later version. |
14 (at your option) any later version. |
255 } |
267 } |
256 |
268 |
257 function build_backup_script() { |
269 function build_backup_script() { |
258 global $table_prefix, $wpdb; |
270 global $table_prefix, $wpdb; |
259 |
271 |
260 echo "<div class='wrap'>"; |
272 echo '<fieldset class="options backup-running"><legend>' . __( 'Progress', 'wp-db-backup' ) . '</legend> |
261 echo '<fieldset class="options"><legend>' . __( 'Progress', 'wp-db-backup' ) . '</legend> |
273 |
262 <p><strong>' . |
274 <div class="panel-heading"> |
263 __( 'DO NOT DO THE FOLLOWING AS IT WILL CAUSE YOUR BACKUP TO FAIL:', 'wp-db-backup' ) . |
275 <h3>Backup In Progress...</h3> |
264 '</strong></p> |
276 </div> |
265 <ol> |
277 |
266 <li>' . __( 'Close this browser', 'wp-db-backup' ) . '</li> |
278 <div class="panel-content"> |
267 <li>' . __( 'Reload this page', 'wp-db-backup' ) . '</li> |
279 <div class="progress-bar"> |
268 <li>' . __( 'Click the Stop or Back buttons in your browser', 'wp-db-backup' ) . '</li> |
280 <div id="progress-status"></div> |
269 </ol> |
281 <div id="meterbox" style="height:11px;width:80%;padding:3px;border:1px solid #659fff;"><div id="meter" style="color:#fff;height:11px;line-height:11px;background-color:#659fff;width:0%;text-align:center;font-size:6pt;"></div></div> |
270 <p><strong>' . __( 'Progress:', 'wp-db-backup' ) . '</strong></p> |
282 <div id="progress_message"></div>'?> |
271 <div id="meterbox" style="height:11px;width:80%;padding:3px;border:1px solid #659fff;"><div id="meter" style="color:#fff;height:11px;line-height:11px;background-color:#659fff;width:0%;text-align:center;font-size:6pt;"> </div></div> |
283 </div> |
272 <div id="progress_message"></div> |
284 |
273 <div id="errors"></div> |
285 <div class="info-notice"> |
|
286 <img src="<?php echo plugin_dir_url( __FILE__ ) . 'assets/warning.svg'; ?>"> |
|
287 <p> |
|
288 Whilst the backup is in progress, please do not close the browser, reload or change the page, or click the stop or back browser buttons. This would result in the backup failing. |
|
289 </p> |
|
290 </div> |
|
291 |
|
292 <?php echo '<div id="errors"></div> |
|
293 <iframe id="backuploader" src="about:blank" style="display:none;border:none;height:1em;width:1px;"></iframe> |
274 </fieldset> |
294 </fieldset> |
275 <iframe id="backuploader" src="about:blank" style="visibility:hidden;border:none;height:1em;width:1px;"></iframe> |
|
276 <script type="text/javascript"> |
295 <script type="text/javascript"> |
277 //<![CDATA[ |
296 //<![CDATA[ |
278 window.onbeforeunload = function() { |
297 window.onbeforeunload = function() { |
279 return "' . __( 'Navigating away from this page will cause your backup to fail.', 'wp-db-backup' ) . '"; |
298 return "' . __( 'Navigating away from this page will cause your backup to fail.', 'wp-db-backup' ) . '"; |
280 } |
299 } |
281 function setMeter(pct) { |
300 function setMeter(pct) { |
|
301 var meterStatus = document.getElementById("progress-status"); |
282 var meter = document.getElementById("meter"); |
302 var meter = document.getElementById("meter"); |
283 meter.style.width = pct + "%"; |
303 meter.style.width = pct + "%"; |
284 meter.innerHTML = Math.floor(pct) + "%"; |
304 meterStatus.innerHTML = Math.floor(pct) + "%"; |
285 } |
305 } |
286 function setProgress(str) { |
306 function setProgress(str) { |
287 var progress = document.getElementById("progress_message"); |
307 var progress = document.getElementById("progress_message"); |
288 progress.innerHTML = str; |
308 progress.innerHTML = str; |
289 } |
309 } |
511 continue; |
530 continue; |
512 var ul = d.getElementsByTagName('ul').item(0); |
531 var ul = d.getElementsByTagName('ul').item(0); |
513 if ( ul ) { |
532 if ( ul ) { |
514 var lis = ul.getElementsByTagName('li'); |
533 var lis = ul.getElementsByTagName('li'); |
515 if ( 2 < lis.length ) { |
534 if ( 2 < lis.length ) { |
516 var text = document.createElement('p'); |
535 var text = document.querySelector('.instructions-container p'); |
517 text.className = 'instructions'; |
536 text.style.display = 'block'; |
518 text.innerHTML = '<?php _e( 'Click and hold down <code>[SHIFT]</code> to toggle multiple checkboxes', 'wp-db-backup' ); ?>'; |
|
519 ul.parentNode.insertBefore(text, ul); |
|
520 } |
537 } |
521 } |
538 } |
522 t[k].p = d.getElementsByTagName("input"); |
539 t[k].p = d.getElementsByTagName("input"); |
523 for(var i=0; i < t[k].p.length; i++) { |
540 for(var i=0; i < t[k].p.length; i++) { |
524 if(t[k].name == t[k].p[i].getAttribute('name')) { |
541 if(t[k].name == t[k].p[i].getAttribute('name')) { |
525 t[k].p[i].id = k + '-table-' + i; |
542 t[k].p[i].id = k + '-table-' + i; |
526 t[k].p[i].onkeyup = t[k].p[i].onclick = function(e) { |
543 var label = document.getElementById(t[k].p[i].id).parentNode; |
|
544 t[k].p[i].onkeyup = label.onclick = function(e) { |
527 e = e ? e : event; |
545 e = e ? e : event; |
528 if ( 16 == e.keyCode ) |
546 if ( 16 == e.keyCode ) |
529 return; |
547 return; |
530 var match = /([\w-]*)-table-(\d*)/.exec(this.id); |
548 var match = /([\w-]*)-table-(\d*)/.exec(this.querySelector('input').id); |
531 var listname = match[1]; |
549 var listname = match[1]; |
532 var that = match[2]; |
550 var that = match[2]; |
533 if ( null === t[listname].s ) |
551 if ( null === t[listname].s ) |
534 t[listname].s = that; |
552 t[listname].s = that; |
535 else if ( e.shiftKey ) { |
553 else if ( e.shiftKey ) { |
|
554 console.log(this); |
536 var start = Math.min(that, t[listname].s) + 1; |
555 var start = Math.min(that, t[listname].s) + 1; |
537 var end = Math.max(that, t[listname].s); |
556 var end = Math.max(that, t[listname].s); |
|
557 this.querySelector('input').checked = true; |
538 for( var j=start; j < end; j++) |
558 for( var j=start; j < end; j++) |
539 t[listname].p[j].checked = t[listname].p[j].checked ? false : true; |
559 t[listname].p[j].checked = t[listname].p[j].checked ? false : true; |
540 t[listname].s = null; |
560 t[listname].s = null; |
541 } |
561 } |
542 } |
562 } |
612 <?php |
632 <?php |
613 } |
633 } |
614 |
634 |
615 function admin_load() { |
635 function admin_load() { |
616 add_action( 'admin_head', array( &$this, 'admin_header' ) ); |
636 add_action( 'admin_head', array( &$this, 'admin_header' ) ); |
617 wp_enqueue_style( 'wp-db-backup-styles', plugin_dir_url( __FILE__ ) . 'assets/css/style.css' ); |
637 wp_enqueue_style( 'wp-db-backup-styles', plugin_dir_url( __FILE__ ) . 'assets/css/style.css', array( 'common', 'forms' ) ); |
|
638 wp_enqueue_script( 'wp-db-backup-script', plugin_dir_url( __FILE__ ) . 'assets/js/script.js', array( 'jquery' ), $this->version, true ); |
618 } |
639 } |
619 |
640 |
620 function admin_menu() { |
641 function admin_menu() { |
621 $_page_hook = add_management_page( __( 'Backup', 'wp-db-backup' ), __( 'Backup', 'wp-db-backup' ), 'import', $this->basename, array( &$this, 'backup_menu' ) ); |
642 $_page_hook = add_management_page( __( 'Backup', 'wp-db-backup' ), __( 'Backup', 'wp-db-backup' ), 'import', $this->basename, array( &$this, 'backup_menu' ) ); |
622 add_action( 'load-' . $_page_hook, array( &$this, 'admin_load' ) ); |
643 add_action( 'load-' . $_page_hook, array( &$this, 'admin_load' ) ); |
633 } |
654 } |
634 } elseif ( function_exists( 'add_contextual_help' ) ) { |
655 } elseif ( function_exists( 'add_contextual_help' ) ) { |
635 $text = $this->help_menu(); |
656 $text = $this->help_menu(); |
636 add_contextual_help( $_page_hook, $text ); |
657 add_contextual_help( $_page_hook, $text ); |
637 } |
658 } |
638 } |
|
639 |
|
640 function fragment_menu() { |
|
641 $page_hook = add_management_page( __( 'Backup', 'wp-db-backup' ), __( 'Backup', 'wp-db-backup' ), 'import', $this->basename, array( &$this, 'build_backup_script' ) ); |
|
642 add_action( 'load-' . $page_hook, array( &$this, 'admin_load' ) ); |
|
643 } |
659 } |
644 |
660 |
645 /** |
661 /** |
646 * Add WP-DB-Backup-specific help options to the 2.7 =< WP contextual help menu |
662 * Add WP-DB-Backup-specific help options to the 2.7 =< WP contextual help menu |
647 * @return string The text of the help menu. |
663 * @return string The text of the help menu. |
1137 |
1153 |
1138 // security check |
1154 // security check |
1139 $this->wp_secure(); |
1155 $this->wp_secure(); |
1140 |
1156 |
1141 if ( count( $this->errors ) ) { |
1157 if ( count( $this->errors ) ) { |
1142 $feedback .= '<div class="updated wp-db-backup-updated error"><p><strong>' . __( 'The following errors were reported:', 'wp-db-backup' ) . '</strong></p>'; |
1158 $feedback .= '<div class="wp-db-backup-updated error inline"><p><strong>' . __( 'The following errors were reported:', 'wp-db-backup' ) . '</strong></p>'; |
1143 $feedback .= '<p>' . $this->error_display( 'main', false ) . '</p>'; |
1159 $feedback .= '<p>' . $this->error_display( 'main', false ) . '</p>'; |
1144 $feedback .= '</p></div>'; |
1160 $feedback .= '</p></div>'; |
1145 } |
1161 } |
1146 |
1162 |
1147 // did we just save options for wp-cron? |
1163 // did we just save options for wp-cron? |
1148 if ( ( function_exists( 'wp_schedule_event' ) || function_exists( 'wp_cron_init' ) ) && isset( $_POST['wp_cron_backup_options'] ) ) : |
1164 if ( ( function_exists( 'wp_schedule_event' ) || function_exists( 'wp_cron_init' ) ) && isset( $_POST['wp_cron_backup_options'] ) ) : |
|
1165 check_admin_referer( $this->referer_check_key ); |
|
1166 |
1149 do_action( 'wp_db_b_update_cron_options' ); |
1167 do_action( 'wp_db_b_update_cron_options' ); |
1150 |
1168 |
1151 if ( function_exists( 'wp_schedule_event' ) ) { |
1169 if ( function_exists( 'wp_schedule_event' ) ) { |
1152 wp_clear_scheduled_hook( 'wp_db_backup_cron' ); // unschedule previous |
1170 wp_clear_scheduled_hook( 'wp_db_backup_cron' ); // unschedule previous |
1153 $scheds = (array) wp_get_schedules(); |
1171 $scheds = (array) wp_get_schedules(); |
1166 |
1184 |
1167 if ( is_email( $_POST['cron_backup_recipient'] ) ) { |
1185 if ( is_email( $_POST['cron_backup_recipient'] ) ) { |
1168 update_option( 'wp_cron_backup_recipient', sanitize_text_field( $_POST['cron_backup_recipient'] ), false ); |
1186 update_option( 'wp_cron_backup_recipient', sanitize_text_field( $_POST['cron_backup_recipient'] ), false ); |
1169 } |
1187 } |
1170 |
1188 |
1171 $feedback .= '<div class="updated wp-db-backup-updated"><p>' . __( 'Scheduled Backup Options Saved!', 'wp-db-backup' ) . '</p></div>'; |
1189 $feedback .= '<div class="wp-db-backup-updated wp-db-backup-schedule-updated"><p>' . __( 'Scheduled Backup Options Saved!', 'wp-db-backup' ) . '</p></div>'; |
1172 endif; |
1190 endif; |
1173 |
1191 |
1174 $other_tables = array(); |
1192 $other_tables = array(); |
1175 $also_backup = array(); |
1193 $also_backup = array(); |
1176 |
1194 |
1177 // Get complete db table list |
1195 // Get complete db table list |
1178 $all_tables = $wpdb->get_results( 'SHOW TABLES', ARRAY_N ); |
1196 $all_tables = $this->get_tables(); |
1179 $all_tables = array_map( |
|
1180 function( $a ) { |
|
1181 return $a[0]; |
|
1182 }, |
|
1183 $all_tables |
|
1184 ); |
|
1185 |
1197 |
1186 // Get list of WP tables that actually exist in this DB (for 1.6 compat!) |
1198 // Get list of WP tables that actually exist in this DB (for 1.6 compat!) |
1187 $wp_backup_default_tables = array_intersect( $all_tables, $this->core_table_names ); |
1199 $wp_backup_default_tables = array_intersect( $all_tables, $this->core_table_names ); |
1188 // Get list of non-WP tables |
1200 // Get list of non-WP tables |
1189 $other_tables = array_diff( $all_tables, $wp_backup_default_tables ); |
1201 $other_tables = array_diff( $all_tables, $wp_backup_default_tables ); |
1190 |
1202 |
1191 if ( '' != $feedback ) { |
|
1192 echo $feedback; |
|
1193 } |
|
1194 |
|
1195 if ( ! $this->wp_secure() ) { |
1203 if ( ! $this->wp_secure() ) { |
1196 return; |
1204 return; |
1197 } |
1205 } |
1198 |
1206 |
1199 // Give the new dirs the same perms as wp-content. |
1207 // Give the new dirs the same perms as wp-content. |
1202 $dir_perms = '0777'; |
1210 $dir_perms = '0777'; |
1203 |
1211 |
1204 // the file doesn't exist and can't create it |
1212 // the file doesn't exist and can't create it |
1205 if ( ! file_exists( $this->backup_dir ) && ! @mkdir( $this->backup_dir ) ) { |
1213 if ( ! file_exists( $this->backup_dir ) && ! @mkdir( $this->backup_dir ) ) { |
1206 ?> |
1214 ?> |
1207 <div class="updated wp-db-backup-updated error"> |
1215 <div class="wp-db-backup-updated error inline"> |
1208 <p><?php _e( 'WARNING: Your backup directory does <strong>NOT</strong> exist, and we cannot create it.', 'wp-db-backup' ); ?></p> |
1216 <p><?php _e( 'WARNING: Your backup directory does <strong>NOT</strong> exist, and we cannot create it.', 'wp-db-backup' ); ?></p> |
1209 <p><?php printf( __( 'Using your FTP client, try to create the backup directory yourself: %s', 'wp-db-backup' ), '<code>' . $this->backup_dir . '</code>' ); ?></p> |
1217 <p><?php printf( __( 'Using your FTP client, try to create the backup directory yourself: %s', 'wp-db-backup' ), '<code>' . $this->backup_dir . '</code>' ); ?></p> |
1210 </div> |
1218 </div> |
1211 <?php |
1219 <?php |
1212 // not writable due to write permissions |
1220 // not writable due to write permissions |
1213 $whoops = true; |
1221 $whoops = true; |
1214 } elseif ( ! is_writable( $this->backup_dir ) && ! @chmod( $this->backup_dir, $dir_perms ) ) { |
1222 } elseif ( ! is_writable( $this->backup_dir ) && ! @chmod( $this->backup_dir, $dir_perms ) ) { |
1215 ?> |
1223 ?> |
1216 <div class="updated wp-db-backup-updated error"> |
1224 <div class="wp-db-backup-updated error inline"> |
1217 <p><?php _e( 'WARNING: Your backup directory is <strong>NOT</strong> writable! We cannot create the backup files.', 'wp-db-backup' ); ?></p> |
1225 <p><?php _e( 'WARNING: Your backup directory is <strong>NOT</strong> writable! We cannot create the backup files.', 'wp-db-backup' ); ?></p> |
1218 <p><?php printf( __( 'Using your FTP client, try to set the backup directory’s write permission to %1$s or %2$s: %3$s', 'wp-db-backup' ), '<code>777</code>', '<code>a+w</code>', '<code>' . $this->backup_dir . '</code>' ); ?></p> |
1226 <p><?php printf( __( 'Using your FTP client, try to set the backup directory’s write permission to %1$s or %2$s: %3$s', 'wp-db-backup' ), '<code>777</code>', '<code>a+w</code>', '<code>' . $this->backup_dir . '</code>' ); ?></p> |
1219 </div> |
1227 </div> |
1220 <?php |
1228 <?php |
1221 $whoops = true; |
1229 $whoops = true; |
1226 $this->close( $this->fp ); |
1234 $this->close( $this->fp ); |
1227 @unlink( $this->backup_dir . 'test' ); |
1235 @unlink( $this->backup_dir . 'test' ); |
1228 // the directory is not writable probably due to safe mode |
1236 // the directory is not writable probably due to safe mode |
1229 } else { |
1237 } else { |
1230 ?> |
1238 ?> |
1231 <div class="updated wp-db-backup-updated error"> |
1239 <div class="wp-db-backup-updated error inline"> |
1232 <p><?php _e( 'WARNING: Your backup directory is <strong>NOT</strong> writable! We cannot create the backup files.', 'wp-db-backup' ); ?></p> |
1240 <p><?php _e( 'WARNING: Your backup directory is <strong>NOT</strong> writable! We cannot create the backup files.', 'wp-db-backup' ); ?></p> |
1233 <?php |
1241 <?php |
1234 if ( ini_get( 'safe_mode' ) ) { |
1242 if ( ini_get( 'safe_mode' ) ) { |
1235 ?> |
1243 ?> |
1236 <p><?php _e( 'This problem seems to be caused by your server’s <code>safe_mode</code> file ownership restrictions, which limit what files web applications like WordPress can create.', 'wp-db-backup' ); ?></p> |
1244 <p><?php _e( 'This problem seems to be caused by your server’s <code>safe_mode</code> file ownership restrictions, which limit what files web applications like WordPress can create.', 'wp-db-backup' ); ?></p> |
1247 |
1255 |
1248 if ( ! file_exists( $this->backup_dir . 'index.php' ) ) { |
1256 if ( ! file_exists( $this->backup_dir . 'index.php' ) ) { |
1249 @touch( $this->backup_dir . 'index.php' ); |
1257 @touch( $this->backup_dir . 'index.php' ); |
1250 } |
1258 } |
1251 ?> |
1259 ?> |
1252 <div class='wrap'> |
1260 <div id="wpdb" class='wrap'> |
1253 <h2><?php _e( 'Backup', 'wp-db-backup' ); ?></h2> |
1261 <div class="header"> |
|
1262 <img src="<?php echo plugin_dir_url( __FILE__ ) . 'assets/logo.svg'; ?>"> |
|
1263 <h2 class="title"><?php _e( 'Database Backup for WordPress', 'wp-db-backup' ); ?></h2> |
|
1264 </div> |
|
1265 |
|
1266 <div class="subnav"> |
|
1267 <ul> |
|
1268 <li> |
|
1269 <a class="active" href="#backup" data-type="backup">Backup Now</a> |
|
1270 </li> |
|
1271 <li> |
|
1272 <a href="#schedule" data-type="schedule">Scheduled Backup</a> |
|
1273 </li> |
|
1274 </ul> |
|
1275 </div> |
|
1276 |
|
1277 <div class="content-wrap"> |
|
1278 |
|
1279 <?php |
|
1280 if ( '' != $feedback ) { |
|
1281 echo $feedback; |
|
1282 } |
|
1283 |
|
1284 if ( isset( $_POST['do_backup'] ) && $_POST['do_backup'] === 'fragments' ) { |
|
1285 $this->build_backup_script(); |
|
1286 } |
|
1287 ?> |
|
1288 |
1254 <form method="post" action=""> |
1289 <form method="post" action=""> |
1255 <?php |
1290 <?php |
1256 if ( function_exists( 'wp_nonce_field' ) ) { |
1291 if ( function_exists( 'wp_nonce_field' ) ) { |
1257 wp_nonce_field( $this->referer_check_key ); |
1292 wp_nonce_field( $this->referer_check_key ); |
1258 } |
1293 } |
1259 ?> |
1294 ?> |
1260 <fieldset class="options"><legend><?php _e( 'Tables', 'wp-db-backup' ); ?></legend> |
1295 |
|
1296 <fieldset class="options backup-content"> |
|
1297 <legend><?php _e( 'Tables', 'wp-db-backup' ); ?></legend> |
|
1298 |
|
1299 <div class="panel-heading"> |
|
1300 <h3>Tables</h3> |
|
1301 </div> |
|
1302 |
|
1303 <div class="panel-content tables"> |
|
1304 |
1261 <div class="tables-list core-tables alternate"> |
1305 <div class="tables-list core-tables alternate"> |
1262 <h4><?php _e( 'These core WordPress tables will always be backed up:', 'wp-db-backup' ); ?></h4> |
1306 <div class="instructions-container"> |
|
1307 <h4><?php _e( 'Core WordPress tables to backup', 'wp-db-backup' ); ?></h4> |
|
1308 </div> |
1263 <ul> |
1309 <ul> |
1264 <?php |
1310 <?php |
1265 $excs = (array) get_option( 'wp_db_backup_excs' ); |
1311 $excs = (array) get_option( 'wp_db_backup_excs' ); |
1266 foreach ( $wp_backup_default_tables as $table ) { |
1312 foreach ( $wp_backup_default_tables as $table ) { |
1267 if ( $table == $wpdb->comments ) { |
1313 if ( $table == $wpdb->comments ) { |
1268 $checked = ( isset( $excs['spam'] ) && is_array( $excs['spam'] ) && in_array( $table, $excs['spam'] ) ) ? ' checked=\'checked\'' : ''; |
1314 $checked = ( isset( $excs['spam'] ) && is_array( $excs['spam'] ) && in_array( $table, $excs['spam'] ) ) ? ' checked=\'checked\'' : ''; |
1269 echo "<li><input type='hidden' name='core_tables[]' value='$table' /><code>$table</code> <span class='instructions'> <input type='checkbox' name='exclude-spam[]' value='$table' $checked /> " . __( 'Exclude spam comments', 'wp-db-backup' ) . '</span></li>'; |
1315 echo "<li><input type='hidden' name='core_tables[]' value='$table' /><code>$table</code> <span class='instructions'><label for='exclude-spam'><input type='checkbox' id='exclude-spam' name='exclude-spam[]' value='$table' $checked /> " . __( 'Exclude spam comments', 'wp-db-backup' ) . '</label></span></li>'; |
1270 } elseif ( function_exists( 'wp_get_post_revisions' ) && $table == $wpdb->posts ) { |
1316 } elseif ( function_exists( 'wp_get_post_revisions' ) && $table == $wpdb->posts ) { |
1271 $checked = ( isset( $excs['revisions'] ) && is_array( $excs['revisions'] ) && in_array( $table, $excs['revisions'] ) ) ? ' checked=\'checked\'' : ''; |
1317 $checked = ( isset( $excs['revisions'] ) && is_array( $excs['revisions'] ) && in_array( $table, $excs['revisions'] ) ) ? ' checked=\'checked\'' : ''; |
1272 echo "<li><input type='hidden' name='core_tables[]' value='$table' /><code>$table</code> <span class='instructions'> <input type='checkbox' name='exclude-revisions[]' value='$table' $checked /> " . __( 'Exclude post revisions', 'wp-db-backup' ) . '</span></li>'; |
1318 echo "<li><input type='hidden' name='core_tables[]' value='$table' /><code>$table</code> <span class='instructions'><label for='exclude-revisions'><input type='checkbox'id='exclude-revisions' name='exclude-revisions[]' value='$table' $checked /> " . __( 'Exclude post revisions', 'wp-db-backup' ) . '</label></span></li>'; |
1273 } else { |
1319 } else { |
1274 echo "<li><input type='hidden' name='core_tables[]' value='$table' /><code>$table</code></li>"; |
1320 echo "<li><input type='hidden' name='core_tables[]' value='$table' /><code>$table</code></li>"; |
1275 } |
1321 } |
1276 } |
1322 } |
1277 ?> |
1323 ?> |
1278 </ul> |
1324 </ul> |
1279 </div> |
1325 </div> |
|
1326 |
1280 <div class="tables-list extra-tables" id="extra-tables-list"> |
1327 <div class="tables-list extra-tables" id="extra-tables-list"> |
|
1328 |
1281 <?php |
1329 <?php |
1282 if ( count( $other_tables ) > 0 ) { |
1330 if ( count( $other_tables ) > 0 ) { |
1283 ?> |
1331 ?> |
1284 <h4><?php _e( 'You may choose to include any of the following tables:', 'wp-db-backup' ); ?></h4> |
1332 <div class="instructions-container"> |
|
1333 <h4><?php _e( 'Additional tables to backup', 'wp-db-backup' ); ?></h4> |
|
1334 <p hidden><?php _e( 'Hold <code class="shift-key">SHIFT</code> to toggle multiple checkboxes', 'wp-db-backup' ); ?></p> |
|
1335 </div> |
1285 <ul> |
1336 <ul> |
1286 <?php |
1337 <?php |
1287 foreach ( $other_tables as $table ) { |
1338 foreach ( $other_tables as $table ) { |
1288 ?> |
1339 ?> |
1289 <li><label><input type="checkbox" name="other_tables[]" value="<?php echo $table; ?>" /> <code><?php echo $table; ?></code></label> |
1340 <li><label><input type="checkbox" name="other_tables[]" value="<?php echo $table; ?>" /> <code><?php echo $table; ?></code></label> |
1293 </ul> |
1344 </ul> |
1294 <?php |
1345 <?php |
1295 } |
1346 } |
1296 ?> |
1347 ?> |
1297 </div> |
1348 </div> |
|
1349 |
|
1350 </div><!--panel-content--> |
1298 </fieldset> |
1351 </fieldset> |
1299 |
1352 |
1300 <fieldset class="options"> |
1353 |
|
1354 <!--BACKUP PANEL--> |
|
1355 <fieldset class="options backup-content"> |
1301 <legend><?php _e( 'Backup Options', 'wp-db-backup' ); ?></legend> |
1356 <legend><?php _e( 'Backup Options', 'wp-db-backup' ); ?></legend> |
1302 <p><?php _e( 'What to do with the backup file:', 'wp-db-backup' ); ?></p> |
1357 |
|
1358 <div class="panel-heading"> |
|
1359 <h3>Backup Options</h3> |
|
1360 </div> |
|
1361 |
|
1362 <div class="panel-content backup"> |
1303 <ul> |
1363 <ul> |
1304 <li><label for="do_download"> |
1364 <li><label for="do_download"> |
1305 <input type="radio" checked="checked" id="do_download" name="deliver" value="http" style="border:none;" /> |
1365 <input type="radio" checked="checked" id="do_download" name="deliver" value="http" style="border:none;" /> |
1306 <?php _e( 'Download to your computer', 'wp-db-backup' ); ?> |
1366 <?php _e( 'Download', 'wp-db-backup' ); ?> |
1307 </label></li> |
1367 </label></li> |
1308 <li><label for="do_email"> |
1368 <li><label for="do_email"> |
1309 <input type="radio" name="deliver" id="do_email" value="smtp" style="border:none;" /> |
1369 <input type="radio" name="deliver" id="do_email" value="smtp" style="border:none;" /> |
1310 <?php |
1370 <?php |
1311 $backup_recip = get_option( 'wpdb_backup_recip' ); |
1371 $backup_recip = get_option( 'wpdb_backup_recip' ); |
1312 if ( empty( $backup_recip ) ) { |
1372 if ( empty( $backup_recip ) ) { |
1313 $backup_recip = get_option( 'admin_email' ); |
1373 $backup_recip = get_option( 'admin_email' ); |
1314 } |
1374 } |
1315 _e( 'Email backup to:', 'wp-db-backup' ); |
1375 _e( 'Send to email address', 'wp-db-backup' ); |
1316 ?> |
1376 ?> |
1317 <input type="text" name="backup_recipient" size="20" value="<?php echo esc_attr( $backup_recip ); ?>" /> |
1377 |
|
1378 <div class="email"> |
|
1379 <label for="backup_recipient">Email Address</label> |
|
1380 <input type="text" id="backup_recipient" name="backup_recipient" size="20" value="<?php echo esc_attr( $backup_recip ); ?>" /> |
|
1381 </div> |
1318 </label></li> |
1382 </label></li> |
1319 </ul> |
1383 </ul> |
1320 <?php if ( ! $whoops ) : ?> |
1384 <?php if ( ! $whoops ) : ?> |
1321 <input type="hidden" name="do_backup" id="do_backup" value="backup" /> |
1385 <input type="hidden" name="do_backup" id="do_backup" value="backup" /> |
1322 <p class="submit"> |
1386 <p class="submit"> |
1323 <input type="submit" name="submit" onclick="document.getElementById('do_backup').value='fragments';" value="<?php _e( 'Backup now!', 'wp-db-backup' ); ?>" /> |
1387 <input type="submit" name="submit" onclick="document.getElementById('do_backup').value='fragments';" value="<?php _e( 'Backup now', 'wp-db-backup' ); ?>" /> |
1324 </p> |
1388 </p> |
1325 <?php else : ?> |
1389 <?php else : ?> |
1326 <div class="updated wp-db-backup-updated error"><p><?php _e( 'WARNING: Your backup directory is <strong>NOT</strong> writable!', 'wp-db-backup' ); ?></p></div> |
1390 <div class="wp-db-backup-updated error inline"><p><?php _e( 'WARNING: Your backup directory is <strong>NOT</strong> writable!', 'wp-db-backup' ); ?></p></div> |
1327 <?php endif; // ! whoops ?> |
1391 <?php endif; // ! whoops ?> |
|
1392 |
|
1393 </div><!--panel-content--> |
1328 </fieldset> |
1394 </fieldset> |
1329 <?php do_action( 'wp_db_b_backup_opts' ); ?> |
1395 <?php do_action( 'wp_db_b_backup_opts' ); ?> |
1330 </form> |
1396 </form> |
1331 |
1397 |
1332 <?php |
1398 <?php |
1333 // this stuff only displays if some sort of wp-cron is available |
1399 // this stuff only displays if some sort of wp-cron is available |
1334 $cron = ( function_exists( 'wp_schedule_event' ) ) ? true : false; // wp-cron in WP 2.1+ |
1400 $cron = ( function_exists( 'wp_schedule_event' ) ) ? true : false; // wp-cron in WP 2.1+ |
1335 $cron_old = ( function_exists( 'wp_cron_init' ) && ! $cron ) ? true : false; // wp-cron plugin by Skippy |
1401 $cron_old = ( function_exists( 'wp_cron_init' ) && ! $cron ) ? true : false; // wp-cron plugin by Skippy |
1336 |
1402 |
1337 if ( $cron_old || $cron ) : |
1403 if ( $cron_old || $cron ) : |
1338 echo '<fieldset class="options"><legend>' . __( 'Scheduled Backup', 'wp-db-backup' ) . '</legend>'; |
1404 echo '<fieldset class="options schedule-content" hidden><legend>' . __( 'Scheduled Backup', 'wp-db-backup' ) . '</legend>'; |
|
1405 echo '<div class="panel-heading"><h3>Scheduled Backup</h3></div>'; |
|
1406 |
|
1407 echo '<div class="panel-content scheduled-backup">'; |
|
1408 |
1339 $datetime = get_option( 'date_format' ) . ' ' . get_option( 'time_format' ); |
1409 $datetime = get_option( 'date_format' ) . ' ' . get_option( 'time_format' ); |
1340 if ( $cron ) : |
1410 if ( $cron ) : |
1341 $next_cron = wp_next_scheduled( 'wp_db_backup_cron' ); |
1411 $next_cron = wp_next_scheduled( 'wp_db_backup_cron' ); |
1342 if ( ! empty( $next_cron ) ) : |
1412 if ( ! empty( $next_cron ) ) : |
1343 ?> |
1413 ?> |
1344 <p id="backup-time-wrap"> |
1414 <p id="backup-time-wrap"> |
1345 <?php printf( __( 'Next Backup: %s', 'wp-db-backup' ), '<span id="next-backup-time">' . gmdate( $datetime, $next_cron + ( get_option( 'gmt_offset' ) * 3600 ) ) . '</span>' ); ?> |
1415 <?php printf( __( '<strong>Next Backup:</strong> %s', 'wp-db-backup' ), '<span id="next-backup-time">' . gmdate( $datetime, $next_cron + ( get_option( 'gmt_offset' ) * 3600 ) ) . '</span>' ); ?> |
1346 </p> |
1416 </p> |
1347 <?php |
1417 <?php |
1348 endif; |
1418 endif; |
1349 elseif ( $cron_old ) : |
1419 elseif ( $cron_old ) : |
1350 ?> |
1420 ?> |
1359 <form method="post" action=""> |
1429 <form method="post" action=""> |
1360 <?php |
1430 <?php |
1361 if ( function_exists( 'wp_nonce_field' ) ) { |
1431 if ( function_exists( 'wp_nonce_field' ) ) { |
1362 wp_nonce_field( $this->referer_check_key );} |
1432 wp_nonce_field( $this->referer_check_key );} |
1363 ?> |
1433 ?> |
1364 <div class="tables-list"> |
1434 |
1365 <h4><?php _e( 'Schedule: ', 'wp-db-backup' ); ?></h4> |
1435 <div class="panel-content row"> |
|
1436 <div class="tables-list scheduled"> |
|
1437 <h4><?php _e( 'Schedule', 'wp-db-backup' ); ?></h4> |
1366 <?php |
1438 <?php |
1367 if ( $cron_old ) : |
1439 if ( $cron_old ) : |
1368 $wp_cron_backup_schedule = get_option( 'wp_cron_backup_schedule' ); |
1440 $wp_cron_backup_schedule = get_option( 'wp_cron_backup_schedule' ); |
1369 $schedule = array( |
1441 $schedule = array( |
1370 0 => __( 'None', 'wp-db-backup' ), |
1442 0 => __( 'None', 'wp-db-backup' ), |
1371 1 => __( 'Daily', 'wp-db-backup' ), |
1443 1 => __( 'Daily', 'wp-db-backup' ), |
1372 ); |
1444 ); |
1373 foreach ( $schedule as $value => $name ) { |
1445 foreach ( $schedule as $value => $name ) { |
1374 echo ' <input type="radio" style="border:none;" name="cron_schedule"'; |
1446 echo '<input type="radio" style="border:none;" name="cron_schedule"'; |
1375 if ( $wp_cron_backup_schedule == $value ) { |
1447 if ( $wp_cron_backup_schedule == $value ) { |
1376 echo ' checked="checked" '; |
1448 echo ' checked="checked" '; |
1377 } |
1449 } |
1378 echo 'value="' . $value . '" /> ' . $name; |
1450 echo 'value="' . $value . '" /> ' . $name; |
1379 } |
1451 } |
1380 elseif ( $cron ) : |
1452 elseif ( $cron ) : |
1381 echo apply_filters( 'wp_db_b_schedule_choices', wp_get_schedules() ); |
1453 echo apply_filters( 'wp_db_b_schedule_choices', wp_get_schedules() ); |
1382 endif; |
1454 endif; |
1383 |
1455 |
1384 $cron_recipient = get_option( 'wp_cron_backup_recipient' ); |
1456 $cron_recipient = get_option( 'wp_cron_backup_recipient' ); |
1385 |
1457 |
1386 if ( ! is_email( $cron_recipient ) ) { |
1458 if ( ! is_email( $cron_recipient ) ) { |
1387 $cron_recipient = get_option( 'admin_email' ); |
1459 $cron_recipient = get_option( 'admin_email' ); |
1388 } |
1460 } |
1389 |
1461 |
1390 $cron_recipient_input = '<p><label for="cron_backup_recipient">' . __( 'Email backup to:', 'wp-db-backup' ) . ' <input type="text" name="cron_backup_recipient" id="cron_backup_recipient" size="20" value="' . $cron_recipient . '" /></label></p>'; |
1462 $cron_recipient_input = '<div class="email"><label for="cron_backup_recipient">' . __( 'Email backup to', 'wp-db-backup' ) . ' <input type="text" name="cron_backup_recipient" id="cron_backup_recipient" size="20" value="' . $cron_recipient . '" /></div></label>'; |
1391 echo apply_filters( 'wp_db_b_cron_recipient_input', $cron_recipient_input ); |
1463 echo apply_filters( 'wp_db_b_cron_recipient_input', $cron_recipient_input ); |
1392 echo '<p class="submit"><input type="submit" name="submit" value="' . __( 'Schedule backup', 'wp-db-backup' ) . '" /></p>'; |
|
1393 echo '</div>'; |
1464 echo '</div>'; |
1394 $cron_tables = get_option( 'wp_cron_backup_tables' ); |
1465 $cron_tables = get_option( 'wp_cron_backup_tables' ); |
1395 |
1466 |
1396 if ( ! is_array( $cron_tables ) ) { |
1467 if ( ! is_array( $cron_tables ) ) { |
1397 $cron_tables = array(); |
1468 $cron_tables = array(); |
1398 } |
1469 } |
1399 |
1470 |
1400 if ( count( $other_tables ) > 0 ) { |
1471 if ( count( $other_tables ) > 0 ) { |
1401 echo '<div class="tables-list alternate" id="include-tables-list">'; |
1472 echo '<div class="tables-list alternate" id="include-tables-list">'; |
1402 echo '<h4>' . __( 'Tables to include in the scheduled backup:', 'wp-db-backup' ) . '</h4><ul>'; |
1473 echo '<div class="instructions-container">'; |
|
1474 echo '<h4>' . __( 'Tables to include in the scheduled backup:', 'wp-db-backup' ) . '</h4>'; |
|
1475 if ( count( $other_tables ) > 1 ) { |
|
1476 echo '<p>' . __( 'Hold <code class="shift-key">SHIFT</code> to toggle multiple checkboxes', 'wp-db-backup' ) . '</p>'; |
|
1477 } |
|
1478 echo '</div><ul>'; |
1403 foreach ( $other_tables as $table ) { |
1479 foreach ( $other_tables as $table ) { |
1404 echo '<li><input type="checkbox" '; |
1480 echo '<li><label><input type="checkbox" '; |
1405 if ( in_array( $table, $cron_tables ) ) { |
1481 if ( in_array( $table, $cron_tables ) ) { |
1406 echo 'checked="checked" '; |
1482 echo 'checked="checked" '; |
1407 } |
1483 } |
1408 echo "name='wp_cron_backup_tables[]' value='{$table}' /> <code>{$table}</code></li>"; |
1484 echo "name='wp_cron_backup_tables[]' value='{$table}' /> <code>{$table}</code></label></li>"; |
1409 } |
1485 } |
1410 echo '</ul></div>'; |
1486 echo '</ul></div>'; |
1411 } |
1487 echo '</div><!-- panel-content .row -->'; |
1412 |
1488 } |
|
1489 |
|
1490 echo '<p class="submit"><input type="submit" name="submit" value="' . __( 'Save schedule', 'wp-db-backup' ) . '" /></p>'; |
|
1491 |
1413 echo '<input type="hidden" name="wp_cron_backup_options" value="SET" /></form>'; |
1492 echo '<input type="hidden" name="wp_cron_backup_options" value="SET" /></form>'; |
|
1493 echo '</div><!-- .panel-content scheduled-backup -->'; |
1414 echo '</fieldset>'; |
1494 echo '</fieldset>'; |
1415 endif; // end of wp_cron (legacy) section |
1495 endif; // end of wp_cron (legacy) section |
1416 |
1496 |
|
1497 echo '</div><!-- .content-wrap -->'; |
1417 echo '</div><!-- .wrap -->'; |
1498 echo '</div><!-- .wrap -->'; |
1418 |
1499 |
1419 } // end wp_backup_menu() |
1500 } // end wp_backup_menu() |
1420 |
1501 |
1421 function get_sched() { |
1502 function get_sched() { |