コード例 #1
0
/**
 * Check if a backup is possible with regards to file
 * permissions etc.
 *
 * @return bool
 */
function is_backup_possible()
{
    if (!wp_is_writable(Path::get_path()) || !is_dir(Path::get_path())) {
        return false;
    }
    if (!is_readable(Path::get_root())) {
        return false;
    }
    if (disk_space_low()) {
        return false;
    }
    if (!Requirement_Mysqldump_Command_Path::test() && !Requirement_PDO::test()) {
        return false;
    }
    if (!Requirement_Zip_Command_Path::test() && !Requirement_Zip_Archive::test()) {
        return false;
    }
    return true;
}
コード例 #2
0
function set_server_config_notices()
{
    $notices = Notices::get_instance();
    $messages = array();
    if (!is_dir(Path::get_path())) {
        $messages[] = sprintf(__('The backups directory can\'t be created because your %s directory isn\'t writable. Please create the folder manually.', 'backupwordpress'), '<code>' . esc_html(dirname(Path::get_path())) . '</code>');
    }
    if (is_dir(Path::get_path()) && !wp_is_writable(Path::get_path())) {
        $messages[] = __('The backups directory isn\'t writable. Please fix the permissions.', 'backupwordpress');
    }
    if (Backup_Utilities::is_safe_mode_on()) {
        $messages[] = sprintf(__('%1$s is running in %2$s, please contact your host and ask them to disable it. BackUpWordPress may not work correctly whilst %3$s is on.', 'backupwordpress'), '<code>PHP</code>', sprintf('<a href="%1$s">%2$s</a>', __('http://php.net/manual/en/features.safe-mode.php', 'backupwordpress'), __('Safe Mode', 'backupwordpress')), '<code>' . __('Safe Mode', 'backupwordpress') . '</code>');
    }
    if (defined('HMBKP_PATH') && HMBKP_PATH) {
        // Suppress open_basedir warning https://bugs.php.net/bug.php?id=53041
        if (!path_in_php_open_basedir(HMBKP_PATH)) {
            $messages[] = sprintf(__('Your server has an %1$s restriction in effect and your custom backups directory (%2$s) is not within the allowed path(s): (%3$s).', 'backupwordpress'), '<code>open_basedir</code>', '<code>' . esc_html(HMBKP_PATH) . '</code>', '<code>' . esc_html(@ini_get('open_basedir')) . '</code>');
        } elseif (!file_exists(HMBKP_PATH)) {
            $messages[] = sprintf(__('Your custom path does not exist', 'backupwordpress'));
        } else {
            if (!is_dir(HMBKP_PATH)) {
                $messages[] = sprintf(__('Your custom backups directory %1$s doesn\'t exist and can\'t be created, your backups will be saved to %2$s instead.', 'backupwordpress'), '<code>' . esc_html(HMBKP_PATH) . '</code>', '<code>' . esc_html(Path::get_path()) . '</code>');
            }
            if (is_dir(HMBKP_PATH) && !wp_is_writable(HMBKP_PATH)) {
                $messages[] = sprintf(__('Your custom backups directory %1$s isn\'t writable, new backups will be saved to %2$s instead.', 'backupwordpress'), '<code>' . esc_html(HMBKP_PATH) . '</code>', '<code>' . esc_html(Path::get_path()) . '</code>');
            }
        }
    }
    if (!is_readable(Path::get_root())) {
        $messages[] = sprintf(__('Your site root path %s isn\'t readable.', 'backupwordpress'), '<code>' . Path::get_root() . '</code>');
    }
    if (!Requirement_Mysqldump_Command_Path::test() && !Requirement_PDO::test()) {
        $messages[] = sprintf(__('Your site cannot be backed up because your server doesn\'t support %1$s or %2$s. Please contact your host and ask them to enable them.', 'backupwordpress'), '<code>mysqldump</code>', '<code>PDO::mysql</code>');
    }
    if (!Requirement_Zip_Command_Path::test() && !Requirement_Zip_Archive::test()) {
        $messages[] = sprintf(__('Your site cannot be backed up because your server doesn\'t support %1$s or %2$s. Please contact your host and ask them to enable them.', 'backupwordpress'), '<code>zip</code>', '<code>ZipArchive</code>');
    }
    if (disk_space_low()) {
        $messages[] = sprintf(__('Your server only has %s of disk space left which probably isn\'t enough to complete a backup. Try deleting some existing backups or other files to free up space.', 'backupwordpress'), '<code>' . size_format(disk_free_space(Path::get_path())) . '</code>');
    }
    if (count($messages) > 0) {
        $notices->set_notices('server_config', $messages, false);
    }
}