| 1 |
<?php |
| 2 |
/** |
| 3 |
* Destination file. |
| 4 |
* |
| 5 |
* @package wpdbbkp |
| 6 |
*/ |
| 7 |
|
| 8 |
if ( ! defined( 'ABSPATH' ) ) { |
| 9 |
exit; // Exit if accessed directly. |
| 10 |
} |
| 11 |
|
| 12 |
/** |
| 13 |
* Error checking. |
| 14 |
* |
| 15 |
* @param string $trouble - Trouble response. |
| 16 |
*/ |
| 17 |
function backupbreeze_preflight_problem( $trouble ) { |
| 18 |
$error_log = $trouble; |
| 19 |
} |
| 20 |
|
| 21 |
// set up variables. |
| 22 |
$host = get_option( 'backupbreeze_ftp_host' ); |
| 23 |
$user = get_option( 'backupbreeze_ftp_user' ); |
| 24 |
$pass = get_option( 'backupbreeze_ftp_pass' ); |
| 25 |
$subdir = get_option( 'backupbreeze_ftp_subdir' ); |
| 26 |
if ( '' === $subdir ) { |
| 27 |
$subdir = '/'; |
| 28 |
} |
| 29 |
|
| 30 |
if ( $host ) { |
| 31 |
// If in WP Dashboard or Admin Panels. |
| 32 |
if ( is_admin() ) { |
| 33 |
// If user has WP manage options permissions. |
| 34 |
if ( current_user_can( 'manage_options' ) ) { |
| 35 |
// Connect to host ONLY if the 2 security conditions are valid / met. |
| 36 |
$conn = ftp_connect( $host ); |
| 37 |
if ( ! $conn ) { |
| 38 |
$trouble = 'I could not connect to your FTP server.<br />Please check your FTP Host settings and try again (leave FTP Host BLANK for local backups).'; |
| 39 |
backupbreeze_preflight_problem( $trouble ); |
| 40 |
} |
| 41 |
$result = ftp_login( $conn, $user, $pass ); |
| 42 |
if ( ! $result ) { |
| 43 |
$trouble = 'I could not log in to your FTP server.<br />Please check your FTP Username and Password, then try again.<br />For local backups, please leave the FTP Host option BLANK.'; |
| 44 |
backupbreeze_preflight_problem( $trouble ); |
| 45 |
} |
| 46 |
$success = ftp_chdir( $conn, $subdir ); |
| 47 |
if ( ! $success ) { |
| 48 |
$trouble = 'I cannot change into the FTP subdirectory you specified. Does it exist?<br />You must create it first using an FTP client like FileZilla.<br />Please check and try again.'; |
| 49 |
backupbreeze_preflight_problem( $trouble ); |
| 50 |
} |
| 51 |
} |
| 52 |
} |
| 53 |
} |
| 54 |
|